Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run:
timeout: 5m

# Modules download mode (do not modify go.mod)
module-download-mode: readonly
modules-download-mode: readonly

# Include test files (see below to exclude certain linters)
tests: true
Expand All @@ -21,7 +21,9 @@ issues:
- gosec

output:
formats: colored-line-number
formats:
- format: colored-line-number
path: stdout
print-issued-lines: true
print-linter-name: true

Expand Down
4 changes: 4 additions & 0 deletions api/v3/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net/url"
"strings"

"k8s.io/apimachinery/pkg/runtime/schema"

autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -37,6 +39,8 @@ type WMSWFS interface {
*WFS | *WMS
metav1.Object

GroupKind() schema.GroupKind
Inspire() *Inspire
Mapfile() *Mapfile
PodSpecPatch() *corev1.PodSpec
HorizontalPodAutoscalerPatch() *HorizontalPodAutoscalerPatch
Expand Down
44 changes: 44 additions & 0 deletions api/v3/shared_validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package v3

import (
"github.com/pdok/smooth-operator/model"
sharedValidation "github.com/pdok/smooth-operator/pkg/validation"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/validation/field"
)

func ValidateUpdate[W WMSWFS](newW, oldW W, validate func(W, *[]string, *field.ErrorList)) ([]string, error) {
warnings := []string{}
allErrs := field.ErrorList{}

sharedValidation.ValidateLabelsOnUpdate(oldW.GetLabels(), newW.GetLabels(), &allErrs)

path := field.NewPath("spec").Child("service").Child("url")
oldURL, err := model.ParseURL(oldW.URLPath())
if err != nil {
allErrs = append(allErrs, field.InternalError(path, err))
}
newURL, err := model.ParseURL(oldW.URLPath())
if err != nil {
allErrs = append(allErrs, field.InternalError(path, err))
}
sharedValidation.CheckUrlImmutability(
model.URL{URL: oldURL},
model.URL{URL: newURL},
&allErrs,
path,
)

if (newW.Inspire() == nil && oldW.Inspire() != nil) || (newW.Inspire() != nil && oldW.Inspire() == nil) {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec").Child("service").Child("inspire"), "cannot change from inspire to not inspire or the other way around"))
}

validate(newW, &warnings, &allErrs)

if len(allErrs) == 0 {
return warnings, nil
}
return warnings, apierrors.NewInvalid(
newW.GroupKind(),
newW.GetName(), allErrs)
}
17 changes: 11 additions & 6 deletions api/v3/wfs_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ SOFTWARE.
package v3

import (
"slices"

shared_model "github.com/pdok/smooth-operator/model"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"slices"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down Expand Up @@ -215,6 +217,14 @@ func (wfs *WFS) HasPostgisData() bool {
return false
}

func (wfs *WFS) GroupKind() schema.GroupKind {
return schema.GroupKind{Group: GroupVersion.Group, Kind: wfs.Kind}
}

func (wfs *WFS) Inspire() *Inspire {
return wfs.Spec.Service.Inspire
}

func (wfs *WFS) Mapfile() *Mapfile {
return wfs.Spec.Service.Mapfile
}
Expand Down Expand Up @@ -254,8 +264,3 @@ func (wfs *WFS) GeoPackages() []*Gpkg {

return gpkgs
}

//nolint:revive
func (wfs *WFS) GetBaseUrl() string {
return wfs.Spec.Service.URL
}
22 changes: 1 addition & 21 deletions api/v3/wfs_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,8 @@ func (wfs *WFS) ValidateCreate() ([]string, error) {
wfs.Name, allErrs)
}

// TODO fix linting (dupl)
func (wfs *WFS) ValidateUpdate(wfsOld *WFS) ([]string, error) {
warnings := []string{}
allErrs := field.ErrorList{}

sharedValidation.ValidateLabelsOnUpdate(wfsOld.Labels, wfs.Labels, &allErrs)

sharedValidation.CheckBaseUrlImmutability(wfsOld, wfs, &allErrs)

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

ValidateWFS(wfs, &warnings, &allErrs)

if len(allErrs) == 0 {
return warnings, nil
}

return warnings, apierrors.NewInvalid(
schema.GroupKind{Group: "pdok.nl", Kind: "WFS"},
wfs.Name, allErrs)
return ValidateUpdate(wfs, wfsOld, ValidateWFS)
}

func ValidateWFS(wfs *WFS, warnings *[]string, allErrs *field.ErrorList) {
Expand Down
42 changes: 22 additions & 20 deletions api/v3/wms_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"slices"
"sort"

"k8s.io/apimachinery/pkg/runtime/schema"

shared_model "github.com/pdok/smooth-operator/model"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -118,9 +120,9 @@ type WMSService struct {
Layer Layer `json:"layer"`
}

func (s WMSService) KeywordsIncludingInspireKeyword() []string {
keywords := s.Keywords
if s.Inspire != nil && !slices.Contains(keywords, "infoMapAccessService") {
func (wmsService WMSService) KeywordsIncludingInspireKeyword() []string {
keywords := wmsService.Keywords
if wmsService.Inspire != nil && !slices.Contains(keywords, "infoMapAccessService") {
keywords = append(keywords, "infoMapAccessService")
}

Expand Down Expand Up @@ -542,6 +544,14 @@ func (wms *WMS) HasPostgisData() bool {
return false
}

func (wms *WMS) GroupKind() schema.GroupKind {
return schema.GroupKind{Group: GroupVersion.Group, Kind: wms.Kind}
}

func (wms *WMS) Inspire() *Inspire {
return wms.Spec.Service.Inspire
}

func (wms *WMS) Mapfile() *Mapfile {
return wms.Spec.Service.Mapfile
}
Expand Down Expand Up @@ -573,27 +583,19 @@ func (wms *WMS) URLPath() string {
func (wms *WMS) GeoPackages() []*Gpkg {
gpkgs := make([]*Gpkg, 0)

// TODO fix linting (nestif)
if wms.Spec.Service.Layer.Layers != nil {
for _, layer := range wms.Spec.Service.Layer.Layers {
if layer.Data != nil {
if layer.Data.Gpkg != nil {
gpkgs = append(gpkgs, layer.Data.Gpkg)
}
} else if layer.Layers != nil {
for _, childLayer := range layer.Layers {
if childLayer.Data != nil && childLayer.Data.Gpkg != nil {
gpkgs = append(gpkgs, childLayer.Data.Gpkg)
}
for _, layer := range wms.Spec.Service.Layer.Layers {
if layer.Data != nil {
if layer.Data.Gpkg != nil {
gpkgs = append(gpkgs, layer.Data.Gpkg)
}
} else if layer.Layers != nil {
for _, childLayer := range layer.Layers {
if childLayer.Data != nil && childLayer.Data.Gpkg != nil {
gpkgs = append(gpkgs, childLayer.Data.Gpkg)
}
}
}
}

return gpkgs
}

//nolint:revive
func (wms *WMS) GetBaseUrl() string {
return wms.Spec.Service.URL
}
22 changes: 1 addition & 21 deletions api/v3/wms_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,12 @@
wms.Name, allErrs)
}

// TODO fix linting (dupl)
func (wms *WMS) ValidateUpdate(wmsOld *WMS) ([]string, error) {
warnings := []string{}
allErrs := field.ErrorList{}

sharedValidation.ValidateLabelsOnUpdate(wmsOld.Labels, wms.Labels, &allErrs)

sharedValidation.CheckBaseUrlImmutability(wmsOld, wms, &allErrs)

if (wms.Spec.Service.Inspire == nil && wmsOld.Spec.Service.Inspire != nil) || (wms.Spec.Service.Inspire != nil && wmsOld.Spec.Service.Inspire == nil) {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec").Child("service").Child("inspire"), "cannot change from inspire to not inspire or the other way around"))
}

ValidateWMS(wms, &warnings, &allErrs)

if len(allErrs) == 0 {
return warnings, nil
}

return warnings, apierrors.NewInvalid(
schema.GroupKind{Group: "pdok.nl", Kind: "WFS"},
wms.Name, allErrs)
return ValidateUpdate(wms, wmsOld, ValidateWMS)
}

// TODO fix linting (cyclop)
func ValidateWMS(wms *WMS, warnings *[]string, allErrs *field.ErrorList) {

Check failure on line 40 in api/v3/wms_validation.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

calculated cyclomatic complexity for function ValidateWMS is 51, max is 15 (cyclop)

Check failure on line 40 in api/v3/wms_validation.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

calculated cyclomatic complexity for function ValidateWMS is 51, max is 15 (cyclop)
if strings.Contains(wms.GetName(), "wms") {
sharedValidation.AddWarning(
warnings,
Expand Down Expand Up @@ -223,7 +203,7 @@
}

// TODO fix linting (nestif)
if layer.Visible {

Check failure on line 206 in api/v3/wms_validation.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

`if layer.Visible` has complex nested blocks (complexity: 7) (nestif)

Check failure on line 206 in api/v3/wms_validation.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

`if layer.Visible` has complex nested blocks (complexity: 7) (nestif)
hasVisibleLayer = true

if layer.Title == nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/pdok/featureinfo-generator v1.4.0-beta1
github.com/pdok/ogc-capabilities-generator v1.0.0-beta7
github.com/pdok/ogc-specifications v1.0.0-beta7
github.com/pdok/smooth-operator v0.1.0
github.com/pdok/smooth-operator v0.1.1
github.com/peterbourgon/ff v1.7.1
github.com/stretchr/testify v1.10.0
github.com/traefik/traefik/v3 v3.3.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ github.com/pdok/ogc-capabilities-generator v1.0.0-beta7 h1:w0dP2RQX0KEEovrq57NCM
github.com/pdok/ogc-capabilities-generator v1.0.0-beta7/go.mod h1:slk89sAgmWU5NCIKwGyciQWnm0RHmwhJYQ431E2CwSk=
github.com/pdok/ogc-specifications v1.0.0-beta7 h1:AFSO8iCYbD1MrjOS2q+PGp2PmSqAH+O7cuA7JeePCXE=
github.com/pdok/ogc-specifications v1.0.0-beta7/go.mod h1:YDngwkwrWOfc5MYnEYseiv97K1Y9bZXlVzwi/8EaIl8=
github.com/pdok/smooth-operator v0.1.0 h1:i1uZa3Niuh6ljl4UTGcC48sC01H3CaWHiIfK7pQTix8=
github.com/pdok/smooth-operator v0.1.0/go.mod h1:przwM7mBGmNPqabyhImKVZ15WL4zbqLqH4ExbuWKhWE=
github.com/pdok/smooth-operator v0.1.1 h1:rmsup4HmzJsxt4ZT9GWfj498dKLRfDhyuILeEkjju/A=
github.com/pdok/smooth-operator v0.1.1/go.mod h1:przwM7mBGmNPqabyhImKVZ15WL4zbqLqH4ExbuWKhWE=
github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
github.com/peterbourgon/ff v1.7.1 h1:xt1lxTG+Nr2+tFtysY7abFgPoH3Lug8CwYJMOmJRXhk=
github.com/peterbourgon/ff v1.7.1/go.mod h1:fYI5YA+3RDqQRExmFbHnBjEeWzh9TrS8rnRpEq7XIg0=
Expand Down
14 changes: 8 additions & 6 deletions internal/controller/mapserver/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)

// TODO fix linting (funlen)
func GetVolumesForDeployment[O pdoknlv3.WMSWFS](obj O, configMapNames types.HashedConfigMapNames) []v1.Volume {

Check failure on line 33 in internal/controller/mapserver/deployment.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

Function 'GetVolumesForDeployment' is too long (115 > 100) (funlen)

Check failure on line 33 in internal/controller/mapserver/deployment.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

Function 'GetVolumesForDeployment' is too long (115 > 100) (funlen)
baseVolume := v1.Volume{Name: "base"}
if use, size := mapperutils.UseEphemeralVolume(obj); use {
baseVolume.Ephemeral = &v1.EphemeralVolumeSource{
Expand Down Expand Up @@ -216,25 +216,27 @@
}
}

// TODO fix linting (cyclop,gocritic,revive)
// TODO fix linting (cyclop)
// Resources for mapserver container
func GetResourcesForDeployment[O pdoknlv3.WMSWFS](obj O) v1.ResourceRequirements {

Check failure on line 221 in internal/controller/mapserver/deployment.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

calculated cyclomatic complexity for function GetResourcesForDeployment is 28, max is 15 (cyclop)

Check failure on line 221 in internal/controller/mapserver/deployment.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

calculated cyclomatic complexity for function GetResourcesForDeployment is 28, max is 15 (cyclop)
resources := v1.ResourceRequirements{
Limits: v1.ResourceList{},
Requests: v1.ResourceList{},
}

maxResourceVal := func(v1 *resource.Quantity, v2 *resource.Quantity) *resource.Quantity {
if v1 != nil && v2 != nil {
switch {
case v1 != nil && v2 != nil:
if v1.Value() > v2.Value() {
return v1
} else {
return v2
}
} else if v1 != nil && v2 == nil {
return v2
case v1 != nil && v2 == nil:
return v1
} else if v1 == nil || v2 != nil {
case v1 == nil || v2 != nil:
return v2
default:

}

return &resource.Quantity{}
Expand Down
Loading