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: 3 additions & 3 deletions api/v2beta1/shared_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
}
}

func ConvertAutoscaling(src Autoscaling) *autoscalingv2.HorizontalPodAutoscalerSpec {
func ConvertAutoscaling(src Autoscaling) *pdoknlv3.HorizontalPodAutoscalerPatch {
var minReplicas *int32
if src.MinReplicas != nil {
//nolint:gosec
Expand All @@ -54,7 +54,7 @@

var maxReplicas int32
if src.MaxReplicas != nil {
maxReplicas = int32(*src.MaxReplicas)

Check failure on line 57 in api/v2beta1/shared_conversion.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

G115: integer overflow conversion int -> int32 (gosec)

Check failure on line 57 in api/v2beta1/shared_conversion.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

G115: integer overflow conversion int -> int32 (gosec)
}

metrics := make([]autoscalingv2.MetricSpec, 0)
Expand All @@ -65,13 +65,13 @@
Name: corev1.ResourceCPU,
Target: autoscalingv2.MetricTarget{
Type: autoscalingv2.UtilizationMetricType,
AverageUtilization: Pointer(int32(*src.AverageCPUUtilization)),

Check failure on line 68 in api/v2beta1/shared_conversion.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

G115: integer overflow conversion int -> int32 (gosec)

Check failure on line 68 in api/v2beta1/shared_conversion.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

G115: integer overflow conversion int -> int32 (gosec)
},
},
})
}

