@@ -28,6 +28,8 @@ import (
28
28
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
29
29
30
30
"sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
31
+ infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
32
+ "sigs.k8s.io/cluster-api-provider-aws/v2/feature"
31
33
)
32
34
33
35
var log = ctrl .Log .WithName ("awsmachinepool-resource" )
@@ -62,12 +64,12 @@ func (r *AWSMachinePool) validateRootVolume() field.ErrorList {
62
64
return allErrs
63
65
}
64
66
65
- if v1beta2 .VolumeTypesProvisioned .Has (string (r .Spec .AWSLaunchTemplate .RootVolume .Type )) && r .Spec .AWSLaunchTemplate .RootVolume .IOPS == 0 {
67
+ if infrav1 .VolumeTypesProvisioned .Has (string (r .Spec .AWSLaunchTemplate .RootVolume .Type )) && r .Spec .AWSLaunchTemplate .RootVolume .IOPS == 0 {
66
68
allErrs = append (allErrs , field .Required (field .NewPath ("spec.awsLaunchTemplate.rootVolume.iops" ), "iops required if type is 'io1' or 'io2'" ))
67
69
}
68
70
69
71
if r .Spec .AWSLaunchTemplate .RootVolume .Throughput != nil {
70
- if r .Spec .AWSLaunchTemplate .RootVolume .Type != v1beta2 .VolumeTypeGP3 {
72
+ if r .Spec .AWSLaunchTemplate .RootVolume .Type != infrav1 .VolumeTypeGP3 {
71
73
allErrs = append (allErrs , field .Required (field .NewPath ("spec.awsLaunchTemplate.rootVolume.throughput" ), "throughput is valid only for type 'gp3'" ))
72
74
}
73
75
if * r .Spec .AWSLaunchTemplate .RootVolume .Throughput < 0 {
@@ -86,12 +88,12 @@ func (r *AWSMachinePool) validateNonRootVolumes() field.ErrorList {
86
88
var allErrs field.ErrorList
87
89
88
90
for _ , volume := range r .Spec .AWSLaunchTemplate .NonRootVolumes {
89
- if v1beta2 .VolumeTypesProvisioned .Has (string (volume .Type )) && volume .IOPS == 0 {
91
+ if infrav1 .VolumeTypesProvisioned .Has (string (volume .Type )) && volume .IOPS == 0 {
90
92
allErrs = append (allErrs , field .Required (field .NewPath ("spec.template.spec.nonRootVolumes.iops" ), "iops required if type is 'io1' or 'io2'" ))
91
93
}
92
94
93
95
if volume .Throughput != nil {
94
- if volume .Type != v1beta2 .VolumeTypeGP3 {
96
+ if volume .Type != infrav1 .VolumeTypeGP3 {
95
97
allErrs = append (allErrs , field .Required (field .NewPath ("spec.template.spec.nonRootVolumes.throughput" ), "throughput is valid only for type 'gp3'" ))
96
98
}
97
99
if * volume .Throughput < 0 {
@@ -162,6 +164,22 @@ func (r *AWSMachinePool) validateRefreshPreferences() field.ErrorList {
162
164
return allErrs
163
165
}
164
166
167
+ func (r * AWSMachinePool ) ignitionEnabled () bool {
168
+ return r .Spec .Ignition != nil
169
+ }
170
+
171
+ func (r * AWSMachinePool ) validateIgnition () field.ErrorList {
172
+ var allErrs field.ErrorList
173
+
174
+ // Feature gate is not enabled but ignition is enabled then send a forbidden error.
175
+ if ! feature .Gates .Enabled (feature .BootstrapFormatIgnition ) && r .ignitionEnabled () {
176
+ allErrs = append (allErrs , field .Forbidden (field .NewPath ("spec" , "ignition" ),
177
+ "can be set only if the BootstrapFormatIgnition feature gate is enabled" ))
178
+ }
179
+
180
+ return allErrs
181
+ }
182
+
165
183
// ValidateCreate will do any extra validation when creating a AWSMachinePool.
166
184
func (r * AWSMachinePool ) ValidateCreate () (admission.Warnings , error ) {
167
185
log .Info ("AWSMachinePool validate create" , "machine-pool" , klog .KObj (r ))
@@ -177,6 +195,7 @@ func (r *AWSMachinePool) ValidateCreate() (admission.Warnings, error) {
177
195
allErrs = append (allErrs , r .validateSpotInstances ()... )
178
196
allErrs = append (allErrs , r .validateRefreshPreferences ()... )
179
197
allErrs = append (allErrs , r .validateInstanceMarketType ()... )
198
+ allErrs = append (allErrs , r .validateIgnition ()... )
180
199
181
200
if len (allErrs ) == 0 {
182
201
return nil , nil
@@ -243,4 +262,11 @@ func (r *AWSMachinePool) Default() {
243
262
log .Info ("DefaultInstanceWarmup is zero, setting 300 seconds as default" )
244
263
r .Spec .DefaultInstanceWarmup .Duration = 300 * time .Second
245
264
}
265
+
266
+ if r .ignitionEnabled () && r .Spec .Ignition .Version == "" {
267
+ r .Spec .Ignition .Version = infrav1 .DefaultIgnitionVersion
268
+ }
269
+ if r .ignitionEnabled () && r .Spec .Ignition .StorageType == "" {
270
+ r .Spec .Ignition .StorageType = infrav1 .DefaultMachinePoolIgnitionStorageType
271
+ }
246
272
}
0 commit comments