Skip to content

Commit 30cf806

Browse files
author
Jelle Dijkstra
committed
Running wfs
1 parent 85f8de4 commit 30cf806

File tree

15 files changed

+213
-55
lines changed

15 files changed

+213
-55
lines changed

api/v3/shared_types.go

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,33 @@ type WMSWFS interface {
3636
// Sha1 hash of the objects name
3737
ID() string
3838
URLPath() string
39+
40+
GeoPackages() []*Gpkg
3941
}
4042

4143
type Mapfile struct {
4244
ConfigMapKeyRef corev1.ConfigMapKeySelector `json:"configMapKeyRef"`
4345
}
4446

4547
type Options struct {
46-
IncludeIngress bool `json:"includeIngress"`
47-
AutomaticCasing bool `json:"automaticCasing"`
48-
ValidateRequests *bool `json:"validateRequests,omitempty"`
49-
RewriteGroupToDataLayers *bool `json:"rewriteGroupToDataLayers,omitempty"`
50-
DisableWebserviceProxy *bool `json:"disableWebserviceProxy,omitempty"`
51-
PrefetchData *bool `json:"prefetchData,omitempty"`
48+
// +kubebuilder:default:=true
49+
IncludeIngress bool `json:"includeIngress"`
50+
51+
// +kubebuilder:default:=true
52+
AutomaticCasing bool `json:"automaticCasing"`
53+
54+
// +kubebuilder:default:=true
55+
ValidateRequests *bool `json:"validateRequests,omitempty"`
56+
57+
// +kubebuilder:default:=false
58+
RewriteGroupToDataLayers *bool `json:"rewriteGroupToDataLayers,omitempty"`
59+
60+
// +kubebuilder:default:=false
61+
DisableWebserviceProxy *bool `json:"disableWebserviceProxy,omitempty"`
62+
63+
// +kubebuilder:default:=true
64+
PrefetchData *bool `json:"prefetchData,omitempty"`
65+
5266
ValidateChildStyleNameEqual *bool `json:"validateChildStyleNameEqual,omitempty"`
5367
}
5468

@@ -108,8 +122,16 @@ func SetHost(url string) {
108122
host = strings.TrimSuffix(url, "/")
109123
}
110124

