Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove check for root volume device name on create #3798

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/v1beta2/awsmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (r *AWSMachine) validateRootVolume() field.ErrorList {
}

if r.Spec.RootVolume.DeviceName != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we log this info and not return error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Updated :)

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
Expand Down
6 changes: 4 additions & 2 deletions api/v1beta2/awsmachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta2/awsmachinetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions api/v1beta2/awsmachinetemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion exp/api/v1beta2/awsmachinepool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions exp/api/v1beta2/awsmachinepool_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down