Skip to content

Commit 7c90a8d

Browse files
authored
Merge pull request #6 from PDOK/PDOK-17805-mapserver-operator-mapfile-generator-configmap
PDOK-17805 Setup mapfile generator in configmap
2 parents 705fcfb + 8119171 commit 7c90a8d

File tree

14 files changed

+680
-45
lines changed

14 files changed

+680
-45
lines changed

api/v2beta1/shared_conversion.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ func ConverseResources(src corev1.ResourceRequirements) *corev1.PodSpec {
8383
}
8484
}
8585

86-
func ConverseColumnAndAliasesV2ToColumnsWithAliasV3(columns []string, aliases map[string]string) []pdoknlv3.Columns {
87-
v3Columns := make([]pdoknlv3.Columns, 0)
86+
func ConverseColumnAndAliasesV2ToColumnsWithAliasV3(columns []string, aliases map[string]string) []pdoknlv3.Column {
87+
v3Columns := make([]pdoknlv3.Column, 0)
8888
for _, column := range columns {
89-
col := pdoknlv3.Columns{
89+
col := pdoknlv3.Column{
9090
Name: column,
9191
}
9292

@@ -101,7 +101,7 @@ func ConverseColumnAndAliasesV2ToColumnsWithAliasV3(columns []string, aliases ma
101101
return v3Columns
102102
}
103103

104-
func ConverseColumnsWithAliasV3ToColumnsAndAliasesV2(columns []pdoknlv3.Columns) ([]string, map[string]string) {
104+
func ConverseColumnsWithAliasV3ToColumnsAndAliasesV2(columns []pdoknlv3.Column) ([]string, map[string]string) {
105105
v2Columns := make([]string, 0)
106106
v2Aliases := make(map[string]string)
107107

api/v3/shared_types.go

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package v3
22

3-
import corev1 "k8s.io/api/core/v1"
3+
import (
4+
corev1 "k8s.io/api/core/v1"
5+
"strings"
6+
)
7+
8+
var baseURL string
49

510
type Mapfile struct {
611
ConfigMapKeyRef corev1.ConfigMapKeySelector `json:"configMapKeyRef"`
@@ -43,17 +48,17 @@ type Data struct {
4348
}
4449

4550
type Gpkg struct {
46-
BlobKey string `json:"blobKey"`
47-
TableName string `json:"tableName"`
48-
GeometryType string `json:"geometryType"`
49-
Columns []Columns `json:"columns"`
51+
BlobKey string `json:"blobKey"`
52+
TableName string `json:"tableName"`
53+
GeometryType string `json:"geometryType"`
54+
Columns []Column `json:"columns"`
5055
}
5156

5257
// Postgis - reference to table in a Postgres database
5358
type Postgis struct {
54-
TableName string `json:"tableName"`
55-
GeometryType string `json:"geometryType"`
56-
Columns []Columns `json:"columns"`
59+
TableName string `json:"tableName"`
60+
GeometryType string `json:"geometryType"`
61+
Columns []Column `json:"columns"`
5762
}
5863

5964
type TIF struct {
@@ -63,7 +68,48 @@ type TIF struct {
6368
GetFeatureInfoIncludesClass *bool `json:"getFeatureInfoIncludesClass,omitempty"`
6469
}
6570

66-
type Columns struct {
71+
type Column struct {
6772
Name string `json:"name"`
6873
Alias *string `json:"alias,omitempty"`
6974
}
75+
76+
func SetBaseURL(url string) {
77+
baseURL = strings.TrimSuffix(url, "/")
78+
}
79+
80+
func GetBaseURL() string {
81+
return baseURL
82+
}
83+
84+
func (d *Data) GetColumns() *[]Column {
85+
switch {
86+
case d.Gpkg != nil:
87+
return &d.Gpkg.Columns
88+
case d.Postgis != nil:
89+
return &d.Postgis.Columns
90+
default:
91+
return nil
92+
}
93+
}
94+
95+
func (d *Data) GetTableName() *string {
96+
switch {
97+
case d.Gpkg != nil:
98+
return &d.Gpkg.TableName
99+
case d.Postgis != nil:
100+
return &d.Postgis.TableName
101+
default:
102+
return nil
103+
}
104+
}
105+
106+
func (d *Data) GetGeometryType() *string {
107+
switch {
108+
case d.Gpkg != nil:
109+
return &d.Gpkg.GeometryType
110+
case d.Postgis != nil:
111+
return &d.Postgis.GeometryType
112+
default:
113+
return nil
114+
}
115+
}

api/v3/wfs_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,12 @@ type FeatureBbox struct {
117117
DefaultCRS shared_model.BBox `json:"defaultCRS"`
118118
WGS84 *shared_model.BBox `json:"wgs84,omitempty"`
119119
}
120+
121+
func (wfs *WFS) HasPostgisData() bool {
122+
for _, featureType := range wfs.Spec.Service.FeatureTypes {
123+
if featureType.Data.Postgis != nil {
124+
return true
125+
}
126+
}
127+
return false
128+
}

api/v3/zz_generated.deepcopy.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"crypto/tls"
21+
"errors"
2122
"flag"
2223
"os"
2324
"path/filepath"
@@ -45,7 +46,8 @@ import (
4546
)
4647

4748
const (
48-
defaultMultitoolImage = "docker.io/pdok/docker-multitool:0.9.1"
49+
defaultMultitoolImage = "docker.io/pdok/docker-multitool:0.9.1"
50+
defaultMapfileGeneratorImage = "docker.io/pdok/mapfile-generator:1.9.3"
4951
)
5052

5153
var (
@@ -71,7 +73,9 @@ func main() {
7173
var secureMetrics bool
7274
var enableHTTP2 bool
7375
var tlsOpts []func(*tls.Config)
76+
var baseURL string
7477
var multitoolImage string
78+
var mapfileGeneratorImage string
7579
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
7680
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
7781
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -89,7 +93,10 @@ func main() {
8993
flag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
9094
flag.BoolVar(&enableHTTP2, "enable-http2", false,
9195
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
96+
flag.StringVar(&baseURL, "baseurl", "", "The base url which is used in the mapserver service.")
9297
flag.StringVar(&multitoolImage, "multitool-image", defaultMultitoolImage, "The image to use in the blob download init-container.")
98+
flag.StringVar(&mapfileGeneratorImage, "mapfile-generator-image", defaultMapfileGeneratorImage, "The image to use in the mapfile generator init-container.")
99+
93100
opts := zap.Options{
94101
Development: true,
95102
}
@@ -98,6 +105,12 @@ func main() {
98105

99106
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
100107

108+
if baseURL == "" {
109+
setupLog.Error(errors.New("baseURL is required"), "A value for baseURL must be specified.")
110+
os.Exit(1)
111+
}
112+
pdoknlv3.SetBaseURL(baseURL)
113+
101114
// if the enable-http2 flag is false (the default), http/2 should be disabled
102115
// due to its vulnerabilities. More specifically, disabling http/2 will
103116
// prevent from being vulnerable to the HTTP/2 Stream Cancellation and
@@ -219,9 +232,10 @@ func main() {
219232
os.Exit(1)
220233
}
221234
if err = (&controller.WFSReconciler{
222-
Client: mgr.GetClient(),
223-
Scheme: mgr.GetScheme(),
224-
MultitoolImage: multitoolImage,
235+
Client: mgr.GetClient(),
236+
Scheme: mgr.GetScheme(),
237+
MultitoolImage: multitoolImage,
238+
MapfileGeneratorImage: mapfileGeneratorImage,
225239
}).SetupWithManager(mgr); err != nil {
226240
setupLog.Error(err, "unable to create controller", "controller", "WFS")
227241
os.Exit(1)

config/manager/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ spec:
6363
args:
6464
- --leader-elect
6565
- --health-probe-bind-address=:8081
66+
- --baseurl=https://test.example.nl
6667
image: controller:latest
6768
name: manager
6869
ports: []

config/rbac/role.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ kind: ClusterRole
44
metadata:
55
name: manager-role
66
rules:
7+
- apiGroups:
8+
- pdok.nl
9+
resources:
10+
- ownerinfo
11+
verbs:
12+
- get
13+
- list
14+
- watch
15+
- apiGroups:
16+
- pdok.nl
17+
resources:
18+
- ownerinfo/status
19+
verbs:
20+
- get
721
- apiGroups:
822
- pdok.nl
923
resources:

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ godebug default=go1.23
77
require (
88
github.com/onsi/ginkgo/v2 v2.21.0
99
github.com/onsi/gomega v1.35.1
10-
github.com/pdok/smooth-operator v0.0.4
1110
k8s.io/api v0.32.0
1211
k8s.io/apimachinery v0.32.0
1312
k8s.io/client-go v0.32.0
1413
sigs.k8s.io/controller-runtime v0.20.0
1514
sigs.k8s.io/yaml v1.4.0
1615
)
1716

17+
require github.com/pdok/smooth-operator v0.0.6
18+
1819
require (
1920
cel.dev/expr v0.18.0 // indirect
2021
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
@@ -27,7 +28,7 @@ require (
2728
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
2829
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
2930
github.com/felixge/httpsnoop v1.0.4 // indirect
30-
github.com/fsnotify/fsnotify v1.8.0 // indirectC
31+
github.com/fsnotify/fsnotify v1.8.0 // indirect; indirectC
3132
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
3233
github.com/go-errors/errors v1.4.2 // indirect
3334
github.com/go-logr/logr v1.4.2 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM
9999
github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
100100
github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
101101
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
102-
github.com/pdok/smooth-operator v0.0.4 h1:NVt7srlkSyiZooqn9R2pnMapY6jwZDVTj4QxUjy7UB0=
103-
github.com/pdok/smooth-operator v0.0.4/go.mod h1:oZWFuIKJGjN/C6ocgMNfMZ7SbLQi+N0qaWj7j95Wdec=
102+
github.com/pdok/smooth-operator v0.0.6 h1:IwgY3X2zYA2XLw0eKmBBN1Md6gNWnoVl0i1R8/wFHvs=
103+
github.com/pdok/smooth-operator v0.0.6/go.mod h1:oZWFuIKJGjN/C6ocgMNfMZ7SbLQi+N0qaWj7j95Wdec=
104104
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
105105
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
106106
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package mapfilegenerator
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
"fmt"
7+
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
8+
smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1"
9+
)
10+
11+
func GetConfig[W *pdoknlv3.WFS | *pdoknlv3.WMS](webservice W, ownerInfo *smoothoperatorv1.OwnerInfo) (config string, err error) {
12+
switch any(webservice).(type) {
13+
case *pdoknlv3.WFS:
14+
if WFS, ok := any(webservice).(*pdoknlv3.WFS); ok {
15+
return createConfigForWFS(WFS, ownerInfo)
16+
}
17+
case *pdoknlv3.WMS:
18+
if _, ok := any(webservice).(*pdoknlv3.WMS); ok {
19+
return "", errors.New("not implemented for WMS")
20+
}
21+
default:
22+
return "", fmt.Errorf("unexpected input, webservice should be of type WFS or WMS, webservice: %v", webservice)
23+
}
24+
return "", fmt.Errorf("unexpected input, webservice should be of type WFS or WMS, webservice: %v", webservice)
25+
}
26+
27+
func createConfigForWFS(wfs *pdoknlv3.WFS, ownerInfo *smoothoperatorv1.OwnerInfo) (config string, err error) {
28+
input, err := MapWFSToMapfileGeneratorInput(wfs, ownerInfo)
29+
if err != nil {
30+
return "", err
31+
}
32+
33+
jsonConfig, err := json.MarshalIndent(input, "", " ")
34+
if err != nil {
35+
return "", err
36+
}
37+
return string(jsonConfig), nil
38+
}

0 commit comments

Comments
 (0)