Skip to content

Commit a3895c2

Browse files
committed
Resolve conflicts and merge
2 parents eaf9d3e + 97f2781 commit a3895c2

28 files changed

+1589
-447
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ help: ## Display this help.
4444
.PHONY: manifests
4545
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
4646
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:allowDangerousTypes=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases
47+
## allowDangerousTypes=true for v2beta structs
4748

4849
.PHONY: generate
4950
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.

PROJECT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ resources:
3333
conversion: true
3434
spoke:
3535
- v2beta1
36+
validation: true
3637
webhookVersion: v1
3738
- api:
3839
crdVersion: v1

api/v2beta1/shared_conversion.go

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

33
import (
4+
"fmt"
45
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
6+
shared_model "github.com/pdok/smooth-operator/model"
57
autoscalingv2 "k8s.io/api/autoscaling/v2beta1"
68
corev1 "k8s.io/api/core/v1"
79
)
@@ -10,12 +12,36 @@ func Pointer[T interface{}](val T) *T {
1012
return &val
1113
}
1214

13-
func PointerValWithDefault[T interface{}](ptr *T, defaultValue T) T {
14-
if ptr == nil {
15-
return defaultValue
15+
func PointerVal[T interface{}](val *T, def T) T {
16+
if val == nil {
17+
return def
18+
} else {
19+
return *val
1620
}
21+
}
22+
23+
func ConverseOptionsV2ToV3(src WMSWFSOptions) *pdoknlv3.Options {
24+
return &pdoknlv3.Options{
25+
AutomaticCasing: src.AutomaticCasing,
26+
IncludeIngress: src.IncludeIngress,
27+
PrefetchData: src.PrefetchData,
28+
ValidateRequests: src.ValidateRequests,
29+
RewriteGroupToDataLayers: src.RewriteGroupToDataLayers,
30+
DisableWebserviceProxy: src.DisableWebserviceProxy,
31+
ValidateChildStyleNameEqual: src.ValidateChildStyleNameEqual,
32+
}
33+
}
1734

18-
return *ptr
35+
func ConverseOptionsV3ToV2(src *pdoknlv3.Options) WMSWFSOptions {
36+
return WMSWFSOptions{
37+
AutomaticCasing: src.AutomaticCasing,
38+
PrefetchData: src.PrefetchData,
39+
IncludeIngress: src.IncludeIngress,
40+
ValidateRequests: src.ValidateRequests,
41+
RewriteGroupToDataLayers: src.RewriteGroupToDataLayers,
42+
DisableWebserviceProxy: src.DisableWebserviceProxy,
43+
ValidateChildStyleNameEqual: src.ValidateChildStyleNameEqual,
44+
}
1945
}
2046

2147
func ConverseAutoscaling(src Autoscaling) *autoscalingv2.HorizontalPodAutoscalerSpec {
@@ -89,3 +115,142 @@ func ConverseColumnsWithAliasV3ToColumnsAndAliasesV2(columns []pdoknlv3.Columns)
89115

90116
return v2Columns, v2Aliases
91117
}
118+
119+
func ConverseV2DataToV3(v2 Data) pdoknlv3.Data {
120+
v3 := pdoknlv3.Data{}
121+
122+
if v2.GPKG != nil {
123+
v3.Gpkg = &pdoknlv3.Gpkg{
124+
BlobKey: v2.GPKG.BlobKey,
125+
TableName: v2.GPKG.Table,
126+
GeometryType: v2.GPKG.GeometryType,
127+
Columns: ConverseColumnAndAliasesV2ToColumnsWithAliasV3(
128+
v2.GPKG.Columns,
129+
v2.GPKG.Aliases,
130+
),
131+
}
132+
}
133+
134+
if v2.Postgis != nil {
135+
v3.Postgis = &pdoknlv3.Postgis{
136+
TableName: v2.Postgis.Table,
137+
GeometryType: v2.Postgis.GeometryType,
138+
Columns: ConverseColumnAndAliasesV2ToColumnsWithAliasV3(
139+
v2.Postgis.Columns,
140+
v2.Postgis.Aliases,
141+
),
142+
}
143+
}
144+
145+
if v2.Tif != nil {
146+
v3.TIF = &pdoknlv3.TIF{
147+
BlobKey: v2.Tif.BlobKey,
148+
Resample: v2.Tif.Resample,
149+
Offsite: v2.Tif.Offsite,
150+
GetFeatureInfoIncludesClass: v2.Tif.GetFeatureInfoIncludesClass,
151+
}
152+
}
153+
154+
return v3
155+
}
156+
157+
func ConverseV3DataToV2(v3 pdoknlv3.Data) Data {
158+
v2 := Data{}
159+
160+
if v3.Gpkg != nil {
161+
columns, aliases := ConverseColumnsWithAliasV3ToColumnsAndAliasesV2(v3.Gpkg.Columns)
162+
v2.GPKG = &GPKG{
163+
BlobKey: v3.Gpkg.BlobKey,
164+
Table: v3.Gpkg.TableName,
165+
GeometryType: v3.Gpkg.GeometryType,
166+
Columns: columns,
167+
Aliases: aliases,
168+
}
169+
}
170+
171+
if v3.Postgis != nil {
172+
columns, aliases := ConverseColumnsWithAliasV3ToColumnsAndAliasesV2(v3.Postgis.Columns)
173+
v2.Postgis = &Postgis{
174+
Table: v3.Postgis.TableName,
175+
GeometryType: v3.Postgis.GeometryType,
176+
Columns: columns,
177+
Aliases: aliases,
178+
}
179+
}
180+
181+
if v3.TIF != nil {
182+
v2.Tif = &Tif{
183+
BlobKey: v3.TIF.BlobKey,
184+
Offsite: v3.TIF.Offsite,
185+
Resample: v3.TIF.Resample,
186+
GetFeatureInfoIncludesClass: v3.TIF.GetFeatureInfoIncludesClass,
187+
}
188+
}
189+
190+
return v2
191+
}
192+
193+
func NewV2KubernetesObject(lifecycle *shared_model.Lifecycle, podSpecPatch *corev1.PodSpec, scalingSpec *autoscalingv2.HorizontalPodAutoscalerSpec) Kubernetes {
194+
kub := Kubernetes{}
195+
196+
if lifecycle != nil && lifecycle.TTLInDays != nil {
197+
kub.Lifecycle = &Lifecycle{
198+
TTLInDays: Pointer(int(*lifecycle.TTLInDays)),
199+
}
200+
}
201+
202+
// TODO - healthcheck
203+
if podSpecPatch != nil {
204+
kub.Resources = &podSpecPatch.Containers[0].Resources
205+
}
206+
207+
if scalingSpec != nil {
208+
kub.Autoscaling = &Autoscaling{
209+
MaxReplicas: Pointer(int(scalingSpec.MaxReplicas)),
210+
}
211+
212+
if scalingSpec.MinReplicas != nil {
213+
kub.Autoscaling.MinReplicas = Pointer(int(*scalingSpec.MinReplicas))
214+
}
215+
216+
if scalingSpec.Metrics != nil {
217+
kub.Autoscaling.AverageCPUUtilization = Pointer(
218+
int(*scalingSpec.Metrics[0].Resource.TargetAverageUtilization),
219+
)
220+
}
221+
}
222+
223+
return kub
224+
}
225+
226+
func LabelsToV2General(labels map[string]string) General {
227+
general := General{
228+
Dataset: labels["dataset"],
229+
DatasetOwner: labels["dataset-owner"],
230+
DataVersion: nil,
231+
}
232+
233+
if serviceVersion, ok := labels["service-version"]; ok {
234+
general.ServiceVersion = &serviceVersion
235+
}
236+
237+
if theme, ok := labels["theme"]; ok {
238+
general.Theme = &theme
239+
}
240+
241+
return general
242+
}
243+
244+
func CreateBaseURL(host string, kind string, general General) string {
245+
URI := fmt.Sprintf("%s/%s", general.DatasetOwner, general.Dataset)
246+
if general.Theme != nil {
247+
URI += "/" + *general.Theme
248+
}
249+
URI += "/" + kind
250+
251+
if general.ServiceVersion != nil {
252+
URI += "/" + *general.ServiceVersion
253+
}
254+
255+
return fmt.Sprintf("%s/%s", host, URI)
256+
}

0 commit comments

Comments
 (0)