Skip to content

Commit 944db8a

Browse files
Merge pull request #1 from PDOK/jd/wfs-conversion
WFS Conversion
2 parents 287ddcf + 932a15d commit 944db8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5195
-247
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ go.work
2525
*.swp
2626
*.swo
2727
*~
28+
29+
prod-manifests/

.golangci.yml

Lines changed: 103 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,113 @@
1+
---
12
run:
3+
# Timeout for analysis.
24
timeout: 5m
3-
allow-parallel-runners: true
5+
6+
# Modules download mode (do not modify go.mod)
7+
module-download-mode: readonly
8+
9+
# Include test files (see below to exclude certain linters)
10+
tests: true
411

512
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
1113
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
14+
# Exclude certain linters for test code
15+
- path: "_test\\.go"
1616
linters:
17+
- bodyclose
1718
- dupl
18-
- lll
19-
linters:
20-
disable-all: true
21-
enable:
22-
- dupl
23-
- errcheck
24-
- copyloopvar
25-
- ginkgolinter
26-
- goconst
27-
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
31-
- govet
32-
- ineffassign
33-
- lll
34-
- misspell
35-
- nakedret
36-
- prealloc
37-
- revive
38-
- staticcheck
39-
- typecheck
40-
- unconvert
41-
- unparam
42-
- unused
19+
- dogsled
20+
- funlen
21+
22+
output:
23+
formats: colored-line-number
24+
print-issued-lines: true
25+
print-linter-name: true
4326

4427
linters-settings:
45-
revive:
28+
depguard:
4629
rules:
47-
- name: comment-spacings
30+
main:
31+
# Packages that are not allowed where the value is a suggestion.
32+
deny:
33+
- pkg: "github.com/pkg/errors"
34+
desc: Should be replaced by standard lib errors package
35+
cyclop:
36+
# The maximal code complexity to report.
37+
max-complexity: 15
38+
skip-tests: true
39+
funlen:
40+
lines: 100
41+
nestif:
42+
min-complexity: 6
43+
forbidigo:
44+
forbid:
45+
- http\.NotFound.* # return RFC 7807 problem details instead
46+
- http\.Error.* # return RFC 7807 problem details instead
47+
gomoddirectives:
48+
replace-allow-list:
49+
- github.com/abbot/go-http-auth # https://github.com/traefik/traefik/issues/6873#issuecomment-637654361
50+
51+
linters:
52+
disable-all: true
53+
enable:
54+
# enabled by default by golangci-lint
55+
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
56+
- gosimple # specializes in simplifying a code
57+
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
58+
- ineffassign # detects when assignments to existing variables are not used
59+
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
60+
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
61+
- unused # checks for unused constants, variables, functions and types
62+
# extra enabled by us
63+
- asasalint # checks for pass []any as any in variadic func(...any)
64+
- asciicheck # checks that your code does not contain non-ASCII identifiers
65+
- bidichk # checks for dangerous unicode character sequences
66+
- bodyclose # checks whether HTTP response body is closed successfully
67+
- cyclop # checks function and package cyclomatic complexity
68+
- dupl # tool for code clone detection
69+
- durationcheck # checks for two durations multiplied together
70+
- dogsled # find assignments/declarations with too many blank identifiers
71+
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
72+
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
73+
- exhaustive # checks exhaustiveness of enum switch statements
74+
- exptostd # detects functions from golang.org/x/exp/ that can be replaced by std functions
75+
- copyloopvar # checks for pointers to enclosing loop variables
76+
- fatcontext # detects nested contexts in loops and function literals
77+
- forbidigo # forbids identifiers
78+
- funlen # tool for detection of long functions
79+
- gocheckcompilerdirectives # validates go compiler directive comments (//go:)
80+
- goconst # finds repeated strings that could be replaced by a constant
81+
- gocritic # provides diagnostics that check for bugs, performance and style issues
82+
- gofmt # checks if the code is formatted according to 'gofmt' command
83+
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
84+
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
85+
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
86+
- goprintffuncname # checks that printf-like functions are named with f at the end
87+
- gosec # inspects source code for security problems
88+
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
89+
- makezero # finds slice declarations with non-zero initial length
90+
- mirror # reports wrong mirror patterns of bytes/strings usage
91+
- misspell # finds commonly misspelled English words
92+
- nakedret # finds naked returns in functions greater than a specified function length
93+
- nestif # reports deeply nested if statements
94+
- nilerr # finds the code that returns nil even if it checks that the error is not nil
95+
- nolintlint # reports ill-formed or insufficient nolint directives
96+
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
97+
- perfsprint # Golang linter for performance, aiming at usages of fmt.Sprintf which have faster alternatives
98+
- predeclared # finds code that shadows one of Go's predeclared identifiers
99+
- promlinter # checks Prometheus metrics naming via promlint
100+
- reassign # checks that package variables are not reassigned
101+
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
102+
- rowserrcheck # checks whether Err of rows is checked successfully
103+
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
104+
- sloglint # A Go linter that ensures consistent code style when using log/slog
105+
- tagliatelle # checks the struct tags.
106+
- testableexamples # checks if examples are testable (have an expected output)
107+
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
108+
- usetesting # detects using os.Setenv instead of t.Setenv since Go1.17
109+
- unconvert # removes unnecessary type conversions
110+
- unparam # reports unused function parameters
111+
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
112+
- wastedassign # finds wasted assignment statements
113+
fast: false

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ WORKDIR /workspace
77
# Copy the Go Modules manifests
88
COPY go.mod go.mod
99
COPY go.sum go.sum
10+
11+
COPY --from=repos ./smooth-operator /smooth-operator
12+
1013
# cache deps before building and copying source so that we don't need to re-download as much
1114
# and so that source changes don't invalidate our downloaded layer
1215
RUN go mod download

