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