@@ -39,8 +39,8 @@ import (
3939 smoothoperatorutils "github.com/pdok/smooth-operator/pkg/util"
4040 traefikiov1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
4141 appsv1 "k8s.io/api/apps/v1"
42- v2 "k8s.io/api/autoscaling/v2"
43- v1 "k8s.io/api/core/v1"
42+ autoscalingv2 "k8s.io/api/autoscaling/v2"
43+ corev1 "k8s.io/api/core/v1"
4444 k8serrors "k8s.io/apimachinery/pkg/api/errors"
4545 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4646 "k8s.io/apimachinery/pkg/types"
@@ -238,7 +238,7 @@ var _ = Describe("WMS Controller", func() {
238238 Expect (containerMapserver .Name ).Should (Equal ("mapserver" ))
239239 Expect (containerMapserver .Ports [0 ].ContainerPort ).Should (Equal (int32 (80 )))
240240 Expect (containerMapserver .Image ).Should (Equal (reconcilerImages .MapserverImage ))
241- Expect (containerMapserver .ImagePullPolicy ).Should (Equal (v1 .PullIfNotPresent ))
241+ Expect (containerMapserver .ImagePullPolicy ).Should (Equal (corev1 .PullIfNotPresent ))
242242 Expect (containerMapserver .Resources .Limits .Memory ().String ()).Should (Equal ("800M" ))
243243 Expect (containerMapserver .Resources .Requests .Cpu ().String ()).Should (Equal ("100m" ))
244244 Expect (len (containerMapserver .LivenessProbe .Exec .Command )).Should (Equal (3 ))
@@ -265,11 +265,11 @@ var _ = Describe("WMS Controller", func() {
265265 ogcWebserviceProxyCommands := []string {"/ogc-webservice-proxy" , "-h=http://127.0.0.1/" , "-t=wms" , "-s=/input/service-config.yaml" , "-v" , "-r" , "-d=15" }
266266 Expect (containerOgcWebserviceProxy .Command ).Should (Equal (ogcWebserviceProxyCommands ))
267267 Expect (containerOgcWebserviceProxy .Image ).Should (Equal (reconcilerImages .OgcWebserviceProxyImage ))
268- Expect (containerOgcWebserviceProxy .ImagePullPolicy ).Should (Equal (v1 .PullIfNotPresent ))
268+ Expect (containerOgcWebserviceProxy .ImagePullPolicy ).Should (Equal (corev1 .PullIfNotPresent ))
269269 Expect (containerOgcWebserviceProxy .Ports [0 ].ContainerPort ).Should (Equal (int32 (9111 )))
270270 Expect (containerOgcWebserviceProxy .Resources .Limits .Memory ().String ()).Should (Equal ("200M" ))
271271 Expect (containerOgcWebserviceProxy .Resources .Requests .Cpu ().String ()).Should (Equal ("50m" ))
272- volumeMountsContainerOgcWebserviceProxy := []v1 .VolumeMount {
272+ volumeMountsContainerOgcWebserviceProxy := []corev1 .VolumeMount {
273273 {Name : mapserver .ConfigMapOgcWebserviceProxyVolumeName , MountPath : "/input" , ReadOnly : true },
274274 }
275275 Expect (containerOgcWebserviceProxy .VolumeMounts ).Should (Equal (volumeMountsContainerOgcWebserviceProxy ))
@@ -281,12 +281,12 @@ var _ = Describe("WMS Controller", func() {
281281 blobDownloadContainer , err := getInitContainer ("blob-download" , deployment )
282282 Expect (err ).NotTo (HaveOccurred ())
283283 Expect (blobDownloadContainer .Image ).Should (Equal (reconcilerImages .MultitoolImage ))
284- volumeMounts := []v1 .VolumeMount {
284+ volumeMounts := []corev1 .VolumeMount {
285285 {Name : "base" , MountPath : "/srv/data" },
286286 {Name : "data" , MountPath : "/var/www" },
287287 {Name : mapserver .ConfigMapBlobDownloadVolumeName , MountPath : "/src/scripts" , ReadOnly : true },
288288 }
289- envFrom := []v1 .EnvFromSource {
289+ envFrom := []corev1 .EnvFromSource {
290290 utils .NewEnvFromSource (utils .EnvFromSourceTypeConfigMap , "blobs-config" ),
291291 utils .NewEnvFromSource (utils .EnvFromSourceTypeSecret , "blobs-secret" ),
292292 }
@@ -298,7 +298,7 @@ var _ = Describe("WMS Controller", func() {
298298 mapfileGeneratorContainer , err := getInitContainer ("mapfile-generator" , deployment )
299299 Expect (err ).NotTo (HaveOccurred ())
300300 Expect (mapfileGeneratorContainer .Image ).Should (Equal (reconcilerImages .MapfileGeneratorImage ))
301- volumeMounts = []v1 .VolumeMount {
301+ volumeMounts = []corev1 .VolumeMount {
302302 {Name : "base" , MountPath : "/srv/data" },
303303 {Name : mapserver .ConfigMapMapfileGeneratorVolumeName , MountPath : "/input" , ReadOnly : true },
304304 {Name : mapserver .ConfigMapStylingFilesVolumeName , MountPath : "/styling" , ReadOnly : true },
@@ -310,24 +310,24 @@ var _ = Describe("WMS Controller", func() {
310310 capabilitiesGeneratorContainer , err := getInitContainer ("capabilities-generator" , deployment )
311311 Expect (err ).NotTo (HaveOccurred ())
312312 Expect (capabilitiesGeneratorContainer .Image ).Should (Equal (reconcilerImages .CapabilitiesGeneratorImage ))
313- Expect (capabilitiesGeneratorContainer .ImagePullPolicy ).Should (Equal (v1 .PullIfNotPresent ))
313+ Expect (capabilitiesGeneratorContainer .ImagePullPolicy ).Should (Equal (corev1 .PullIfNotPresent ))
314314
315- volumeMounts = []v1 .VolumeMount {
315+ volumeMounts = []corev1 .VolumeMount {
316316 {Name : "data" , MountPath : "/var/www" },
317317 {Name : mapserver .ConfigMapCapabilitiesGeneratorVolumeName , MountPath : "/input" , ReadOnly : true },
318318 }
319319 Expect (capabilitiesGeneratorContainer .VolumeMounts ).Should (Equal (volumeMounts ))
320- env := []v1 .EnvVar {
320+ env := []corev1 .EnvVar {
321321 {Name : "SERVICECONFIG" , Value : "/input/input.yaml" },
322322 }
323323 Expect (capabilitiesGeneratorContainer .Env ).Should (Equal (env ))
324324
325325 featureinfoGeneratorContainer , err := getInitContainer ("featureinfo-generator" , deployment )
326326 Expect (err ).NotTo (HaveOccurred ())
327327 Expect (featureinfoGeneratorContainer .Image ).Should (Equal (reconcilerImages .FeatureinfoGeneratorImage ))
328- Expect (featureinfoGeneratorContainer .ImagePullPolicy ).Should (Equal (v1 .PullIfNotPresent ))
328+ Expect (featureinfoGeneratorContainer .ImagePullPolicy ).Should (Equal (corev1 .PullIfNotPresent ))
329329 Expect (featureinfoGeneratorContainer .Command ).Should (Equal ([]string {"featureinfo-generator" }))
330- volumeMounts = []v1 .VolumeMount {
330+ volumeMounts = []corev1 .VolumeMount {
331331 {Name : "base" , MountPath : "/srv/data" , ReadOnly : false },
332332 {Name : mapserver .ConfigMapFeatureinfoGeneratorVolumeName , MountPath : "/input" , ReadOnly : true },
333333 }
@@ -337,33 +337,27 @@ var _ = Describe("WMS Controller", func() {
337337 legendGeneratorContainer , err := getInitContainer ("legend-generator" , deployment )
338338 Expect (err ).NotTo (HaveOccurred ())
339339 Expect (legendGeneratorContainer .Image ).Should (Equal (reconcilerImages .MapserverImage ))
340- Expect (legendGeneratorContainer .ImagePullPolicy ).Should (Equal (v1 .PullIfNotPresent ))
340+ Expect (legendGeneratorContainer .ImagePullPolicy ).Should (Equal (corev1 .PullIfNotPresent ))
341341 Expect (len (legendGeneratorContainer .Command )).Should (BeNumerically ("==" , 3 ))
342- volumeMounts = []v1 .VolumeMount {
342+ volumeMounts = []corev1 .VolumeMount {
343343 {Name : "base" , MountPath : "/srv/data" , ReadOnly : false },
344344 {Name : "data" , MountPath : "/var/www" , ReadOnly : false },
345- // TODO: de volgende volAmount is bedoeld voor CR met mapfile. Bouw daarvoor een aparte test voor
346- //{Name: mapserver.ConfigMapVolumeName, MountPath: "/srv/mapserver/config/default_mapserver.conf"},
347345 {Name : mapserver .ConfigMapLegendGeneratorVolumeName , MountPath : "/input" , ReadOnly : true },
348346 }
349347 Expect (legendGeneratorContainer .VolumeMounts ).Should (Equal (volumeMounts ))
350348
351- env = []v1 .EnvVar {
349+ env = []corev1 .EnvVar {
352350 {Name : "MS_MAPFILE" , Value : "service.map" , ValueFrom : nil },
353-
354- // TODO: de volgende volAmount is bedoeld voor CR met mapfile. Bouw daarvoor een aparte test voor
355- //{Name: "MAPSERVER_CONFIG_FILE", Value: "/srv/mapserver/config/default_mapserver.conf"},
356- //{Name: "MS_MAPFILE", Value: "/srv/data/config/mapfile/service.map"},
357351 }
358352 Expect (legendGeneratorContainer .Env ).Should (Equal (env ))
359353
360354 legendFixerContainer , err := getInitContainer ("legend-fixer" , deployment )
361355 Expect (err ).NotTo (HaveOccurred ())
362356 Expect (legendFixerContainer .Image ).Should (Equal (reconcilerImages .MultitoolImage ))
363- Expect (legendFixerContainer .ImagePullPolicy ).Should (Equal (v1 .PullIfNotPresent ))
357+ Expect (legendFixerContainer .ImagePullPolicy ).Should (Equal (corev1 .PullIfNotPresent ))
364358 Expect (len (legendFixerContainer .Command )).Should (BeNumerically ("==" , 2 ))
365359
366- volumeMounts = []v1 .VolumeMount {
360+ volumeMounts = []corev1 .VolumeMount {
367361 {Name : "data" , MountPath : "/var/www" , ReadOnly : false },
368362 {Name : mapserver .ConfigMapLegendGeneratorVolumeName , MountPath : "/input" , ReadOnly : true },
369363 }
@@ -384,7 +378,7 @@ var _ = Describe("WMS Controller", func() {
384378 mapserver .ConfigMapFeatureinfoGeneratorVolumeName ,
385379 }
386380 for _ , ev := range expectedVolumes {
387- Expect (slices .IndexFunc (deployment .Spec .Template .Spec .Volumes , func (v v1 .Volume ) bool {
381+ Expect (slices .IndexFunc (deployment .Spec .Template .Spec .Volumes , func (v corev1 .Volume ) bool {
388382 return v .Name == ev
389383 })).ShouldNot (BeEquivalentTo (- 1 ))
390384 }
@@ -509,11 +503,11 @@ var _ = Describe("WMS Controller", func() {
509503 Expect (containerOgcWebserviceProxy .Name ).Should (Equal ("ogc-webservice-proxy" ))
510504 ogcWebserviceProxyCommands := []string {"/ogc-webservice-proxy" , "-h=http://127.0.0.1/" , "-t=wms" , "-s=/input/service-config.yaml" , "-r" , "-d=15" }
511505 Expect (containerOgcWebserviceProxy .Command ).Should (Equal (ogcWebserviceProxyCommands ))
512- Expect (containerOgcWebserviceProxy .ImagePullPolicy ).Should (Equal (v1 .PullIfNotPresent ))
506+ Expect (containerOgcWebserviceProxy .ImagePullPolicy ).Should (Equal (corev1 .PullIfNotPresent ))
513507 Expect (containerOgcWebserviceProxy .Ports [0 ].ContainerPort ).Should (Equal (int32 (9111 )))
514508 Expect (containerOgcWebserviceProxy .Resources .Limits .Memory ().String ()).Should (Equal ("200M" ))
515509 Expect (containerOgcWebserviceProxy .Resources .Requests .Cpu ().String ()).Should (Equal ("50m" ))
516- volumeMountsContainerOgcWebserviceProxy := []v1 .VolumeMount {
510+ volumeMountsContainerOgcWebserviceProxy := []corev1 .VolumeMount {
517511 {Name : mapserver .ConfigMapOgcWebserviceProxyVolumeName , MountPath : "/input" , ReadOnly : true },
518512 }
519513 Expect (containerOgcWebserviceProxy .VolumeMounts ).Should (Equal (volumeMountsContainerOgcWebserviceProxy ))
@@ -754,7 +748,7 @@ var _ = Describe("WMS Controller", func() {
754748 }, "10s" , "1s" ).Should (BeTrue ())
755749
756750 Expect (autoscaler .GetName ()).To (Equal (wms .GetName () + "-mapserver" ))
757- Expect (autoscaler .Spec .ScaleTargetRef ).To (Equal (v2 .CrossVersionObjectReference {
751+ Expect (autoscaler .Spec .ScaleTargetRef ).To (Equal (autoscalingv2 .CrossVersionObjectReference {
758752 Kind : "Deployment" ,
759753 Name : wms .GetName () + "-mapserver" ,
760754 }))
@@ -769,40 +763,40 @@ var _ = Describe("WMS Controller", func() {
769763 Expect (autoscaler .Spec .Behavior ).ToNot (BeNil ())
770764 Expect (autoscaler .Spec .Behavior .ScaleDown ).ToNot (BeNil ())
771765 Expect (autoscaler .Spec .Behavior .ScaleUp ).ToNot (BeNil ())
772- Expect (autoscaler .Spec .Behavior .ScaleDown ).To (Equal (& v2 .HPAScalingRules {
766+ Expect (autoscaler .Spec .Behavior .ScaleDown ).To (Equal (& autoscalingv2 .HPAScalingRules {
773767 StabilizationWindowSeconds : smoothoperatorutils .Pointer (int32 (3600 )),
774- SelectPolicy : smoothoperatorutils .Pointer (v2 .MaxChangePolicySelect ),
775- Policies : []v2 .HPAScalingPolicy {
768+ SelectPolicy : smoothoperatorutils .Pointer (autoscalingv2 .MaxChangePolicySelect ),
769+ Policies : []autoscalingv2 .HPAScalingPolicy {
776770 {
777771 PeriodSeconds : int32 (600 ),
778772 Value : int32 (1 ),
779- Type : v2 .PodsScalingPolicy ,
773+ Type : autoscalingv2 .PodsScalingPolicy ,
780774 },
781775 {
782776 PeriodSeconds : int32 (600 ),
783777 Value : int32 (10 ),
784- Type : v2 .PercentScalingPolicy ,
778+ Type : autoscalingv2 .PercentScalingPolicy ,
785779 },
786780 },
787781 }))
788- Expect (autoscaler .Spec .Behavior .ScaleUp ).To (Equal (& v2 .HPAScalingRules {
782+ Expect (autoscaler .Spec .Behavior .ScaleUp ).To (Equal (& autoscalingv2 .HPAScalingRules {
789783 StabilizationWindowSeconds : smoothoperatorutils .Pointer (int32 (0 )),
790- SelectPolicy : smoothoperatorutils .Pointer (v2 .MaxChangePolicySelect ),
791- Policies : []v2 .HPAScalingPolicy {
784+ SelectPolicy : smoothoperatorutils .Pointer (autoscalingv2 .MaxChangePolicySelect ),
785+ Policies : []autoscalingv2 .HPAScalingPolicy {
792786 {
793787 PeriodSeconds : int32 (60 ),
794788 Value : int32 (20 ),
795- Type : v2 .PodsScalingPolicy ,
789+ Type : autoscalingv2 .PodsScalingPolicy ,
796790 },
797791 },
798792 }))
799- Expect (autoscaler .Spec .Metrics ).To (Equal ([]v2 .MetricSpec {
793+ Expect (autoscaler .Spec .Metrics ).To (Equal ([]autoscalingv2 .MetricSpec {
800794 {
801- Type : v2 .ResourceMetricSourceType ,
802- Resource : & v2 .ResourceMetricSource {
803- Name : v1 .ResourceCPU ,
804- Target : v2 .MetricTarget {
805- Type : v2 .UtilizationMetricType ,
795+ Type : autoscalingv2 .ResourceMetricSourceType ,
796+ Resource : & autoscalingv2 .ResourceMetricSource {
797+ Name : corev1 .ResourceCPU ,
798+ Target : autoscalingv2 .MetricTarget {
799+ Type : autoscalingv2 .UtilizationMetricType ,
806800 AverageUtilization : smoothoperatorutils .Pointer (int32 (120 )),
807801 },
808802 },
@@ -823,18 +817,18 @@ var _ = Describe("WMS Controller", func() {
823817 }, "10s" , "1s" ).Should (BeTrue ())
824818
825819 Expect (service .GetName ()).To (Equal (wms .GetName () + "-mapserver" ))
826- Expect (service .Spec .Ports ).To (Equal ([]v1 .ServicePort {
820+ Expect (service .Spec .Ports ).To (Equal ([]corev1 .ServicePort {
827821 {
828822 Name : "mapserver" ,
829823 Port : 80 ,
830824 TargetPort : intstr .FromInt32 (80 ),
831- Protocol : v1 .ProtocolTCP ,
825+ Protocol : corev1 .ProtocolTCP ,
832826 },
833827 {
834828 Name : "metric" ,
835829 Port : 9117 ,
836830 TargetPort : intstr .FromInt32 (9117 ),
837- Protocol : v1 .ProtocolTCP ,
831+ Protocol : corev1 .ProtocolTCP ,
838832 },
839833 {
840834 Name : "ogc-webservice-proxy" ,
@@ -898,6 +892,72 @@ var _ = Describe("WMS Controller", func() {
898892 }},
899893 }))
900894 })
895+
896+ It ("Static mapfile options." , func () {
897+ wmsResource := & pdoknlv3.WMS {}
898+ wmsResource .Namespace = namespace
899+ wmsResource .Name = typeNamespacedNameWms .Name
900+ err := k8sClient .Get (ctx , typeNamespacedNameWms , wmsResource )
901+ Expect (client .IgnoreNotFound (err )).NotTo (HaveOccurred ())
902+
903+ By ("Cleanup the specific resource instance WMS" )
904+ Expect (k8sClient .Delete (ctx , wmsResource )).To (Succeed ())
905+
906+ sampleWms , err := getUniqueWMSSample (counter )
907+ counter ++
908+ sampleWms .Spec .Service .Mapfile = & pdoknlv3.Mapfile {ConfigMapKeyRef : corev1.ConfigMapKeySelector {Key : "mapfile.map" }}
909+ typeNamespacedNameWms .Name = sampleWms .Name
910+
911+ Expect (err ).NotTo (HaveOccurred ())
912+
913+ Expect (k8sClient .Create (ctx , sampleWms .DeepCopy ())).To (Succeed ())
914+ Expect (k8sClient .Get (ctx , typeNamespacedNameWms , wms )).To (Succeed ())
915+
916+ controllerReconciler := getWMSReconciler ()
917+
918+ By ("Reconciling the WMS and checking the configMap" )
919+ reconcileWMS (controllerReconciler , wms , typeNamespacedNameWms )
920+ deployment := & appsv1.Deployment {}
921+ err = k8sClient .Get (ctx , types.NamespacedName {Namespace : namespace , Name : getBareDeployment (wms , MapserverName ).GetName ()}, deployment )
922+ Expect (err ).NotTo (HaveOccurred ())
923+
924+ volumeMounts := []corev1.VolumeMount {
925+ {Name : "base" , MountPath : "/srv/data" , ReadOnly : false },
926+ {Name : "data" , MountPath : "/var/www" , ReadOnly : false },
927+ {Name : mapserver .ConfigMapLegendGeneratorVolumeName , MountPath : "/input" , ReadOnly : true },
928+ {Name : "mapfile" , MountPath : "/srv/data/config/mapfile" },
929+ }
930+ legendGeneratorContainer , err := getInitContainer ("legend-generator" , deployment )
931+
932+ Expect (legendGeneratorContainer .VolumeMounts ).Should (Equal (volumeMounts ))
933+
934+ env := []corev1.EnvVar {
935+ {Name : "MS_MAPFILE" , Value : "mapfile.map" , ValueFrom : nil },
936+ }
937+ Expect (legendGeneratorContainer .Env ).Should (Equal (env ))
938+ envContainer := []corev1.EnvVar {
939+ {Name : "SERVICE_TYPE" , Value : "WMS" , ValueFrom : nil },
940+ {
941+ Name : "MAPSERVER_CONFIG_FILE" ,
942+ Value : "/srv/mapserver/config/default_mapserver.conf" ,
943+ ValueFrom : nil ,
944+ },
945+ {
946+ Name : "AZURE_STORAGE_CONNECTION_STRING" ,
947+ Value : "" ,
948+ ValueFrom : & corev1.EnvVarSource {
949+ SecretKeyRef : & corev1.SecretKeySelector {
950+ LocalObjectReference : corev1.LocalObjectReference {
951+ Name : blobsSecretName ,
952+ },
953+ Key : "AZURE_STORAGE_CONNECTION_STRING" ,
954+ },
955+ },
956+ },
957+ {Name : "MS_MAPFILE" , Value : "mapfile.map" , ValueFrom : nil },
958+ }
959+ Expect (deployment .Spec .Template .Spec .Containers [0 ].Env ).Should (Equal (envContainer ))
960+ })
901961 })
902962})
903963
@@ -978,12 +1038,12 @@ func checkWMSLabels(labelSets ...map[string]string) {
9781038 }
9791039}
9801040
981- func getInitContainer (name string , deployment * appsv1.Deployment ) (v1 .Container , error ) {
1041+ func getInitContainer (name string , deployment * appsv1.Deployment ) (corev1 .Container , error ) {
9821042 for _ , container := range deployment .Spec .Template .Spec .InitContainers {
9831043 if container .Name == name {
9841044 return container , nil
9851045 }
9861046 }
9871047
988- return v1 .Container {}, fmt .Errorf ("init container with name %s not found" , name )
1048+ return corev1 .Container {}, fmt .Errorf ("init container with name %s not found" , name )
9891049}
0 commit comments