return &autoscalingv2.HorizontalPodAutoscalerSpec{
return &pdoknlv3.HorizontalPodAutoscalerPatch{
MinReplicas: minReplicas,
MaxReplicas: maxReplicas,
Metrics: metrics,
Expand Down Expand Up @@ -196,7 +196,7 @@
return v2
}

func NewV2KubernetesObject(lifecycle *shared_model.Lifecycle, podSpecPatch *corev1.PodSpec, scalingSpec *autoscalingv2.HorizontalPodAutoscalerSpec) Kubernetes {
func NewV2KubernetesObject(lifecycle *shared_model.Lifecycle, podSpecPatch *corev1.PodSpec, scalingSpec *pdoknlv3.HorizontalPodAutoscalerPatch) Kubernetes {
kub := Kubernetes{}

if lifecycle != nil && lifecycle.TTLInDays != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/v2beta1/wfs_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type WFSService struct {
Inspire bool `json:"inspire"`
Abstract string `json:"abstract"`
// +kubebuilder:default="https://creativecommons.org/publicdomain/zero/1.0/deed.nl"
AccessConstraints string `json:"accessConstraints"`
AccessConstraints *string `json:"accessConstraints,omitempty"`
Keywords []string `json:"keywords"`
MetadataIdentifier string `json:"metadataIdentifier"`
Authority Authority `json:"authority"`
Expand Down
4 changes: 2 additions & 2 deletions api/v2beta1/wms_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (v2Layer WMSLayer) MapToV3(v2Service WMSService) pdoknlv3.Layer {
BoundingBoxes: []pdoknlv3.WMSBoundingBox{},
MinScaleDenominator: nil,
MaxScaleDenominator: nil,
Visible: &v2Layer.Visible,
Visible: v2Layer.Visible,
}

if v2Layer.SourceMetadataIdentifier != nil {
Expand Down Expand Up @@ -443,7 +443,7 @@ func mapV3LayerToV2Layers(v3Layer pdoknlv3.Layer, parent *pdoknlv3.Layer, servic
Styles: []Style{},
}

v2Layer.Visible = *v3Layer.Visible
v2Layer.Visible = v3Layer.Visible

if parent != nil {
v2Layer.Group = parent.Name
Expand Down
4 changes: 2 additions & 2 deletions api/v2beta1/wms_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type WMSService struct {
Title string `json:"title"`
Abstract string `json:"abstract"`
// +kubebuilder:default="https://creativecommons.org/publicdomain/zero/1.0/deed.nl"
AccessConstraints string `json:"accessConstraints"`
AccessConstraints *string `json:"accessConstraints,omitempty"` // Pointer for CRD conversion as defaulting is not applied there
Keywords []string `json:"keywords"`
MetadataIdentifier string `json:"metadataIdentifier"`
Authority Authority `json:"authority"`
Expand All @@ -77,7 +77,7 @@ type WMSService struct {
type WMSLayer struct {
Name string `json:"name"`
Group *string `json:"group,omitempty"`
Visible bool `json:"visible"`
Visible *bool `json:"visible,omitempty"`
Title *string `json:"title,omitempty"`
Abstract *string `json:"abstract,omitempty"`
Keywords []string `json:"keywords,omitempty"`
Expand Down
15 changes: 15 additions & 0 deletions api/v2beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions api/v3/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ const (
ServiceTypeWFS ServiceType = "WFS"
)

// HorizontalPodAutoscalerPatch - copy of autoscalingv2.HorizontalPodAutoscalerSpec without ScaleTargetRef
// This way we don't have to specify the scaleTargetRef field in the CRD.
type HorizontalPodAutoscalerPatch struct {
MinReplicas *int32 `json:"minReplicas,omitempty"`
MaxReplicas int32 `json:"maxReplicas"`
Metrics []autoscalingv2.MetricSpec `json:"metrics,omitempty"`
Behavior *autoscalingv2.HorizontalPodAutoscalerBehavior `json:"behavior,omitempty"`
}

// WMSWFS is the common interface used for both WMS and WFS resources.
// +kubebuilder:object:generate=false
type WMSWFS interface {
Expand All @@ -30,7 +39,7 @@ type WMSWFS interface {

Mapfile() *Mapfile
PodSpecPatch() *corev1.PodSpec
HorizontalPodAutoscalerPatch() *autoscalingv2.HorizontalPodAutoscalerSpec
HorizontalPodAutoscalerPatch() *HorizontalPodAutoscalerPatch
Type() ServiceType
Options() *Options
HasPostgisData() bool
Expand Down Expand Up @@ -182,7 +191,7 @@ type Postgis struct {
// +kubebuilder:validation:Type=object
type TIF struct {
// BlobKey to the TIFF file
// +kubebuilder:validation:Pattern=`\.(tif|tiff)$`
// +kubebuilder:validation:Pattern=`\.(tif?f|vrt)$`
// +kubebuilder:validation:MinLength:=1
BlobKey string `json:"blobKey"`

Expand Down
12 changes: 5 additions & 7 deletions api/v3/wfs_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ package v3

import (
shared_model "github.com/pdok/smooth-operator/model"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -73,9 +72,9 @@ type WFSSpec struct {
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
// Optional strategic merge patch for the pod in the deployment. E.g. to patch the resources or add extra env vars.
PodSpecPatch *corev1.PodSpec `json:"podSpecPatch,omitempty"`
HorizontalPodAutoscalerPatch *autoscalingv2.HorizontalPodAutoscalerSpec `json:"horizontalPodAutoscalerPatch,omitempty"`
Options Options `json:"options,omitempty"`
PodSpecPatch *corev1.PodSpec `json:"podSpecPatch,omitempty"`
HorizontalPodAutoscalerPatch *HorizontalPodAutoscalerPatch `json:"horizontalPodAutoscalerPatch,omitempty"`
Options Options `json:"options,omitempty"`

// service configuration
Service WFSService `json:"service"`
Expand Down Expand Up @@ -120,9 +119,8 @@ type WFSService struct {
// AccessConstraints URL
// +kubebuilder:validation:Pattern:="https?://"
// +kubebuilder:default="https://creativecommons.org/publicdomain/zero/1.0/deed.nl"

// +kubebuilder:validation:MinLength:=1
AccessConstraints string `json:"accessConstraints"`
AccessConstraints *string `json:"accessConstraints,omitempty"`

// Default CRS (DataEPSG)
// +kubebuilder:validation:Pattern:="^EPSG:(28992|25831|25832|3034|3035|3857|4258|4326)$"
Expand Down Expand Up @@ -218,7 +216,7 @@ func (wfs *WFS) PodSpecPatch() *corev1.PodSpec {
return wfs.Spec.PodSpecPatch
}

func (wfs *WFS) HorizontalPodAutoscalerPatch() *autoscalingv2.HorizontalPodAutoscalerSpec {
func (wfs *WFS) HorizontalPodAutoscalerPatch() *HorizontalPodAutoscalerPatch {
return wfs.Spec.HorizontalPodAutoscalerPatch
}

Expand Down
79 changes: 46 additions & 33 deletions api/v3/wms_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ package v3

import (
shared_model "github.com/pdok/smooth-operator/model"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"maps"
Expand Down Expand Up @@ -55,7 +54,7 @@ type WMSSpec struct {
PodSpecPatch *corev1.PodSpec `json:"podSpecPatch,omitempty"`

// Optional specification for the HorizontalAutoscaler
HorizontalPodAutoscalerPatch *autoscalingv2.HorizontalPodAutoscalerSpec `json:"horizontalPodAutoscalerPatch,omitempty"`
HorizontalPodAutoscalerPatch *HorizontalPodAutoscalerPatch `json:"horizontalPodAutoscalerPatch,omitempty"`

// Optional options for the configuration of the service.
Options Options `json:"options,omitempty"`
Expand Down Expand Up @@ -92,7 +91,7 @@ type WMSService struct {
// AccessConstraints (licence) that are applicable to the service
// +kubebuilder:validation:Pattern:=`https?://.*`
// +kubebuilder:default="https://creativecommons.org/publicdomain/zero/1.0/deed.nl"
AccessConstraints string `json:"accessConstraints,omitempty"`
AccessConstraints *string `json:"accessConstraints,omitempty"`

// TODO??
MaxSize *int32 `json:"maxSize,omitempty"`
Expand Down Expand Up @@ -139,6 +138,7 @@ type ConfigMapRef struct {
}

// +kubebuilder:validation:XValidation:message="A layer should have sublayers or data, not both", rule="(has(self.data) || has(self.layers)) && !(has(self.data) && has(self.layers))"
// +kubebuilder:validation:XValidation:message="A layer should have keywords when visible", rule="!self.visible || has(self.keywords)"
type Layer struct {
// Name of the layer, required for layers on the 2nd or 3rd level
// +kubebuilder:validations:MinLength:=1
Expand All @@ -152,9 +152,9 @@ type Layer struct {
// +kubebuilder:validations:MinLength:=1
Abstract *string `json:"abstract,omitempty"`

// Keywords of the layer
// Keywords of the layer, required if the layer is visible
// +kubebuilder:validations:MinItems:=1
Keywords []string `json:"keywords"`
Keywords []string `json:"keywords,omitempty"`

// BoundingBoxes of the layer. If omitted the boundingboxes of the parent layer of the service is used.
BoundingBoxes []WMSBoundingBox `json:"boundingBoxes,omitempty"`
Expand All @@ -170,11 +170,11 @@ type Layer struct {
DatasetMetadataURL *MetadataURL `json:"datasetMetadataUrl,omitempty"`

// The minimum scale at which this layer functions
// +kubebuilder:validation:Pattern:=`^[1-9][0-9]*(.[0-9]+)$`
// +kubebuilder:validation:Pattern:=`^[0-9]+(.[0-9]+)?$`
MinScaleDenominator *string `json:"minscaledenominator,omitempty"`

// The maximum scale at which this layer functions
// +kubebuilder:validation:Pattern:=`^[1-9][0-9]*(.[0-9]+)$`
// +kubebuilder:validation:Pattern:=`^[1-9][0-9]*(.[0-9]+)?$`
MaxScaleDenominator *string `json:"maxscaledenominator,omitempty"`

// List of styles used by the layer
Expand Down Expand Up @@ -313,39 +313,38 @@ type AnnotatedLayer struct {
func (wmsService *WMSService) GetAnnotatedLayers() []AnnotatedLayer {
result := make([]AnnotatedLayer, 0)

topLayer := wmsService.Layer
annotatedTopLayer := AnnotatedLayer{
GroupName: nil,
IsTopLayer: true,
IsGroupLayer: topLayer.Name != nil,
IsDataLayer: false,
Layer: topLayer,
firstLayer := AnnotatedLayer{}
if wmsService.Layer.Name != nil && len(*wmsService.Layer.Name) > 0 {
firstLayer = AnnotatedLayer{
GroupName: nil,
IsTopLayer: wmsService.Layer.IsTopLayer(),
IsGroupLayer: wmsService.Layer.IsGroupLayer(),
IsDataLayer: wmsService.Layer.IsDataLayer(),
Layer: wmsService.Layer,
}
result = append(result, firstLayer)
}
result = append(result, annotatedTopLayer)

for _, topLayerChild := range topLayer.Layers {
groupName := topLayer.Name
isGroupLayer := topLayerChild.Layers != nil && len(topLayerChild.Layers) > 0
for _, subLayer := range wmsService.Layer.Layers {
groupName := wmsService.Layer.Name
isGroupLayer := subLayer.IsGroupLayer()
isDataLayer := !isGroupLayer
result = append(result, AnnotatedLayer{
GroupName: groupName,
IsTopLayer: false,
IsGroupLayer: isGroupLayer,
IsDataLayer: isDataLayer,
Layer: topLayerChild,
Layer: subLayer,
})

if len(topLayerChild.Layers) > 0 {
for _, middleLayerChild := range topLayerChild.Layers {
groupName = topLayerChild.Name
result = append(result, AnnotatedLayer{
GroupName: groupName,
IsTopLayer: false,
IsGroupLayer: false,
IsDataLayer: true,
Layer: middleLayerChild,
})
}
for _, subSubLayer := range subLayer.Layers {
result = append(result, AnnotatedLayer{
GroupName: subLayer.Name,
IsTopLayer: false,
IsGroupLayer: false,
IsDataLayer: true,
Layer: subSubLayer,
})
}
}

Expand Down Expand Up @@ -423,8 +422,22 @@ func (layer *Layer) IsGroupLayer() bool {
return len(layer.Layers) > 0
}

func (layer *Layer) IsTopLayer(service *WMSService) bool {
return layer.Name == service.Layer.Name
// IsTopLayer - a layer is a toplayer if and only if it has sublayers that are group layers.
// In other words the layer is level 1 in a 3 level hierarchy.
func (layer *Layer) IsTopLayer() bool {
if layer.IsGroupLayer() {
for _, childLayer := range layer.Layers {
if childLayer.IsGroupLayer() {
return true
}
}
}

return false
}

func (layer *Layer) IsVisible() bool {
return layer.Visible == nil || *layer.Visible
}

func (layer *Layer) hasBoundingBoxForCRS(crs string) bool {
Expand Down Expand Up @@ -523,7 +536,7 @@ func (wms *WMS) PodSpecPatch() *corev1.PodSpec {
return wms.Spec.PodSpecPatch
}

func (wms *WMS) HorizontalPodAutoscalerPatch() *autoscalingv2.HorizontalPodAutoscalerSpec {
func (wms *WMS) HorizontalPodAutoscalerPatch() *HorizontalPodAutoscalerPatch {
return wms.Spec.HorizontalPodAutoscalerPatch
}

Expand Down
Loading
Loading