From 318e1a54ef95147800397523cdeeb036a27a0535 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Thu, 27 Oct 2022 08:13:30 +0100 Subject: [PATCH] fix: remove check for root volume device name on create Signed-off-by: Marcus Noble --- api/v1beta2/awsmachine_webhook.go | 2 +- api/v1beta2/awsmachine_webhook_test.go | 6 ++++-- api/v1beta2/awsmachinetemplate_webhook.go | 2 +- .../awsmachinetemplate_webhook_test.go | 20 +++++++++++++++++++ exp/api/v1beta2/awsmachinepool_webhook.go | 2 +- .../v1beta2/awsmachinepool_webhook_test.go | 15 ++++++++++++++ 6 files changed, 42 insertions(+), 5 deletions(-) diff --git a/api/v1beta2/awsmachine_webhook.go b/api/v1beta2/awsmachine_webhook.go index 7575548f5b..5d22ecac99 100644 --- a/api/v1beta2/awsmachine_webhook.go +++ b/api/v1beta2/awsmachine_webhook.go @@ -193,7 +193,7 @@ func (r *AWSMachine) validateRootVolume() field.ErrorList { } if r.Spec.RootVolume.DeviceName != "" { - allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.rootVolume.deviceName"), "root volume shouldn't have device name")) + log.Info("root volume shouldn't have a device name (this can be ignored if performing a `clusterctl move`)") } return allErrs diff --git a/api/v1beta2/awsmachine_webhook_test.go b/api/v1beta2/awsmachine_webhook_test.go index 913c5bb2c0..2b52c8ee5a 100644 --- a/api/v1beta2/awsmachine_webhook_test.go +++ b/api/v1beta2/awsmachine_webhook_test.go @@ -80,16 +80,18 @@ func TestAWSMachine_Create(t *testing.T) { wantErr: true, }, { - name: "ensure root volume has no device name", + name: "ensure root volume with device name works (for clusterctl move)", machine: &AWSMachine{ Spec: AWSMachineSpec{ RootVolume: &Volume{ DeviceName: "name", + Type: "gp2", + Size: *aws.Int64(8), }, InstanceType: "test", }, }, - wantErr: true, + wantErr: false, }, { name: "ensure non root volume have device names", diff --git a/api/v1beta2/awsmachinetemplate_webhook.go b/api/v1beta2/awsmachinetemplate_webhook.go index 806eb4a379..6fed6a336b 100644 --- a/api/v1beta2/awsmachinetemplate_webhook.go +++ b/api/v1beta2/awsmachinetemplate_webhook.go @@ -68,7 +68,7 @@ func (r *AWSMachineTemplate) validateRootVolume() field.ErrorList { } if spec.RootVolume.DeviceName != "" { - allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.template.spec.rootVolume.deviceName"), "root volume shouldn't have device name")) + log.Info("root volume shouldn't have a device name (this can be ignored if performing a `clusterctl move`)") } return allErrs diff --git a/api/v1beta2/awsmachinetemplate_webhook_test.go b/api/v1beta2/awsmachinetemplate_webhook_test.go index 8755d22461..427c757f13 100644 --- a/api/v1beta2/awsmachinetemplate_webhook_test.go +++ b/api/v1beta2/awsmachinetemplate_webhook_test.go @@ -20,6 +20,7 @@ import ( "context" "testing" + "github.com/aws/aws-sdk-go/aws" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/pointer" ) @@ -60,6 +61,25 @@ func TestAWSMachineTemplateValidateCreate(t *testing.T) { }, wantError: true, }, + { + name: "ensure RootVolume DeviceName can be set for use with clusterctl move", + inputTemplate: &AWSMachineTemplate{ + ObjectMeta: metav1.ObjectMeta{}, + Spec: AWSMachineTemplateSpec{ + Template: AWSMachineTemplateResource{ + Spec: AWSMachineSpec{ + RootVolume: &Volume{ + DeviceName: "name", + Type: "gp2", + Size: *aws.Int64(8), + }, + InstanceType: "test", + }, + }, + }, + }, + wantError: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/exp/api/v1beta2/awsmachinepool_webhook.go b/exp/api/v1beta2/awsmachinepool_webhook.go index f35fb68249..762603b00b 100644 --- a/exp/api/v1beta2/awsmachinepool_webhook.go +++ b/exp/api/v1beta2/awsmachinepool_webhook.go @@ -75,7 +75,7 @@ func (r *AWSMachinePool) validateRootVolume() field.ErrorList { } if r.Spec.AWSLaunchTemplate.RootVolume.DeviceName != "" { - allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.awsLaunchTemplate.rootVolume.deviceName"), "root volume shouldn't have device name")) + log.Info("root volume shouldn't have a device name (this can be ignored if performing a `clusterctl move`)") } return allErrs diff --git a/exp/api/v1beta2/awsmachinepool_webhook_test.go b/exp/api/v1beta2/awsmachinepool_webhook_test.go index 5e14762065..9c04493ca9 100644 --- a/exp/api/v1beta2/awsmachinepool_webhook_test.go +++ b/exp/api/v1beta2/awsmachinepool_webhook_test.go @@ -124,6 +124,21 @@ func TestAWSMachinePool_ValidateCreate(t *testing.T) { }, wantErr: false, }, + { + name: "Ensure root volume with device name works (for clusterctl move)", + pool: &AWSMachinePool{ + Spec: AWSMachinePoolSpec{ + AWSLaunchTemplate: AWSLaunchTemplate{ + RootVolume: &infrav1.Volume{ + DeviceName: "name", + Type: "gp2", + Size: *aws.Int64(8), + }, + }, + }, + }, + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {