diff --git a/api/v1alpha2/linodemachine_types.go b/api/v1alpha2/linodemachine_types.go index 703895692..b1a459e62 100644 --- a/api/v1alpha2/linodemachine_types.go +++ b/api/v1alpha2/linodemachine_types.go @@ -82,7 +82,6 @@ type LinodeMachineSpec struct { // image is the Linode image to use for the instance. // +optional - // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable" Image string `json:"image,omitempty"` // interfaces is a list of legacy network interfaces to use for the instance. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachines.yaml index 63531193e..f8ae9f811 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachines.yaml @@ -414,9 +414,6 @@ spec: image: description: image is the Linode image to use for the instance. type: string - x-kubernetes-validations: - - message: Value is immutable - rule: self == oldSelf instanceID: description: instanceID is the Linode instance ID for this machine. type: integer diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachinetemplates.yaml index f4a2ec8f2..5e7dbdbb2 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachinetemplates.yaml @@ -417,9 +417,6 @@ spec: image: description: image is the Linode image to use for the instance. type: string - x-kubernetes-validations: - - message: Value is immutable - rule: self == oldSelf instanceID: description: instanceID is the Linode instance ID for this machine. diff --git a/internal/webhook/v1alpha2/linodemachine_webhook.go b/internal/webhook/v1alpha2/linodemachine_webhook.go index f88cde878..d52a64632 100644 --- a/internal/webhook/v1alpha2/linodemachine_webhook.go +++ b/internal/webhook/v1alpha2/linodemachine_webhook.go @@ -88,6 +88,20 @@ func (r *linodeMachineValidator) ValidateUpdate(ctx context.Context, oldObj, new } linodemachinelog.Info("validate update", "name", old.Name) + newMachine, ok := newObj.(*infrav1alpha2.LinodeMachine) + if !ok { + return nil, apierrors.NewBadRequest("expected a LinodeMachine Resource") + } + + // ensure that spec.Image is immutable + if old.Spec.Image != newMachine.Spec.Image { + return nil, &field.Error{ + Field: "spec.image", + Type: field.ErrorTypeInvalid, + Detail: "Field is immutable", + } + } + // TODO(user): fill in your validation logic upon object update. return nil, nil }