Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions internal/controller/configmaps.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controller

import (
"fmt"
"strings"

pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
Expand Down Expand Up @@ -116,14 +117,7 @@ func mutateConfigMap[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, configMap *cor
configMap.Immutable = smoothoperatorutils.Pointer(true)
configMap.Data = map[string]string{}

staticFileName, contents := static.GetStaticFiles()
for _, name := range staticFileName {
content := contents[name]
if name == "include.conf" {
content = []byte(strings.ReplaceAll(string(content), "/{{ service_path }}", obj.URL().Path))
}
configMap.Data[name] = string(content)
}
updateConfigMapWithStaticFiles(configMap, obj)

if err := smoothoperatorutils.EnsureSetGVK(reconcilerClient, configMap, configMap); err != nil {
return err
Expand All @@ -133,3 +127,21 @@ func mutateConfigMap[R Reconciler, O pdoknlv3.WMSWFS](r R, obj O, configMap *cor
}
return smoothoperatorutils.AddHashSuffix(configMap)
}

func updateConfigMapWithStaticFiles[O pdoknlv3.WMSWFS](configMap *corev1.ConfigMap, obj O) {
staticFileName, contents := static.GetStaticFiles()
for _, name := range staticFileName {
content := contents[name]
if name == "include.conf" {
ingressRouteUrls := obj.IngressRouteURLs(true)
rewriteRules := make([]string, 0)
for _, ingressRouteURL := range ingressRouteUrls {
rewriteRules = append(rewriteRules, fmt.Sprintf(" \"%s/legend(.*)\" => \"/legend$1\"", ingressRouteURL.URL.Path))
rewriteRules = append(rewriteRules, fmt.Sprintf(" \"%s(.*)\" => \"/mapserver$1\"", ingressRouteURL.URL.Path))
}

content = []byte(strings.ReplaceAll(string(content), "{{ rewrite_rules }}", strings.Join(rewriteRules, ",\n")))
}
configMap.Data[name] = string(content)
}
}
31 changes: 31 additions & 0 deletions internal/controller/configmaps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package controller

import (
"os"
"testing"

pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
"github.com/pdok/mapserver-operator/internal/controller/constants"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
"sigs.k8s.io/yaml"
)

func TestMapserverConfigMaps(t *testing.T) {
wfsBytes, err := os.ReadFile("test_data/wfs/complete/input/wfs.yaml")
assert.NoError(t, err)
o := &pdoknlv3.WFS{}
err = yaml.Unmarshal(wfsBytes, o)
assert.NoError(t, err)
generatedConfigMap := getBareConfigMap(o, constants.MapserverName)
generatedConfigMap.Data = make(map[string]string)
updateConfigMapWithStaticFiles(generatedConfigMap, o)

expectedConfigMap := v1.ConfigMap{}
expectedBytes, err := os.ReadFile("test_data/wfs/complete/expected/configmap-mapserver.yaml")
assert.NoError(t, err)
err = yaml.Unmarshal(expectedBytes, &expectedConfigMap)
assert.NoError(t, err)

assert.Equal(t, expectedConfigMap.Data, generatedConfigMap.Data)
}
3 changes: 1 addition & 2 deletions internal/controller/static/files/include.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ $HTTP["remoteip"] =~ "^(127\.0\.0\.1|172\.(1[6-9]|2[0-9]|3[01])\.|10\.|192\.168\
}

url.rewrite-once = (
"/{{ service_path }}/legend(.*)" => "/legend$1",
"/{{ service_path }}(.*)" => "/mapserver$1"
{{ rewrite_rules }}
)

magnet.attract-raw-url-to += ( "/srv/mapserver/config/ogc.lua" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data:
MAP "/srv/data/config/mapfile/service.map"
END
END
include.conf: |-
include.conf: |
server.modules += ( "mod_status" )

$HTTP["remoteip"] =~ "^(127\.0\.0\.1|172\.(1[6-9]|2[0-9]|3[01])\.|10\.|192\.168\.)" {
Expand All @@ -18,7 +18,9 @@ data:

url.rewrite-once = (
"/datasetOwner/dataset/theme/wfs/v1_0/legend(.*)" => "/legend$1",
"/datasetOwner/dataset/theme/wfs/v1_0(.*)" => "/mapserver$1"
"/datasetOwner/dataset/theme/wfs/v1_0(.*)" => "/mapserver$1",
"/other/path/legend(.*)" => "/legend$1",
"/other/path(.*)" => "/mapserver$1"
)

magnet.attract-raw-url-to += ( "/srv/mapserver/config/ogc.lua" )
Expand Down Expand Up @@ -110,7 +112,7 @@ data:
end
end
end
scraping-error.xml: |-
scraping-error.xml: |
<?xml version="1.0" encoding="UTF-8"?>
<ows:ExceptionReport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows/1.1" version="2.0.0" xml:lang="en-US" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd">
<ows:Exception exceptionCode="InvalidParameterValue" locator="typename">
Expand All @@ -130,7 +132,7 @@ metadata:
service-type: wfs
service-version: v1_0
theme: theme
name: complete-wfs-mapserver-4dm5625f45
name: complete-wfs-mapserver-bfcm4d47kh
namespace: default
ownerReferences:
- apiVersion: pdok.nl/v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ spec:
- emptyDir: {}
name: data
- configMap:
name: complete-wfs-mapserver-4dm5625f45
name: complete-wfs-mapserver-bfcm4d47kh
defaultMode: 420
name: mapserver
- configMap:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ metadata:
service-type: wms
service-version: v1_0
theme: "2016"
name: complete-wms-mapserver-84kmc4cbf6
name: complete-wms-mapserver-88ckd472mk
namespace: default
ownerReferences:
- apiVersion: pdok.nl/v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ spec:
- emptyDir: {}
name: data
- configMap:
name: complete-wms-mapserver-84kmc4cbf6
name: complete-wms-mapserver-88ckd472mk
defaultMode: 420
name: mapserver
- configMap:
Expand Down
Loading