Skip to content

Commit 4d743b3

Browse files
Merge pull request #49 from PDOK/jd/wms-fixes
Jd/wms fixes
2 parents a448bd3 + 79a28aa commit 4d743b3

File tree

6 files changed

+114
-91
lines changed

6 files changed

+114
-91
lines changed

internal/controller/legendgenerator/legend_generator.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ func GetLegendGeneratorInitContainer(wms *pdoknlv3.WMS, image string, srvDir str
1111
Name: "legend-generator",
1212
Image: image,
1313
ImagePullPolicy: corev1.PullIfNotPresent,
14-
Env: []corev1.EnvVar{mapserver.GetMapfileEnvVar(wms)},
14+
Env: []corev1.EnvVar{
15+
{
16+
Name: "MAPSERVER_CONFIG_FILE",
17+
Value: "/srv/mapserver/config/default_mapserver.conf",
18+
},
19+
mapserver.GetMapfileEnvVar(wms),
20+
},
1521
Command: []string{
1622
"bash",
1723
"-c",
@@ -33,7 +39,6 @@ exit $exit_code;
3339
VolumeMounts: []corev1.VolumeMount{
3440
{Name: "base", MountPath: srvDir + "/data", ReadOnly: false},
3541
getDataVolumeMount(),
36-
getConfigVolumeMount(),
3742
},
3843
}
3944

@@ -45,6 +50,9 @@ exit $exit_code;
4550
initContainer.VolumeMounts = append(initContainer.VolumeMounts, volumeMount)
4651
}
4752

53+
// Adding config volumemount here to get the same order as in the old ansible operator
54+
initContainer.VolumeMounts = append(initContainer.VolumeMounts, getConfigVolumeMount())
55+
4856
return &initContainer, nil
4957
}
5058