111-
func GetHost() string {
112-
return host
125+
func GetHost(includeProtocol bool) string {
126+
if includeProtocol {
127+
return host
128+
} else {
129+
if strings.HasPrefix(host, "http") {
130+
return strings.Split(host, "://")[1]
131+
} else {
132+
return host
133+
}
134+
}
113135
}
114136

115137
func GetBaseURLPath[T WMSWFS](o T) string {

api/v3/wfs_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,15 @@ func (wfs *WFS) ID() string {
157157
func (wfs *WFS) URLPath() string {
158158
return wfs.Spec.Service.URL
159159
}
160+
161+
func (wfs *WFS) GeoPackages() []*Gpkg {
162+
gpkgs := make([]*Gpkg, 0)
163+
164+
for _, ft := range wfs.Spec.Service.FeatureTypes {
165+
if ft.Data.Gpkg != nil {
166+
gpkgs = append(gpkgs, ft.Data.Gpkg)
167+
}
168+
}
169+
170+
return gpkgs
171+
}

api/v3/wms_types.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,25 @@ func (wms *WMS) ID() string {
343343
func (wms *WMS) URLPath() string {
344344
return wms.Spec.Service.URL
345345
}
346+
347+
func (wms *WMS) GeoPackages() []*Gpkg {
348+
gpkgs := make([]*Gpkg, 0)
349+
350+
if wms.Spec.Service.Layer.Layers != nil {
351+
for _, layer := range *wms.Spec.Service.Layer.Layers {
352+
if layer.Data != nil {
353+
if layer.Data.Gpkg != nil {
354+
gpkgs = append(gpkgs, layer.Data.Gpkg)
355+
}
356+
} else if layer.Layers != nil {
357+
for _, childLayer := range *layer.Layers {
358+
if childLayer.Data != nil && childLayer.Data.Gpkg != nil {
359+
gpkgs = append(gpkgs, childLayer.Data.Gpkg)
360+
}
361+
}
362+
}
363+
}
364+
}
365+
366+
return gpkgs
367+
}

cmd/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"crypto/tls"
2121
"errors"
2222
"flag"
23+
"github.com/pdok/mapserver-operator/internal/controller/mapfilegenerator"
2324
smoothoperator "github.com/pdok/smooth-operator/api/v1"
2425
traefikiov1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
2526
"os"
@@ -54,6 +55,7 @@ const (
5455
defaultCapabilitiesGeneratorImage = "acrpdokprodman.azurecr.io/mirror/docker.io/pdok/ogc-capabilities-generator:1.0.0-beta7"
5556
defaultFeatureinfoGeneratorImage = "acrpdokprodman.azurecr.io/mirror/docker.io/pdok/featureinfo-generator:v1.4.0-beta1"
5657
defaultOgcWebserviceProxyImage = "acrpdokprodman.azurecr.io/pdok/ogc-webservice-proxy:0.1.8"
58+
defaultApacheExporterImage = "acrpdokprodman.azurecr.io/mirror/docker.io/lusotycoon/apache-exporter:v0.7.0"
5759
)
5860

5961
var (
@@ -81,7 +83,8 @@ func main() {
8183
var enableHTTP2 bool
8284
var tlsOpts []func(*tls.Config)
8385
var host string
84-
var multitoolImage, mapfileGeneratorImage, mapserverImage, capabilitiesGeneratorImage, featureinfoGeneratorImage, ogcWebserviceProxyImage string
86+
var mapserverDebugLevel int
87+
var multitoolImage, mapfileGeneratorImage, mapserverImage, capabilitiesGeneratorImage, featureinfoGeneratorImage, ogcWebserviceProxyImage, apacheExporterImage string
8588
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
8689
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
8790
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -106,6 +109,8 @@ func main() {
106109
flag.StringVar(&capabilitiesGeneratorImage, "capabilities-generator-image", defaultCapabilitiesGeneratorImage, "The image to use in the capabilities generator init-container.")
107110
flag.StringVar(&featureinfoGeneratorImage, "featureinfo-generator-image", defaultFeatureinfoGeneratorImage, "The image to use in the featureinfo generator init-container.")
108111
flag.StringVar(&ogcWebserviceProxyImage, "ogc-webservice-proxy-image", defaultOgcWebserviceProxyImage, "The image to use in the ogc webservice proxy container.")
112+
flag.StringVar(&apacheExporterImage, "apache-exporter-image", defaultApacheExporterImage, "The image to use in the apache-exporter container.")
113+
flag.IntVar(&mapserverDebugLevel, "mapserver-debug-level", 0, "Debug level for the mapserver container, between 0 (error only) and 5 (very very verbose).")
109114

110115
opts := zap.Options{
111116
Development: true,
@@ -120,6 +125,7 @@ func main() {
120125
os.Exit(1)
121126
}
122127
pdoknlv3.SetHost(host)
128+
mapfilegenerator.SetDebugLevel(mapserverDebugLevel)
123129

124130
// if the enable-http2 flag is false (the default), http/2 should be disabled
125131
// due to its vulnerabilities. More specifically, disabling http/2 will
@@ -244,6 +250,7 @@ func main() {
244250
CapabilitiesGeneratorImage: capabilitiesGeneratorImage,
245251
FeatureinfoGeneratorImage: featureinfoGeneratorImage,
246252
OgcWebserviceProxyImage: ogcWebserviceProxyImage,
253+
ApacheExporterImage: apacheExporterImage,
247254
},
248255
}).SetupWithManager(mgr); err != nil {
249256
setupLog.Error(err, "unable to create controller", "controller", "WMS")
@@ -257,6 +264,7 @@ func main() {
257264
MapfileGeneratorImage: mapfileGeneratorImage,
258265
MapserverImage: mapserverImage,
259266
CapabilitiesGeneratorImage: capabilitiesGeneratorImage,
267+
ApacheExporterImage: apacheExporterImage,
260268
},
261269
}).SetupWithManager(mgr); err != nil {
262270
setupLog.Error(err, "unable to create controller", "controller", "WFS")

config/crd/bases/pdok.nl_wfs.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,18 +1094,24 @@ spec:
10941094
options:
10951095
properties:
10961096
automaticCasing:
1097+
default: true
10971098
type: boolean
10981099
disableWebserviceProxy:
1100+
default: false
10991101
type: boolean
11001102
includeIngress:
1103+
default: true
11011104
type: boolean
11021105
prefetchData:
1106+
default: true
11031107
type: boolean
11041108
rewriteGroupToDataLayers:
1109+
default: false
11051110
type: boolean
11061111
validateChildStyleNameEqual:
11071112
type: boolean
11081113
validateRequests:
1114+
default: true
11091115
type: boolean
11101116
required:
11111117
- automaticCasing

config/crd/bases/pdok.nl_wms.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,18 +1154,24 @@ spec:
11541154
options:
11551155
properties:
11561156
automaticCasing:
1157+
default: true
11571158
type: boolean
11581159
disableWebserviceProxy:
1160+
default: false
11591161
type: boolean
11601162
includeIngress:
1163+
default: true
11611164
type: boolean
11621165
prefetchData:
1166+
default: true
11631167
type: boolean
11641168
rewriteGroupToDataLayers:
1169+
default: false
11651170
type: boolean
11661171
validateChildStyleNameEqual:
11671172
type: boolean
11681173
validateRequests:
1174+
default: true
11691175
type: boolean
11701176
required:
11711177
- automaticCasing

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ kind: Kustomization
55
images:
66
- name: controller
77
newName: local-registry:5000/mapserver-operator
8-
newTag: v3.0.34
8+
newTag: v3.0.2

config/manager/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec:
6363
args:
6464
- --leader-elect
6565
- --health-probe-bind-address=:8081
66-
- --baseurl=https://test.example.nl
66+
- --baseurl=http://localhost:32788
6767
image: controller:latest
6868
name: manager
6969
ports: []

internal/controller/blobdownload/blob_download.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,25 @@ func GetScript() string {
3030
}
3131

3232
func GetBlobDownloadInitContainer[O pdoknlv3.WMSWFS](obj O, image, blobsConfigName, blobsSecretName, srvDir string) (*corev1.Container, error) {
33+
blobkeys := []string{}
34+
for _, gpkg := range obj.GeoPackages() {
35+
blobkeys = append(blobkeys, gpkg.BlobKey)
36+
}
37+
3338
initContainer := corev1.Container{
3439
Name: "blob-download",
3540
Image: image,
3641
ImagePullPolicy: corev1.PullIfNotPresent,
42+
Env: []corev1.EnvVar{
43+
{
44+
Name: "GEOPACKAGE_TARGET_PATH",
45+
Value: "/srv/data/gpkg",
46+
},
47+
{
48+
Name: "GEOPACKAGE_DOWNLOAD_LIST",
49+
Value: strings.Join(blobkeys, ";"),
50+
},
51+
},
3752
EnvFrom: []corev1.EnvFromSource{
3853
// Todo add this ConfigMap
3954
utils.NewEnvFromSource(utils.EnvFromSourceTypeConfigMap, blobsConfigName),
@@ -71,7 +86,7 @@ func GetBlobDownloadInitContainer[O pdoknlv3.WMSWFS](obj O, image, blobsConfigNa
7186
if options.PrefetchData != nil && *options.PrefetchData {
7287
mount := corev1.VolumeMount{
7388
Name: mapserver.ConfigMapBlobDownloadVolumeName,
74-
MountPath: "/src/scripts",
89+
MountPath: "/srv/scripts",
7590
ReadOnly: true,
7691
}
7792
initContainer.VolumeMounts = append(initContainer.VolumeMounts, mount)

internal/controller/blobdownload/gpkg_download.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function download() {
6161
fi
6262

6363
local gpkg=$1
64-
local file={{ gpkg_path }}/$2
64+
local file=$GEOPACKAGE_TARGET_PATH/$2
6565
local url=${BLOBS_ENDPOINT}/${gpkg}
6666

6767
download_gpkg $gpkg $file $url
@@ -112,12 +112,17 @@ function download_all() {
112112
local start_time=$(date '+%s')
113113

114114
# create target location if not exists
115-
mkdir -p {{ gpkg_path }}
116-
chown 999:999 {{ gpkg_path }}
117-
118-
{% for blobKey in (service.featureTypes if type == 'wfs' else service.layers if type == 'wms' else []) | json_query('[].data.gpkg.blobKey') | unique %}
119-
download {{ blobKey }} {{ blobKey.split('/') | last }};
120-
{% endfor %}
115+
mkdir -p $GEOPACKAGE_TARGET_PATH
116+
chown 999:999 $GEOPACKAGE_TARGET_PATH
117+
118+
# Download all geopackages from GEOPACKAGE_DOWNLOAD_LIST
119+
# Example: GEOPACKAGE_DOWNLOAD_LIST=path/1/file.gpkg;path/3/other_file.gpkg
120+
gpkgs=(${GEOPACKAGE_DOWNLOAD_LIST//;/ })
121+
for gpkg_path in "${gpkgs[@]}"
122+
do
123+
filename=$(basename $gpkg_path)
124+
download $gpkg_path $filename
125+
done
121126

122127
echo msg=\"All GeoPackages downloaded\" total_time_seconds=$(expr $(date '+%s') - $start_time)
123128
}

0 commit comments

Comments
 (0)