Skip to content

Commit 38e5485

Browse files
Merge pull request #14 from PDOK/jd/pdok-18316-kubebuilder-scaffolding
Kubebuilder scaffolding
2 parents a1d5f3e + 63d44f2 commit 38e5485

29 files changed

+655
-324
lines changed

.devcontainer/devcontainer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "Kubebuilder DevContainer",
3+
"image": "golang:1.25",
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
6+
"ghcr.io/devcontainers/features/git:1": {}
7+
},
8+
9+
"runArgs": ["--network=host"],
10+
11+
"customizations": {
12+
"vscode": {
13+
"settings": {
14+
"terminal.integrated.shell.linux": "/bin/bash"
15+
},
16+
"extensions": [
17+
"ms-kubernetes-tools.vscode-kubernetes-tools",
18+
"ms-azuretools.vscode-docker"
19+
]
20+
}
21+
},
22+
23+
"onCreateCommand": "bash .devcontainer/post-install.sh"
24+
}
25+

.devcontainer/post-install.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -x
3+
4+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-$(go env GOARCH)
5+
chmod +x ./kind
6+
mv ./kind /usr/local/bin/kind
7+
8+
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/$(go env GOARCH)
9+
chmod +x kubebuilder
10+
mv kubebuilder /usr/local/bin/
11+
12+
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
13+
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/$(go env GOARCH)/kubectl"
14+
chmod +x kubectl
15+
mv kubectl /usr/local/bin/kubectl
16+
17+
docker network create -d=bridge --subnet=172.19.0.0/24 kind
18+
19+
kind version
20+
kubebuilder version
21+
docker --version
22+
go version
23+
kubectl version --client

.dockerignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore build and test binaries.
3-
bin/
2+
# Ignore everything by default and re-include only needed files
3+
**
4+
5+
# Re-include Go source files (but not *_test.go)
6+
!**/*.go
7+
**/*_test.go
8+
9+
# Re-include Go module files
10+
!go.mod
11+
!go.sum

.github/workflows/build-and-publish-image.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ jobs:
1010
docker:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
14-
- name: Set up Go
15-
uses: actions/setup-go@v4
13+
- name: Clone the code
14+
uses: actions/checkout@v4
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
1617
with:
17-
go-version: '1.23'
18+
go-version-file: go.mod
1819
- name: Make test
1920
run: |
2021
make test

.github/workflows/lint-go.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ jobs:
1212
name: lint
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/setup-go@v4
15+
- name: Clone the code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Go
19+
uses: actions/setup-go@v5
1620
with:
17-
go-version: '1.23'
21+
go-version-file: go.mod
1822
cache: false
1923

20-
- uses: actions/checkout@v3
21-
2224
- name: tidy
2325
uses: katexochen/go-tidy-check@v2
2426

25-
- name: golangci-lint
26-
uses: golangci/golangci-lint-action@v3
27+
- name: Run linter
28+
uses: golangci/golangci-lint-action@v8
2729
with:
28-
version: latest
30+
version: v2.5.0

.github/workflows/test-go.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ jobs:
1111
test:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- name: Clone the code
15+
uses: actions/checkout@v4
1516

16-
- name: Set up Go
17-
uses: actions/setup-go@v4
17+
- name: Setup Go
18+
uses: actions/setup-go@v5
1819
with:
19-
go-version: '1.23'
20+
go-version-file: go.mod
2021

2122
- name: Make test
2223
uses: nick-fields/retry@v3

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ go.work
2626
*.swp
2727
*.swo
2828
*~
29+
30+
# Kubeconfig might contain secrets
31+
*.kubeconfig

.golangci.yml

