Skip to content

Commit 7ee188b

Browse files
author
Jelle Dijkstra
committed
Updates kubebuilder scaffolding
2 parents 66f2dc0 + 2b870fc commit 7ee188b

Some content is hidden

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

54 files changed

+3294
-1034
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
name: build
3+
env:
4+
image: pdok/uptime-operator
5+
on:
6+
push:
7+
tags:
8+
- '*'
9+
jobs:
10+
docker:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Set up Go
15+
uses: actions/setup-go@v4
16+
with:
17+
go-version: '1.23'
18+
- name: Make test
19+
run: |
20+
make test
21+
echo "removing generated code from coverage results"
22+
diffs="$(git status -s)"
23+
if [[ -n "$diffs" ]]; then echo "there are diffs after make test: $diffs"; exit 250; fi
24+
- name: Docker meta
25+
id: docker_meta
26+
uses: docker/metadata-action@v3
27+
with:
28+
images: ${{ env.image }}
29+
tags: |
30+
type=semver,pattern={{major}}
31+
type=semver,pattern={{major}}.{{minor}}
32+
type=semver,pattern={{version}}
33+
- name: Login to PDOK Docker Hub
34+
if: startsWith(env.image, 'pdok/')
35+
uses: docker/login-action@v1
36+
with:
37+
username: koalapdok
38+
password: ${{ secrets.DOCKERHUB_PUSH }}
39+
- name: Set up Docker Buildx
40+
uses: docker/setup-buildx-action@v1
41+
- name: Cache Docker layers
42+
uses: actions/cache@v4
43+
with:
44+
path: /tmp/.buildx-cache
45+
key: ${{ runner.os }}-buildx-${{ github.sha }}
46+
restore-keys: |
47+
${{ runner.os }}-buildx-
48+
- name: Build and push
49+
id: docker_build
50+
uses: docker/build-push-action@v2
51+
with:
52+
push: true
53+
tags: ${{ steps.docker_meta.outputs.tags }}
54+
labels: ${{ steps.docker_meta.outputs.labels }}
55+
cache-from: type=local,src=/tmp/.buildx-cache
56+
cache-to: type=local,dest=/tmp/.buildx-cache-new
57+
- # Temp fix to cleanup cache
58+
# https://github.com/docker/build-push-action/issues/252
59+
# https://github.com/moby/buildkit/issues/1896
60+
name: Move cache
61+
run: |
62+
rm -rf /tmp/.buildx-cache
63+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
64+
- name: Build result notification
65+
if: success() || failure()
66+
uses: 8398a7/action-slack@v3
67+
with:
68+
fields: all
69+
status: custom
70+
custom_payload: |
71+
{
72+
attachments: [{
73+
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
74+
text: `${process.env.AS_WORKFLOW} ${{ job.status }} for ${process.env.AS_REPO}!\n${process.env.AS_JOB} job on ${process.env.AS_REF} (commit: ${process.env.AS_COMMIT}, version: ${{ steps.docker_meta.outputs.version }}) by ${process.env.AS_AUTHOR} took ${process.env.AS_TOOK}`,
75+
}]
76+
}
77+
env:
78+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

.github/workflows/lint-go.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: lint (go)
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
permissions:
9+
contents: read
10+
jobs:
11+
lint:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/setup-go@v4
16+
with:
17+
go-version: '1.23'
18+
cache: false
19+
20+
- uses: actions/checkout@v3
21+
22+
- name: tidy
23+
uses: katexochen/go-tidy-check@v2
24+
25+
- name: golangci-lint
26+
uses: golangci/golangci-lint-action@v3
27+
with:
28+
version: latest

.github/workflows/test-go.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: test (go)
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
permissions:
9+
contents: write
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: '1.23'
20+
21+
- name: Make test
22+
uses: nick-fields/retry@v3
23+
env:
24+
PINGDOM_API_TOKEN: ${{ secrets.PINGDOM_API_TOKEN }}
25+
BETTERSTACK_API_TOKEN: ${{ secrets.BETTERSTACK_API_TOKEN }}
26+
with:
27+
timeout_minutes: 5
28+
max_attempts: 2
29+
retry_on: error
30+
command: |
31+
make test
32+
echo "removing generated code from coverage results"
33+
mv cover.out cover.out.tmp && grep -vP "uptime-operator/(api/v1alpha1|cmd|test/utils)/" cover.out.tmp > cover.out
34+
35+
- name: Update coverage report
36+
uses: ncruces/go-coverage-report@v0
37+
with:
38+
coverage-file: cover.out
39+
report: true
40+
chart: false
41+
amend: false
42+
reuse-go: true
43+
if: |
44+
github.event_name == 'push'
45+
continue-on-error: false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Binaries for programs and plugins
23
*.exe
34
*.exe~

.golangci.bck.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
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)
10+
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+
22+
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+
55+
linters:
56+
disable-all: true
57+
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

.golangci.yml

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,109 @@
11
version: "2"
22
run:
3-
allow-parallel-runners: true
3+
tests: true
4+
output:
5+
formats:
6+
text:
7+
path: stdout
8+
print-linter-name: true
9+
print-issued-lines: true
410
linters:
511
default: none
612
enable:
13+
- asasalint
14+
- asciicheck
15+
- bidichk
16+
- bodyclose
717
- copyloopvar
18+
- cyclop
19+
- dogsled
820
- dupl
21+
- durationcheck
922
- errcheck
10-
- ginkgolinter
23+
- errname
24+
- errorlint
25+
- exhaustive
26+
- exptostd
27+
- fatcontext
28+
- forbidigo
29+
- funlen
30+
- gocheckcompilerdirectives
1131
- goconst
12-
- gocyclo
32+
- gocritic
33+
- gomoddirectives
34+
- gomodguard
35+
- goprintffuncname
36+
- gosec
1337
- govet
1438
- ineffassign
15-
- lll
39+
- loggercheck
40+
- makezero
41+
- mirror
1642
- misspell
1743
- nakedret
18-
- prealloc
44+
- nestif
45+
- nilerr
46+
- nolintlint
47+
- nosprintfhostport
48+
- perfsprint
49+
- predeclared
50+
- promlinter
51+
- reassign
1952
- revive
53+
- rowserrcheck
54+
- sloglint
55+
- sqlclosecheck
2056
- staticcheck
57+
- tagliatelle
58+
- testableexamples
59+
- tparallel
2160
- unconvert
2261
- unparam
2362
- unused
63+
- usestdlibvars
64+
- usetesting
65+
- wastedassign
2466
settings:
25-
revive:
67+
cyclop:
68+
max-complexity: 15
69+
depguard:
2670
rules:
27-
- name: comment-spacings
28-
- name: import-shadowing
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
2990
exclusions:
3091
generated: lax
92+
presets:
93+
- comments
94+
- common-false-positives
95+
- legacy
96+
- std-error-handling
3197
rules:
3298
- linters:
33-
- lll
34-
path: api/*
35-
- linters:
99+
- bodyclose
100+
- dogsled
36101
- dupl
37-
- lll
38-
path: internal/*
102+
- funlen
103+
path: _test\.go
104+
- linters:
105+
- cyclop
106+
path: (.+)_test\.go
39107
paths:
40108
- third_party$
41109
- builtin$

0 commit comments

Comments
 (0)