Skip to content

Commit 9ad68b9

Browse files
author
Jelle Dijkstra
committed
Tests
1 parent d9f72c9 commit 9ad68b9

File tree

17 files changed

+1042
-348
lines changed

17 files changed

+1042
-348
lines changed

api/v3/shared_types.go

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

33
import (
4+
"crypto/sha1"
5+
"io"
46
autoscalingv2 "k8s.io/api/autoscaling/v2"
57
corev1 "k8s.io/api/core/v1"
68
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -17,6 +19,7 @@ const (
1719
ServiceTypeWFS ServiceType = "WFS"
1820
)
1921

22+
// +kubebuilder:object:generate=false
2023
type WMSWFS interface {
2124
*WFS | *WMS
2225
metav1.Object
@@ -26,6 +29,9 @@ type WMSWFS interface {
2629
HorizontalPodAutoscalerPatch() *autoscalingv2.HorizontalPodAutoscalerSpec
2730
Type() ServiceType
2831
Options() *Options
32+
HasPostgisData() bool
33+
// Sha1 hash of the objects name
34+
Id() string
2935
}
3036

3137
type Mapfile struct {
@@ -151,3 +157,10 @@ func (d *Data) GetGeometryType() *string {
151157
return nil
152158
}
153159
}
160+
161+
func Sha1HashOfName[O WMSWFS](obj O) string {
162+
s := sha1.New()
163+
io.WriteString(s, obj.GetName())
164+
165+
return string(s.Sum(nil))
166+
}

api/v3/wfs_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,7 @@ func (wfs *WFS) HorizontalPodAutoscalerPatch() *autoscalingv2.HorizontalPodAutos
146146
func (wfs *WFS) Options() *Options {
147147
return wfs.Spec.Options
148148
}
149+
150+
func (wfs *WFS) Id() string {
151+
return Sha1HashOfName(wfs)
152+
}

api/v3/wms_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ func (wms *WMS) GetAuthority() *Authority {
234234
return nil
235235
}
236236

237+
func (wms *WMS) HasPostgisData() bool {
238+
for _, layer := range wms.Spec.Service.Layer.getAllLayers() {
239+
if layer.Data != nil && layer.Data.Postgis != nil {
240+
return true
241+
}
242+
}
243+
return false
244+
}
245+
237246
func (wms *WMS) Mapfile() *Mapfile {
238247
return wms.Spec.Service.Mapfile
239248
}
@@ -253,3 +262,7 @@ func (wms *WMS) HorizontalPodAutoscalerPatch() *autoscalingv2.HorizontalPodAutos
253262
func (wms *WMS) Options() *Options {
254263
return wms.Spec.Options
255264
}
265+
266+
func (wms *WMS) Id() string {
267+
return Sha1HashOfName(wms)
268+
}

config/samples/samples.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package samples
2+
3+
import (
4+
_ "embed"
5+
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
6+
"sigs.k8s.io/yaml"
7+
)
8+
9+
//go:embed v3_wfs.yaml
10+
var v3WFSContent string
11+
12+
func V3WFS() (*pdoknlv3.WFS, error) {
13+
var sample pdoknlv3.WFS
14+
err := yaml.Unmarshal([]byte(v3WFSContent), &sample)
15+
return &sample, err
16+
}

config/samples/v3_wfs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ spec:
3939
includeIngress: false
4040
service:
4141
prefix: ""
42-
url: https://service.pdok.nl/test
42+
url: https://service.pdok.nl/eigenaar/dataset/wfs/1.0.0
4343
inspire:
4444
serviceMetadataUrl:
4545
csw:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/onsi/ginkgo/v2 v2.21.0
99
github.com/onsi/gomega v1.35.1
1010
github.com/pdok/ogc-specifications v1.0.0-beta2
11-
github.com/pdok/smooth-operator v0.0.6
11+
github.com/pdok/smooth-operator v0.0.7
1212
github.com/traefik/traefik/v3 v3.3.4
1313
k8s.io/api v0.32.0
1414
k8s.io/apimachinery v0.32.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaR
137137
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
138138
github.com/pdok/ogc-specifications v1.0.0-beta2 h1:BSMd8HiABpKTQButuMaHDj9XKrisnd5ifL1/fM5AwyE=
139139
github.com/pdok/ogc-specifications v1.0.0-beta2/go.mod h1:rkrIwIBIUl4oyn3aMVtJLipDRtFHp3oa9dSu/MyDt1o=
140-
github.com/pdok/smooth-operator v0.0.6 h1:IwgY3X2zYA2XLw0eKmBBN1Md6gNWnoVl0i1R8/wFHvs=
141-
github.com/pdok/smooth-operator v0.0.6/go.mod h1:oZWFuIKJGjN/C6ocgMNfMZ7SbLQi+N0qaWj7j95Wdec=
140+
github.com/pdok/smooth-operator v0.0.7 h1:6G/kunhCW/RG+dQIMu8kU55I758a/upuQHNy4CVM1Kw=
141+
github.com/pdok/smooth-operator v0.0.7/go.mod h1:oZWFuIKJGjN/C6ocgMNfMZ7SbLQi+N0qaWj7j95Wdec=
142142
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
143143
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
144144
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

internal/controller/blobdownload/blob_download.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
77
"github.com/pdok/mapserver-operator/internal/controller/mapperutils"
8+
"github.com/pdok/mapserver-operator/internal/controller/mapserver"
9+
"github.com/pdok/mapserver-operator/internal/controller/utils"
810
corev1 "k8s.io/api/core/v1"
911
"k8s.io/apimachinery/pkg/api/resource"
1012
"regexp"
@@ -31,20 +33,10 @@ func GetBlobDownloadInitContainer[O pdoknlv3.WMSWFS](obj O, image, blobsConfigNa
3133
Image: image,
3234
ImagePullPolicy: corev1.PullIfNotPresent,
3335
EnvFrom: []corev1.EnvFromSource{
34-
{
35-
ConfigMapRef: &corev1.ConfigMapEnvSource{
36-
LocalObjectReference: corev1.LocalObjectReference{
37-
Name: blobsConfigName, // Todo add this ConfigMap
38-
},
39-
},
40-
},
41-
{
42-
SecretRef: &corev1.SecretEnvSource{
43-
LocalObjectReference: corev1.LocalObjectReference{
44-
Name: blobsSecretName, // Todo add this Secret
45-
},
46-
},
47-
},
36+
// Todo add this ConfigMap
37+
utils.NewEnvFromSource(utils.EnvFromSourceTypeConfigMap, blobsConfigName),
38+
// Todo add this Secret
39+
utils.NewEnvFromSource(utils.EnvFromSourceTypeSecret, blobsSecretName),
4840
},
4941
Resources: corev1.ResourceRequirements{
5042
Requests: corev1.ResourceList{
@@ -73,6 +65,17 @@ func GetBlobDownloadInitContainer[O pdoknlv3.WMSWFS](obj O, image, blobsConfigNa
7365
corev1.ResourceCPU: resourceCPU,
7466
}
7567

68+
if options := obj.Options(); options != nil {
69+
if options.PrefetchData != nil && *options.PrefetchData {
70+
mount := corev1.VolumeMount{
71+
Name: mapserver.ConfigMapBlobDownloadVolumeName,
72+
MountPath: "/src/scripts",
73+
ReadOnly: true,
74+
}
75+
initContainer.VolumeMounts = append(initContainer.VolumeMounts, mount)
76+
}
77+
}
78+
7679
return &initContainer, nil
7780
}
7881

internal/controller/blobdownload/blob_download_test.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestGetArgsForWFS(t *testing.T) {
110110
}
111111
for _, tt := range tests {
112112
t.Run(tt.name, func(t *testing.T) {
113-
args, err := GetArgs(tt.args.WFS)
113+
args, err := GetArgs(&tt.args.WFS)
114114
if (err != nil) != tt.wantErr {
115115
t.Errorf("GetArgs() error = %v, wantErr %v", err, tt.wantErr)
116116
return
@@ -145,7 +145,7 @@ func TestGetArgsForWMS(t *testing.T) {
145145
Title: "wms-gpkg-service-title",
146146
Layer: v3.Layer{
147147
Name: "wms-gpkg-layer-name",
148-
Title: stringPtr("wms-gpkg-layer-title"),
148+
Title: smoothoperatorutils.Pointer("wms-gpkg-layer-title"),
149149
Styles: []v3.Style{
150150
{
151151
Legend: &v3.Legend{
@@ -156,11 +156,11 @@ func TestGetArgsForWMS(t *testing.T) {
156156
Layers: &[]v3.Layer{
157157
{
158158
Name: "wms-gpkg-layer-1-name",
159-
Title: stringPtr("wms-gpkg-layer-1-title"),
159+
Title: smoothoperatorutils.Pointer("wms-gpkg-layer-1-title"),
160160
Styles: []v3.Style{
161161
{
162162
Name: "wms-gpkg-style-1-name",
163-
Title: stringPtr("wms-gpkg-style-1-title"),
163+
Title: smoothoperatorutils.Pointer("wms-gpkg-style-1-title"),
164164
Legend: &v3.Legend{
165165
Width: 50,
166166
Height: 50,
@@ -177,11 +177,11 @@ func TestGetArgsForWMS(t *testing.T) {
177177
},
178178
{
179179
Name: "wms-gpkg-layer-2-name",
180-
Title: stringPtr("wms-gpkg-layer-2-title"),
180+
Title: smoothoperatorutils.Pointer("wms-gpkg-layer-2-title"),
181181
Styles: []v3.Style{
182182
{
183183
Name: "wms-gpkg-style-2-name",
184-
Title: stringPtr("wms-gpkg-style-2-title"),
184+
Title: smoothoperatorutils.Pointer("wms-gpkg-style-2-title"),
185185
Legend: &v3.Legend{
186186
BlobKey: "resources-bucket/key/gpkg-layer-2-legend.png",
187187
},
@@ -222,15 +222,15 @@ func TestGetArgsForWMS(t *testing.T) {
222222
Title: "wms-tif-service-title",
223223
Layer: v3.Layer{
224224
Name: "wms-tif-layer-name",
225-
Title: stringPtr("wms-tif-layer-title"),
225+
Title: smoothoperatorutils.Pointer("wms-tif-layer-title"),
226226
Layers: &[]v3.Layer{
227227
{
228228
Name: "wms-tif-layer-1-name",
229-
Title: stringPtr("wms-tif-layer-1-title"),
229+
Title: smoothoperatorutils.Pointer("wms-tif-layer-1-title"),
230230
Styles: []v3.Style{
231231
{
232232
Name: "wms-tif-style-1-name",
233-
Title: stringPtr("wms-tif-style-1-title"),
233+
Title: smoothoperatorutils.Pointer("wms-tif-style-1-title"),
234234
Legend: &v3.Legend{
235235
BlobKey: "resources-bucket/key/tif-layer-1-legend.png",
236236
},
@@ -244,11 +244,11 @@ func TestGetArgsForWMS(t *testing.T) {
244244
},
245245
{
246246
Name: "wms-tif-layer-2-name",
247-
Title: stringPtr("wms-tif-layer-2-title"),
247+
Title: smoothoperatorutils.Pointer("wms-tif-layer-2-title"),
248248
Styles: []v3.Style{
249249
{
250250
Name: "wms-tif-style-2-name",
251-
Title: stringPtr("wms-tif-style-2-title"),
251+
Title: smoothoperatorutils.Pointer("wms-tif-style-2-title"),
252252
Legend: &v3.Legend{
253253
BlobKey: "resources-bucket/key/tif-layer-2-legend.png",
254254
},
@@ -283,7 +283,7 @@ func TestGetArgsForWMS(t *testing.T) {
283283
}
284284
for _, tt := range tests {
285285
t.Run(tt.name, func(t *testing.T) {
286-
args, err := GetArgs(tt.args.WMS)
286+
args, err := GetArgs(&tt.args.WMS)
287287
if (err != nil) != tt.wantErr {
288288
t.Errorf("GetArgs() error = %v, wantErr %v", err, tt.wantErr)
289289
return
@@ -326,8 +326,3 @@ func TestGetScript(t *testing.T) {
326326
})
327327
}
328328
}
329-
330-
// TODO Move to smoothoperator
331-
func stringPtr(s string) *string {
332-
return &s
333-
}

internal/controller/capabilitiesgenerator/mapper.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,43 @@ import (
44
"encoding/xml"
55
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
66
"github.com/pdok/mapserver-operator/internal/controller/mapperutils"
7+
"github.com/pdok/mapserver-operator/internal/controller/mapserver"
78
"github.com/pdok/ogc-specifications/pkg/wfs200"
89
"github.com/pdok/ogc-specifications/pkg/wsc110"
910
smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1"
11+
corev1 "k8s.io/api/core/v1"
1012
)
1113

1214
const (
1315
inspireSchemaLocations = "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0 http://inspire.ec.europa.eu/schemas/inspire_dls/1.0/inspire_dls.xsd"
1416
capabilitiesFilename = "/var/www/config/capabilities_wfs_200.xml"
1517
)
1618

19+
func GetCapabilitiesGeneratorInitContainer[O pdoknlv3.WMSWFS](obj O, image string) (*corev1.Container, error) {
20+
initContainer := corev1.Container{
21+
Name: "capabilities-generator",
22+
Image: image,
23+
ImagePullPolicy: corev1.PullIfNotPresent,
24+
Env: []corev1.EnvVar{
25+
{
26+
Name: "SERVICECONFIG",
27+
Value: "/input/input.yaml",
28+
},
29+
},
30+
VolumeMounts: []corev1.VolumeMount{
31+
{Name: "data", MountPath: "/var/www", ReadOnly: false},
32+
{Name: mapserver.ConfigMapCapabilitiesGeneratorVolumeName, MountPath: "/input", ReadOnly: true},
33+
},
34+
}
35+
return &initContainer, nil
36+
}
37+
1738
func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoperatorv1.OwnerInfo) (Config, error) {
1839
config := Config{
1940
Global: Global{
2041
Namespace: mapperutils.GetNamespaceURI(wfs.Spec.Service.Prefix, ownerInfo),
2142
Prefix: wfs.Spec.Service.Prefix,
22-
OnlineResourceurl: pdoknlv3.GetBaseURL(),
43+
OnlineResourceurl: pdoknlv3.GetHost(),
2344
Path: mapperutils.GetPath(wfs),
2445
Version: *mapperutils.GetLabelValueByKey(wfs.ObjectMeta.Labels, "service-version"),
2546
},
@@ -37,7 +58,7 @@ func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoper
3758
Href string
3859
}{
3960
Type: "simple",
40-
Href: pdoknlv3.GetBaseURL(),
61+
Href: pdoknlv3.GetHost(),
4162
}),
4263
},
4364
ServiceIdentification: wfs200.ServiceIdentification{

0 commit comments

Comments
 (0)