Skip to content

Commit

Permalink
fix(vi): add warning for create virtual image with storage type 'Kube… (
Browse files Browse the repository at this point in the history
#619)

fix(vi): add warning for create virtual image with storage type 'Kubernetes'

Signed-off-by: dmitry.lopatin <[email protected]>
  • Loading branch information
LopatinDmitr authored Jan 14, 2025
1 parent b185f6e commit e7db733
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
15 changes: 13 additions & 2 deletions images/virtualization-artifact/pkg/controller/vi/vi_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
19 changes: 18 additions & 1 deletion templates/virtualization-controller/validation-webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e7db733

Please sign in to comment.