diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index f1d271a..23d2dfe 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -18,7 +18,6 @@ name: Checks permissions: checks: write contents: read - pull-requests: read jobs: checks: name: Checks @@ -42,13 +41,11 @@ jobs: - name: Dependency Licenses Review run: make check-dependency-licenses - name: Check for spelling errors - uses: reviewdog/action-misspell@v1 - with: - exclude: ./vendor/* - fail_on_error: true - github_token: ${{ secrets.GITHUB_TOKEN }} - ignore: importas - reporter: github-check + uses: crate-ci/typos@v1 + env: + CLICOLOR: "1" + - name: Delete typos binary + run: rm typos - name: Check if source code files have license header run: make check-addlicense - name: REUSE Compliance Check diff --git a/.golangci.yaml b/.golangci.yaml index 02b55d6..cc7da58 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -56,7 +56,6 @@ linters: - ineffassign - intrange - iotamixing - - misspell - modernize - nilerr - nolintlint @@ -147,7 +146,7 @@ linters: require-specific: true modernize: disable: - # omitzero requires removing omitempty tags in kubernetes api struct types which are nested, which is intepreted by controller-gen and breaks the CRDs. + # omitzero requires removing omitempty tags in kubernetes api struct types which are nested, which is interpreted by controller-gen and breaks the CRDs. - omitzero perfsprint: # modernize generates nicer fix code diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 0000000..7dd0e8b --- /dev/null +++ b/.typos.toml @@ -0,0 +1,10 @@ +# SPDX-FileCopyrightText: 2025 SAP SE +# +# SPDX-License-Identifier: Apache-2.0 + +[default.extend-words] + +[files] +extend-exclude = [ + "go.mod", +] diff --git a/Makefile b/Makefile index 294c337..4dc5e34 100644 --- a/Makefile +++ b/Makefile @@ -75,10 +75,16 @@ GO_TESTFLAGS += GO_TESTENV += GO_BUILDENV += +# These definitions are overridable, e.g. to provide fixed version/commit values when +# no .git directory is present or to provide a fixed build date for reproducibility. +BININFO_VERSION ?= $(shell git describe --tags --always --abbrev=7) +BININFO_COMMIT_HASH ?= $(shell git rev-parse --verify HEAD) +BININFO_BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") + build-all: build/manager build/manager: FORCE generate - env $(GO_BUILDENV) go build $(GO_BUILDFLAGS) -ldflags '-s -w $(GO_LDFLAGS)' -o build/manager ./cmd + 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 DESTDIR = ifeq ($(shell uname -s),Darwin) @@ -121,9 +127,14 @@ run-shellcheck: FORCE install-shellcheck @printf "\e[1;36m>> shellcheck\e[0m\n" @find . -type f \( -name '*.bash' -o -name '*.ksh' -o -name '*.zsh' -o -name '*.sh' -o -name '*.shlib' \) -exec shellcheck {} + +run-typos: FORCE + @printf "\e[1;36m>> typos\e[0m\n" + @printf "\e[1;36m>> Typos install instructions can be found here https://github.com/crate-ci/typos#install \e[0m\n" + @typos + build/cover.out: FORCE generate install-setup-envtest | build @printf "\e[1;36m>> Running tests\e[0m\n" - 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) + 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) @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/' > $@ build/cover.html: build/cover.out @@ -173,6 +184,9 @@ clean: FORCE git clean -dxf build vars: FORCE + @printf "BININFO_BUILD_DATE=$(BININFO_BUILD_DATE)\n" + @printf "BININFO_COMMIT_HASH=$(BININFO_COMMIT_HASH)\n" + @printf "BININFO_VERSION=$(BININFO_VERSION)\n" @printf "DESTDIR=$(DESTDIR)\n" @printf "GO_BUILDENV=$(GO_BUILDENV)\n" @printf "GO_BUILDFLAGS=$(GO_BUILDFLAGS)\n" @@ -216,6 +230,7 @@ help: FORCE @printf " \e[36mgenerate\e[0m Generate code for Kubernetes CRDs and deepcopy.\n" @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" @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" + @printf " \e[36mrun-typos\e[0m Check for spelling errors using typos.\n" @printf " \e[36mbuild/cover.out\e[0m Run tests and generate coverage report.\n" @printf " \e[36mbuild/cover.html\e[0m Generate an HTML file with source code annotations from the coverage report.\n" @printf " \e[36mcheck-addlicense\e[0m Check license headers in all non-vendored .go files with addlicense.\n" diff --git a/cmd/main.go b/cmd/main.go index 9334a1f..80ac604 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -20,8 +20,11 @@ package main import ( "crypto/tls" "flag" + "fmt" "os" + gruntime "runtime" + "github.com/sapcc/go-api-declarations/bininfo" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) // to ensure that exec-entrypoint and run can make use of them. _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -154,6 +157,10 @@ func main() { metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization } restConfig := ctrl.GetConfigOrDie() + // This will set the managed field manager to openstack-hypervisor-operator + restConfig.UserAgent = fmt.Sprintf("%s/%s (%s/%s) %s", + bininfo.Component(), bininfo.VersionOr("devel"), gruntime.GOOS, gruntime.GOARCH, + bininfo.CommitOr("edge")) var cacheOptions cache.Options if global.LabelSelector != "" { diff --git a/go.mod b/go.mod index 944b4cc..366b24f 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/gophercloud/utils/v2 v2.0.0-20251121145439-0a38d66a3d88 github.com/onsi/ginkgo/v2 v2.27.2 github.com/onsi/gomega v1.38.2 + github.com/sapcc/go-api-declarations v1.18.0 k8s.io/api v0.34.1 k8s.io/apimachinery v0.34.1 k8s.io/client-go v0.34.1 diff --git a/go.sum b/go.sum index adf373e..32180c0 100644 --- a/go.sum +++ b/go.sum @@ -135,6 +135,8 @@ github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUO github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sapcc/go-api-declarations v1.18.0 h1:I73wuBKJEAeAI7nYuB4tHY9n9pydj5mgM7Zn+9fryAA= +github.com/sapcc/go-api-declarations v1.18.0/go.mod h1:N2klk2oDNa1lsS6gUBnCDJedHy/c2vmwJ1sryckRW40= github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0= github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= diff --git a/shell.nix b/shell.nix index 84db48e..677df4f 100644 --- a/shell.nix +++ b/shell.nix @@ -16,6 +16,7 @@ mkShell { renovate reuse setup-envtest + typos # keep this line if you use bash bashInteractive ];