Skip to content

Commit c05b4b9

Browse files
authored
Merge pull request #15 from PDOK/PDOK-17796-WMS-reconcile
WMS Reconcile
2 parents 144b56a + 31e5ae9 commit c05b4b9

File tree

21 files changed

+2353
-712
lines changed

21 files changed

+2353
-712
lines changed

api/v3/shared_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,8 @@ func Sha1HashOfName[O WMSWFS](obj O) string {
158158

159159
return hex.EncodeToString(s.Sum(nil))
160160
}
161+
162+
func (o *Options) UseWebserviceProxy() bool {
163+
// options.DisableWebserviceProxy not set or false
164+
return o != nil && (o.DisableWebserviceProxy == nil || !*o.DisableWebserviceProxy)
165+
}

cmd/main.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ import (
4848
)
4949

5050
const (
51-
defaultMapserverImage = "acrpdokprodman.azurecr.io/mirror/docker.io/pdok/mapserver:8.4.0-4"
5251
defaultMultitoolImage = "acrpdokprodman.azurecr.io/pdok/docker-multitool:0.9.4"
5352
defaultMapfileGeneratorImage = "acrpdokprodman.azurecr.io/pdok/mapfile-generator:1.9.5"
53+
defaultMapserverImage = "acrpdokprodman.azurecr.io/mirror/docker.io/pdok/mapserver:8.4.0-4-nl"
5454
defaultCapabilitiesGeneratorImage = "acrpdokprodman.azurecr.io/mirror/docker.io/pdok/ogc-capabilities-generator:1.0.0-beta5"
5555
defaultFeatureinfoGeneratorImage = "acrpdokprodman.azurecr.io/mirror/docker.io/pdok/featureinfo-generator:v1.4.0-beta1"
56+
defaultOgcWebserviceProxyImage = "acrpdokprodman.azurecr.io/pdok/ogc-webservice-proxy:0.1.8"
5657
)
5758

