Skip to content

Commit 97f2781

Browse files
Merge pull request #5 from PDOK/jd/wfs-admission
WFS validation
2 parents c1f950e + 6f3bc2f commit 97f2781

File tree

17 files changed

+497
-658
lines changed

17 files changed

+497
-658
lines changed

PROJECT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ resources:
3333
conversion: true
3434
spoke:
3535
- v2beta1
36+
validation: true
3637
webhookVersion: v1
3738
- api:
3839
crdVersion: v1

api/v3/wfs_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ type WFSService struct {
8686
Title string `json:"title"`
8787
Abstract string `json:"abstract"`
8888
Keywords []string `json:"keywords"`
89-
Fees *string `json:"fees"`
89+
Fees *string `json:"fees,omitempty"`
9090
AccessConstraints string `json:"accessConstraints"`
9191
DefaultCrs string `json:"defaultCrs"`
9292
OtherCrs []string `json:"otherCrs,omitempty"`
93-
Bbox *Bbox `json:"bbox"`
93+
Bbox *Bbox `json:"bbox,omitempty"`
9494
// CountDefault -> wfs_maxfeatures in mapfile
95-
CountDefault *string `json:"countDefault"`
95+
CountDefault *string `json:"countDefault,omitempty"`
9696
FeatureTypes []FeatureType `json:"featureTypes"`
9797
}
9898

api/v3/wfs_validation.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package v3
2+
3+
import (
4+
"fmt"
5+
sharedValidation "github.com/pdok/smooth-operator/pkg/validation"
6+
"strings"
7+
)
8+
9+
func (wfs *WFS) ValidateCreate() ([]string, error) {
10+
warnings := []string{}
11+
reasons := []string{}
12+
13+
err := sharedValidation.ValidateLabelsOnCreate(wfs.Labels)
14+
if err != nil {
15+
reasons = append(reasons, fmt.Sprintf("%v", err))
16+
}
17+
18+
validateWFS(wfs, &warnings, &reasons)
19+
20+
if len(reasons) > 0 {
21+
return warnings, fmt.Errorf("%s", strings.Join(reasons, ". "))
22+
} else {
23+
return warnings, nil
24+
}
25+
}
26+
27+
func (wfs *WFS) ValidateUpdate(wfsOld *WFS) ([]string, error) {
28+
warnings := []string{}
29+
reasons := []string{}
30+
31+
// Check labels did not change
32+
err := sharedValidation.ValidateLabelsOnUpdate(wfsOld.Labels, wfs.Labels)
33+
if err != nil {
34+
reasons = append(reasons, fmt.Sprintf("%v", err))
35+
}
36+
37+
// Check service.baseURL did not change
38+
if wfs.Spec.Service.BaseURL != wfsOld.Spec.Service.BaseURL {
39+
reasons = append(reasons, fmt.Sprintf("service.baseURL is immutable"))
40+
}
41+
42+
if (wfs.Spec.Service.Inspire == nil && wfsOld.Spec.Service.Inspire != nil) || (wfs.Spec.Service.Inspire != nil && wfsOld.Spec.Service.Inspire == nil) {
43+
reasons = append(reasons, fmt.Sprintf("services cannot change from inspire to not inspire or the other way around"))
44+
}
45+
46+
validateWFS(wfs, &warnings, &reasons)
47+
48+
if len(reasons) > 0 {
49+
return warnings, fmt.Errorf("%s", strings.Join(reasons, ". "))
50+
} else {
51+
return warnings, nil
52+
}
53+
}
54+
55+
func validateWFS(wfs *WFS, warnings *[]string, reasons *[]string) {
56+
if strings.Contains(wfs.GetName(), "wfs") {
57+
*warnings = append(*warnings, sharedValidation.FormatValidationWarning("name should not contain wfs", wfs.GroupVersionKind(), wfs.GetName()))
58+
}
59+
60+
service := wfs.Spec.Service
61+
62+
err := sharedValidation.ValidateBaseURL(service.BaseURL)
63+
if err != nil {
64+
*reasons = append(*reasons, fmt.Sprintf("%v", err))
65+
}
66+
67+
if service.Mapfile == nil && service.DefaultCrs != "EPSG:28992" && service.Bbox == nil {
68+
*reasons = append(*reasons, fmt.Sprintf("service.bbox.defaultCRS is required when service.defaultCRS is not 'EPSG:28992'"))
69+
}
70+
71+
if service.Mapfile != nil {
72+
if service.Bbox != nil {
73+
*warnings = append(*warnings, sharedValidation.FormatValidationWarning("service.bbox is not used when service.mapfile is configured", wfs.GroupVersionKind(), wfs.GetName()))
74+
}
75+
}
76+
}

