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
55 changes: 23 additions & 32 deletions api/v2beta1/shared_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,47 @@

pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
shared_model "github.com/pdok/smooth-operator/model"
smoothoperatorutils "github.com/pdok/smooth-operator/pkg/util"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
)

func Pointer[T interface{}](val T) *T {
return &val
}

func PointerVal[T interface{}](val *T, def T) T {
if val == nil {
return def
}

return *val
}
func ConvertOptionsV2ToV3(src WMSWFSOptions) pdoknlv3.Options {
defaults := pdoknlv3.GetDefaultOptions()

func ConvertOptionsV2ToV3(src WMSWFSOptions) *pdoknlv3.Options {
return &pdoknlv3.Options{
return pdoknlv3.Options{
AutomaticCasing: src.AutomaticCasing,
IncludeIngress: src.IncludeIngress,
PrefetchData: src.PrefetchData,
ValidateRequests: src.ValidateRequests,
RewriteGroupToDataLayers: src.RewriteGroupToDataLayers,
DisableWebserviceProxy: src.DisableWebserviceProxy,
ValidateChildStyleNameEqual: src.ValidateChildStyleNameEqual,
PrefetchData: smoothoperatorutils.PointerVal(src.PrefetchData, defaults.PrefetchData),
ValidateRequests: smoothoperatorutils.PointerVal(src.ValidateRequests, defaults.ValidateRequests),
RewriteGroupToDataLayers: smoothoperatorutils.PointerVal(src.RewriteGroupToDataLayers, defaults.RewriteGroupToDataLayers),
DisableWebserviceProxy: smoothoperatorutils.PointerVal(src.DisableWebserviceProxy, defaults.DisableWebserviceProxy),
ValidateChildStyleNameEqual: smoothoperatorutils.PointerVal(src.ValidateChildStyleNameEqual, defaults.ValidateChildStyleNameEqual),
}
}

func ConvertOptionsV3ToV2(src *pdoknlv3.Options) WMSWFSOptions {
func ConvertOptionsV3ToV2(src pdoknlv3.Options) WMSWFSOptions {
return WMSWFSOptions{
AutomaticCasing: src.AutomaticCasing,
PrefetchData: src.PrefetchData,
IncludeIngress: src.IncludeIngress,
ValidateRequests: src.ValidateRequests,
RewriteGroupToDataLayers: src.RewriteGroupToDataLayers,
DisableWebserviceProxy: src.DisableWebserviceProxy,
ValidateChildStyleNameEqual: src.ValidateChildStyleNameEqual,
PrefetchData: &src.PrefetchData,
ValidateRequests: &src.ValidateRequests,
RewriteGroupToDataLayers: &src.RewriteGroupToDataLayers,
DisableWebserviceProxy: &src.DisableWebserviceProxy,
ValidateChildStyleNameEqual: &src.ValidateChildStyleNameEqual,
}
}

func ConvertAutoscaling(src Autoscaling) *pdoknlv3.HorizontalPodAutoscalerPatch {
var minReplicas *int32
if src.MinReplicas != nil {
//nolint:gosec
minReplicas = Pointer(int32(*src.MinReplicas))
minReplicas = smoothoperatorutils.Pointer(int32(*src.MinReplicas))
}

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

Check failure on line 48 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 48 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,7 +56,7 @@
Name: corev1.ResourceCPU,
Target: autoscalingv2.MetricTarget{
Type: autoscalingv2.UtilizationMetricType,
AverageUtilization: Pointer(int32(*src.AverageCPUUtilization)),
AverageUtilization: smoothoperatorutils.Pointer(int32(*src.AverageCPUUtilization)),

Check failure on line 59 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 59 in api/v2beta1/shared_conversion.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

G115: integer overflow conversion int -> int32 (gosec)
},
},
})
Expand Down Expand Up @@ -164,7 +155,7 @@
BlobKey: v2.Tif.BlobKey,
Resample: v2.Tif.Resample,
Offsite: v2.Tif.Offsite,
GetFeatureInfoIncludesClass: v2.Tif.GetFeatureInfoIncludesClass,
GetFeatureInfoIncludesClass: smoothoperatorutils.PointerVal(v2.Tif.GetFeatureInfoIncludesClass, false),
}
}

Expand Down Expand Up @@ -200,7 +191,7 @@
BlobKey: v3.TIF.BlobKey,
Offsite: v3.TIF.Offsite,
Resample: v3.TIF.Resample,
GetFeatureInfoIncludesClass: v3.TIF.GetFeatureInfoIncludesClass,
GetFeatureInfoIncludesClass: &v3.TIF.GetFeatureInfoIncludesClass,
}
}

