Skip to content

Commit 8852aed

Browse files
authored
🌱 add make verify-generated-files. Update controller-gen to v1.18 (#1676)
1 parent a53c6da commit 8852aed

28 files changed

+257
-253
lines changed

.builder-image-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.24
1+
1.0.25

.github/actions/e2e/action.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ runs:
4444
shell: bash
4545
env:
4646
hcloudctl_version: 1.40.0
47-
run: curl -fsSL https://github.com/hetznercloud/cli/releases/download/v${{ env.hcloudctl_version }}/hcloud-linux-amd64.tar.gz | tar -xzv hcloud ; mv hcloud hack/tools/bin/hcloud
47+
run: |
48+
curl -fsSL https://github.com/hetznercloud/cli/releases/download/v${{ env.hcloudctl_version }}/hcloud-linux-amd64.tar.gz | tar -xzv hcloud
49+
mkdir -p hack/tools/bin/
50+
mv hcloud hack/tools/bin/hcloud
4851
4952
- name: Generate metadata
5053
id: meta

.github/actions/fixes/action.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Fix env var HOME and git permissions
2+
description: Fix env var HOME and git permissions
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Fix HOME Directory
7+
shell: bash
8+
run: |
9+
# Issue [HOME is overridden for containers](https://github.com/actions/runner/issues/863)
10+
h=$(getent passwd $(id -un) | cut -d: -f6)
11+
if [ "$h" = "$HOME" ]; then
12+
echo "HOME fine: $HOME"
13+
exit 0
14+
fi
15+
echo "HOME=$HOME was broken. Setting it to $h"
16+
ls -ld $HOME
17+
ls -ld $h
18+
echo "USER: $USER"
19+
echo "id: $(id)"
20+
echo "HOME=$h" >> $GITHUB_ENV
21+
22+
- name: Fixup git permissions
23+
# https://github.com/actions/checkout/issues/766
24+
shell: bash
25+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

.github/workflows/main-promote-builder-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Promote Latest tag to Caph Builder Image
1111
runs-on: ubuntu-latest
1212
container:
13-
image: ghcr.io/syself/caph-builder:1.0.24
13+
image: ghcr.io/syself/caph-builder:1.0.25
1414
credentials:
1515
username: ${{ github.actor }}
1616
password: ${{ secrets.github_token }}

.github/workflows/pr-e2e.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,20 @@ jobs:
3838
name: Test Release
3939
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
4040
runs-on: ubuntu-latest
41+
container:
42+
image: ghcr.io/syself/caph-builder:1.0.25
43+
credentials:
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.github_token }}
46+
env:
47+
BUILD_IN_CONTAINER: "false"
4148
steps:
4249
- name: checkout
4350
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
51+
52+
- name: Fix broken env var HOME
53+
uses: ./.github/actions/fixes
54+
4455
- name: Test Release
4556
id: manager-image
4657
uses: ./.github/actions/test-release

.github/workflows/pr-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
name: "Lint Pull Request"
2323
runs-on: ubuntu-latest
2424
container:
25-
image: ghcr.io/syself/caph-builder:1.0.24
25+
image: ghcr.io/syself/caph-builder:1.0.25
2626
credentials:
2727
username: ${{ github.actor }}
2828
password: ${{ secrets.github_token }}

.github/workflows/pr-verify.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,26 @@ jobs:
1010
pull-requests: write
1111
issues: write
1212
runs-on: ubuntu-latest
13+
container:
14+
image: ghcr.io/syself/caph-builder:1.0.25
15+
credentials:
16+
username: ${{ github.actor }}
17+
password: ${{ secrets.github_token }}
1318
name: Verify Pull Request
1419
steps:
1520
- name: Checkout repository
1621
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1722