Lines changed: 115 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,120 @@
1-
---
1+
version: "2"
22
run:
3-
# Timeout for analysis.
4-
timeout: 5m
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)
103
tests: true
11-
12-
issues:
13-
exclude-rules:
14-
# Exclude certain linters for test code
15-
- path: "_test\\.go"
16-
linters:
17-
- bodyclose
18-
- dupl
19-
- dogsled
20-
- funlen
21-
224
output:
23-
formats: colored-line-number
24-
print-issued-lines: true
25-
print-linter-name: true
26-
27-
linters-settings:
28-
depguard:
29-
rules:
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
50-
tagliatelle:
51-
case:
52-
rules:
53-
json: snake # since betterstack uses snake instead of camel case for JSON
54-
5+
formats:
6+
text:
7+
path: stdout
8+
print-linter-name: true
9+
print-issued-lines: true
5510
linters:
56-
disable-all: true
11+
default: none
12+
enable:
13+
- asasalint
14+
- asciicheck
15+
- bidichk
16+
- bodyclose
17+
- copyloopvar
18+
- cyclop
19+
- dogsled
20+
- dupl
21+
- durationcheck
22+
- errcheck
23+
- errname
24+
- errorlint
25+
- exhaustive
26+
- exptostd
27+
- fatcontext
28+
- forbidigo
29+
- funlen
30+
- gocheckcompilerdirectives
31+
- goconst
32+
- gocritic
33+
- gomoddirectives
34+
- gomodguard
35+
- goprintffuncname
36+
- gosec
37+
- govet
38+
- ineffassign
39+
- loggercheck
40+
- makezero
41+
- mirror
42+
- misspell
43+
- nakedret
44+
- nestif
45+
- nilerr
46+
- nolintlint
47+
- nosprintfhostport
48+
- perfsprint
49+
- predeclared
50+
- promlinter
51+
- reassign
52+
- revive
53+
- rowserrcheck
54+
- sloglint
55+
- sqlclosecheck
56+
- staticcheck
57+
- tagliatelle
58+
- testableexamples
59+
- tparallel
60+
- unconvert
61+
- unparam
62+
- unused
63+
- usestdlibvars
64+
- usetesting
65+
- wastedassign
66+
settings:
67+
cyclop:
68+
max-complexity: 15
69+
depguard:
70+
rules:
71+
main:
72+
deny:
73+
- pkg: github.com/pkg/errors
74+
desc: Should be replaced by standard lib errors package
75+
forbidigo:
76+
forbid:
77+
- pattern: http\.NotFound.*
78+
- pattern: http\.Error.*
79+
funlen:
80+
lines: 100
81+
gomoddirectives:
82+
replace-allow-list:
83+
- github.com/abbot/go-http-auth
84+
nestif:
85+
min-complexity: 6
86+
tagliatelle:
87+
case:
88+
rules:
89+
json: snake
90+
exclusions:
91+
generated: lax
92+
presets:
93+
- comments
94+
- common-false-positives
95+
- legacy
96+
- std-error-handling
97+
rules:
98+
- linters:
99+
- bodyclose
100+
- dogsled
101+
- dupl
102+
- funlen
103+
path: _test\.go
104+
- linters:
105+
- cyclop
106+
path: (.+)_test\.go
107+
paths:
108+
- third_party$
109+
- builtin$
110+
- examples$
111+
formatters:
57112
enable:
58-
# enabled by default by golangci-lint
59-
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
60-
- gosimple # specializes in simplifying a code
61-
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
62-
- ineffassign # detects when assignments to existing variables are not used
63-
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
64-
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
65-
- unused # checks for unused constants, variables, functions and types
66-
# extra enabled by us
67-
- asasalint # checks for pass []any as any in variadic func(...any)
68-
- asciicheck # checks that your code does not contain non-ASCII identifiers
69-
- bidichk # checks for dangerous unicode character sequences
70-
- bodyclose # checks whether HTTP response body is closed successfully
71-
- cyclop # checks function and package cyclomatic complexity
72-
- dupl # tool for code clone detection
73-
- durationcheck # checks for two durations multiplied together
74-
- dogsled # find assignments/declarations with too many blank identifiers
75-
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
76-
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
77-
- exhaustive # checks exhaustiveness of enum switch statements
78-
- exptostd # detects functions from golang.org/x/exp/ that can be replaced by std functions
79-
- copyloopvar # checks for pointers to enclosing loop variables
80-
- fatcontext # detects nested contexts in loops and function literals
81-
- forbidigo # forbids identifiers
82-
- funlen # tool for detection of long functions
83-
- gocheckcompilerdirectives # validates go compiler directive comments (//go:)
84-
- goconst # finds repeated strings that could be replaced by a constant
85-
- gocritic # provides diagnostics that check for bugs, performance and style issues
86-
- gofmt # checks if the code is formatted according to 'gofmt' command
87-
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
88-
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
89-
- 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
90-
- goprintffuncname # checks that printf-like functions are named with f at the end
91-
- gosec # inspects source code for security problems
92-
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
93-
- makezero # finds slice declarations with non-zero initial length
94-
- mirror # reports wrong mirror patterns of bytes/strings usage
95-
- misspell # finds commonly misspelled English words
96-
- nakedret # finds naked returns in functions greater than a specified function length
97-
- nestif # reports deeply nested if statements
98-
- nilerr # finds the code that returns nil even if it checks that the error is not nil
99-
- nolintlint # reports ill-formed or insufficient nolint directives
100-
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
101-
- perfsprint # Golang linter for performance, aiming at usages of fmt.Sprintf which have faster alternatives
102-
- predeclared # finds code that shadows one of Go's predeclared identifiers
103-
- promlinter # checks Prometheus metrics naming via promlint
104-
- reassign # checks that package variables are not reassigned
105-
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
106-
- rowserrcheck # checks whether Err of rows is checked successfully
107-
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
108-
- sloglint # A Go linter that ensures consistent code style when using log/slog
109-
- tagliatelle # checks the struct tags.
110-
- usetesting # detects using os.Setenv instead of t.Setenv since Go1.17
111-
- testableexamples # checks if examples are testable (have an expected output)
112-
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
113-
- unconvert # removes unnecessary type conversions
114-
- unparam # reports unused function parameters
115-
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
116-
- wastedassign # finds wasted assignment statements
117-
fast: false
113+
- gofmt
114+
- goimports
115+
exclusions:
116+
generated: lax
117+
paths:
118+
- third_party$
119+
- builtin$
120+
- examples$

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.23 AS builder
2+
FROM golang:1.25 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

0 commit comments

Comments
 (0)