diff --git a/Dockerfile b/Dockerfile index 97a94cd..ec65092 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM golang:1.22 as builder WORKDIR /workspace ADD . /workspace/ -RUN make -f webhook.mk build-local +RUN make -f build.mk build-local # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/webhook.mk b/build.mk similarity index 100% rename from webhook.mk rename to build.mk diff --git a/config/crd/bases/storage.kubesphere.io_initializers.yaml b/config/crd/bases/storage.kubesphere.io_initializers.yaml index 3621e2b..cc8d4a1 100644 --- a/config/crd/bases/storage.kubesphere.io_initializers.yaml +++ b/config/crd/bases/storage.kubesphere.io_initializers.yaml @@ -1549,6 +1549,142 @@ spec: type: object type: array type: object + pod: + description: Pod matches the pod which mounts the pvc + properties: + fieldSelector: + description: FieldSelector is the field selector, which + only supports "name" and "namespace" as key, and "In" + and "NotIn" as operator. + items: + description: |- + FieldSelectorRequirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the field selector key that the + requirement applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. + The list of operators may grow in the future. + type: string + values: + description: |- + values is an array of string values. + If the operator is In or NotIn, the values array must be non-empty. + If the operator is Exists or DoesNotExist, the values array must be empty. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + labelSelector: + description: LabelSelector is the label selector + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that the selector + applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + type: object + pvc: + description: PVC matches the PVC itself + properties: + fieldSelector: + description: FieldSelector is the field selector, which + only supports "name" and "namespace" as key, and "In" + and "NotIn" as operator. + items: + description: |- + FieldSelectorRequirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the field selector key that the + requirement applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. + The list of operators may grow in the future. + type: string + values: + description: |- + values is an array of string values. + If the operator is In or NotIn, the values array must be non-empty. + If the operator is Exists or DoesNotExist, the values array must be empty. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + labelSelector: + description: LabelSelector is the label selector + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that the selector + applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + type: object storageClass: description: StorageClass matches the PVC's storage class properties: diff --git a/config/samples/storage.kubesphere.io_v1alpha1_initializer.yaml b/config/samples/storage.kubesphere.io_v1alpha1_initializer.yaml index a4bc8bc..43f7574 100644 --- a/config/samples/storage.kubesphere.io_v1alpha1_initializer.yaml +++ b/config/samples/storage.kubesphere.io_v1alpha1_initializer.yaml @@ -42,6 +42,19 @@ spec: imagePullPolicy: IfNotPresent pvcMatchers: - name: local-1 + pvc: + fieldSelector: + - key: name + operator: In + values: + - ttt-mongodb-test-0 + - mongodb-mongodb-test-0 + pod: + labelSelector: + - key: app + operator: In + values: + - mongodb-test storageClass: fieldSelector: - key: name diff --git a/pkg/apis/storage/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/storage/v1alpha1/zz_generated.deepcopy.go index 0187358..33a546d 100644 --- a/pkg/apis/storage/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/storage/v1alpha1/zz_generated.deepcopy.go @@ -181,6 +181,16 @@ func (in *PVCInitializer) DeepCopy() *PVCInitializer { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PVCMatcher) DeepCopyInto(out *PVCMatcher) { *out = *in + if in.PVC != nil { + in, out := &in.PVC, &out.PVC + *out = new(GenericSelector) + (*in).DeepCopyInto(*out) + } + if in.Pod != nil { + in, out := &in.Pod, &out.Pod + *out = new(GenericSelector) + (*in).DeepCopyInto(*out) + } if in.StorageClass != nil { in, out := &in.StorageClass, &out.StorageClass *out = new(GenericSelector)