5859
var (
@@ -80,11 +81,7 @@ func main() {
8081
var enableHTTP2 bool
8182
var tlsOpts []func(*tls.Config)
8283
var host string
83-
var mapserverImage string
84-
var multitoolImage string
85-
var mapfileGeneratorImage string
86-
var capabilitiesGeneratorImage string
87-
var featureinfoGeneratorImage string
84+
var multitoolImage, mapfileGeneratorImage, mapserverImage, capabilitiesGeneratorImage, featureinfoGeneratorImage, ogcWebserviceProxyImage string
8885
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
8986
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
9087
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -103,11 +100,12 @@ func main() {
103100
flag.BoolVar(&enableHTTP2, "enable-http2", false,
104101
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
105102
flag.StringVar(&host, "baseurl", "", "The host which is used in the mapserver service.")
106-
flag.StringVar(&mapserverImage, "mapserver-image", defaultMapserverImage, "The image to use in the blob download init-container.")
107103
flag.StringVar(&multitoolImage, "multitool-image", defaultMultitoolImage, "The image to use in the blob download init-container.")
108104
flag.StringVar(&mapfileGeneratorImage, "mapfile-generator-image", defaultMapfileGeneratorImage, "The image to use in the mapfile generator init-container.")
105+
flag.StringVar(&mapserverImage, "mapserver-image", defaultMapserverImage, "The image to use in the mapserver container.")
109106
flag.StringVar(&capabilitiesGeneratorImage, "capabilities-generator-image", defaultCapabilitiesGeneratorImage, "The image to use in the capabilities generator init-container.")
110107
flag.StringVar(&featureinfoGeneratorImage, "featureinfo-generator-image", defaultFeatureinfoGeneratorImage, "The image to use in the featureinfo generator init-container.")
108+
flag.StringVar(&ogcWebserviceProxyImage, "ogc-webservice-proxy-image", defaultOgcWebserviceProxyImage, "The image to use in the ogc webservice proxy container.")
111109

112110
opts := zap.Options{
113111
Development: true,
@@ -237,20 +235,29 @@ func main() {
237235
}
238236

239237
if err = (&controller.WMSReconciler{
240-
Client: mgr.GetClient(),
241-
Scheme: mgr.GetScheme(),
242-
FeatureinfoGeneratorImage: featureinfoGeneratorImage,
238+
Client: mgr.GetClient(),
239+
Scheme: mgr.GetScheme(),
240+
Images: controller.Images{
241+
MultitoolImage: multitoolImage,
242+
MapfileGeneratorImage: mapfileGeneratorImage,
243+
MapserverImage: mapserverImage,
244+
CapabilitiesGeneratorImage: capabilitiesGeneratorImage,
245+
FeatureinfoGeneratorImage: featureinfoGeneratorImage,
246+
OgcWebserviceProxyImage: ogcWebserviceProxyImage,
247+
},
243248
}).SetupWithManager(mgr); err != nil {
244249
setupLog.Error(err, "unable to create controller", "controller", "WMS")
245250
os.Exit(1)
246251
}
247252
if err = (&controller.WFSReconciler{
248-
Client: mgr.GetClient(),
249-
Scheme: mgr.GetScheme(),
250-
MapserverImage: mapserverImage,
251-
MultitoolImage: multitoolImage,
252-
MapfileGeneratorImage: mapfileGeneratorImage,
253-
CapabilitiesGeneratorImage: capabilitiesGeneratorImage,
253+
Client: mgr.GetClient(),
254+
Scheme: mgr.GetScheme(),
255+
Images: controller.Images{
256+
MultitoolImage: multitoolImage,
257+
MapfileGeneratorImage: mapfileGeneratorImage,
258+
MapserverImage: mapserverImage,
259+
CapabilitiesGeneratorImage: capabilitiesGeneratorImage,
260+
},
254261
}).SetupWithManager(mgr); err != nil {
255262
setupLog.Error(err, "unable to create controller", "controller", "WFS")
256263
os.Exit(1)

config/samples/v3_wms.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
app.kubernetes.io/managed-by: kustomize
77
dataset: dataset
88
dataset-owner: owner
9-
service-type: wfs
9+
service-type: wms
1010
service-version: 1.0.0
1111
name: sample-v3
1212
spec:

internal/controller/blobdownload/blob_download.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ func downloadTiffs(sb *strings.Builder, wms *pdoknlv3.WMS) error {
139139
}
140140

141141
func downloadStylingAssets(sb *strings.Builder, wms *pdoknlv3.WMS) error {
142+
if wms.Spec.Service.StylingAssets == nil { // TODO Is StylingAssets required and should this return an error?
143+
return nil
144+
}
145+
142146
re := regexp.MustCompile(".*\\.(ttf)$")
143147
for _, blobKey := range wms.Spec.Service.StylingAssets.BlobKeys {
144148
fileName, err := getFilenameFromBlobKey(blobKey)

internal/controller/featureinfogenerator/featureinfo_generator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"encoding/json"
55
"fmt"
66
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
7+
"github.com/pdok/mapserver-operator/internal/controller/mapserver"
78
corev1 "k8s.io/api/core/v1"
89
)
910

1011
const (
11-
htmlTemplatesPath = "/srv/data/config/templates"
12-
ConfigMapFeatureinfoGeneratorVolumeName = "featureinfo-generator-config"
12+
htmlTemplatesPath = "/srv/data/config/templates"
1313
)
1414

1515
func GetFeatureinfoGeneratorInitContainer(image string, srvDir string) (*corev1.Container, error) {
@@ -28,7 +28,7 @@ func GetFeatureinfoGeneratorInitContainer(image string, srvDir string) (*corev1.
2828
},
2929
VolumeMounts: []corev1.VolumeMount{
3030
{Name: "base", MountPath: srvDir + "/data", ReadOnly: false},
31-
{Name: ConfigMapFeatureinfoGeneratorVolumeName, MountPath: "/input", ReadOnly: true},
31+
{Name: mapserver.ConfigMapFeatureinfoGeneratorVolumeName, MountPath: "/input", ReadOnly: true},
3232
},
3333
}
3434

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package legendgenerator
2+
3+
import (
4+
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
5+
"github.com/pdok/mapserver-operator/internal/controller/mapserver"
6+
corev1 "k8s.io/api/core/v1"
7+
)
8+
9+
func GetLegendGeneratorInitContainer(wms *pdoknlv3.WMS, image string, srvDir string) (*corev1.Container, error) {
10+
initContainer := corev1.Container{
11+
Name: "legend-generator",
12+
Image: image,
13+
ImagePullPolicy: corev1.PullIfNotPresent,
14+
Env: []corev1.EnvVar{mapserver.GetMapfileEnvVar(wms)},
15+
Command: []string{
16+
"bash",
17+
"-c",
18+
`set -eu;
19+
cat /input/input | xargs -n 2 echo | while read layer style; do
20+
echo Generating legend for layer: $layer, style: $style;
21+
mkdir -p /var/www/legend/$layer;
22+
mapserv -nh 'QUERY_STRING=SERVICE=WMS&language=dut&version=1.3.0&service=WMS&request=GetLegendGraphic&sld_version=1.1.0&layer='$layer'&format=image/png&STYLE='$style'' > /var/www/legend/$layer/${style}.png;
23+
done
24+
`,
25+
},
26+
VolumeMounts: []corev1.VolumeMount{
27+
{Name: "base", MountPath: srvDir + "/data", ReadOnly: false},
28+
getDataVolumeMount(),
29+
getConfigVolumeMount(),
30+
},
31+
}
32+
33+
if wms.Spec.Service.Mapfile != nil {
34+
volumeMount := corev1.VolumeMount{
35+
Name: "mapfile",
36+
MountPath: "/srv/data/config/mapfile",
37+
}
38+
initContainer.VolumeMounts = append(initContainer.VolumeMounts, volumeMount)
39+
}
40+
41+
return &initContainer, nil
42+
}
43+
44+
func GetLegendFixerInitContainer(image string) *corev1.Container {
45+
return &corev1.Container{
46+
Name: "legend-fixer",
47+
Image: image,
48+
ImagePullPolicy: corev1.PullIfNotPresent,
49+
Command: []string{
50+
"/bin/bash",
51+
"/input/legend-fixer.sh",
52+
},
53+
VolumeMounts: []corev1.VolumeMount{
54+
getDataVolumeMount(),
55+
getConfigVolumeMount(),
56+
},
57+
}
58+
}
59+
60+
func GetConfigMapData(wms *pdoknlv3.WMS) map[string]string {
61+
data := map[string]string{
62+
"default_mapserver.conf": defaultMapserverConf,
63+
}
64+
65+
addLayerInput(wms, data)
66+
if wms.Spec.Options.RewriteGroupToDataLayers != nil && *wms.Spec.Options.RewriteGroupToDataLayers {
67+
addLegendFixerConfig(wms, data)
68+
}
69+
return data
70+
}
71+
72+
func getDataVolumeMount() corev1.VolumeMount {
73+
return corev1.VolumeMount{Name: "data", MountPath: "/var/www", ReadOnly: false}
74+
}
75+
76+
func getConfigVolumeMount() corev1.VolumeMount {
77+
return corev1.VolumeMount{Name: mapserver.ConfigMapLegendGeneratorVolumeName, MountPath: "/input", ReadOnly: true}
78+
}

internal/controller/legendgenerator/mapper_test.go renamed to internal/controller/legendgenerator/legend_generator_test.go

Lines changed: 10 additions & 24 deletions
Large diffs are not rendered by default.

internal/controller/legendgenerator/mapper.go

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ package legendgenerator
33
import (
44
"fmt"
55
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
6-
"github.com/pdok/mapserver-operator/internal/controller"
7-
smoothoperatorutils "github.com/pdok/smooth-operator/pkg/util"
8-
corev1 "k8s.io/api/core/v1"
9-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10-
"os"
6+
7+
_ "embed"
118
"sigs.k8s.io/yaml"
129
"strings"
1310
)
1411

12+
// TODO Reuse default_mapserver.conf from static_files?
1513
const (
1614
defaultMapserverConf = `CONFIG
1715
ENV
@@ -21,6 +19,9 @@ END
2119
`
2220
)
2321

22+
//go:embed legend-fixer.sh
23+
var legendFixerScript string
24+
2425
type LegendReference struct {
2526
Layer string `yaml:"layer" json:"layer"`
2627
Style string `yaml:"style" json:"style"`
@@ -30,33 +31,6 @@ type OgcWebserviceProxyConfig struct {
3031
GroupLayers map[string][]string `yaml:"grouplayers" json:"grouplayers"`
3132
}
3233

33-
func getBareConfigMapLegendGenerator(obj metav1.Object) *corev1.ConfigMap {
34-
return &corev1.ConfigMap{
35-
ObjectMeta: metav1.ObjectMeta{
36-
Name: obj.GetName() + "-legend-generator",
37-
Namespace: obj.GetNamespace(),
38-
},
39-
}
40-
}
41-
42-
func GetLegendGeneratorConfigMap(wms *pdoknlv3.WMS) *corev1.ConfigMap {
43-
result := getBareConfigMapLegendGenerator(wms)
44-
labels := controller.AddCommonLabels(wms, smoothoperatorutils.CloneOrEmptyMap(wms.GetLabels()))
45-
result.Labels = labels
46-
47-
result.Immutable = smoothoperatorutils.Pointer(true)
48-
result.Data = map[string]string{}
49-
result.Data["default_mapserver.conf"] = defaultMapserverConf
50-
51-
addLayerInput(wms, result.Data)
52-
53-
if wms.Spec.Options.RewriteGroupToDataLayers != nil && *wms.Spec.Options.RewriteGroupToDataLayers {
54-
addLegendFixerConfig(wms, result.Data)
55-
}
56-
57-
return result
58-
}
59-
6034
func addLayerInput(wms *pdoknlv3.WMS, data map[string]string) {
6135
legendReferences := make([]LegendReference, 0)
6236

@@ -100,10 +74,7 @@ func processLayer(layer *pdoknlv3.Layer, legendReferences *[]LegendReference) {
10074
}
10175

10276
func addLegendFixerConfig(wms *pdoknlv3.WMS, data map[string]string) {
103-
fileBytes, err := os.ReadFile("./legend-fixer.sh")
104-
if err == nil {
105-
data["legend-fixer.sh"] = string(fileBytes)
106-
}
77+
data["legend-fixer.sh"] = legendFixerScript
10778

10879
topLayer := wms.Spec.Service.Layer
10980

@@ -154,7 +125,7 @@ func addLegendFixerConfig(wms *pdoknlv3.WMS, data map[string]string) {
154125
}
155126

156127
ogcWebServiceProxyConfig := OgcWebserviceProxyConfig{GroupLayers: groupLayers}
157-
proxyConfigData, err := yaml.Marshal(ogcWebServiceProxyConfig)
128+
proxyConfigData, _ := yaml.Marshal(ogcWebServiceProxyConfig)
158129
data["ogc-webservice-proxy-config.yaml"] = string(proxyConfigData)
159130
}
160131

0 commit comments

Comments
 (0)