internal/controller/mapserver/deployment.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ func GetVolumesForDeployment[O pdoknlv3.WMSWFS](obj O, configMapNames types.Hash
8585
if mapfile := obj.Mapfile(); mapfile != nil {
8686
volumes = append(volumes, v1.Volume{
8787
Name: "mapfile",
88-
VolumeSource: newVolumeSource(mapfile.ConfigMapKeyRef.Key),
88+
VolumeSource: newVolumeSource(mapfile.ConfigMapKeyRef.Name),
89+
})
90+
}
91+
92+
if obj.Type() == pdoknlv3.ServiceTypeWMS && obj.Options().UseWebserviceProxy() {
93+
volumes = append(volumes, v1.Volume{
94+
Name: ConfigMapOgcWebserviceProxyVolumeName,
95+
VolumeSource: newVolumeSource(configMapNames.OgcWebserviceProxy),
8996
})
9097
}
9198

@@ -143,19 +150,14 @@ func GetVolumesForDeployment[O pdoknlv3.WMSWFS](obj O, configMapNames types.Hash
143150

144151
// Add mapfilegenerator config and styling-files (if applicable) here to get the same order as the ansible operator
145152
// Needed to compare deployments from the ansible operator and this one
146-
volumes = append(volumes, v1.Volume{
147-
Name: ConfigMapMapfileGeneratorVolumeName,
148-
VolumeSource: newVolumeSource(configMapNames.MapfileGenerator),
149-
})
150-
if stylingFilesVolume != nil {
151-
volumes = append(volumes, *stylingFilesVolume)
152-
}
153-
154-
if obj.Type() == pdoknlv3.ServiceTypeWMS && obj.Options().UseWebserviceProxy() {
153+
if obj.Mapfile() == nil {
155154
volumes = append(volumes, v1.Volume{
156-
Name: ConfigMapOgcWebserviceProxyVolumeName,
157-
VolumeSource: newVolumeSource(configMapNames.OgcWebserviceProxy),
155+
Name: ConfigMapMapfileGeneratorVolumeName,
156+
VolumeSource: newVolumeSource(configMapNames.MapfileGenerator),
158157
})
158+
if stylingFilesVolume != nil {
159+
volumes = append(volumes, *stylingFilesVolume)
160+
}
159161
}
160162

161163
return volumes
@@ -316,8 +318,9 @@ func GetResourcesForDeployment[O pdoknlv3.WMSWFS](obj O) v1.ResourceRequirements
316318
}
317319

318320
ephemeralStorageLimit := mapperutils.EphemeralStorageLimit(obj)
319-
if ephemeralStorageLimit == nil || ephemeralStorageLimit.IsZero() {
320-
ephemeralStorageLimit = smoothoperatorutils.Pointer(resource.MustParse("200M"))
321+
defaultEphemeralStorageLimit := resource.MustParse("200M")
322+
if ephemeralStorageLimit == nil || ephemeralStorageLimit.IsZero() || ephemeralStorageLimit.Value() < defaultEphemeralStorageLimit.Value() {
323+
ephemeralStorageLimit = smoothoperatorutils.Pointer(defaultEphemeralStorageLimit)
321324
}
322325
resources.Limits[v1.ResourceEphemeralStorage] = *maxResourceVal(ephemeralStorageLimit, ephemeralStorageRequest)
323326
}

internal/controller/shared_controller.go

Lines changed: 75 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func mutateDeployment[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, deployment *a
203203

204204
deployment.Spec.Template = corev1.PodTemplateSpec{
205205
ObjectMeta: metav1.ObjectMeta{
206-
Annotations: smoothoperatorutils.CloneOrEmptyMap(deployment.Spec.Template.GetAnnotations()),
206+
Annotations: annotations,
207207
Labels: labels,
208208
},
209209
Spec: corev1.PodSpec{
@@ -262,21 +262,24 @@ func getInitContainerForDeployment[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O)
262262
initContainers := []corev1.Container{
263263
*blobDownloadInitContainer,
264264
*capabilitiesGeneratorInitContainer,
265-
*mapfileGeneratorInitContainer,
265+
}
266+
267+
if obj.Mapfile() == nil {
268+
initContainers = append(initContainers, *mapfileGeneratorInitContainer)
266269
}
267270

268271
if wms, ok := any(obj).(*pdoknlv3.WMS); ok {
269-
legendGeneratorInitContainer, err := legendgenerator.GetLegendGeneratorInitContainer(wms, images.MapserverImage, srvDir)
272+
featureInfoInitContainer, err := featureinfogenerator.GetFeatureinfoGeneratorInitContainer(images.FeatureinfoGeneratorImage, srvDir)
270273
if err != nil {
271274
return nil, err
272275
}
273-
initContainers = append(initContainers, *legendGeneratorInitContainer)
276+
initContainers = append(initContainers, *featureInfoInitContainer)
274277

275-
featureInfoInitContainer, err := featureinfogenerator.GetFeatureinfoGeneratorInitContainer(images.FeatureinfoGeneratorImage, srvDir)
278+
legendGeneratorInitContainer, err := legendgenerator.GetLegendGeneratorInitContainer(wms, images.MapserverImage, srvDir)
276279
if err != nil {
277280
return nil, err
278281
}
279-
initContainers = append(initContainers, *featureInfoInitContainer)
282+
initContainers = append(initContainers, *legendGeneratorInitContainer)
280283

281284
if wms.Options().RewriteGroupToDataLayers {
282285
legendFixerInitContainer := legendgenerator.GetLegendFixerInitContainer(images.MultitoolImage)
@@ -300,66 +303,70 @@ func getContainersForDeployment[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O) ([]
300303
return nil, err
301304
}
302305

303-
containers := []corev1.Container{
304-
{
305-
Name: MapserverName,
306-
Image: images.MapserverImage,
307-
ImagePullPolicy: corev1.PullIfNotPresent,
308-
Ports: []corev1.ContainerPort{
309-
{
310-
ContainerPort: 80,
311-
Protocol: corev1.ProtocolTCP,
312-
},
306+
mapserverContainer := corev1.Container{
307+
Name: MapserverName,
308+
Image: images.MapserverImage,
309+
ImagePullPolicy: corev1.PullIfNotPresent,
310+
Ports: []corev1.ContainerPort{
311+
{
312+
ContainerPort: 80,
313+
Protocol: corev1.ProtocolTCP,
313314
},
314-
Env: mapserver.GetEnvVarsForDeployment(obj, blobsSecret.Name),
315-
VolumeMounts: mapserver.GetVolumeMountsForDeployment(obj, srvDir),
316-
Resources: mapserver.GetResourcesForDeployment(obj),
317-
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
318-
TerminationMessagePath: "/dev/termination-log",
319-
LivenessProbe: livenessProbe,
320-
ReadinessProbe: readinessProbe,
321-
StartupProbe: startupProbe,
322-
Lifecycle: &corev1.Lifecycle{
323-
PreStop: &corev1.LifecycleHandler{
324-
Exec: &corev1.ExecAction{
325-
Command: []string{"sleep", "15"},
326-
},
315+
},
316+
Env: mapserver.GetEnvVarsForDeployment(obj, blobsSecret.Name),
317+
VolumeMounts: mapserver.GetVolumeMountsForDeployment(obj, srvDir),
318+
Resources: mapserver.GetResourcesForDeployment(obj),
319+
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
320+
TerminationMessagePath: "/dev/termination-log",
321+
LivenessProbe: livenessProbe,
322+
ReadinessProbe: readinessProbe,
323+
StartupProbe: startupProbe,
324+
Lifecycle: &corev1.Lifecycle{
325+
PreStop: &corev1.LifecycleHandler{
326+
Exec: &corev1.ExecAction{
327+
Command: []string{"sleep", "15"},
327328
},
328329
},
329330
},
330-
{
331-
Name: "apache-exporter",
332-
Image: images.ApacheExporterImage,
333-
ImagePullPolicy: corev1.PullIfNotPresent,
334-
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
335-
TerminationMessagePath: "/dev/termination-log",
336-
Ports: []corev1.ContainerPort{
337-
{
338-
ContainerPort: 9117,
339-
Protocol: corev1.ProtocolTCP,
340-
},
331+
}
332+
333+
apacheContainer := corev1.Container{
334+
Name: "apache-exporter",
335+
Image: images.ApacheExporterImage,
336+
ImagePullPolicy: corev1.PullIfNotPresent,
337+
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
338+
TerminationMessagePath: "/dev/termination-log",
339+
Ports: []corev1.ContainerPort{
340+
{
341+
ContainerPort: 9117,
342+
Protocol: corev1.ProtocolTCP,
341343
},
342-
Args: []string{
343-
"--scrape_uri=http://localhost/server-status?auto",
344+
},
345+
Args: []string{
346+
"--scrape_uri=http://localhost/server-status?auto",
347+
},
348+
Resources: corev1.ResourceRequirements{
349+
Limits: corev1.ResourceList{
350+
corev1.ResourceMemory: resource.MustParse("48M"),
344351
},
345-
Resources: corev1.ResourceRequirements{
346-
Limits: corev1.ResourceList{
347-
corev1.ResourceMemory: resource.MustParse("48M"),
348-
},
349-
Requests: corev1.ResourceList{
350-
corev1.ResourceCPU: resource.MustParse("0.02"),
351-
},
352+
Requests: corev1.ResourceList{
353+
corev1.ResourceCPU: resource.MustParse("0.02"),
352354
},
353355
},
354356
}
355357

358+
containers := []corev1.Container{
359+
mapserverContainer,
360+
apacheContainer,
361+
}
356362
if wms, ok := any(obj).(*pdoknlv3.WMS); ok {
357363
if wms.Options().UseWebserviceProxy() {
358364
ogcWebserviceProxyContainer, err := ogcwebserviceproxy.GetOgcWebserviceProxyContainer(wms, images.OgcWebserviceProxyImage)
359365
if err != nil {
360366
return nil, err
361367
}
362-
containers = append(containers, *ogcWebserviceProxyContainer)
368+
369+
return append(containers, *ogcWebserviceProxyContainer), nil
363370
}
364371
}
365372

@@ -545,10 +552,10 @@ func getMatchRule[O pdoknlv3.WMSWFS](obj O) string {
545552
func getLegendMatchRule(wms *pdoknlv3.WMS) string {
546553
host := pdoknlv3.GetHost(false)
547554
if strings.Contains(host, "localhost") {
548-
return "Host(`localhost`) && Path(`/" + pdoknlv3.GetBaseURLPath(wms) + "/legend`)"
555+
return "Host(`localhost`) && PathPrefix(`/" + pdoknlv3.GetBaseURLPath(wms) + "/legend`)"
549556
}
550557

551-
return "(Host(`localhost`) || Host(`" + host + "`)) && Path(`/" + pdoknlv3.GetBaseURLPath(wms) + "/legend`)"
558+
return "(Host(`localhost`) || Host(`" + host + "`)) && PathPrefix(`/" + pdoknlv3.GetBaseURLPath(wms) + "/legend`)"
552559
}
553560

554561
func getBareConfigMapMapfileGenerator[O pdoknlv3.WMSWFS](obj O) *corev1.ConfigMap {
@@ -659,8 +666,10 @@ func mutateHorizontalPodAutoscaler[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O,
659666
}
660667
if len(metrics) == 0 {
661668
var avgU int32 = 90
662-
if podSpecPatch != nil && podSpecPatch.Resources != nil && podSpecPatch.Resources.Requests.Cpu() != nil {
663-
avgU = 80
669+
if podSpecPatch != nil && podSpecPatch.Resources != nil {
670+
if cpu := podSpecPatch.Resources.Requests.Cpu(); cpu != nil && !cpu.IsZero() {
671+
avgU = 80
672+
}
664673
}
665674
metrics = append(metrics, autoscalingv2.MetricSpec{
666675
Type: autoscalingv2.ResourceMetricSourceType,
@@ -777,12 +786,6 @@ func mutateService[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, service *corev1.
777786
TargetPort: intstr.FromInt32(mapserverPortNr),
778787
Protocol: corev1.ProtocolTCP,
779788
},
780-
{
781-
Name: metricPortName,
782-
Port: metricPortNr,
783-
TargetPort: intstr.FromInt32(metricPortNr),
784-
Protocol: corev1.ProtocolTCP,
785-
},
786789
}
787790

788791
if obj.Type() == pdoknlv3.ServiceTypeWMS {
@@ -794,6 +797,14 @@ func mutateService[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, service *corev1.
794797
}
795798
}
796799

800+
// Add port here to get the same port order as the odl ansible operator
801+
ports = append(ports, corev1.ServicePort{
802+
Name: metricPortName,
803+
Port: metricPortNr,
804+
TargetPort: intstr.FromInt32(metricPortNr),
805+
Protocol: corev1.ProtocolTCP,
806+
})
807+
797808
service.Spec = corev1.ServiceSpec{
798809
Type: corev1.ServiceTypeClusterIP,
799810
ClusterIP: service.Spec.ClusterIP,
@@ -1037,7 +1048,7 @@ func createOrUpdateAllForWMSWFS[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Con
10371048
// end region ConfigMap
10381049

10391050
// region ConfigMap-MapfileGenerator
1040-
{
1051+
if obj.Mapfile() == nil {
10411052
configMapMfg := getBareConfigMapMapfileGenerator(obj)
10421053
if err = mutateConfigMapMapfileGenerator(r, obj, configMapMfg, ownerInfo); err != nil {
10431054
return operationResults, err
@@ -1069,7 +1080,7 @@ func createOrUpdateAllForWMSWFS[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Con
10691080
// end region ConfigMap-CapabilitiesGenerator
10701081

10711082
// region ConfigMap-BlobDownload
1072-
{
1083+
if obj.Options().PrefetchData {
10731084
configMapBd := getBareConfigMapBlobDownload(obj)
10741085
if err = mutateConfigMapBlobDownload(r, obj, configMapBd); err != nil {
10751086
return operationResults, err
@@ -1159,7 +1170,7 @@ func createOrUpdateAllForWMSWFS[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Con
11591170
// end region Deployment
11601171

11611172
// region TraefikMiddleware
1162-
{
1173+
if obj.Options().IncludeIngress {
11631174
middleware := getBareCorsHeadersMiddleware(obj)
11641175
operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, middleware)], err = controllerutil.CreateOrUpdate(ctx, reconcilerClient, middleware, func() error {
11651176
return mutateCorsHeadersMiddleware(r, obj, middleware)
@@ -1195,7 +1206,7 @@ func createOrUpdateAllForWMSWFS[R Reconciler, O pdoknlv3.WMSWFS](ctx context.Con
11951206
// end region HorizontalAutoScaler
11961207

11971208
// region IngressRoute
1198-
{
1209+
if obj.Options().IncludeIngress {
11991210
ingress := getBareIngressRoute(obj)
12001211
operationResults[smoothoperatorutils.GetObjectFullName(reconcilerClient, ingress)], err = controllerutil.CreateOrUpdate(ctx, reconcilerClient, ingress, func() error {
12011212
return mutateIngressRoute(r, obj, ingress)

internal/controller/test_manifests/v3_wfs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ spec:
3636
options:
3737
automaticCasing: true
3838
prefetchData: false
39-
includeIngress: false
39+
includeIngress: true
4040
service:
4141
prefix: "test"
4242
url: https://service.pdok.nl/eigenaar/dataset/wfs/1.0.0

internal/controller/test_manifests/v3_wms.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ spec:
5656
resolution:
5757
defResolution:
5858
stylingAssets:
59-
mapfile:
6059
layer:
6160
name: top-layer-name
6261
title: Top "Layer" Title

0 commit comments

Comments
 (0)