@@ -91,32 +91,40 @@ func (m *OCIManagedMachinePool) validateVersion(allErrs field.ErrorList) field.E
91
91
92
92
func (m * OCIManagedMachinePool ) ValidateUpdate (old runtime.Object ) (admission.Warnings , error ) {
93
93
var allErrs field.ErrorList
94
+ var warnings admission.Warnings
95
+
94
96
oldManagedMachinePool , ok := old .(* OCIManagedMachinePool )
95
97
if ! ok {
96
98
return nil , apierrors .NewBadRequest (fmt .Sprintf ("expected an OCIManagedMachinePool but got a %T" , old ))
97
99
}
98
100
99
101
allErrs = m .validateVersion (allErrs )
102
+
100
103
if ! reflect .DeepEqual (m .Spec .Version , oldManagedMachinePool .Spec .Version ) {
101
104
newImage := m .getImageId ()
102
105
oldImage := oldManagedMachinePool .getImageId ()
103
- // if an image has been provided in updated machine pool and it matches old image id,
104
- // and if Kubernetes version has been updated, that means the image is not correct. If the version has
105
- // been changed, the image should have been updated by the user, or set as nil in which case
106
- // CAPOCI will lookup a correct image
107
- if newImage != nil && reflect .DeepEqual (newImage , oldImage ) {
108
- allErrs = append (
109
- allErrs ,
110
- field .Invalid (field .NewPath ("spec" , "nodeSourceViaImage" , "imageId" ),
111
- m .getImageId (), "image id has not been updated for the newer version, " +
112
- "either provide a newer image or set the field as nil" ))
113
106
107
+ if newImage != nil && reflect .DeepEqual (newImage , oldImage ) {
108
+ // if an image has been provided in updated machine pool and it matches old image id,
109
+ // and if Kubernetes version has been updated, that means that it might be a custom image.
110
+ // This allows the use of custom images that support multiple Kubernetes versions. If the image is not a custom image
111
+ // then the image should have been updated by the user, or set as nil in which case
112
+ // CAPOCI will lookup a correct image.
113
+ warnMsg := fmt .Sprintf ("Kubernetes version was updated from %q to %q without changing the imageId. " +
114
+ "If you are not using a custom multi-version image, this may cause nodepool creation to fail." ,
115
+ * oldManagedMachinePool .Spec .Version , * m .Spec .Version )
116
+ warnings = append (warnings , warnMsg )
114
117
}
115
118
}
116
- if len (allErrs ) == 0 {
117
- return nil , nil
119
+
120
+ // If there are any hard errors (like an invalid version format), return them.
121
+ // Also return the list of accumulated warnings.
122
+ if len (allErrs ) > 0 {
123
+ return warnings , apierrors .NewInvalid (m .GroupVersionKind ().GroupKind (), m .Name , allErrs )
118
124
}
119
- return nil , apierrors .NewInvalid (m .GroupVersionKind ().GroupKind (), m .Name , allErrs )
125
+
126
+ // If there are no errors, return the warnings.
127
+ return warnings , nil
120
128
}
121
129
122
130
func (m * OCIManagedMachinePool ) ValidateDelete () (admission.Warnings , error ) {
0 commit comments