Expand All @@ -212,7 +203,7 @@

if lifecycle != nil && lifecycle.TTLInDays != nil {
kub.Lifecycle = &Lifecycle{
TTLInDays: Pointer(int(*lifecycle.TTLInDays)),
TTLInDays: smoothoperatorutils.Pointer(int(*lifecycle.TTLInDays)),
}
}

Expand All @@ -223,15 +214,15 @@

if scalingSpec != nil {
kub.Autoscaling = &Autoscaling{
MaxReplicas: Pointer(int(scalingSpec.MaxReplicas)),
MaxReplicas: smoothoperatorutils.Pointer(int(scalingSpec.MaxReplicas)),
}

if scalingSpec.MinReplicas != nil {
kub.Autoscaling.MinReplicas = Pointer(int(*scalingSpec.MinReplicas))
kub.Autoscaling.MinReplicas = smoothoperatorutils.Pointer(int(*scalingSpec.MinReplicas))
}

if scalingSpec.Metrics != nil {
kub.Autoscaling.AverageCPUUtilization = Pointer(
kub.Autoscaling.AverageCPUUtilization = smoothoperatorutils.Pointer(
int(*scalingSpec.Metrics[0].Resource.Target.AverageUtilization),
)
}
Expand Down
14 changes: 9 additions & 5 deletions api/v2beta1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,15 @@ type Lifecycle struct {

// WMSWFSOptions is the struct with options available in the operator
type WMSWFSOptions struct {
IncludeIngress bool `json:"includeIngress"`
AutomaticCasing bool `json:"automaticCasing"`
ValidateRequests *bool `json:"validateRequests,omitempty"`
RewriteGroupToDataLayers *bool `json:"rewriteGroupToDataLayers,omitempty"`
DisableWebserviceProxy *bool `json:"disableWebserviceProxy,omitempty"`
// +kubebuilder:default:=true
IncludeIngress bool `json:"includeIngress"`
// +kubebuilder:default:=true
AutomaticCasing bool `json:"automaticCasing"`
// +kubebuilder:default:=true
ValidateRequests *bool `json:"validateRequests,omitempty"`
RewriteGroupToDataLayers *bool `json:"rewriteGroupToDataLayers,omitempty"`
DisableWebserviceProxy *bool `json:"disableWebserviceProxy,omitempty"`
// +kubebuilder:default:=true
PrefetchData *bool `json:"prefetchData,omitempty"`
ValidateChildStyleNameEqual *bool `json:"validateChildStyleNameEqual,omitempty"`
}
Expand Down
13 changes: 7 additions & 6 deletions api/v2beta1/wfs_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package v2beta1

import (
smoothoperatorutils "github.com/pdok/smooth-operator/pkg/util"
"log"

sharedModel "github.com/pdok/smooth-operator/model"
Expand All @@ -49,7 +50,7 @@
// Set LifeCycle if defined
if src.Spec.Kubernetes.Lifecycle != nil && src.Spec.Kubernetes.Lifecycle.TTLInDays != nil {
dst.Spec.Lifecycle = &sharedModel.Lifecycle{
TTLInDays: Pointer(int32(*src.Spec.Kubernetes.Lifecycle.TTLInDays)),
TTLInDays: smoothoperatorutils.Pointer(int32(*src.Spec.Kubernetes.Lifecycle.TTLInDays)),

Check failure on line 53 in api/v2beta1/wfs_conversion.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

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

Expand All @@ -62,7 +63,7 @@
dst.Spec.PodSpecPatch = ConvertResources(*src.Spec.Kubernetes.Resources)
}

dst.Spec.Options = *ConvertOptionsV2ToV3(src.Spec.Options)
dst.Spec.Options = ConvertOptionsV2ToV3(src.Spec.Options)

service := pdoknlv3.WFSService{
// TODO what is prefix, Geonovum subdomain?
Expand Down Expand Up @@ -162,7 +163,7 @@

dst.Spec.Kubernetes = NewV2KubernetesObject(src.Spec.Lifecycle, src.Spec.PodSpecPatch, src.Spec.HorizontalPodAutoscalerPatch)

dst.Spec.Options = ConvertOptionsV3ToV2(&src.Spec.Options)
dst.Spec.Options = ConvertOptionsV3ToV2(src.Spec.Options)

service := WFSService{
Title: src.Spec.Service.Title,
Expand All @@ -178,9 +179,9 @@
}

if src.Spec.Service.Bbox != nil {
service.Extent = Pointer(src.Spec.Service.Bbox.DefaultCRS.ToExtent())
service.Extent = smoothoperatorutils.Pointer(src.Spec.Service.Bbox.DefaultCRS.ToExtent())
} else {
service.Extent = Pointer("-25000 250000 280000 860000")
service.Extent = smoothoperatorutils.Pointer("-25000 250000 280000 860000")
}

if src.Spec.Service.Mapfile != nil {
Expand Down Expand Up @@ -213,7 +214,7 @@
}

if featureType.Bbox != nil {
featureTypeV2.Extent = Pointer(featureType.Bbox.DefaultCRS.ToExtent())
featureTypeV2.Extent = smoothoperatorutils.Pointer(featureType.Bbox.DefaultCRS.ToExtent())
}

service.FeatureTypes = append(service.FeatureTypes, featureTypeV2)
Expand Down
43 changes: 21 additions & 22 deletions api/v2beta1/wms_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (src *WMS) ToV3(target *pdoknlv3.WMS) {
// Set LifeCycle if defined
if src.Spec.Kubernetes.Lifecycle != nil && src.Spec.Kubernetes.Lifecycle.TTLInDays != nil {
dst.Spec.Lifecycle = &sharedModel.Lifecycle{
TTLInDays: Pointer(int32(*src.Spec.Kubernetes.Lifecycle.TTLInDays)),
TTLInDays: smoothoperatorutils.Pointer(int32(*src.Spec.Kubernetes.Lifecycle.TTLInDays)),
}
}

Expand All @@ -72,16 +72,15 @@ func (src *WMS) ToV3(target *pdoknlv3.WMS) {
dst.Spec.PodSpecPatch = ConvertResources(*src.Spec.Kubernetes.Resources)
}

dst.Spec.Options = *ConvertOptionsV2ToV3(src.Spec.Options)
dst.Spec.Options = ConvertOptionsV2ToV3(src.Spec.Options)

service := pdoknlv3.WMSService{
URL: CreateBaseURL("https://service.pdok.nl", "wms", src.Spec.General),
OwnerInfoRef: "pdok",
Title: src.Spec.Service.Title,
Abstract: src.Spec.Service.Abstract,
Keywords: src.Spec.Service.Keywords,
Fees: nil,
AccessConstraints: src.Spec.Service.AccessConstraints,
AccessConstraints: smoothoperatorutils.PointerVal(src.Spec.Service.AccessConstraints, "https://creativecommons.org/publicdomain/zero/1.0/deed.nl"),
MaxSize: nil,
Resolution: nil,
DefResolution: nil,
Expand All @@ -91,15 +90,15 @@ func (src *WMS) ToV3(target *pdoknlv3.WMS) {
}

if src.Spec.Service.Maxsize != nil {
service.MaxSize = Pointer(int32(*src.Spec.Service.Maxsize))
service.MaxSize = smoothoperatorutils.Pointer(int32(*src.Spec.Service.Maxsize))
}

if src.Spec.Service.Resolution != nil {
service.Resolution = Pointer(int32(*src.Spec.Service.Resolution))
service.Resolution = smoothoperatorutils.Pointer(int32(*src.Spec.Service.Resolution))
}

if src.Spec.Service.DefResolution != nil {
service.DefResolution = Pointer(int32(*src.Spec.Service.DefResolution))
service.DefResolution = smoothoperatorutils.Pointer(int32(*src.Spec.Service.DefResolution))
}

if src.Spec.Service.Mapfile != nil {
Expand Down Expand Up @@ -154,13 +153,13 @@ func (dst *WMS) ConvertFrom(srcRaw conversion.Hub) error {

dst.Spec.Kubernetes = NewV2KubernetesObject(src.Spec.Lifecycle, src.Spec.PodSpecPatch, src.Spec.HorizontalPodAutoscalerPatch)

dst.Spec.Options = ConvertOptionsV3ToV2(&src.Spec.Options)
dst.Spec.Options = ConvertOptionsV3ToV2(src.Spec.Options)

service := WMSService{
Title: src.Spec.Service.Title,
Abstract: src.Spec.Service.Abstract,
Keywords: src.Spec.Service.Keywords,
AccessConstraints: src.Spec.Service.AccessConstraints,
AccessConstraints: &src.Spec.Service.AccessConstraints,
Extent: nil,
DataEPSG: src.Spec.Service.DataEPSG,
Layers: []WMSLayer{},
Expand All @@ -187,11 +186,11 @@ func (dst *WMS) ConvertFrom(srcRaw conversion.Hub) error {
}

if src.Spec.Service.DefResolution != nil {
service.DefResolution = Pointer(int(*src.Spec.Service.DefResolution))
service.DefResolution = smoothoperatorutils.Pointer(int(*src.Spec.Service.DefResolution))
}

if src.Spec.Service.Resolution != nil {
service.Resolution = Pointer(int(*src.Spec.Service.Resolution))
service.Resolution = smoothoperatorutils.Pointer(int(*src.Spec.Service.Resolution))
}

if src.Spec.Service.StylingAssets != nil {
Expand All @@ -216,7 +215,7 @@ func (dst *WMS) ConvertFrom(srcRaw conversion.Hub) error {
}

if src.Spec.Service.MaxSize != nil {
service.Maxsize = Pointer(float64(*src.Spec.Service.MaxSize))
service.Maxsize = smoothoperatorutils.Pointer(float64(*src.Spec.Service.MaxSize))
}

service.Layers = mapV3LayerToV2Layers(src.Spec.Service.Layer, nil, src.Spec.Service.DataEPSG)
Expand All @@ -227,9 +226,9 @@ func (dst *WMS) ConvertFrom(srcRaw conversion.Hub) error {
if service.Extent == nil {
service.Extent = l.Extent
} else {
bbox := Pointer(sharedModel.ExtentToBBox(*service.Extent)).DeepCopy()
bbox := smoothoperatorutils.Pointer(sharedModel.ExtentToBBox(*service.Extent)).DeepCopy()
bbox.Combine(sharedModel.ExtentToBBox(*l.Extent))
service.Extent = Pointer(bbox.ToExtent())
service.Extent = smoothoperatorutils.Pointer(bbox.ToExtent())
}
}
}
Expand Down Expand Up @@ -322,7 +321,7 @@ func (v2Service WMSService) MapLayersToV3() pdoknlv3.Layer {
Keywords: v2Service.Keywords,
Layers: []pdoknlv3.Layer{},
BoundingBoxes: boundingBoxes,
Visible: smoothoperatorutils.Pointer(true),
Visible: true,
}

// adding the bottom layers to the middle layers they are grouped by
Expand Down Expand Up @@ -361,7 +360,7 @@ func (v2Layer WMSLayer) MapToV3(v2Service WMSService) pdoknlv3.Layer {
BoundingBoxes: []pdoknlv3.WMSBoundingBox{},
MinScaleDenominator: nil,
MaxScaleDenominator: nil,
Visible: v2Layer.Visible,
Visible: smoothoperatorutils.PointerVal(v2Layer.Visible, true),
}

if v2Layer.SourceMetadataIdentifier != nil {
Expand Down Expand Up @@ -393,11 +392,11 @@ func (v2Layer WMSLayer) MapToV3(v2Service WMSService) pdoknlv3.Layer {
}

if v2Layer.MinScale != nil {
layer.MinScaleDenominator = Pointer(strconv.FormatFloat(*v2Layer.MinScale, 'f', -1, 64))
layer.MinScaleDenominator = smoothoperatorutils.Pointer(strconv.FormatFloat(*v2Layer.MinScale, 'f', -1, 64))
}

if v2Layer.MaxScale != nil {
layer.MaxScaleDenominator = Pointer(strconv.FormatFloat(*v2Layer.MaxScale, 'f', -1, 64))
layer.MaxScaleDenominator = smoothoperatorutils.Pointer(strconv.FormatFloat(*v2Layer.MaxScale, 'f', -1, 64))
}

for _, style := range v2Layer.Styles {
Expand All @@ -418,7 +417,7 @@ func (v2Layer WMSLayer) MapToV3(v2Service WMSService) pdoknlv3.Layer {
}

if v2Layer.Data != nil {
layer.Data = Pointer(ConvertV2DataToV3(*v2Layer.Data))
layer.Data = smoothoperatorutils.Pointer(ConvertV2DataToV3(*v2Layer.Data))
}

return layer
Expand All @@ -444,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 All @@ -460,7 +459,7 @@ func mapV3LayerToV2Layers(v3Layer pdoknlv3.Layer, parent *pdoknlv3.Layer, servic

for _, bb := range v3Layer.BoundingBoxes {
if bb.CRS == serviceEPSG {
v2Layer.Extent = Pointer(bb.BBox.ToExtent())
v2Layer.Extent = smoothoperatorutils.Pointer(bb.BBox.ToExtent())
}
}

Expand Down Expand Up @@ -498,7 +497,7 @@ func mapV3LayerToV2Layers(v3Layer pdoknlv3.Layer, parent *pdoknlv3.Layer, servic
}

if v3Layer.Data != nil {
v2Layer.Data = Pointer(ConvertV3DataToV2(*v3Layer.Data))
v2Layer.Data = smoothoperatorutils.Pointer(ConvertV3DataToV2(*v3Layer.Data))
}

layers = append(layers, v2Layer)
Expand Down
Loading
Loading