Skip to content

Commit b652119

Browse files
author
Léon van der Kaap
committed
Finished admission tester
1 parent 8d6f8dc commit b652119

File tree

9 files changed

+88
-38
lines changed

9 files changed

+88
-38
lines changed

api/v2beta1/wfs_conversion.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,31 @@ func (src *WFS) ConvertTo(dstRaw conversion.Hub) error {
3939
dst := dstRaw.(*pdoknlv3.WFS)
4040
log.Printf("ConvertTo: Converting WFS from Spoke version v2beta1 to Hub version v3;"+
4141
"source: %s/%s, target: %s/%s", src.Namespace, src.Name, dst.Namespace, dst.Name)
42+
V3WFSHubFromV2(src, dst)
4243

43-
dst.ObjectMeta = src.ObjectMeta
44+
return nil
45+
}
46+
47+
func V3WFSHubFromV2(src *WFS, target *pdoknlv3.WFS) {
48+
target.ObjectMeta = src.ObjectMeta
4449

4550
// Set LifeCycle if defined
4651
if src.Spec.Kubernetes.Lifecycle != nil && src.Spec.Kubernetes.Lifecycle.TTLInDays != nil {
47-
dst.Spec.Lifecycle = &sharedModel.Lifecycle{
52+
target.Spec.Lifecycle = &sharedModel.Lifecycle{
4853
TTLInDays: Pointer(int32(*src.Spec.Kubernetes.Lifecycle.TTLInDays)),
4954
}
5055
}
5156

5257
if src.Spec.Kubernetes.Autoscaling != nil {
53-
dst.Spec.HorizontalPodAutoscalerPatch = ConvertAutoscaling(*src.Spec.Kubernetes.Autoscaling)
58+
target.Spec.HorizontalPodAutoscalerPatch = ConvertAutoscaling(*src.Spec.Kubernetes.Autoscaling)
5459
}
5560

5661
// TODO converse src.Spec.Kubernetes.HealthCheck when we know what the implementation in v3 will be
5762
if src.Spec.Kubernetes.Resources != nil {
58-
dst.Spec.PodSpecPatch = ConvertResources(*src.Spec.Kubernetes.Resources)
63+
target.Spec.PodSpecPatch = ConvertResources(*src.Spec.Kubernetes.Resources)
5964
}
6065

61-
dst.Spec.Options = *ConvertOptionsV2ToV3(src.Spec.Options)
66+
target.Spec.Options = *ConvertOptionsV2ToV3(src.Spec.Options)
6267

6368
service := pdoknlv3.WFSService{
6469
// TODO what is prefix, Geonovum subdomain?
@@ -114,9 +119,7 @@ func (src *WFS) ConvertTo(dstRaw conversion.Hub) error {
114119
service.FeatureTypes = append(service.FeatureTypes, convertV2FeatureTypeToV3(featureType))
115120
}
116121

117-
dst.Spec.Service = service
118-
119-
return nil
122+
target.Spec.Service = service
120123
}
121124

122125
func convertV2FeatureTypeToV3(src FeatureType) pdoknlv3.FeatureType {

api/v2beta1/wms_conversion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ func (src *WMS) ConvertTo(dstRaw conversion.Hub) error {
4343
dst := dstRaw.(*pdoknlv3.WMS)
4444
log.Printf("ConvertTo: Converting WMS from Spoke version v2beta1 to Hub version v3;"+
4545
"source: %s/%s, target: %s/%s", src.Namespace, src.Name, dst.Namespace, dst.Name)
46-
V3HubFromV2(src, dst)
46+
V3WMSHubFromV2(src, dst)
4747

4848
return nil
4949
}
5050

51-
func V3HubFromV2(src *WMS, target *pdoknlv3.WMS) {
51+
func V3WMSHubFromV2(src *WMS, target *pdoknlv3.WMS) {
5252
dst := target
5353

5454
dst.ObjectMeta = src.ObjectMeta

api/v2beta1/wms_conversion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestV2ToV3(t *testing.T) {
1313
err := yaml.Unmarshal([]byte(input), &v2wms)
1414
assert.NoError(t, err)
1515
var target pdoknlv3.WMS
16-
V3HubFromV2(&v2wms, &target)
16+
V3WMSHubFromV2(&v2wms, &target)
1717
assert.Equal(t, "NWB - Wegen WMS", target.Spec.Service.Title)
1818
a := 0
1919
_ = a

api/v3/wms_validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func validateWMS(wms *WMS, warnings *[]string, reasons *[]string) {
106106
*reasons = append(*reasons, "layer.boundingBoxes must contain a boundingBox for CRS '"+service.DataEPSG+"' when service.dataEPSG is not 'EPSG:28992'")
107107
}
108108

109-
if !*layer.Visible {
109+
if layer.Visible != nil && !*layer.Visible {
110110
if layer.Title != nil {
111111
*warnings = append(*warnings, sharedValidation.FormatValidationWarning("layer.title is not used when layer.visible=false", wms.GroupVersionKind(), wms.GetName()))
112112
}
@@ -175,7 +175,7 @@ func validateWMS(wms *WMS, warnings *[]string, reasons *[]string) {
175175
}
176176
layerType := layer.GetLayerType(&service)
177177
if layerType == GroupLayer || layerType == TopLayer {
178-
if !*layer.Visible {
178+
if layer.Visible != nil && !*layer.Visible {
179179
layerReasons = append(layerReasons, layerType+" must be visible")
180180
}
181181
if layer.Data != nil {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/pdok/featureinfo-generator v1.4.0-beta1
1414
github.com/pdok/ogc-capabilities-generator v1.0.0-beta5
1515
github.com/pdok/ogc-specifications v1.0.0-beta5
16-
github.com/pdok/smooth-operator v0.0.10
16+
github.com/pdok/smooth-operator v0.0.11-0.20250417141155-2c2a0eb3e412
1717
github.com/stretchr/testify v1.10.0
1818
github.com/traefik/traefik/v3 v3.3.4
1919
k8s.io/api v0.32.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ github.com/pdok/ogc-specifications v1.0.0-beta5 h1:j7JrXUeW55mVU9ZmJ67r8V6DhbKdg
146146
github.com/pdok/ogc-specifications v1.0.0-beta5/go.mod h1:YDngwkwrWOfc5MYnEYseiv97K1Y9bZXlVzwi/8EaIl8=
147147
github.com/pdok/smooth-operator v0.0.10 h1:dv5ua20wB62fcYiV9UznOMB5GjxpVLWqEzqBDZZO014=
148148
github.com/pdok/smooth-operator v0.0.10/go.mod h1:oZWFuIKJGjN/C6ocgMNfMZ7SbLQi+N0qaWj7j95Wdec=
149+
github.com/pdok/smooth-operator v0.0.11-0.20250417141155-2c2a0eb3e412 h1:PycDu6gAE6EZxuSlF0HfcOQbg0OsecI9YwtLmnsWA08=
150+
github.com/pdok/smooth-operator v0.0.11-0.20250417141155-2c2a0eb3e412/go.mod h1:oZWFuIKJGjN/C6ocgMNfMZ7SbLQi+N0qaWj7j95Wdec=
149151
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
150152
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
151153
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

internal/controller/capabilitiesgenerator/capabilities_generator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ func TestInputForWMS(t *testing.T) {
673673
err := yaml.Unmarshal([]byte(v2wmsstring), &v2wms)
674674
assert.NoError(t, err)
675675
var wms pdoknlv3.WMS
676-
v2beta1.V3HubFromV2(&v2wms, &wms)
676+
v2beta1.V3WMSHubFromV2(&v2wms, &wms)
677677
pdoknlv3.SetHost("http://localhost")
678678

679679
contactPersonPrimary := smoothoperatorv1.ContactPersonPrimary{

internal/controller/legendgenerator/legend_generator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestGetConfigMapDataNoLegendFix(t *testing.T) {
1515
err := yaml.Unmarshal([]byte(v2wmsstring), &v2wms)
1616
assert.NoError(t, err)
1717
var wms pdoknlv3.WMS
18-
v2beta1.V3HubFromV2(&v2wms, &wms)
18+
v2beta1.V3WMSHubFromV2(&v2wms, &wms)
1919

2020
configMapData := GetConfigMapData(&wms)
2121

@@ -34,7 +34,7 @@ func TestGetConfigMapDataLegendFix(t *testing.T) {
3434
err := yaml.Unmarshal([]byte(v2wmsstring), &v2wms)
3535
assert.NoError(t, err)
3636
var wms pdoknlv3.WMS
37-
v2beta1.V3HubFromV2(&v2wms, &wms)
37+
v2beta1.V3WMSHubFromV2(&v2wms, &wms)
3838

3939
configMapData := GetConfigMapData(&wms)
4040

test/e2e/admission_tester/admission_tester.go

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"github.com/pdok/mapserver-operator/api/v2beta1"
67
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
@@ -25,8 +26,6 @@ func main() {
2526
checkWms(path)
2627
} else if strings.HasSuffix(path, "wfs.yaml") {
2728
checkWfs(path)
28-
} else if strings.HasSuffix(path, "atom.yaml") {
29-
checkAtom(path)
3029
}
3130
return nil
3231
})
@@ -37,9 +36,69 @@ func main() {
3736

3837
func checkWms(path string) {
3938
print("Checking ")
39+
print(path)
40+
print("...")
41+
fileString, err := getNormalizedFileString(path)
42+
if err != nil {
43+
return
44+
}
45+
46+
var v2wms v2beta1.WMS
47+
err = yaml.Unmarshal([]byte(fileString), &v2wms)
48+
if err != nil {
49+
fmt.Printf("Could not unmarshall '%s' to v2wms", path)
50+
return
51+
}
52+
var wms pdoknlv3.WMS
53+
v2beta1.V3WMSHubFromV2(&v2wms, &wms)
54+
warnings, err := wms.ValidateCreate()
55+
if err != nil {
56+
println("ERRORS")
57+
println("###")
58+
println(err.Error())
59+
println("###")
60+
} else if len(warnings) > 0 {
61+
println("WARNINGS")
62+
} else {
63+
println("OK")
64+
}
65+
66+
}
67+
68+
func checkWfs(path string) {
69+
print("Checking ")
70+
print(path)
71+
print("...")
72+
fileString, err := getNormalizedFileString(path)
73+
if err != nil {
74+
return
75+
}
76+
77+
var v2wfs v2beta1.WFS
78+
err = yaml.Unmarshal([]byte(fileString), &v2wfs)
79+
if err != nil {
80+
fmt.Printf("Could not unmarshall '%s' to v2wms", path)
81+
return
82+
}
83+
var wfs pdoknlv3.WFS
84+
v2beta1.V3WFSHubFromV2(&v2wfs, &wfs)
85+
warnings, err := wfs.ValidateCreate()
86+
if err != nil {
87+
println("ERRORS")
88+
println("###")
89+
println(err.Error())
90+
println("###")
91+
} else if len(warnings) > 0 {
92+
println("WARNINGS")
93+
} else {
94+
println("OK")
95+
}
96+
}
97+
98+
func getNormalizedFileString(path string) (string, error) {
4099
fileBytes, err := os.ReadFile(path)
41100
if err != nil {
42-
log.Fatalf("Could not read file '%s', exiting", path)
101+
return "", errors.New(fmt.Sprintf("Could not read file '%s', exiting", path))
43102
}
44103
fileString := string(fileBytes)
45104
fileString = strings.ReplaceAll(fileString, "${BLOBS_RESOURCES_BUCKET}", "resources")
@@ -64,24 +123,10 @@ func checkWms(path string) {
64123
fileString = strings.ReplaceAll(fileString, "${REQUESTS_CPU}", "1001")
65124
fileString = strings.ReplaceAll(fileString, "${REQUESTS_MEM}", "100M")
66125
fileString = strings.ReplaceAll(fileString, "${REQUESTS_EPHEMERAL_STORAGE}", "101M")
126+
fileString = strings.ReplaceAll(fileString, "${LIMITS_MEM}", "103M")
67127

68-
var v2wms v2beta1.WMS
69-
err = yaml.Unmarshal([]byte(fileString), &v2wms)
70-
if err != nil {
71-
println(err)
72-
println(path)
73-
os.Exit(1)
128+
if strings.Contains(fileString, "${") {
129+
return "", errors.New(fmt.Sprintf("File '%s' still has an unreplaced variable", path))
74130
}
75-
var wms pdoknlv3.WMS
76-
v2beta1.V3HubFromV2(&v2wms, &wms)
77-
}
78-
79-
func checkWfs(path string) {
80-
//print("Did not check ")
81-
//println(path)
82-
}
83-
84-
func checkAtom(path string) {
85-
//print("Did not check ")
86-
//println(path)
131+
return fileString, nil
87132
}

0 commit comments

Comments
 (0)