build-push-deploy-locally.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,31 @@ echo "Running: make generate"
66
make generate
77

88
echo ""
9-
echo "Running: build -t local-registry:5000/wfs-wms-operator:$TAG --build-context repos=./.. ."
10-
docker build -t "local-registry:5000/wfs-wms-operator:$TAG" --build-context repos=./.. .
9+
echo "Running: build -t local-registry:5000/mapserver-operator:$TAG --build-context repos=./.. ."
10+
docker build -t "local-registry:5000/mapserver-operator:$TAG" --build-context repos=./.. .
1111

1212
echo ""
13-
echo "Running: push local-registry:5000/wfs-wms-operator:$TAG"
14-
docker push "local-registry:5000/wfs-wms-operator:$TAG"
13+
echo "Running: push local-registry:5000/mapserver-operator:$TAG"
14+
docker push "local-registry:5000/mapserver-operator:$TAG"
1515

16-
echo ""
17-
echo "Installing cert-manager"
18-
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.17.0/cert-manager.yaml
16+
if [[ $(kubectl get pod -l app=webhook -n cert-manager | grep "cert-manager") ]]; then
17+
echo "Cert-manager already installed"
18+
else
19+
echo ""
20+
echo "Installing cert-manager"
21+
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.17.0/cert-manager.yaml
22+
fi
23+
24+
echo "Waiting for cert-manager"
25+
while [[ $(kubectl get pod -l app=webhook -n cert-manager -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do
26+
sleep 1
27+
done
28+
echo "Cert-manager ready"
1929

2030
echo ""
2131
echo "Running: make install"
2232
make install
2333

2434
echo ""
25-
echo "Running: deploy IMG=local-registry:5000/wfs-wms-operator:$TAG"
26-
make deploy "IMG=local-registry:5000/wfs-wms-operator:$TAG"
35+
echo "Running: deploy IMG=local-registry:5000/mapserver-operator:$TAG"
36+
make deploy "IMG=local-registry:5000/mapserver-operator:$TAG"

cmd/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ func main() {
233233
os.Exit(1)
234234
}
235235
}
236+
// nolint:goconst
237+
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
238+
if err = webhookpdoknlv3.SetupWFSWebhookWithManager(mgr); err != nil {
239+
setupLog.Error(err, "unable to create webhook", "webhook", "WFS")
240+
os.Exit(1)
241+
}
242+
}
236243
// +kubebuilder:scaffold:builder
237244

238245
if metricsCertWatcher != nil {

config/crd/bases/pdok.nl_wfs.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,11 +1157,8 @@ spec:
11571157
- abstract
11581158
- accessConstraints
11591159
- baseUrl
1160-
- bbox
1161-
- countDefault
11621160
- defaultCrs
11631161
- featureTypes
1164-
- fees
11651162
- keywords
11661163
- ownerInfoRef
11671164
- prefix

config/manager/kustomization.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
44
kind: Kustomization
55
images:
66
- name: controller
7-
newName: local-registry:5000/wfs-wms-operator
8-
newTag: v3.0.17
7+
newName: local-registry:5000/mapserver-operator
8+
newTag: v3.0.10

config/samples/v3_wfs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ spec:
3737
includeIngress: false
3838
service:
3939
prefix: ""
40-
baseUrl: https://service.pdok.nl
40+
baseUrl: https://service.pdok.nl/test
4141
inspire:
4242
serviceMetadataUrl:
4343
csw:

config/webhook/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resources:
2-
#- manifests.yaml see https://github.com/kubernetes-sigs/kubebuilder/issues/2231
2+
- manifests.yaml
33
- service.yaml
44

55
configurations:

config/webhook/manifests.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
apiVersion: admissionregistration.k8s.io/v1
3+
kind: ValidatingWebhookConfiguration
4+
metadata:
5+
name: validating-webhook-configuration
6+
webhooks:
7+
- admissionReviewVersions:
8+
- v1
9+
clientConfig:
10+
service:
11+
name: webhook-service
12+
namespace: system
13+
path: /validate-pdok-nl-v3-wfs
14+
failurePolicy: Fail
15+
name: vwfs-v3.kb.io
16+
rules:
17+
- apiGroups:
18+
- pdok.nl
19+
apiVersions:
20+
- v3
21+
operations:
22+
- CREATE
23+
- UPDATE
24+
resources:
25+
- wfs
26+
sideEffects: None

0 commit comments

Comments
 (0)