Skip to content

Commit 3119276

Browse files
Merge pull request #44 from PDOK/jd/array-item-order
Jd/array item order
2 parents c8955d6 + 04dd099 commit 3119276

File tree

7 files changed

+109
-84
lines changed

7 files changed

+109
-84
lines changed

internal/controller/mapserver/deployment.go

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ func GetVolumesForDeployment[O pdoknlv3.WMSWFS](obj O, configMapNames types.Hash
7878
Name: ConfigMapVolumeName,
7979
VolumeSource: newVolumeSource(configMapNames.ConfigMap),
8080
},
81-
{
82-
Name: ConfigMapMapfileGeneratorVolumeName,
83-
VolumeSource: newVolumeSource(configMapNames.MapfileGenerator),
84-
},
85-
{
86-
Name: ConfigMapCapabilitiesGeneratorVolumeName,
87-
VolumeSource: newVolumeSource(configMapNames.CapabilitiesGenerator),
88-
},
8981
}
9082

9183
if mapfile := obj.Mapfile(); mapfile != nil {
@@ -95,6 +87,23 @@ func GetVolumesForDeployment[O pdoknlv3.WMSWFS](obj O, configMapNames types.Hash
9587
})
9688
}
9789

90+
if obj.Options().PrefetchData {
91+
vol := newVolumeSource(configMapNames.BlobDownload)
92+
vol.ConfigMap.DefaultMode = smoothoperatorutils.Pointer(int32(0777))
93+
volumes = append(volumes, v1.Volume{
94+
Name: ConfigMapBlobDownloadVolumeName,
95+
VolumeSource: vol,
96+
})
97+
}
98+
99+
// Add capabilitiesgenerator config here to get the same order as the ansible operator
100+
// Needed to compare deployments from the ansible operator and this one
101+
volumes = append(volumes, v1.Volume{
102+
Name: ConfigMapCapabilitiesGeneratorVolumeName,
103+
VolumeSource: newVolumeSource(configMapNames.CapabilitiesGenerator),
104+
})
105+
106+
var stylingFilesVolume *v1.Volume
98107
if obj.Type() == pdoknlv3.ServiceTypeWMS {
99108
lgVolume := v1.Volume{
100109
Name: ConfigMapLegendGeneratorVolumeName,
@@ -119,25 +128,27 @@ func GetVolumesForDeployment[O pdoknlv3.WMSWFS](obj O, configMapNames types.Hash
119128
}
120129
}
121130

122-
stylingFilesVolume := v1.Volume{
131+
stylingFilesVolume = &v1.Volume{
123132
Name: ConfigMapStylingFilesVolumeName,
124133
VolumeSource: v1.VolumeSource{
125134
Projected: &v1.ProjectedVolumeSource{
126135
Sources: stylingFilesVolumeProjections,
127136
},
128137
},
129138
}
130-
volumes = append(volumes, lgVolume, figVolume, stylingFilesVolume)
139+
volumes = append(volumes, figVolume, lgVolume)
131140
}
132141

133-
if obj.Options().PrefetchData {
134-
vol := newVolumeSource(configMapNames.BlobDownload)
135-
vol.ConfigMap.DefaultMode = smoothoperatorutils.Pointer(int32(0777))
136-
volumes = append(volumes, v1.Volume{
137-
Name: ConfigMapBlobDownloadVolumeName,
138-
VolumeSource: vol,
139-
})
142+
// Add mapfilegenerator config and styling-files (if applicable) here to get the same order as the ansible operator
143+
// Needed to compare deployments from the ansible operator and this one
144+
volumes = append(volumes, v1.Volume{
145+
Name: ConfigMapMapfileGeneratorVolumeName,
146+
VolumeSource: newVolumeSource(configMapNames.MapfileGenerator),
147+
})
148+
if stylingFilesVolume != nil {
149+
volumes = append(volumes, *stylingFilesVolume)
140150
}
151+
141152
if obj.Type() == pdoknlv3.ServiceTypeWMS && obj.Options().UseWebserviceProxy() {
142153
volumes = append(volumes, v1.Volume{
143154
Name: ConfigMapOgcWebserviceProxyVolumeName,
@@ -201,6 +212,7 @@ func GetEnvVarsForDeployment[O pdoknlv3.WMSWFS](obj O, blobsSecretName string) [
201212
Name: "MAPSERVER_CONFIG_FILE",
202213
Value: "/srv/mapserver/config/default_mapserver.conf",
203214
},
215+
GetMapfileEnvVar(obj),
204216
{
205217
Name: "AZURE_STORAGE_CONNECTION_STRING",
206218
ValueFrom: &v1.EnvVarSource{
@@ -212,7 +224,6 @@ func GetEnvVarsForDeployment[O pdoknlv3.WMSWFS](obj O, blobsSecretName string) [
212224
},
213225
},
214226
},
215-
GetMapfileEnvVar(obj),
216227
}
217228
}
218229

@@ -338,8 +349,7 @@ func GetProbesForDeployment[O pdoknlv3.WMSWFS](obj O) (livenessProbe *v1.Probe,
338349
}
339350

340351
func getLivenessProbe[O pdoknlv3.WMSWFS](obj O) *v1.Probe {
341-
webserviceType := strings.ToLower(string(obj.Type()))
342-
queryString := "SERVICE=" + webserviceType + "&request=GetCapabilities"
352+
queryString := "SERVICE=" + string(obj.Type()) + "&request=GetCapabilities"
343353
return getProbe(queryString, mimeTextXML)
344354
}
345355

internal/controller/mapserver/deployment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ func TestGetVolumesForDeployment(t *testing.T) {
114114
{Name: "base", VolumeSource: v1.VolumeSource{EmptyDir: &v1.EmptyDirVolumeSource{}}},
115115
{Name: "data", VolumeSource: v1.VolumeSource{EmptyDir: &v1.EmptyDirVolumeSource{}}},
116116
{Name: "mapserver", VolumeSource: v1.VolumeSource{ConfigMap: &v1.ConfigMapVolumeSource{LocalObjectReference: v1.LocalObjectReference{Name: "rws-nwbwegen-v1-0-wfs-mapserver-bb59c7f4f4"}, DefaultMode: smoothoperatorutils.Pointer(int32(420))}}},
117-
{Name: "mapfile-generator-config", VolumeSource: v1.VolumeSource{ConfigMap: &v1.ConfigMapVolumeSource{LocalObjectReference: v1.LocalObjectReference{Name: "rws-nwbwegen-v1-0-wfs-mapfile-generator-bbbtd999dh"}, DefaultMode: smoothoperatorutils.Pointer(int32(420))}}},
118117
{Name: "capabilities-generator-config", VolumeSource: v1.VolumeSource{ConfigMap: &v1.ConfigMapVolumeSource{LocalObjectReference: v1.LocalObjectReference{Name: "rws-nwbwegen-v1-0-wfs-capabilities-generator-6m4mfkgb5d"}, DefaultMode: smoothoperatorutils.Pointer(int32(420))}}},
118+
{Name: "mapfile-generator-config", VolumeSource: v1.VolumeSource{ConfigMap: &v1.ConfigMapVolumeSource{LocalObjectReference: v1.LocalObjectReference{Name: "rws-nwbwegen-v1-0-wfs-mapfile-generator-bbbtd999dh"}, DefaultMode: smoothoperatorutils.Pointer(int32(420))}}},
119119
}
120120

121121
assert.Equal(t, expected, result)

internal/controller/mapserver/test_data/expected_envvars.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ envVars:
33
value: WFS
44
- name: MAPSERVER_CONFIG_FILE
55
value: /srv/mapserver/config/default_mapserver.conf
6+
- name: MS_MAPFILE
7+
value: /srv/data/config/mapfile/service.map
68
- name: AZURE_STORAGE_CONNECTION_STRING
79
valueFrom:
810
secretKeyRef:
911
key: AZURE_STORAGE_CONNECTION_STRING
1012
name: blobs-secret
11-
- name: MS_MAPFILE
12-
value: /srv/data/config/mapfile/service.map

internal/controller/mapserver/test_data/expected_livenessprobe.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ exec:
22
command:
33
- /bin/sh
44
- -c
5-
- 'wget -SO- -T 10 -t 2 ''http://127.0.0.1:80/mapserver?SERVICE=wfs&request=GetCapabilities''
5+
- 'wget -SO- -T 10 -t 2 ''http://127.0.0.1:80/mapserver?SERVICE=WFS&request=GetCapabilities''
66
2>&1 | egrep -aiA10 ''HTTP/1.1 200'' | egrep -i ''Content-Type: text/xml'''
77
failureThreshold: 3
88
initialDelaySeconds: 20

internal/controller/shared_controller.go

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/pdok/mapserver-operator/internal/controller/featureinfogenerator"
12-
"github.com/pdok/mapserver-operator/internal/controller/legendgenerator"
13-
"github.com/pdok/mapserver-operator/internal/controller/mapserver"
14-
"github.com/pdok/mapserver-operator/internal/controller/ogcwebserviceproxy"
15-
"github.com/pdok/mapserver-operator/internal/controller/types"
16-
appsv1 "k8s.io/api/apps/v1"
1711
"k8s.io/apimachinery/pkg/api/resource"
1812

1913
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
2014
"github.com/pdok/mapserver-operator/internal/controller/blobdownload"
2115
"github.com/pdok/mapserver-operator/internal/controller/capabilitiesgenerator"
16+
"github.com/pdok/mapserver-operator/internal/controller/featureinfogenerator"
17+
"github.com/pdok/mapserver-operator/internal/controller/legendgenerator"
2218
"github.com/pdok/mapserver-operator/internal/controller/mapfilegenerator"
2319
"github.com/pdok/mapserver-operator/internal/controller/mapperutils"
20+
"github.com/pdok/mapserver-operator/internal/controller/mapserver"
21+
"github.com/pdok/mapserver-operator/internal/controller/ogcwebserviceproxy"
2422
"github.com/pdok/mapserver-operator/internal/controller/static"
23+
"github.com/pdok/mapserver-operator/internal/controller/types"
2524
smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1"
2625
"github.com/pdok/smooth-operator/model"
2726
smoothoperatork8s "github.com/pdok/smooth-operator/pkg/k8s"
2827
smoothoperatorutils "github.com/pdok/smooth-operator/pkg/util"
2928
traefikdynamic "github.com/traefik/traefik/v3/pkg/config/dynamic"
3029
traefikiov1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
30+
appsv1 "k8s.io/api/apps/v1"
3131
autoscalingv2 "k8s.io/api/autoscaling/v2"
3232
corev1 "k8s.io/api/core/v1"
3333
v1 "k8s.io/api/policy/v1"
@@ -261,8 +261,8 @@ func getInitContainerForDeployment[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O)
261261

262262
initContainers := []corev1.Container{
263263
*blobDownloadInitContainer,
264-
*mapfileGeneratorInitContainer,
265264
*capabilitiesGeneratorInitContainer,
265+
*mapfileGeneratorInitContainer,
266266
}
267267

268268
if wms, ok := any(obj).(*pdoknlv3.WMS); ok {
@@ -301,30 +301,6 @@ func getContainersForDeployment[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O) ([]
301301
}
302302

303303
containers := []corev1.Container{
304-
{
305-
Name: "apache-exporter",
306-
Image: images.ApacheExporterImage,
307-
ImagePullPolicy: corev1.PullIfNotPresent,
308-
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
309-
TerminationMessagePath: "/dev/termination-log",
310-
Ports: []corev1.ContainerPort{
311-
{
312-
ContainerPort: 9117,
313-
Protocol: corev1.ProtocolTCP,
314-
},
315-
},
316-
Args: []string{
317-
"--scrape_uri=http://localhost/server-status?auto",
318-
},
319-
Resources: corev1.ResourceRequirements{
320-
Limits: corev1.ResourceList{
321-
corev1.ResourceMemory: resource.MustParse("48M"),
322-
},
323-
Requests: corev1.ResourceList{
324-
corev1.ResourceCPU: resource.MustParse("0.02"),
325-
},
326-
},
327-
},
328304
{
329305
Name: MapserverName,
330306
Image: images.MapserverImage,
@@ -351,6 +327,30 @@ func getContainersForDeployment[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O) ([]
351327
},
352328
},
353329
},
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+
},
341+
},
342+
Args: []string{
343+
"--scrape_uri=http://localhost/server-status?auto",
344+
},
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+
},
353+
},
354354
}
355355

356356
if wms, ok := any(obj).(*pdoknlv3.WMS); ok {
@@ -414,8 +414,7 @@ func mutateIngressRoute[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, ingressRout
414414
}
415415

416416
middlewareRef := traefikiov1alpha1.MiddlewareRef{
417-
Name: getBareCorsHeadersMiddleware(obj).GetName(),
418-
Namespace: obj.GetNamespace(),
417+
Name: getBareCorsHeadersMiddleware(obj).GetName(),
419418
}
420419

421420
if obj.Type() == pdoknlv3.ServiceTypeWMS {
@@ -463,6 +462,9 @@ func mutateIngressRoute[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, ingressRout
463462
}}
464463
}
465464

465+
// Add finalizers
466+
ingressRoute.Finalizers = []string{"uptime.pdok.nl/finalizer"}
467+
466468
if err := smoothoperatorutils.EnsureSetGVK(reconcilerClient, ingressRoute, ingressRoute); err != nil {
467469
return err
468470
}
@@ -675,8 +677,9 @@ func mutateHorizontalPodAutoscaler[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O,
675677

676678
autoscaler.Spec = autoscalingv2.HorizontalPodAutoscalerSpec{
677679
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
678-
Kind: "Deployment",
679-
Name: getSuffixedName(obj, MapserverName),
680+
APIVersion: "apps/v1",
681+
Kind: "Deployment",
682+
Name: getSuffixedName(obj, MapserverName),
680683
},
681684
MinReplicas: &minReplicas,
682685
MaxReplicas: maxReplicas,
@@ -698,13 +701,13 @@ func mutateHorizontalPodAutoscaler[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O,
698701
SelectPolicy: smoothoperatorutils.Pointer(autoscalingv2.MaxChangePolicySelect),
699702
Policies: []autoscalingv2.HPAScalingPolicy{
700703
{
701-
Type: autoscalingv2.PodsScalingPolicy,
702-
Value: 1,
704+
Type: autoscalingv2.PercentScalingPolicy,
705+
Value: 10,
703706
PeriodSeconds: 600,
704707
},
705708
{
706-
Type: autoscalingv2.PercentScalingPolicy,
707-
Value: 10,
709+
Type: autoscalingv2.PodsScalingPolicy,
710+
Value: 1,
708711
PeriodSeconds: 600,
709712
},
710713
},

internal/controller/wfs_controller_test.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ var _ = Describe("WFS Controller", func() {
160160
By("Waiting for the owned resources to be deleted")
161161
Eventually(func() error {
162162
for _, o := range expectedBareObjects {
163+
// TODO make finalizers work in the test environment
164+
if len(o.GetFinalizers()) > 0 {
165+
continue
166+
}
167+
163168
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: namespace, Name: o.GetName()}, o)
164169
if err == nil {
165170
return errors.New("expected " + smoothoperatorutils.GetObjectFullName(k8sClient, o) + " to not be found")
@@ -236,15 +241,15 @@ var _ = Describe("WFS Controller", func() {
236241
/**
237242
Container tests
238243
*/
239-
container := deployment.Spec.Template.Spec.Containers[1]
244+
container := deployment.Spec.Template.Spec.Containers[0]
240245
Expect(container.Name).Should(Equal("mapserver"))
241246
Expect(container.Ports[0].ContainerPort).Should(Equal(int32(80)))
242247
Expect(container.Image).Should(Equal(reconcilerImages.MapserverImage))
243248
Expect(container.ImagePullPolicy).Should(Equal(v1.PullIfNotPresent))
244249
Expect(container.Resources.Limits.Memory().String()).Should(Equal("12M"))
245250
Expect(container.Resources.Requests.Cpu().String()).Should(Equal("150m"))
246251
Expect(len(container.LivenessProbe.Exec.Command)).Should(Equal(3))
247-
Expect(container.LivenessProbe.Exec.Command[2]).Should(Equal("wget -SO- -T 10 -t 2 'http://127.0.0.1:80/mapserver?SERVICE=wfs&request=GetCapabilities' 2>&1 | egrep -aiA10 'HTTP/1.1 200' | egrep -i 'Content-Type: text/xml'"))
252+
Expect(container.LivenessProbe.Exec.Command[2]).Should(Equal("wget -SO- -T 10 -t 2 'http://127.0.0.1:80/mapserver?SERVICE=WFS&request=GetCapabilities' 2>&1 | egrep -aiA10 'HTTP/1.1 200' | egrep -i 'Content-Type: text/xml'"))
248253
Expect(container.LivenessProbe.FailureThreshold).Should(Equal(int32(3)))
249254
Expect(container.LivenessProbe.InitialDelaySeconds).Should(Equal(int32(20)))
250255
Expect(container.LivenessProbe.PeriodSeconds).Should(Equal(int32(10)))
@@ -530,8 +535,9 @@ var _ = Describe("WFS Controller", func() {
530535

531536
Expect(autoscaler.GetName()).To(Equal(wfs.GetName() + "-wfs-mapserver"))
532537
Expect(autoscaler.Spec.ScaleTargetRef).To(Equal(v2.CrossVersionObjectReference{
533-
Kind: "Deployment",
534-
Name: wfs.GetName() + "-wfs-mapserver",
538+
APIVersion: "apps/v1",
539+
Kind: "Deployment",
540+
Name: wfs.GetName() + "-wfs-mapserver",
535541
}))
536542

537543
/**
@@ -550,13 +556,13 @@ var _ = Describe("WFS Controller", func() {
550556
Policies: []v2.HPAScalingPolicy{
551557
{
552558
PeriodSeconds: int32(600),
553-
Value: int32(1),
554-
Type: v2.PodsScalingPolicy,
559+
Value: int32(10),
560+
Type: v2.PercentScalingPolicy,
555561
},
556562
{
557563
PeriodSeconds: int32(600),
558-
Value: int32(10),
559-
Type: v2.PercentScalingPolicy,
564+
Value: int32(1),
565+
Type: v2.PodsScalingPolicy,
560566
},
561567
},
562568
}))
@@ -645,7 +651,7 @@ var _ = Describe("WFS Controller", func() {
645651
Expect(ingressRoute.Spec.Routes[0]).To(Equal(traefikiov1alpha1.Route{
646652
Kind: "Rule",
647653
Match: "Host(`localhost`) && Path(`/eigenaar/dataset/wfs/1.0.0`)",
648-
Middlewares: []traefikiov1alpha1.MiddlewareRef{{Name: wfs.GetName() + "-wfs-mapserver-headers", Namespace: "default"}},
654+
Middlewares: []traefikiov1alpha1.MiddlewareRef{{Name: wfs.GetName() + "-wfs-mapserver-headers"}},
649655
Services: []traefikiov1alpha1.Service{{
650656
LoadBalancerSpec: traefikiov1alpha1.LoadBalancerSpec{
651657
Kind: "Service",

0 commit comments

Comments
 (0)