Skip to content

Commit bdccb3b

Browse files
committed
url uses url struct and podspecpatch required
1 parent 62a5c20 commit bdccb3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+144
-272
lines changed

api/v2beta1/shared_conversion.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package v2beta1
22

33
import (
4-
"fmt"
4+
"net/url"
55

66
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
77
"github.com/pdok/mapserver-operator/internal/controller/constants"
@@ -80,7 +80,7 @@ func ConvertAutoscaling(src Autoscaling) *pdoknlv3.HorizontalPodAutoscalerPatch
8080
}
8181
}
8282

83-
func ConvertResources(src corev1.ResourceRequirements) *corev1.PodSpec {
83+
func ConvertResources(src corev1.ResourceRequirements) corev1.PodSpec {
8484
targetResources := src
8585

8686
if src.Requests != nil {
@@ -92,7 +92,7 @@ func ConvertResources(src corev1.ResourceRequirements) *corev1.PodSpec {
9292
delete(targetResources.Limits, "ephemeralStorage")
9393
}
9494

95-
return &corev1.PodSpec{
95+
return corev1.PodSpec{
9696
Containers: []corev1.Container{
9797
{
9898
Name: constants.MapserverName,
@@ -209,7 +209,7 @@ func ConvertV3DataToV2(v3 pdoknlv3.Data) Data {
209209
return v2
210210
}
211211

212-
func NewV2KubernetesObject(lifecycle *smoothoperatormodel.Lifecycle, podSpecPatch *corev1.PodSpec, scalingSpec *pdoknlv3.HorizontalPodAutoscalerPatch) Kubernetes {
212+
func NewV2KubernetesObject(lifecycle *smoothoperatormodel.Lifecycle, podSpecPatch corev1.PodSpec, scalingSpec *pdoknlv3.HorizontalPodAutoscalerPatch) Kubernetes {
213213
kub := Kubernetes{}
214214

215215
if lifecycle != nil && lifecycle.TTLInDays != nil {
@@ -218,9 +218,7 @@ func NewV2KubernetesObject(lifecycle *smoothoperatormodel.Lifecycle, podSpecPatc
218218
}
219219
}
220220

221-
if podSpecPatch != nil {
222-
kub.Resources = &podSpecPatch.Containers[0].Resources
223-
}
221+
kub.Resources = &podSpecPatch.Containers[0].Resources
224222

225223
if scalingSpec != nil {
226224
kub.Autoscaling = &Autoscaling{
@@ -259,16 +257,20 @@ func LabelsToV2General(labels map[string]string) General {
259257
return general
260258
}
261259

262-
func CreateBaseURL(host string, kind string, general General) string {
263-
URI := fmt.Sprintf("%s/%s", general.DatasetOwner, general.Dataset)
260+
func CreateBaseURL(host string, kind string, general General) (*smoothoperatormodel.URL, error) {
261+
baseURL, err := url.Parse(host + "/")
262+
if err != nil {
263+
return nil, err
264+
}
265+
baseURL = baseURL.JoinPath(general.DatasetOwner, general.Dataset)
264266
if general.Theme != nil {
265-
URI += "/" + *general.Theme
267+
baseURL = baseURL.JoinPath(*general.Theme)
266268
}
267-
URI += "/" + kind
269+
baseURL = baseURL.JoinPath(kind)
268270

269271
if general.ServiceVersion != nil {
270-
URI += "/" + *general.ServiceVersion
272+
baseURL = baseURL.JoinPath(*general.ServiceVersion)
271273
}
272274

273-
return fmt.Sprintf("%s/%s", host, URI)
275+
return &smoothoperatormodel.URL{URL: baseURL}, nil
274276
}

api/v2beta1/wfs_conversion.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,14 @@ func (src *WFS) ToV3(dst *pdoknlv3.WFS) error {
7171
}
7272
}
7373

74+
url, err := CreateBaseURL(pdoknlv3.GetHost(true), "wfs", src.Spec.General)
75+
if err != nil {
76+
return err
77+
}
78+
7479
service := pdoknlv3.WFSService{
7580
Prefix: src.Spec.General.Dataset,
76-
URL: CreateBaseURL("https://service.pdok.nl", "wfs", src.Spec.General),
81+
URL: *url,
7782
OwnerInfoRef: "pdok",
7883
Title: src.Spec.Service.Title,
7984
Abstract: src.Spec.Service.Abstract,

api/v2beta1/wms_conversion.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ func (src *WMS) ConvertTo(dstRaw conversion.Hub) error {
4444
dst := dstRaw.(*pdoknlv3.WMS)
4545
log.Printf("ConvertTo: Converting WMS from Spoke version v2beta1 to Hub version v3;"+
4646
"source: %s/%s, target: %s/%s", src.Namespace, src.Name, dst.Namespace, dst.Name)
47-
src.ToV3(dst)
48-
49-
return nil
47+
return src.ToV3(dst)
5048
}
5149

5250
//nolint:gosec
53-
func (src *WMS) ToV3(target *pdoknlv3.WMS) {
51+
func (src *WMS) ToV3(target *pdoknlv3.WMS) error {
5452
dst := target
5553

5654
dst.ObjectMeta = src.ObjectMeta
@@ -76,9 +74,14 @@ func (src *WMS) ToV3(target *pdoknlv3.WMS) {
7674
dst.Spec.Options = ConvertOptionsV2ToV3(src.Spec.Options)
7775
dst.Spec.HealthCheck = convertHealthCheckToV3(src.Spec.Kubernetes.HealthCheck)
7876

77+
url, err := CreateBaseURL(pdoknlv3.GetHost(true), "wms", src.Spec.General)
78+
if err != nil {
79+
return err
80+
}
81+
7982
service := pdoknlv3.WMSService{
8083
Prefix: src.Spec.General.Dataset,
81-
URL: CreateBaseURL("https://service.pdok.nl", "wms", src.Spec.General),
84+
URL: *url,
8285
OwnerInfoRef: "pdok",
8386
Title: src.Spec.Service.Title,
8487
Abstract: src.Spec.Service.Abstract,
@@ -140,6 +143,7 @@ func (src *WMS) ToV3(target *pdoknlv3.WMS) {
140143
}
141144

142145
dst.Spec.Service = service
146+
return nil
143147
}
144148

145149
func convertHealthCheckToV3(v2 *HealthCheck) *pdoknlv3.HealthCheckWMS {

api/v2beta1/wms_conversion_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ func TestV2ToV3(t *testing.T) {
1515
err := yaml.Unmarshal([]byte(input), v2wms)
1616
assert.NoError(t, err)
1717
var target pdoknlv3.WMS
18-
v2wms.ToV3(&target)
18+
err = v2wms.ToV3(&target)
19+
assert.NoError(t, err)
1920
assert.Equal(t, "NWB - Wegen WMS", target.Spec.Service.Title)
2021
a := 0
2122
_ = a

api/v3/shared_types.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package v3
22

33
import (
4-
"net/url"
54
"strings"
65

6+
smoothoperatormodel "github.com/pdok/smooth-operator/model"
7+
78
"k8s.io/apimachinery/pkg/runtime/schema"
89

910
autoscalingv2 "k8s.io/api/autoscaling/v2"
@@ -38,15 +39,15 @@ type WMSWFS interface {
3839
GroupKind() schema.GroupKind
3940
Inspire() *Inspire
4041
Mapfile() *Mapfile
41-
PodSpecPatch() *corev1.PodSpec
42+
PodSpecPatch() corev1.PodSpec
4243
HorizontalPodAutoscalerPatch() *HorizontalPodAutoscalerPatch
4344
Type() ServiceType
4445
TypedName() string
4546
Options() Options
4647
HasPostgisData() bool
4748

4849
// URLPath returns the configured service URL
49-
URLPath() string
50+
URL() smoothoperatormodel.URL
5051

5152
GeoPackages() []*Gpkg
5253

@@ -249,12 +250,6 @@ func GetHost(includeProtocol bool) string {
249250
return host
250251
}
251252

252-
func GetBaseURLPath[T WMSWFS](o T) string {
253-
serviceURL := o.URLPath()
254-
parsed, _ := url.Parse(serviceURL)
255-
return strings.TrimPrefix(parsed.Path, "/")
256-
}
257-
258253
func (d *Data) GetColumns() *[]Column {
259254
switch {
260255
case d.Gpkg != nil:

api/v3/shared_validation.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package v3
22

33
import (
4-
smoothoperatormodel "github.com/pdok/smooth-operator/model"
54
sharedValidation "github.com/pdok/smooth-operator/pkg/validation"
65

76
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -15,17 +14,9 @@ func ValidateUpdate[W WMSWFS](newW, oldW W, validate func(W, *[]string, *field.E
1514
sharedValidation.ValidateLabelsOnUpdate(oldW.GetLabels(), newW.GetLabels(), &allErrs)
1615

1716
path := field.NewPath("spec").Child("service").Child("url")
18-
oldURL, err := smoothoperatormodel.ParseURL(oldW.URLPath())
19-
if err != nil {
20-
allErrs = append(allErrs, field.InternalError(path, err))
21-
}
22-
newURL, err := smoothoperatormodel.ParseURL(oldW.URLPath())
23-
if err != nil {
24-
allErrs = append(allErrs, field.InternalError(path, err))
25-
}
2617
sharedValidation.CheckUrlImmutability(
27-
smoothoperatormodel.URL{URL: oldURL},
28-
smoothoperatormodel.URL{URL: newURL},
18+
oldW.URL(),
19+
newW.URL(),
2920
&allErrs,
3021
path,
3122
)

api/v3/wfs_types.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type WFS struct {
5252
metav1.TypeMeta `json:",inline"`
5353
metav1.ObjectMeta `json:"metadata,omitempty"`
5454

55-
Spec WFSSpec `json:"spec,omitempty"`
55+
Spec WFSSpec `json:"spec"`
5656
Status smoothoperatormodel.OperatorStatus `json:"status,omitempty"`
5757
}
5858

@@ -77,8 +77,8 @@ type WFSSpec struct {
7777
// +kubebuilder:validation:Type=object
7878
// +kubebuilder:validation:Schemaless
7979
// +kubebuilder:pruning:PreserveUnknownFields
80-
// Optional strategic merge patch for the pod in the deployment. E.g. to patch the resources or add extra env vars.
81-
PodSpecPatch *corev1.PodSpec `json:"podSpecPatch,omitempty"`
80+
// Strategic merge patch for the pod in the deployment. E.g. to patch the resources or add extra env vars.
81+
PodSpecPatch corev1.PodSpec `json:"podSpecPatch"`
8282
HorizontalPodAutoscalerPatch *HorizontalPodAutoscalerPatch `json:"horizontalPodAutoscalerPatch,omitempty"`
8383
// TODO omitting the options field or setting an empty value results in incorrect defaulting of the options
8484
Options *Options `json:"options,omitempty"`
@@ -96,9 +96,7 @@ type WFSService struct {
9696
Prefix string `json:"prefix"`
9797

9898
// URL of the service
99-
// +kubebuilder:validation:Pattern:=`^https?://.*$`
100-
// +kubebuilder:validation:MinLength:=1
101-
URL string `json:"url"`
99+
URL smoothoperatormodel.URL `json:"url"`
102100

103101
// Config for Inspire services
104102
Inspire *Inspire `json:"inspire,omitempty"`
@@ -258,7 +256,7 @@ func (wfs *WFS) TypedName() string {
258256
return name + "-" + typeSuffix
259257
}
260258

261-
func (wfs *WFS) PodSpecPatch() *corev1.PodSpec {
259+
func (wfs *WFS) PodSpecPatch() corev1.PodSpec {
262260
return wfs.Spec.PodSpecPatch
263261
}
264262

@@ -274,7 +272,7 @@ func (wfs *WFS) Options() Options {
274272
return *wfs.Spec.Options
275273
}
276274

277-
func (wfs *WFS) URLPath() string {
275+
func (wfs *WFS) URL() smoothoperatormodel.URL {
278276
return wfs.Spec.Service.URL
279277
}
280278

api/v3/wfs_validation.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v3
22

33
import (
4+
corev1 "k8s.io/api/core/v1"
45
"strings"
56

67
sharedValidation "github.com/pdok/smooth-operator/pkg/validation"
@@ -48,16 +49,33 @@ func ValidateWFS(wfs *WFS, warnings *[]string, allErrs *field.ErrorList) {
4849
service := wfs.Spec.Service
4950
path := field.NewPath("spec").Child("service")
5051

51-
err := sharedValidation.ValidateBaseURL(service.URL)
52-
if err != nil {
53-
*allErrs = append(*allErrs, field.Invalid(path.Child("url"), service.URL, err.Error()))
54-
}
55-
5652
if service.Mapfile == nil && service.DefaultCrs != "EPSG:28992" && service.Bbox == nil {
5753
*allErrs = append(*allErrs, field.Required(path.Child("bbox").Child("defaultCRS"), "when service.defaultCRS is not 'EPSG:28992'"))
5854
}
5955

6056
if service.Mapfile != nil && service.Bbox != nil {
6157
sharedValidation.AddWarning(warnings, *path.Child("bbox"), "is not used when service.mapfile is configured", wfs.GroupVersionKind(), wfs.GetName())
6258
}
59+
60+
podSpecPatch := wfs.Spec.PodSpecPatch
61+
ValidateEphemeralStorage(podSpecPatch, allErrs)
62+
}
63+
64+
func ValidateEphemeralStorage(podSpecPatch corev1.PodSpec, allErrs *field.ErrorList) {
65+
path := field.NewPath("spec").
66+
Child("podSpecPatch").
67+
Child("containers").
68+
Key("mapserver").
69+
Child("resources").
70+
Child("limits").
71+
Child(corev1.ResourceEphemeralStorage.String())
72+
storageSet := false
73+
for _, container := range podSpecPatch.Containers {
74+
if container.Name == "mapserver" {
75+
_, storageSet = container.Resources.Limits[corev1.ResourceEphemeralStorage]
76+
}
77+
}
78+
if !storageSet {
79+
*allErrs = append(*allErrs, field.Required(path, ""))
80+
}
6381
}

api/v3/wms_types.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ type WMSSpec struct {
5656
// +kubebuilder:validation:Type=object
5757
// +kubebuilder:validation:Schemaless
5858
// +kubebuilder:pruning:PreserveUnknownFields
59-
// Optional strategic merge patch for the pod in the deployment. E.g. to patch the resources or add extra env vars.
60-
PodSpecPatch *corev1.PodSpec `json:"podSpecPatch,omitempty"`
59+
// Strategic merge patch for the pod in the deployment. E.g. to patch the resources or add extra env vars.
60+
PodSpecPatch corev1.PodSpec `json:"podSpecPatch"`
6161

6262
// Optional specification for the HorizontalAutoscaler
6363
HorizontalPodAutoscalerPatch *HorizontalPodAutoscalerPatch `json:"horizontalPodAutoscalerPatch,omitempty"`
@@ -78,8 +78,7 @@ type WMSService struct {
7878
Prefix string `json:"prefix"`
7979

8080
// URL of the service
81-
// +kubebuilder:validation:Format:=uri
82-
URL string `json:"url"`
81+
URL smoothoperatormodel.URL `json:"url"`
8382

8483
// Title of the service
8584
// +kubebuilder:validation:MinLength:=1
@@ -604,7 +603,7 @@ func (wms *WMS) TypedName() string {
604603
return name + "-" + typeSuffix
605604
}
606605

607-
func (wms *WMS) PodSpecPatch() *corev1.PodSpec {
606+
func (wms *WMS) PodSpecPatch() corev1.PodSpec {
608607
return wms.Spec.PodSpecPatch
609608
}
610609

@@ -620,7 +619,7 @@ func (wms *WMS) Options() Options {
620619
return *wms.Spec.Options
621620
}
622621

623-
func (wms *WMS) URLPath() string {
622+
func (wms *WMS) URL() smoothoperatormodel.URL {
624623
return wms.Spec.Service.URL
625624
}
626625

api/v3/wms_validation.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ func ValidateWMS(wms *WMS, warnings *[]string, allErrs *field.ErrorList) {
5353
service := wms.Spec.Service
5454
path := field.NewPath("spec").Child("service")
5555

56-
err := sharedValidation.ValidateBaseURL(service.URL)
57-
if err != nil {
58-
*allErrs = append(*allErrs, field.Invalid(path.Child("url"), service.URL, err.Error()))
59-
}
60-
6156
if service.Mapfile != nil {
6257
if service.Resolution != nil {
6358
sharedValidation.AddWarning(
@@ -295,6 +290,9 @@ func ValidateWMS(wms *WMS, warnings *[]string, allErrs *field.ErrorList) {
295290
"at least one layer must be visible",
296291
))
297292
}
293+
294+
podSpecPatch := wms.Spec.PodSpecPatch
295+
ValidateEphemeralStorage(podSpecPatch, allErrs)
298296
}
299297

300298
func findEqualChildStyleNames(layer *Layer, equalStyleNames *map[string][]string) {

0 commit comments

Comments
 (0)