23+
- name: Fix Env Var HOME
24+
uses: ./.github/actions/fixes
25+
# Fixes:
26+
# fatal: detected dubious ownership in repository at '/__w/clu...
27+
# To add an exception for this directory, call:
28+
# git config --global --add safe.directory /__w...
29+
1830
# Take from https://github.com/kubernetes-sigs/kubebuilder/blob/master/.github/workflows/verify.yml
1931
- name: Validate PR Title Format
32+
shell: bash
2033
env:
2134
TITLE: ${{ github.event.pull_request.title }}
2235
run: |
@@ -48,13 +61,17 @@ jobs:
4861
- name: Verify Starlark
4962
run: make verify-starlark
5063

64+
- name: Verify Generated Files of Git Repo
65+
run: make BUILD_IN_CONTAINER=false verify-generated-files
66+
5167
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
5268
with:
5369
node-version: "22"
5470
- name: Install renovate
5571
run: npm i -g [email protected] # TODO update this via renovatebot
5672

5773
- name: Validate config
74+
shell: bash
5875
run: |
5976
for file in $(find . -name "*.json5"); do
6077
renovate-config-validator ${file}

.github/workflows/schedule-scan-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
if: github.repository == 'syself/cluster-api-provider-hetzner'
1212
container:
13-
image: ghcr.io/syself/caph-builder:1.0.24
13+
image: ghcr.io/syself/caph-builder:1.0.25
1414
credentials:
1515
username: ${{ github.actor }}
1616
password: ${{ secrets.github_token }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ bin
88
hack/tools/bin
99
testbin/*
1010
temp
11+
/tmp
1112
# Test binary, build with `go test -c`
1213
*.test
1314
.coverage

Makefile

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.31.0
8888
############
8989
# Binaries #
9090
############
91-
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen)
92-
controller-gen: $(CONTROLLER_GEN) ## Build a local copy of controller-gen
93-
$(CONTROLLER_GEN): # Build controller-gen from tools folder.
94-
go install sigs.k8s.io/controller-tools/cmd/[email protected]
9591

9692
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/kustomize)
9793
kustomize: $(KUSTOMIZE) ## Build a local copy of kustomize
@@ -124,12 +120,6 @@ clusterctl: $(CLUSTERCTL) ## Build a local copy of clusterctl
124120
$(CLUSTERCTL):
125121
go install sigs.k8s.io/cluster-api/cmd/[email protected]
126122

127-
HELM := $(abspath $(TOOLS_BIN_DIR)/helm)
128-
helm: $(HELM) ## Build a local copy of helm
129-
$(HELM):
130-
curl -sSL https://get.helm.sh/helm-v3.13.2-$$(go env GOOS)-$$(go env GOARCH).tar.gz | tar xz -C $(TOOLS_BIN_DIR) --strip-components=1 $$(go env GOOS)-$$(go env GOARCH)/helm
131-
chmod a+rx $(HELM)
132-
133123
HCLOUD := $(abspath $(TOOLS_BIN_DIR)/hcloud)
134124
hcloud: $(HCLOUD) ## Build a local copy of hcloud
135125
$(HCLOUD):
@@ -162,7 +152,7 @@ gotestsum: $(GOTESTSUM) # Build gotestsum from tools folder.
162152
$(GOTESTSUM):
163153
go install gotest.tools/[email protected]
164154

165-
all-tools: $(GOTESTSUM) $(go-cover-treemap) $(go-binsize-treemap) $(KIND) $(KUBECTL) $(CLUSTERCTL) $(CTLPTL) $(SETUP_ENVTEST) $(ENVSUBST) $(KUSTOMIZE) $(CONTROLLER_GEN) $(HELM) ## Install all tools required for development
155+
all-tools: $(GOTESTSUM) $(go-cover-treemap) $(go-binsize-treemap) $(KIND) $(KUBECTL) $(CLUSTERCTL) $(CTLPTL) $(SETUP_ENVTEST) $(ENVSUBST) $(KUSTOMIZE) ## Install all tools required for development
166156
echo 'done'
167157

168158
##@ Development
@@ -193,21 +183,29 @@ wait-and-get-secret:
193183
./hack/get-kubeconfig-of-workload-cluster.sh
194184
${TIMEOUT} --foreground 15m bash -c "while ! $(KUBECTL) --kubeconfig=$(WORKER_CLUSTER_KUBECONFIG) get nodes | grep control-plane; do sleep 1; done"
195185

196-
install-cilium-in-wl-cluster: $(HELM)
186+
install-cilium-in-wl-cluster:
197187
# Deploy cilium
198-
$(HELM) repo add cilium https://helm.cilium.io/
199-
$(HELM) repo update cilium
200-
KUBECONFIG=$(WORKER_CLUSTER_KUBECONFIG) $(HELM) upgrade --install cilium cilium/cilium \
188+
helm repo add cilium https://helm.cilium.io/
189+
helm repo update cilium
190+
KUBECONFIG=$(WORKER_CLUSTER_KUBECONFIG) helm upgrade --install cilium cilium/cilium \
201191
--namespace kube-system \
202192
-f templates/cilium/cilium.yaml
203193

194+
204195
install-ccm-in-wl-cluster:
205-
$(HELM) repo add syself https://charts.syself.com
206-
$(HELM) repo update syself
207-
KUBECONFIG=$(WORKER_CLUSTER_KUBECONFIG) $(HELM) upgrade --install ccm syself/ccm-hetzner --version 1.1.10 \
196+
ifeq ($(BUILD_IN_CONTAINER),true)
197+
docker run --rm \
198+
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
199+
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
200+
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
201+
else
202+
helm repo add syself https://charts.syself.com
203+
helm repo update syself
204+
KUBECONFIG=$(WORKER_CLUSTER_KUBECONFIG) helm upgrade --install ccm syself/ccm-hetzner --version 1.1.10 \
208205
--namespace kube-system \
209206
--set privateNetwork.enabled=$(PRIVATE_NETWORK)
210207
@echo 'run "kubectl --kubeconfig=$(WORKER_CLUSTER_KUBECONFIG) ..." to work with the new target cluster'
208+
endif
211209

212210
add-ssh-pub-key:
213211
./hack/ensure-env-variables.sh HCLOUD_TOKEN SSH_KEY SSH_KEY_NAME
@@ -570,6 +568,17 @@ verify-manifests:
570568
verify-container-images: ## Verify container images
571569
trivy image -q --exit-code 1 --ignore-unfixed --severity MEDIUM,HIGH,CRITICAL $(IMAGE_PREFIX)/$(INFRA_SHORT):latest
572570

571+
.PHONY: verify-generated-files
572+
verify-generated-files: ## Verify geneated files in git repo
573+
ifeq ($(BUILD_IN_CONTAINER),true)
574+
docker run --rm \
575+
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
576+
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
577+
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
578+
else
579+
./hack/verify-generated-files.sh
580+
endif
581+
573582
##@ Generate
574583
############
575584
# Generate #
@@ -581,7 +590,7 @@ generate-boilerplate: ## Generates missing boilerplates
581590
# support go modules
582591
generate-modules: ## Generates missing go modules
583592
ifeq ($(BUILD_IN_CONTAINER),true)
584-
docker run --rm -t -i \
593+
docker run --rm \
585594
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
586595
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
587596
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
@@ -599,20 +608,37 @@ generate-modules-ci: generate-modules
599608
exit 1; \
600609
fi
601610

602-
generate-manifests: $(CONTROLLER_GEN) ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
603-
$(CONTROLLER_GEN) \
611+
generate-manifests: ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
612+
ifeq ($(BUILD_IN_CONTAINER),true)
613+
docker run --rm \
614+
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
615+
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
616+
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
617+
else
618+
# Ensure that these old binaries are not longer used. We use
619+
# these from the builder-image now.
620+
rm -f ./hack/tools/bin/controller-gen ./hack/tools/bin/helm
621+
controller-gen \
604622
paths=./api/... \
605623
paths=./controllers/... \
606624
crd:crdVersions=v1 \
607625
rbac:roleName=manager-role \
608626
output:crd:dir=./config/crd/bases \
609627
output:webhook:dir=./config/webhook \
610628
webhook
629+
endif
611630

612-
generate-go-deepcopy: $(CONTROLLER_GEN) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
613-
$(CONTROLLER_GEN) \
631+
generate-go-deepcopy: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
632+
ifeq ($(BUILD_IN_CONTAINER),true)
633+
docker run --rm \
634+
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
635+
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
636+
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
637+
else
638+
controller-gen \
614639
object:headerFile="./hack/boilerplate/boilerplate.generatego.txt" \
615640
paths="./api/..."
641+
endif
616642

617643
generate-api-ci: generate-manifests generate-go-deepcopy
618644
@if ! (git diff --exit-code ); then \
@@ -635,7 +661,7 @@ cluster-templates: $(KUSTOMIZE)
635661
.PHONY: format-golang
636662
format-golang: ## Format the Go codebase and run auto-fixers if supported by the linter.
637663
ifeq ($(BUILD_IN_CONTAINER),true)
638-
docker run --rm -t -i \
664+
docker run --rm \
639665
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
640666
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
641667
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
@@ -652,7 +678,7 @@ format-starlark: ## Format the Starlark codebase
652678
.PHONY: format-yaml
653679
format-yaml: ## Lint YAML files
654680
ifeq ($(BUILD_IN_CONTAINER),true)
655-
docker run --rm -t -i \
681+
docker run --rm \
656682
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
657683
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
658684
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
@@ -668,7 +694,7 @@ endif
668694
.PHONY: lint-golang
669695
lint-golang: ## Lint Golang codebase
670696
ifeq ($(BUILD_IN_CONTAINER),true)
671-
docker run --rm -t -i \
697+
docker run --rm \
672698
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
673699
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
674700
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
@@ -681,7 +707,7 @@ endif
681707
.PHONY: lint-golang-ci
682708
lint-golang-ci:
683709
ifeq ($(BUILD_IN_CONTAINER),true)
684-
docker run --rm -t -i \
710+
docker run --rm \
685711
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
686712
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
687713
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
@@ -694,7 +720,7 @@ endif
694720
.PHONY: lint-yaml
695721
lint-yaml: ## Lint YAML files
696722
ifeq ($(BUILD_IN_CONTAINER),true)
697-
docker run --rm -t -i \
723+
docker run --rm \
698724
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
699725
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
700726
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
@@ -706,7 +732,7 @@ endif
706732
.PHONY: lint-yaml-ci
707733
lint-yaml-ci:
708734
ifeq ($(BUILD_IN_CONTAINER),true)
709-
docker run --rm -t -i \
735+
docker run --rm \
710736
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
711737
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
712738
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
@@ -719,7 +745,7 @@ DOCKERFILES=$(shell find . -not \( -path ./hack -prune \) -not \( -path ./vendor
719745
.PHONY: lint-dockerfile
720746
lint-dockerfile: ## Lint Dockerfiles
721747
ifeq ($(BUILD_IN_CONTAINER),true)
722-
docker run --rm -t -i \
748+
docker run --rm \
723749
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
724750
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
725751
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
@@ -730,7 +756,7 @@ endif
730756

731757
lint-links: ## Link Checker
732758
ifeq ($(BUILD_IN_CONTAINER),true)
733-
docker run --rm -t -i \
759+
docker run --rm \
734760
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
735761
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
736762
else
@@ -751,7 +777,7 @@ format: format-starlark format-golang format-yaml ## Format Codebase
751777
.PHONY: generate-mocks
752778
generate-mocks: ## Generate Mocks
753779
ifeq ($(BUILD_IN_CONTAINER),true)
754-
docker run --rm -t -i \
780+
docker run --rm \
755781
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
756782
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
757783
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
@@ -804,3 +830,10 @@ create-hetzner-installimage-tgz:
804830
@echo "============= ↓↓↓↓↓ Now update the version number here ↓↓↓↓↓ ============="
805831
@git ls-files | xargs grep -P 'hetzner-installimage.*v\d+\.\d+' || true
806832
@echo "↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"
833+
834+
builder-image-shell: ## Start an interactive shell in the builder image.
835+
docker run --rm -t -i \
836+
--entrypoint bash \
837+
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
838+
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
839+
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION)

0 commit comments

Comments
 (0)