Skip to content

Commit 6fb2820

Browse files
committed
Set restconfig user-agent with manager name/version/platform
The user-agent is used by default for managed-fields and makes debugging easier.
1 parent 016c808 commit 6fb2820

File tree

8 files changed

+44
-12
lines changed

8 files changed

+44
-12
lines changed

.github/workflows/checks.yaml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ name: Checks
1818
permissions:
1919
checks: write
2020
contents: read
21-
pull-requests: read
2221
jobs:
2322
checks:
2423
name: Checks
@@ -42,13 +41,11 @@ jobs:
4241
- name: Dependency Licenses Review
4342
run: make check-dependency-licenses
4443
- name: Check for spelling errors
45-
uses: reviewdog/action-misspell@v1
46-
with:
47-
exclude: ./vendor/*
48-
fail_on_error: true
49-
github_token: ${{ secrets.GITHUB_TOKEN }}
50-
ignore: importas
51-
reporter: github-check
44+
uses: crate-ci/typos@v1
45+
env:
46+
CLICOLOR: "1"
47+
- name: Delete typos binary
48+
run: rm typos
5249
- name: Check if source code files have license header
5350
run: make check-addlicense
5451
- name: REUSE Compliance Check

.golangci.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ linters:
5656
- ineffassign
5757
- intrange
5858
- iotamixing
59-
- misspell
6059
- modernize
6160
- nilerr
6261
- nolintlint
@@ -147,7 +146,7 @@ linters:
147146
require-specific: true
148147
modernize:
149148
disable:
150-
# omitzero requires removing omitempty tags in kubernetes api struct types which are nested, which is intepreted by controller-gen and breaks the CRDs.
149+
# omitzero requires removing omitempty tags in kubernetes api struct types which are nested, which is interpreted by controller-gen and breaks the CRDs.
151150
- omitzero
152151
perfsprint:
153152
# modernize generates nicer fix code

.typos.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-FileCopyrightText: 2025 SAP SE
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
[default.extend-words]
6+
7+
[files]
8+
extend-exclude = [
9+
"go.mod",
10+
]

Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,16 @@ GO_TESTFLAGS +=
7575
GO_TESTENV +=
7676
GO_BUILDENV +=
7777

78+
# These definitions are overridable, e.g. to provide fixed version/commit values when
79+
# no .git directory is present or to provide a fixed build date for reproducibility.
80+
BININFO_VERSION ?= $(shell git describe --tags --always --abbrev=7)
81+
BININFO_COMMIT_HASH ?= $(shell git rev-parse --verify HEAD)
82+
BININFO_BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
83+
7884
build-all: build/manager
7985

8086
build/manager: FORCE generate
81-
env $(GO_BUILDENV) go build $(GO_BUILDFLAGS) -ldflags '-s -w $(GO_LDFLAGS)' -o build/manager ./cmd
87+
env $(GO_BUILDENV) go build $(GO_BUILDFLAGS) -ldflags '-s -w -X github.com/sapcc/go-api-declarations/bininfo.binName=manager -X github.com/sapcc/go-api-declarations/bininfo.version=$(BININFO_VERSION) -X github.com/sapcc/go-api-declarations/bininfo.commit=$(BININFO_COMMIT_HASH) -X github.com/sapcc/go-api-declarations/bininfo.buildDate=$(BININFO_BUILD_DATE) $(GO_LDFLAGS)' -o build/manager ./cmd
8288

8389
DESTDIR =
8490
ifeq ($(shell uname -s),Darwin)
@@ -121,9 +127,14 @@ run-shellcheck: FORCE install-shellcheck
121127
@printf "\e[1;36m>> shellcheck\e[0m\n"
122128
@find . -type f \( -name '*.bash' -o -name '*.ksh' -o -name '*.zsh' -o -name '*.sh' -o -name '*.shlib' \) -exec shellcheck {} +
123129

130+
run-typos: FORCE
131+
@printf "\e[1;36m>> typos\e[0m\n"
132+
@printf "\e[1;36m>> Typos install instructions can be found here https://github.com/crate-ci/typos#install \e[0m\n"
133+
@typos
134+
124135
build/cover.out: FORCE generate install-setup-envtest | build
125136
@printf "\e[1;36m>> Running tests\e[0m\n"
126-
KUBEBUILDER_ASSETS=$$(setup-envtest use 1.34 -p path) go run github.com/onsi/ginkgo/v2/ginkgo run --randomize-all -output-dir=build $(GO_BUILDFLAGS) -ldflags '-s -w $(GO_LDFLAGS)' -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTFLAGS) $(GO_TESTPKGS)
137+
KUBEBUILDER_ASSETS=$$(setup-envtest use 1.34 -p path) go run github.com/onsi/ginkgo/v2/ginkgo run --randomize-all -output-dir=build $(GO_BUILDFLAGS) -ldflags '-s -w -X github.com/sapcc/go-api-declarations/bininfo.binName=openstack-hypervisor-operator -X github.com/sapcc/go-api-declarations/bininfo.version=$(BININFO_VERSION) -X github.com/sapcc/go-api-declarations/bininfo.commit=$(BININFO_COMMIT_HASH) -X github.com/sapcc/go-api-declarations/bininfo.buildDate=$(BININFO_BUILD_DATE) $(GO_LDFLAGS)' -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTFLAGS) $(GO_TESTPKGS)
127138
@awk < build/coverprofile.out '$$1 != "mode:" { is_filename[$$1] = true; counts1[$$1]+=$$2; counts2[$$1]+=$$3 } END { for (filename in is_filename) { printf "%s %d %d\n", filename, counts1[filename], counts2[filename]; } }' | sort | $(SED) '1s/^/mode: count\n/' > $@
128139

129140
build/cover.html: build/cover.out
@@ -173,6 +184,9 @@ clean: FORCE
173184
git clean -dxf build
174185

175186
vars: FORCE
187+
@printf "BININFO_BUILD_DATE=$(BININFO_BUILD_DATE)\n"
188+
@printf "BININFO_COMMIT_HASH=$(BININFO_COMMIT_HASH)\n"
189+
@printf "BININFO_VERSION=$(BININFO_VERSION)\n"
176190
@printf "DESTDIR=$(DESTDIR)\n"
177191
@printf "GO_BUILDENV=$(GO_BUILDENV)\n"
178192
@printf "GO_BUILDFLAGS=$(GO_BUILDFLAGS)\n"
@@ -216,6 +230,7 @@ help: FORCE
216230
@printf " \e[36mgenerate\e[0m Generate code for Kubernetes CRDs and deepcopy.\n"
217231
@printf " \e[36mrun-golangci-lint\e[0m Install and run golangci-lint. Installing is used in CI, but you should probably install golangci-lint using your package manager.\n"
218232
@printf " \e[36mrun-shellcheck\e[0m Install and run shellcheck. Installing is used in CI, but you should probably install shellcheck using your package manager.\n"
233+
@printf " \e[36mrun-typos\e[0m Check for spelling errors using typos.\n"
219234
@printf " \e[36mbuild/cover.out\e[0m Run tests and generate coverage report.\n"
220235
@printf " \e[36mbuild/cover.html\e[0m Generate an HTML file with source code annotations from the coverage report.\n"
221236
@printf " \e[36mcheck-addlicense\e[0m Check license headers in all non-vendored .go files with addlicense.\n"

cmd/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ package main
2020
import (
2121
"crypto/tls"
2222
"flag"
23+
"fmt"
2324
"os"
25+
gruntime "runtime"
2426

27+
"github.com/sapcc/go-api-declarations/bininfo"
2528
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2629
// to ensure that exec-entrypoint and run can make use of them.
2730
_ "k8s.io/client-go/plugin/pkg/client/auth"
@@ -154,6 +157,10 @@ func main() {
154157
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
155158
}
156159
restConfig := ctrl.GetConfigOrDie()
160+
// This will set the managed field manager to openstack-hypervisor-operator
161+
restConfig.UserAgent = fmt.Sprintf("%s/%s (%s/%s) %s",
162+
bininfo.Component(), bininfo.VersionOr("devel"), gruntime.GOOS, gruntime.GOARCH,
163+
bininfo.CommitOr("edge"))
157164

158165
var cacheOptions cache.Options
159166
if global.LabelSelector != "" {

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/gophercloud/utils/v2 v2.0.0-20251121145439-0a38d66a3d88
1111
github.com/onsi/ginkgo/v2 v2.27.2
1212
github.com/onsi/gomega v1.38.2
13+
github.com/sapcc/go-api-declarations v1.18.0
1314
k8s.io/api v0.34.1
1415
k8s.io/apimachinery v0.34.1
1516
k8s.io/client-go v0.34.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUO
135135
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
136136
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
137137
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
138+
github.com/sapcc/go-api-declarations v1.18.0 h1:I73wuBKJEAeAI7nYuB4tHY9n9pydj5mgM7Zn+9fryAA=
139+
github.com/sapcc/go-api-declarations v1.18.0/go.mod h1:N2klk2oDNa1lsS6gUBnCDJedHy/c2vmwJ1sryckRW40=
138140
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
139141
github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
140142
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=

shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mkShell {
1616
renovate
1717
reuse
1818
setup-envtest
19+
typos
1920
# keep this line if you use bash
2021
bashInteractive
2122
];

0 commit comments

Comments
 (0)