Skip to content

Commit

Permalink
add accessor
Browse files Browse the repository at this point in the history
Signed-off-by: f10atin9 <[email protected]>
  • Loading branch information
f10atin9 committed Apr 6, 2022
1 parent 52c13ae commit f92026c
Show file tree
Hide file tree
Showing 17 changed files with 1,310 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/controller-manager/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func run(s *options.KubeSphereControllerManagerOptions, ctx context.Context) err
hookServer.Register("/validate-email-iam-kubesphere-io-v1alpha2", &webhook.Admission{Handler: &user.EmailValidator{Client: mgr.GetClient()}})
hookServer.Register("/validate-network-kubesphere-io-v1alpha1", &webhook.Admission{Handler: &webhooks.ValidatingHandler{C: mgr.GetClient()}})
hookServer.Register("/mutate-network-kubesphere-io-v1alpha1", &webhook.Admission{Handler: &webhooks.MutatingHandler{C: mgr.GetClient()}})
hookServer.Register("/persistentvolumeclaims", &webhook.Admission{Handler: &webhooks.AccessorHandler{C: mgr.GetClient()}})

resourceQuotaAdmission, err := quota.NewResourceQuotaAdmission(mgr.GetClient(), mgr.GetScheme())
if err != nil {
Expand Down
34 changes: 34 additions & 0 deletions config/ks-core/templates/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,37 @@ webhooks:
- pods
scope: '*'
sideEffects: None

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: storageclass-accessor.storage.kubesphere.io
webhooks:
- admissionReviewVersions:
- v1beta1
clientConfig:
caBundle: {{ b64enc $ca.Cert | quote }}
service:
name: ks-controller-manager
namespace: {{ .Release.Namespace }}
path: /persistentvolumeclaims
port: 443
failurePolicy: Ignore
matchPolicy: Exact
name: storageclass-accessor.storage.kubesphere.io
namespaceSelector: {}
objectSelector: {}
rules:
- apiGroups:
- '*'
apiVersions:
- '*'
operations:
- CREATE
- UPDATE
- DELETE
resources:
- persistentvolumeclaims
scope: '*'
sideEffects: None
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ require (
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
github.com/kubesphere/pvc-autoresizer v0.1.1
github.com/kubesphere/sonargo v0.0.2
github.com/kubesphere/storageclass-accessor v0.2.0
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect
Expand Down Expand Up @@ -107,16 +108,16 @@ require (
istio.io/api v0.0.0-20201113182140-d4b7e3fc2b44
istio.io/client-go v0.0.0-20201113183938-0734e976e785
istio.io/gogo-genproto v0.0.0-20201113182723-5b8563d8a012 // indirect
k8s.io/api v0.21.4
k8s.io/api v0.22.1
k8s.io/apiextensions-apiserver v0.21.4
k8s.io/apimachinery v0.21.4
k8s.io/apimachinery v0.22.1
k8s.io/apiserver v0.21.2
k8s.io/cli-runtime v0.21.2
k8s.io/client-go v12.0.0+incompatible
k8s.io/code-generator v0.21.2
k8s.io/component-base v0.21.4
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.8.0
k8s.io/klog/v2 v2.9.0
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e
k8s.io/kubectl v0.21.2
k8s.io/metrics v0.21.2
Expand All @@ -126,7 +127,7 @@ require (
kubesphere.io/monitoring-dashboard v0.2.2
rsc.io/letsencrypt v0.0.1 // indirect
sigs.k8s.io/application v0.8.4-0.20201016185654-c8e2959e57a0
sigs.k8s.io/controller-runtime v0.9.8-0.20211019125639-aa2b3e68a52d
sigs.k8s.io/controller-runtime v0.10.0
sigs.k8s.io/controller-tools v0.6.2
sigs.k8s.io/kubefed v0.8.1
sigs.k8s.io/kustomize/api v0.8.8
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ github.com/kubesphere/pvc-autoresizer v0.1.1 h1:Q0VrvLfTiE1f38EvmFpJdBevwN21X7Br
github.com/kubesphere/pvc-autoresizer v0.1.1/go.mod h1:88qz9L1Ov2bvw7L/i5mUT8g5DvBwRCZ60JA2d1WLgB0=
github.com/kubesphere/sonargo v0.0.2 h1:hsSRE3sv3mkPcUAeSABdp7rtfcNW2zzeHXzFa01CTkU=
github.com/kubesphere/sonargo v0.0.2/go.mod h1:ww8n9ANlDXhX5PBZ18iaRnCgEkXN0GMml3/KZXOZ11w=
github.com/kubesphere/storageclass-accessor v0.2.0 h1:rnzKafhneo8160dh6REm3z1yAEaQWz1x/Lwi3QFVLWE=
github.com/kubesphere/storageclass-accessor v0.2.0/go.mod h1:jqZ3tCiw09yOiPkZ3rDmf6QIpbZJx55McnyRaS0ayCY=
github.com/kylelemons/go-gypsy v0.0.0-20160905020020-08cad365cd28/go.mod h1:T/T7jsxVqf9k/zYOqbgNAsANsjxTd1Yq3htjDhQ1H0c=
github.com/kylelemons/godebug v0.0.0-20160406211939-eadb3ce320cb/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
Expand Down
30 changes: 30 additions & 0 deletions pkg/controller/network/webhooks/storageclass_accessor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package webhooks

import (
"context"

accessor "github.com/kubesphere/storageclass-accessor/webhook"
v1 "k8s.io/api/admission/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

type AccessorHandler struct {
C client.Client
decoder *admission.Decoder
}

func (h *AccessorHandler) InjectDecoder(d *admission.Decoder) error {
h.decoder = d
return nil
}

func (h *AccessorHandler) Handle(ctx context.Context, req admission.Request) admission.Response {
review := v1.AdmissionReview{
Request: &req.AdmissionRequest,
}
resp := accessor.AdmitPVC(review)
return admission.Response{
AdmissionResponse: *resp,
}
}
201 changes: 201 additions & 0 deletions vendor/github.com/kubesphere/storageclass-accessor/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f92026c

Please sign in to comment.