@@ -91,32 +91,40 @@ func (m *OCIManagedMachinePool) validateVersion(allErrs field.ErrorList) field.E
9191
9292func (m * OCIManagedMachinePool ) ValidateUpdate (old runtime.Object ) (admission.Warnings , error ) {
9393 var allErrs field.ErrorList
94+ var warnings admission.Warnings
95+
9496 oldManagedMachinePool , ok := old .(* OCIManagedMachinePool )
9597 if ! ok {
9698 return nil , apierrors .NewBadRequest (fmt .Sprintf ("expected an OCIManagedMachinePool but got a %T" , old ))
9799 }
98100
99101 allErrs = m .validateVersion (allErrs )
102+
100103 if ! reflect .DeepEqual (m .Spec .Version , oldManagedMachinePool .Spec .Version ) {
101104 newImage := m .getImageId ()
102105 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" ))
113106
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 )
114117 }
115118 }
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 )
118124 }
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
120128}
121129
122130func (m * OCIManagedMachinePool ) ValidateDelete () (admission.Warnings , error ) {
0 commit comments