Skip to content

Commit 5663dd7

Browse files
Merge pull request #78 from PDOK/jd/ingressrouteurls-validation
More ingressRouteURLs validation
2 parents 35265f4 + 79c0dce commit 5663dd7

File tree

7 files changed

+41
-23
lines changed

7 files changed

+41
-23
lines changed

api/v3/shared_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type WMSWFS interface {
4848

4949
// URL returns the configured service URL
5050
URL() smoothoperatormodel.URL
51-
IngressRouteURLs() smoothoperatormodel.IngressRouteURLs
51+
IngressRouteURLs(includeServiceURLWhenEmpty bool) smoothoperatormodel.IngressRouteURLs
5252

5353
// DatasetMetadataIds returns list of all configured metadata identifiers configured on Layers or Featuretypes
5454
DatasetMetadataIDs() []string

api/v3/shared_validation.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

api/v3/wfs_types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,13 @@ func (wfs *WFS) ReadinessQueryString() (string, string, error) {
323323
return "SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&TYPENAMES=" + wfs.Spec.Service.FeatureTypes[0].Name + "&STARTINDEX=0&COUNT=1", "text/xml", nil
324324
}
325325

326-
func (wfs *WFS) IngressRouteURLs() smoothoperatormodel.IngressRouteURLs {
326+
func (wfs *WFS) IngressRouteURLs(includeServiceURLWhenEmpty bool) smoothoperatormodel.IngressRouteURLs {
327327
if len(wfs.Spec.IngressRouteURLs) == 0 {
328-
return smoothoperatormodel.IngressRouteURLs{{URL: wfs.Spec.Service.URL}}
328+
if includeServiceURLWhenEmpty {
329+
return smoothoperatormodel.IngressRouteURLs{{URL: wfs.Spec.Service.URL}}
330+
}
331+
332+
return smoothoperatormodel.IngressRouteURLs{}
329333
}
330334

331335
return wfs.Spec.IngressRouteURLs

api/v3/wms_types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,13 @@ func (wms *WMS) ReadinessQueryString() (string, string, error) {
690690
return fmt.Sprintf("SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=%s&CRS=EPSG:28992&WIDTH=100&HEIGHT=100&LAYERS=%s&STYLES=&FORMAT=image/png", wms.HealthCheckBBox(), firstDataLayerName), "image/png", nil
691691
}
692692

693-
func (wms *WMS) IngressRouteURLs() smoothoperatormodel.IngressRouteURLs {
693+
func (wms *WMS) IngressRouteURLs(includeServiceURLWhenEmpty bool) smoothoperatormodel.IngressRouteURLs {
694694
if len(wms.Spec.IngressRouteURLs) == 0 {
695-
return smoothoperatormodel.IngressRouteURLs{{URL: wms.Spec.Service.URL}}
695+
if includeServiceURLWhenEmpty {
696+
return smoothoperatormodel.IngressRouteURLs{{URL: wms.Spec.Service.URL}}
697+
}
698+
699+
return smoothoperatormodel.IngressRouteURLs{}
696700
}
697701

698702
return wms.Spec.IngressRouteURLs

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/pdok/featureinfo-generator v1.4.0-beta1
1414
github.com/pdok/ogc-capabilities-generator v1.0.0-beta8
1515
github.com/pdok/ogc-specifications v1.0.0-beta9
16-
github.com/pdok/smooth-operator v0.1.2
16+
github.com/pdok/smooth-operator v0.1.3
1717
github.com/peterbourgon/ff v1.7.1
1818
github.com/stretchr/testify v1.10.0
1919
github.com/traefik/traefik/v3 v3.3.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ github.com/pdok/ogc-capabilities-generator v1.0.0-beta8 h1:8UAv64fArp8wjpwuRIzjj
155155
github.com/pdok/ogc-capabilities-generator v1.0.0-beta8/go.mod h1:2yUZlJikf5gGH6S33FszUiI9+j85gpIINfAFsCF/eNk=
156156
github.com/pdok/ogc-specifications v1.0.0-beta9 h1:VrdggKg4d2tSway/deztAfZTviXKX0AftfUuZTXx5j8=
157157
github.com/pdok/ogc-specifications v1.0.0-beta9/go.mod h1:YDngwkwrWOfc5MYnEYseiv97K1Y9bZXlVzwi/8EaIl8=
158-
github.com/pdok/smooth-operator v0.1.2 h1:ibGRgFjKysu665IUToQhs34hHhptftI+7RBFrGNw4nQ=
159-
github.com/pdok/smooth-operator v0.1.2/go.mod h1:przwM7mBGmNPqabyhImKVZ15WL4zbqLqH4ExbuWKhWE=
158+
github.com/pdok/smooth-operator v0.1.3 h1:Y+JvbFLlyb6pMNFVgAd8G6QsXL0Y6F0srTaROabRnm0=
159+
github.com/pdok/smooth-operator v0.1.3/go.mod h1:przwM7mBGmNPqabyhImKVZ15WL4zbqLqH4ExbuWKhWE=
160160
github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
161161
github.com/peterbourgon/ff v1.7.1 h1:xt1lxTG+Nr2+tFtysY7abFgPoH3Lug8CwYJMOmJRXhk=
162162
github.com/peterbourgon/ff v1.7.1/go.mod h1:fYI5YA+3RDqQRExmFbHnBjEeWzh9TrS8rnRpEq7XIg0=

internal/controller/ingressroute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func mutateIngressRoute[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, ingressRout
9898

9999
ingressRoute.Spec.Routes = []traefikiov1alpha1.Route{}
100100
if obj.Type() == pdoknlv3.ServiceTypeWMS {
101-
for _, ingressRouteURL := range obj.IngressRouteURLs() {
101+
for _, ingressRouteURL := range obj.IngressRouteURLs(true) {
102102
ingressRoute.Spec.Routes = append(ingressRoute.Spec.Routes, makeRoute(getLegendMatchRule(ingressRouteURL.URL), mapserverService, middlewareRef))
103103

104104
if obj.Options().UseWebserviceProxy() {
@@ -108,7 +108,7 @@ func mutateIngressRoute[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, ingressRout
108108
}
109109
}
110110
} else { // WFS
111-
for _, ingressRouteURL := range obj.IngressRouteURLs() {
111+
for _, ingressRouteURL := range obj.IngressRouteURLs(true) {
112112
ingressRoute.Spec.Routes = append(ingressRoute.Spec.Routes, makeRoute(getMatchRule(ingressRouteURL.URL), mapserverService, middlewareRef))
113113
}
114114
}

0 commit comments

Comments
 (0)