Skip to content

Commit 9744269

Browse files
committed
bump smooth-operator
1 parent c74dac6 commit 9744269

File tree

6 files changed

+232
-114
lines changed

6 files changed

+232
-114
lines changed

api/v3/wfs_validation.go

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,82 @@
11
package v3
22

33
import (
4-
"fmt"
54
"strings"
65

6+
apierrors "k8s.io/apimachinery/pkg/api/errors"
7+
"k8s.io/apimachinery/pkg/runtime/schema"
8+
"k8s.io/apimachinery/pkg/util/validation/field"
9+
710
sharedValidation "github.com/pdok/smooth-operator/pkg/validation"
811
)
912

1013
func (wfs *WFS) ValidateCreate() ([]string, error) {
11-
warnings := []string{}
12-
reasons := []string{}
14+
var warnings []string
15+
var allErrs field.ErrorList
1316

1417
err := sharedValidation.ValidateLabelsOnCreate(wfs.Labels)
1518
if err != nil {
16-
reasons = append(reasons, fmt.Sprintf("%v", err))
19+
allErrs = append(allErrs, err)
1720
}
1821

19-
ValidateWFS(wfs, &warnings, &reasons)
22+
ValidateWFS(wfs, &warnings, &allErrs)
2023

21-
if len(reasons) > 0 {
22-
return warnings, fmt.Errorf("%s", strings.Join(reasons, ". "))
24+
if len(allErrs) == 0 {
25+
return warnings, nil
2326
}
2427

25-
return warnings, nil
28+
return warnings, apierrors.NewInvalid(
29+
schema.GroupKind{Group: "pdok.nl", Kind: "WFS"},
30+
wfs.Name, allErrs)
2631
}
2732

2833
func (wfs *WFS) ValidateUpdate(wfsOld *WFS) ([]string, error) {
29-
warnings := []string{}
30-
reasons := []string{}
34+
var warnings []string
35+
var allErrs field.ErrorList
3136

32-
// Check labels did not change
33-
err := sharedValidation.ValidateLabelsOnUpdate(wfsOld.Labels, wfs.Labels)
34-
if err != nil {
35-
reasons = append(reasons, fmt.Sprintf("%v", err))
36-
}
37+
sharedValidation.ValidateLabelsOnUpdate(wfsOld.Labels, wfs.Labels, &allErrs)
3738

38-
sharedValidation.CheckBaseUrlImmutability(wfsOld, wfs, &reasons)
39+
sharedValidation.CheckBaseUrlImmutability(wfsOld, wfs, &allErrs)
3940

4041
if (wfs.Spec.Service.Inspire == nil && wfsOld.Spec.Service.Inspire != nil) || (wfs.Spec.Service.Inspire != nil && wfsOld.Spec.Service.Inspire == nil) {
41-
reasons = append(reasons, "services cannot change from inspire to not inspire or the other way around")
42+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec").Child("service").Child("inspire"), "cannot change from inspire to not inspire or the other way around"))
4243
}
4344

44-
ValidateWFS(wfs, &warnings, &reasons)
45+
ValidateWFS(wfs, &warnings, &allErrs)
4546

46-
if len(reasons) > 0 {
47-
return warnings, fmt.Errorf("%s", strings.Join(reasons, ". "))
47+
if len(allErrs) == 0 {
48+
return warnings, nil
4849
}
4950

50-
return warnings, nil
51+
return warnings, apierrors.NewInvalid(
52+
schema.GroupKind{Group: "pdok.nl", Kind: "WFS"},
53+
wfs.Name, allErrs)
5154
}
5255

53-
func ValidateWFS(wfs *WFS, warnings *[]string, reasons *[]string) {
56+
func ValidateWFS(wfs *WFS, warnings *[]string, allErrs *field.ErrorList) {
5457
if strings.Contains(wfs.GetName(), "wfs") {
55-
*warnings = append(*warnings, sharedValidation.FormatValidationWarning("name should not contain wfs", wfs.GroupVersionKind(), wfs.GetName()))
58+
sharedValidation.AddWarning(
59+
warnings,
60+
*field.NewPath("metadata").Child("name"),
61+
"name should not contain wfs",
62+
wfs.GroupVersionKind(),
63+
wfs.GetName(),
64+
)
5665
}
5766

5867
service := wfs.Spec.Service
68+
path := field.NewPath("spec").Child("service")
5969

6070
err := sharedValidation.ValidateBaseURL(service.URL)
6171
if err != nil {
62-
*reasons = append(*reasons, fmt.Sprintf("%v", err))
72+
*allErrs = append(*allErrs, field.Invalid(path.Child("url"), service.URL, err.Error()))
6373
}
6474

6575
if service.Mapfile == nil && service.DefaultCrs != "EPSG:28992" && service.Bbox == nil {
66-
*reasons = append(*reasons, "service.bbox.defaultCRS is required when service.defaultCRS is not 'EPSG:28992'")
76+
*allErrs = append(*allErrs, field.Required(path.Child("bbox").Child("defaultCRS"), "when service.defaultCRS is not 'EPSG:28992'"))
6777
}
6878

69-
if service.Mapfile != nil {
70-
if service.Bbox != nil {
71-
*warnings = append(*warnings, sharedValidation.FormatValidationWarning("service.bbox is not used when service.mapfile is configured", wfs.GroupVersionKind(), wfs.GetName()))
72-
}
79+
if service.Mapfile != nil && service.Bbox != nil {
80+
sharedValidation.AddWarning(warnings, *path.Child("bbox"), "is not used when service.mapfile is configured", wfs.GroupVersionKind(), wfs.GetName())
7381
}
7482
}

0 commit comments

Comments
 (0)