diff --git a/images/virtualization-artifact/pkg/controller/vi/vi_webhook.go b/images/virtualization-artifact/pkg/controller/vi/vi_webhook.go index 719f0c3ec..322586e91 100644 --- a/images/virtualization-artifact/pkg/controller/vi/vi_webhook.go +++ b/images/virtualization-artifact/pkg/controller/vi/vi_webhook.go @@ -42,8 +42,19 @@ func NewValidator(logger *log.Logger) *Validator { } func (v *Validator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { - err := fmt.Errorf("misconfigured webhook rules: create operation not implemented") - v.logger.Error("Ensure the correctness of ValidatingWebhookConfiguration", "err", err) + vi, ok := obj.(*virtv2.VirtualImage) + if !ok { + return nil, fmt.Errorf("expected a new VirtualMachine but got a %T", obj) + } + + if vi.Spec.Storage == virtv2.StorageKubernetes { + warnings := admission.Warnings{ + fmt.Sprintf("Using the `%s` storage type is deprecated. It is recommended to use `%s` instead.", + virtv2.StorageKubernetes, virtv2.StoragePersistentVolumeClaim), + } + return warnings, nil + } + return nil, nil } diff --git a/templates/virtualization-controller/validation-webhook.yaml b/templates/virtualization-controller/validation-webhook.yaml index 4a92aa840..64d8f8420 100644 --- a/templates/virtualization-controller/validation-webhook.yaml +++ b/templates/virtualization-controller/validation-webhook.yaml @@ -37,11 +37,28 @@ webhooks: {{ .Values.virtualization.internal.controller.cert.ca }} admissionReviewVersions: ["v1"] sideEffects: None + - name: "vi.virtualization-controller.validate.d8-virtualization" + rules: + - apiGroups: [ "virtualization.deckhouse.io" ] + apiVersions: [ "v1alpha2" ] + operations: [ "CREATE", "UPDATE" ] + resources: [ "virtualimages" ] + scope: "Namespaced" + clientConfig: + service: + namespace: d8-{{ .Chart.Name }} + name: virtualization-controller + path: /validate-virtualization-deckhouse-io-v1alpha2-virtualimage + port: 443 + caBundle: | + {{ .Values.virtualization.internal.controller.cert.ca }} + admissionReviewVersions: [ "v1" ] + sideEffects: None - name: "cvi.virtualization-controller.validate.d8-virtualization" rules: - apiGroups: [ "virtualization.deckhouse.io" ] apiVersions: [ "v1alpha2" ] - operations: [ "UPDATE" ] + operations: [ "CREATE", "UPDATE" ] resources: [ "clustervirtualimages" ] scope: "Cluster" clientConfig: