@@ -15,23 +15,33 @@ func ValidateUpdate[W WMSWFS](newW, oldW W, validate func(W, *[]string, *field.E
1515 warnings := []string {}
1616 allErrs := field.ErrorList {}
1717
18- // Check that the ingressRouteUrls contain the base url and no urls have been removed
19- err := sharedValidation .ValidateIngressRouteURLsContainsBaseURL (newW .IngressRouteURLs (), newW .URL (), nil )
20- if err != nil {
21- allErrs = append (allErrs , err )
18+ // Make sure no ingressRouteURLs have been removed
19+ sharedValidation .ValidateIngressRouteURLsNotRemoved (oldW .IngressRouteURLs (true ), newW .IngressRouteURLs (true ), & allErrs , nil )
20+
21+ if len (newW .IngressRouteURLs (false )) == 0 {
22+ // There are no ingressRouteURLs given, spec.service.url is immutable is that case.
23+ path := field .NewPath ("spec" ).Child ("service" ).Child ("url" )
24+ sharedValidation .CheckURLImmutability (
25+ oldW .URL (),
26+ newW .URL (),
27+ & allErrs ,
28+ path ,
29+ )
30+ } else if oldW .URL ().String () != newW .URL ().String () {
31+ // Make sure both the old spec.service.url and the new one are included in the ingressRouteURLs list.
32+ err := sharedValidation .ValidateIngressRouteURLsContainsBaseURL (newW .IngressRouteURLs (true ), oldW .URL (), nil )
33+ if err != nil {
34+ allErrs = append (allErrs , err )
35+ }
36+
37+ err = sharedValidation .ValidateIngressRouteURLsContainsBaseURL (newW .IngressRouteURLs (true ), newW .URL (), nil )
38+ if err != nil {
39+ allErrs = append (allErrs , err )
40+ }
2241 }
23- sharedValidation .ValidateIngressRouteURLsNotRemoved (oldW .IngressRouteURLs (), newW .IngressRouteURLs (), & allErrs , nil )
2442
2543 sharedValidation .ValidateLabelsOnUpdate (oldW .GetLabels (), newW .GetLabels (), & allErrs )
2644
27- path := field .NewPath ("spec" ).Child ("service" ).Child ("url" )
28- sharedValidation .CheckUrlImmutability (
29- oldW .URL (),
30- newW .URL (),
31- & allErrs ,
32- path ,
33- )
34-
3545 if (newW .Inspire () == nil && oldW .Inspire () != nil ) || (newW .Inspire () != nil && oldW .Inspire () == nil ) {
3646 allErrs = append (allErrs , field .Forbidden (field .NewPath ("spec" ).Child ("service" ).Child ("inspire" ), "cannot change from inspire to not inspire or the other way around" ))
3747 }
0 commit comments