From 761d8ab2206c75bcf5cedc25eee79e532b713942 Mon Sep 17 00:00:00 2001 From: rpotla Date: Thu, 9 Oct 2025 11:15:10 -0400 Subject: [PATCH 1/3] make image mutable in LMT --- api/v1alpha2/linodemachine_types.go | 1 - .../bases/infrastructure.cluster.x-k8s.io_linodemachines.yaml | 3 --- ...infrastructure.cluster.x-k8s.io_linodemachinetemplates.yaml | 3 --- 3 files changed, 7 deletions(-) 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. From ba15af6083b9b7406fdff32a4fd678174d4f4cba Mon Sep 17 00:00:00 2001 From: rpotla Date: Thu, 9 Oct 2025 11:40:38 -0400 Subject: [PATCH 2/3] ensure spec.image is immutable in linodeMachine --- internal/webhook/v1alpha2/linodemachine_webhook.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/webhook/v1alpha2/linodemachine_webhook.go b/internal/webhook/v1alpha2/linodemachine_webhook.go index f88cde878..7db832d1e 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) + new, ok := newObj.(*infrav1alpha2.LinodeMachine) + if !ok { + return nil, apierrors.NewBadRequest("expected a LinodeMachine Resource") + } + + // ensure that spec.Image is immutable + if old.Spec.Image != new.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 } From 2a318e4a2a6094cf91eae3ef626d9177d5601b97 Mon Sep 17 00:00:00 2001 From: rpotla Date: Thu, 9 Oct 2025 13:59:34 -0400 Subject: [PATCH 3/3] fix linter --- internal/webhook/v1alpha2/linodemachine_webhook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/webhook/v1alpha2/linodemachine_webhook.go b/internal/webhook/v1alpha2/linodemachine_webhook.go index 7db832d1e..d52a64632 100644 --- a/internal/webhook/v1alpha2/linodemachine_webhook.go +++ b/internal/webhook/v1alpha2/linodemachine_webhook.go @@ -88,13 +88,13 @@ func (r *linodeMachineValidator) ValidateUpdate(ctx context.Context, oldObj, new } linodemachinelog.Info("validate update", "name", old.Name) - new, ok := newObj.(*infrav1alpha2.LinodeMachine) + 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 != new.Spec.Image { + if old.Spec.Image != newMachine.Spec.Image { return nil, &field.Error{ Field: "spec.image", Type: field.ErrorTypeInvalid,