PROJECT

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ resources:
1616
kind: WMS
1717
path: github.com/pdok/mapserver-operator/api/v3
1818
version: v3
19+
webhooks:
20+
conversion: true
21+
spoke:
22+
- v2beta1
23+
webhookVersion: v1
1924
- api:
2025
crdVersion: v1
2126
namespaced: true
@@ -24,4 +29,23 @@ resources:
2429
kind: WFS
2530
path: github.com/pdok/mapserver-operator/api/v3
2631
version: v3
32+
webhooks:
33+
conversion: true
34+
spoke:
35+
- v2beta1
36+
webhookVersion: v1
37+
- api:
38+
crdVersion: v1
39+
namespaced: true
40+
domain: pdok.nl
41+
kind: WFS
42+
path: github.com/pdok/mapserver-operator/api/v2beta1
43+
version: v2beta1
44+
- api:
45+
crdVersion: v1
46+
namespaced: true
47+
domain: pdok.nl
48+
kind: WMS
49+
path: github.com/pdok/mapserver-operator/api/v2beta1
50+
version: v2beta1
2751
version: "3"

api/v2beta1/groupversion_info.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2024 Publieke Dienstverlening op de Kaart
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
// Package v2beta1 contains API Schema definitions for the v2beta1 API group.
26+
// +kubebuilder:object:generate=true
27+
// +groupName=pdok.nl
28+
package v2beta1
29+
30+
import (
31+
"k8s.io/apimachinery/pkg/runtime/schema"
32+
"sigs.k8s.io/controller-runtime/pkg/scheme"
33+
)
34+
35+
var (
36+
// GroupVersion is group version used to register these objects.
37+
GroupVersion = schema.GroupVersion{Group: "pdok.nl", Version: "v2beta1"}
38+
39+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
40+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
41+
42+
// AddToScheme adds the types in this group-version to the given scheme.
43+
AddToScheme = SchemeBuilder.AddToScheme
44+
)

api/v2beta1/shared_conversion.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package v2beta1
2+
3+
import (
4+
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
5+
autoscalingv2 "k8s.io/api/autoscaling/v2beta1"
6+
corev1 "k8s.io/api/core/v1"
7+
)
8+
9+
func Pointer[T interface{}](val T) *T {
10+
return &val
11+
}
12+
13+
func PointerValWithDefault[T interface{}](ptr *T, defaultValue T) T {
14+
if ptr == nil {
15+
return defaultValue
16+
}
17+
18+
return *ptr
19+
}
20+
21+
func ConverseAutoscaling(src Autoscaling) *autoscalingv2.HorizontalPodAutoscalerSpec {
22+
var minReplicas *int32
23+
if src.MinReplicas != nil {
24+
minReplicas = Pointer(int32(*src.MinReplicas))
25+
}
26+
27+
var maxReplicas int32
28+
if src.MaxReplicas != nil {
29+
maxReplicas = int32(*src.MaxReplicas)
30+
}
31+
32+
metrics := make([]autoscalingv2.MetricSpec, 0)
33+
if src.AverageCPUUtilization != nil {
34+
metrics = append(metrics, autoscalingv2.MetricSpec{
35+
Type: autoscalingv2.ResourceMetricSourceType,
36+
Resource: &autoscalingv2.ResourceMetricSource{
37+
Name: corev1.ResourceCPU,
38+
TargetAverageUtilization: Pointer(int32(*src.AverageCPUUtilization)),
39+
},
40+
})
41+
}
42+
43+
return &autoscalingv2.HorizontalPodAutoscalerSpec{
44+
MinReplicas: minReplicas,
45+
MaxReplicas: maxReplicas,
46+
Metrics: metrics,
47+
}
48+
}
49+
50+
func ConverseResources(src corev1.ResourceRequirements) *corev1.PodSpec {
51+
return &corev1.PodSpec{
52+
Containers: []corev1.Container{
53+
{
54+
Resources: src,
55+
},
56+
},
57+
}
58+
}
59+
60+
func ConverseColumnAndAliasesV2ToColumnsWithAliasV3(columns []string, aliases map[string]string) []pdoknlv3.Columns {
61+
v3Columns := make([]pdoknlv3.Columns, 0)
62+
for _, column := range columns {
63+
col := pdoknlv3.Columns{
64+
Name: column,
65+
}
66+
67+
// TODO - multiple aliases per column possible?
68+
if alias, ok := aliases[column]; ok {
69+
col.Alias = &alias
70+
}
71+
72+
v3Columns = append(v3Columns, col)
73+
}
74+
75+
return v3Columns
76+
}
77+
78+
func ConverseColumnsWithAliasV3ToColumnsAndAliasesV2(columns []pdoknlv3.Columns) ([]string, map[string]string) {
79+
v2Columns := make([]string, 0)
80+
v2Aliases := make(map[string]string)
81+
82+
for _, col := range columns {
83+
v2Columns = append(v2Columns, col.Name)
84+
85+
if col.Alias != nil {
86+
v2Aliases[col.Name] = *col.Alias
87+
}
88+
}
89+
90+
return v2Columns, v2Aliases
91+
}

0 commit comments

Comments
 (0)