diff --git a/pkg/webhooks/machine_webhook.go b/pkg/webhooks/machine_webhook.go index bd37cfa32..298a0ff80 100644 --- a/pkg/webhooks/machine_webhook.go +++ b/pkg/webhooks/machine_webhook.go @@ -1372,7 +1372,7 @@ func defaultGCPDisks(disks []*machinev1beta1.GCPDisk, clusterID string) []*machi disk.Type = defaultGCPDiskType } - if disk.Image == "" { + if disk.Boot && disk.Image == "" { disk.Image = defaultGCPDiskImage() } } diff --git a/pkg/webhooks/machine_webhook_test.go b/pkg/webhooks/machine_webhook_test.go index 0fc7bbec9..c68f7f72b 100644 --- a/pkg/webhooks/machine_webhook_test.go +++ b/pkg/webhooks/machine_webhook_test.go @@ -5095,7 +5095,7 @@ func TestDefaultGCPProviderSpec(t *testing.T) { Boot: false, SizeGB: 32, Type: defaultGCPDiskType, - Image: defaultGCPDiskImage(), + Image: "", }, } }, @@ -5124,6 +5124,39 @@ func TestDefaultGCPProviderSpec(t *testing.T) { expectedError: "", expectedWarnings: itWarnings, }, + { + testCase: "non-boot disk without image remains empty", + providerSpec: &machinev1beta1.GCPMachineProviderSpec{ + Disks: []*machinev1beta1.GCPDisk{ + { + Boot: true, + Image: "custom-boot-image", + }, + { + Boot: false, + SizeGB: 100, + }, + }, + }, + modifyDefault: func(p *machinev1beta1.GCPMachineProviderSpec) { + p.Disks = []*machinev1beta1.GCPDisk{ + { + Boot: true, + Image: "custom-boot-image", + Type: defaultGCPDiskType, + }, + { + Boot: false, + SizeGB: 100, + Type: defaultGCPDiskType, + Image: "", + }, + } + }, + expectedOk: true, + expectedError: "", + expectedWarnings: itWarnings, + }, } platformStatus := &osconfigv1.PlatformStatus{