Skip to content

Commit eb8fa3e

Browse files
author
Jelle Dijkstra
committed
Small chances for CR template conversion
1 parent 9fa2567 commit eb8fa3e

File tree

11 files changed

+117
-132
lines changed

11 files changed

+117
-132
lines changed

api/v2beta1/shared_conversion.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func ConvertOptionsV3ToV2(src *pdoknlv3.Options) WMSWFSOptions {
4545
}
4646
}
4747

48-
func ConvertAutoscaling(src Autoscaling) *autoscalingv2.HorizontalPodAutoscalerSpec {
48+
func ConvertAutoscaling(src Autoscaling) *pdoknlv3.HorizontalPodAutoscalerPatch {
4949
var minReplicas *int32
5050
if src.MinReplicas != nil {
5151
//nolint:gosec
@@ -71,7 +71,7 @@ func ConvertAutoscaling(src Autoscaling) *autoscalingv2.HorizontalPodAutoscalerS
7171
})
7272
}
7373

74-
return &autoscalingv2.HorizontalPodAutoscalerSpec{
74+
return &pdoknlv3.HorizontalPodAutoscalerPatch{
7575
MinReplicas: minReplicas,
7676
MaxReplicas: maxReplicas,
7777
Metrics: metrics,
@@ -196,7 +196,7 @@ func ConvertV3DataToV2(v3 pdoknlv3.Data) Data {
196196
return v2
197197
}
198198

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

202202
if lifecycle != nil && lifecycle.TTLInDays != nil {

api/v2beta1/wfs_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type WFSService struct {
6666
Inspire bool `json:"inspire"`
6767
Abstract string `json:"abstract"`
6868
// +kubebuilder:default="https://creativecommons.org/publicdomain/zero/1.0/deed.nl"
69-
AccessConstraints string `json:"accessConstraints"`
69+
AccessConstraints *string `json:"accessConstraints,omitempty"`
7070
Keywords []string `json:"keywords"`
7171
MetadataIdentifier string `json:"metadataIdentifier"`
7272
Authority Authority `json:"authority"`

api/v2beta1/wms_conversion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ func (v2Layer WMSLayer) MapToV3(v2Service WMSService) pdoknlv3.Layer {
360360
BoundingBoxes: []pdoknlv3.WMSBoundingBox{},
361361
MinScaleDenominator: nil,
362362
MaxScaleDenominator: nil,
363-
Visible: &v2Layer.Visible,
363+
Visible: v2Layer.Visible,
364364
}
365365

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

446-
v2Layer.Visible = *v3Layer.Visible
446+
v2Layer.Visible = v3Layer.Visible
447447

448448
if parent != nil {
449449
v2Layer.Group = parent.Name

api/v2beta1/wms_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type WMSService struct {
5858
Title string `json:"title"`
5959
Abstract string `json:"abstract"`
6060
// +kubebuilder:default="https://creativecommons.org/publicdomain/zero/1.0/deed.nl"
61-
AccessConstraints string `json:"accessConstraints"`
61+
AccessConstraints *string `json:"accessConstraints,omitempty"` // Pointer for CRD conversion as defaulting is not applied there
6262
Keywords []string `json:"keywords"`
6363
MetadataIdentifier string `json:"metadataIdentifier"`
6464
Authority Authority `json:"authority"`
@@ -77,7 +77,7 @@ type WMSService struct {
7777
type WMSLayer struct {
7878
Name string `json:"name"`
7979
Group *string `json:"group,omitempty"`
80-
Visible bool `json:"visible"`
80+
Visible *bool `json:"visible,omitempty"`
8181
Title *string `json:"title,omitempty"`
8282
Abstract *string `json:"abstract,omitempty"`
8383
Keywords []string `json:"keywords,omitempty"`

api/v2beta1/zz_generated.deepcopy.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v3/shared_types.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ const (
2222
ServiceTypeWFS ServiceType = "WFS"
2323
)
2424

25+
// HorizontalPodAutoscalerPatch - copy of autoscalingv2.HorizontalPodAutoscalerSpec without ScaleTargetRef
26+
// This way we don't have to specify the scaleTargetRef field in the CRD.
27+
type HorizontalPodAutoscalerPatch struct {
28+
MinReplicas *int32 `json:"minReplicas,omitempty"`
29+
MaxReplicas int32 `json:"maxReplicas"`
30+
Metrics []autoscalingv2.MetricSpec `json:"metrics,omitempty"`
31+
Behavior *autoscalingv2.HorizontalPodAutoscalerBehavior `json:"behavior,omitempty"`
32+
}
33+
2534
// WMSWFS is the common interface used for both WMS and WFS resources.
2635
// +kubebuilder:object:generate=false
2736
type WMSWFS interface {
@@ -30,7 +39,7 @@ type WMSWFS interface {
3039

3140
Mapfile() *Mapfile
3241
PodSpecPatch() *corev1.PodSpec
33-
HorizontalPodAutoscalerPatch() *autoscalingv2.HorizontalPodAutoscalerSpec
42+
HorizontalPodAutoscalerPatch() *HorizontalPodAutoscalerPatch
3443
Type() ServiceType
3544
Options() *Options
3645
HasPostgisData() bool
@@ -182,7 +191,7 @@ type Postgis struct {
182191
// +kubebuilder:validation:Type=object
183192
type TIF struct {
184193
// BlobKey to the TIFF file
185-
// +kubebuilder:validation:Pattern=`\.(tif|tiff)$`
194+
// +kubebuilder:validation:Pattern=`\.(tif?f|vrt)$`
186195
// +kubebuilder:validation:MinLength:=1
187196
BlobKey string `json:"blobKey"`
188197

api/v3/wfs_types.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ package v3
2626

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

8079
// service configuration
8180
Service WFSService `json:"service"`
@@ -120,9 +119,8 @@ type WFSService struct {
120119
// AccessConstraints URL
121120
// +kubebuilder:validation:Pattern:="https?://"
122121
// +kubebuilder:default="https://creativecommons.org/publicdomain/zero/1.0/deed.nl"
123-
124122
// +kubebuilder:validation:MinLength:=1
125-
AccessConstraints string `json:"accessConstraints"`
123+
AccessConstraints *string `json:"accessConstraints,omitempty"`
126124

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

221-
func (wfs *WFS) HorizontalPodAutoscalerPatch() *autoscalingv2.HorizontalPodAutoscalerSpec {
219+
func (wfs *WFS) HorizontalPodAutoscalerPatch() *HorizontalPodAutoscalerPatch {
222220
return wfs.Spec.HorizontalPodAutoscalerPatch
223221
}
224222

api/v3/wms_types.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ package v3
2626

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

5756
// Optional specification for the HorizontalAutoscaler
58-
HorizontalPodAutoscalerPatch *autoscalingv2.HorizontalPodAutoscalerSpec `json:"horizontalPodAutoscalerPatch,omitempty"`
57+
HorizontalPodAutoscalerPatch *HorizontalPodAutoscalerPatch `json:"horizontalPodAutoscalerPatch,omitempty"`
5958

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

9796
// TODO??
9897
MaxSize *int32 `json:"maxSize,omitempty"`
@@ -139,6 +138,7 @@ type ConfigMapRef struct {
139138
}
140139

141140
// +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))"
141+
// +kubebuilder:validation:XValidation:message="A layer should have keywords when visible", rule="!self.visible || has(self.keywords)"
142142
type Layer struct {
143143
// Name of the layer, required for layers on the 2nd or 3rd level
144144
// +kubebuilder:validations:MinLength:=1
@@ -152,9 +152,9 @@ type Layer struct {
152152
// +kubebuilder:validations:MinLength:=1
153153
Abstract *string `json:"abstract,omitempty"`
154154

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

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

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

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

180180
// List of styles used by the layer
@@ -523,7 +523,7 @@ func (wms *WMS) PodSpecPatch() *corev1.PodSpec {
523523
return wms.Spec.PodSpecPatch
524524
}
525525

526-
func (wms *WMS) HorizontalPodAutoscalerPatch() *autoscalingv2.HorizontalPodAutoscalerSpec {
526+
func (wms *WMS) HorizontalPodAutoscalerPatch() *HorizontalPodAutoscalerPatch {
527527
return wms.Spec.HorizontalPodAutoscalerPatch
528528
}
529529

api/v3/zz_generated.deepcopy.go

Lines changed: 44 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)