Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ go.work
*.swp
*.swo
*~

prod-manifests/
140 changes: 103 additions & 37 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,113 @@
---
run:
# Timeout for analysis.
timeout: 5m
allow-parallel-runners: true

# Modules download mode (do not modify go.mod)
module-download-mode: readonly

# Include test files (see below to exclude certain linters)
tests: true

issues:
# don't skip warning about doc comments
# don't exclude the default set of lint
exclude-use-default: false
# restore some of the defaults
# (fill in the rest as needed)
exclude-rules:
- path: "api/*"
linters:
- lll
- path: "internal/*"
# Exclude certain linters for test code
- path: "_test\\.go"
linters:
- bodyclose
- dupl
- lll
linters:
disable-all: true
enable:
- dupl
- errcheck
- copyloopvar
- ginkgolinter
- goconst
- gocyclo
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- revive
- staticcheck
- typecheck
- unconvert
- unparam
- unused
- dogsled
- funlen

output:
formats: colored-line-number
print-issued-lines: true
print-linter-name: true

linters-settings:
revive:
depguard:
rules:
- name: comment-spacings
main:
# Packages that are not allowed where the value is a suggestion.
deny:
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package
cyclop:
# The maximal code complexity to report.
max-complexity: 15
skip-tests: true
funlen:
lines: 100
nestif:
min-complexity: 6
forbidigo:
forbid:
- http\.NotFound.* # return RFC 7807 problem details instead
- http\.Error.* # return RFC 7807 problem details instead
gomoddirectives:
replace-allow-list:
- github.com/abbot/go-http-auth # https://github.com/traefik/traefik/issues/6873#issuecomment-637654361

linters:
disable-all: true
enable:
# enabled by default by golangci-lint
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
- gosimple # specializes in simplifying a code
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # detects when assignments to existing variables are not used
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
- unused # checks for unused constants, variables, functions and types
# extra enabled by us
- asasalint # checks for pass []any as any in variadic func(...any)
- asciicheck # checks that your code does not contain non-ASCII identifiers
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- cyclop # checks function and package cyclomatic complexity
- dupl # tool for code clone detection
- durationcheck # checks for two durations multiplied together
- dogsled # find assignments/declarations with too many blank identifiers
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- exhaustive # checks exhaustiveness of enum switch statements
- exptostd # detects functions from golang.org/x/exp/ that can be replaced by std functions
- copyloopvar # checks for pointers to enclosing loop variables
- fatcontext # detects nested contexts in loops and function literals
- forbidigo # forbids identifiers
- funlen # tool for detection of long functions
- gocheckcompilerdirectives # validates go compiler directive comments (//go:)
- goconst # finds repeated strings that could be replaced by a constant
- gocritic # provides diagnostics that check for bugs, performance and style issues
- gofmt # checks if the code is formatted according to 'gofmt' command
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
- 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
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects source code for security problems
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
- makezero # finds slice declarations with non-zero initial length
- mirror # reports wrong mirror patterns of bytes/strings usage
- misspell # finds commonly misspelled English words
- nakedret # finds naked returns in functions greater than a specified function length
- nestif # reports deeply nested if statements
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- nolintlint # reports ill-formed or insufficient nolint directives
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
- perfsprint # Golang linter for performance, aiming at usages of fmt.Sprintf which have faster alternatives
- predeclared # finds code that shadows one of Go's predeclared identifiers
- promlinter # checks Prometheus metrics naming via promlint
- reassign # checks that package variables are not reassigned
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
- rowserrcheck # checks whether Err of rows is checked successfully
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
- sloglint # A Go linter that ensures consistent code style when using log/slog
- tagliatelle # checks the struct tags.
- testableexamples # checks if examples are testable (have an expected output)
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- usetesting # detects using os.Setenv instead of t.Setenv since Go1.17
- unconvert # removes unnecessary type conversions
- unparam # reports unused function parameters
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
- wastedassign # finds wasted assignment statements
fast: false
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum

COPY --from=repos ./smooth-operator /smooth-operator

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
Expand Down
24 changes: 24 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ resources:
kind: WMS
path: github.com/pdok/mapserver-operator/api/v3
version: v3
webhooks:
conversion: true
spoke:
- v2beta1
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
Expand All @@ -24,4 +29,23 @@ resources:
kind: WFS
path: github.com/pdok/mapserver-operator/api/v3
version: v3
webhooks:
conversion: true
spoke:
- v2beta1
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: pdok.nl
kind: WFS
path: github.com/pdok/mapserver-operator/api/v2beta1
version: v2beta1
- api:
crdVersion: v1
namespaced: true
domain: pdok.nl
kind: WMS
path: github.com/pdok/mapserver-operator/api/v2beta1
version: v2beta1
version: "3"
44 changes: 44 additions & 0 deletions api/v2beta1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
MIT License

Copyright (c) 2024 Publieke Dienstverlening op de Kaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

// Package v2beta1 contains API Schema definitions for the v2beta1 API group.
// +kubebuilder:object:generate=true
// +groupName=pdok.nl
package v2beta1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "pdok.nl", Version: "v2beta1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
91 changes: 91 additions & 0 deletions api/v2beta1/shared_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package v2beta1

import (
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
autoscalingv2 "k8s.io/api/autoscaling/v2beta1"
corev1 "k8s.io/api/core/v1"
)

func Pointer[T interface{}](val T) *T {
return &val
}

func PointerValWithDefault[T interface{}](ptr *T, defaultValue T) T {
if ptr == nil {
return defaultValue
}

return *ptr
}

func ConverseAutoscaling(src Autoscaling) *autoscalingv2.HorizontalPodAutoscalerSpec {
var minReplicas *int32
if src.MinReplicas != nil {
minReplicas = Pointer(int32(*src.MinReplicas))
}

var maxReplicas int32
if src.MaxReplicas != nil {
maxReplicas = int32(*src.MaxReplicas)
}

metrics := make([]autoscalingv2.MetricSpec, 0)
if src.AverageCPUUtilization != nil {
metrics = append(metrics, autoscalingv2.MetricSpec{
Type: autoscalingv2.ResourceMetricSourceType,
Resource: &autoscalingv2.ResourceMetricSource{
Name: corev1.ResourceCPU,
TargetAverageUtilization: Pointer(int32(*src.AverageCPUUtilization)),
},
})
}

return &autoscalingv2.HorizontalPodAutoscalerSpec{
MinReplicas: minReplicas,
MaxReplicas: maxReplicas,
Metrics: metrics,
}
}

func ConverseResources(src corev1.ResourceRequirements) *corev1.PodSpec {
return &corev1.PodSpec{
Containers: []corev1.Container{
{
Resources: src,
},
},
}
}

func ConverseColumnAndAliasesV2ToColumnsWithAliasV3(columns []string, aliases map[string]string) []pdoknlv3.Columns {
v3Columns := make([]pdoknlv3.Columns, 0)
for _, column := range columns {
col := pdoknlv3.Columns{
Name: column,
}

// TODO - multiple aliases per column possible?
if alias, ok := aliases[column]; ok {
col.Alias = &alias
}

v3Columns = append(v3Columns, col)
}

return v3Columns
}

func ConverseColumnsWithAliasV3ToColumnsAndAliasesV2(columns []pdoknlv3.Columns) ([]string, map[string]string) {
v2Columns := make([]string, 0)
v2Aliases := make(map[string]string)

for _, col := range columns {
v2Columns = append(v2Columns, col.Name)

if col.Alias != nil {
v2Aliases[col.Name] = *col.Alias
}
}

return v2Columns, v2Aliases
}
Loading
Loading