Skip to content

Commit a991e28

Browse files
committed
Implement Cluster API v1beta2 contract
1 parent c8000b0 commit a991e28

File tree

168 files changed

+11348
-2312
lines changed

Some content is hidden

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

168 files changed

+11348
-2312
lines changed

.custom-gcl.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: v2.6.2
2+
name: golangci-lint-kube-api-linter
3+
destination: ./bin
4+
plugins:
5+
- module: 'sigs.k8s.io/kube-api-linter'
6+
version: v0.0.0-20251112164541-d94382a24f06

.github/workflows/lint.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ jobs:
2121
uses: golangci/golangci-lint-action@v7
2222
with:
2323
install-mode: goinstall
24-
version: v2.0.2
24+
version: v2.6.2
2525

2626
- name: Run ShellCheck
2727
uses: ludeeus/action-shellcheck@master
2828

2929
- name: Running nilaway
3030
run: |
3131
make lint-nilaway
32+
33+
- name: Running golang-ci-lint-kube-api-linter
34+
run: |
35+
make lint-api

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ dist/*
3333
# e2e files
3434
_artifacts
3535
*-envsubst.yaml
36-
test/e2e/data/infrastructure-scaleway/v1beta1/*.yaml
36+
test/e2e/data/infrastructure-scaleway/v1beta2/*.yaml

.golangci-kal.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
version: "2"
2+
run:
3+
go: "1.24"
4+
allow-parallel-runners: true
5+
linters:
6+
default: none
7+
enable:
8+
- kubeapilinter # linter for Kube API conventions
9+
settings:
10+
custom:
11+
kubeapilinter:
12+
type: module
13+
description: KAL is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices.
14+
settings:
15+
linters:
16+
enable:
17+
- "commentstart" # Ensure comments start with the serialized version of the field name.
18+
- "conditions" # Ensure conditions have the correct json tags and markers.
19+
- "conflictingmarkers"
20+
- "duplicatemarkers" # Ensure there are no exact duplicate markers. for types and fields.
21+
#- "forbiddenmarkers" # Ensure that types and fields do not contain any markers that are forbidden.
22+
- "integers" # Ensure only int32 and int64 are used for integers.
23+
- "jsontags" # Ensure every field has a json tag.
24+
- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items.
25+
#- "nobools" # Bools do not evolve over time, should use enums instead.
26+
- "nodurations" # Prevents usage of `Duration` types.
27+
- "nofloats" # Ensure floats are not used.
28+
- "nomaps" # Ensure maps are not used.
29+
- "nonullable" # Ensure that types and fields do not have the nullable marker.
30+
- "nophase" # Phase fields are discouraged by the Kube API conventions, use conditions instead.
31+
- "notimestamp" # Prevents usage of 'Timestamp' fields
32+
- "optionalfields" # Ensure that all fields marked as optional adhere to being pointers and
33+
# having the `omitempty` value in their `json` tag where appropriate.
34+
- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
35+
- "requiredfields" # Required fields should not be pointers, and should not have `omitempty`.
36+
- "ssatags" # Ensure array fields have the appropriate listType markers
37+
- "statusoptional" # Ensure all first children within status should be optional.
38+
- "statussubresource" # All root objects that have a `status` field should have a status subresource.
39+
- "uniquemarkers" # Ensure that types and fields do not contain more than a single definition of a marker that should only be present once.
40+
41+
# Linters below this line are disabled, pending conversation on how and when to enable them.
42+
disable:
43+
- "*" # We will manually enable new linters after understanding the impact. Disable all by default.
44+
lintersConfig:
45+
conflictingmarkers:
46+
conflicts:
47+
- name: "default_vs_required"
48+
sets:
49+
- ["default", "kubebuilder:default"]
50+
- ["required", "kubebuilder:validation:Required", "k8s:required"]
51+
description: "A field with a default value cannot be required"
52+
conditions:
53+
isFirstField: Warn # Require conditions to be the first field in the status struct.
54+
usePatchStrategy: Forbid # Forbid patchStrategy markers on the Conditions field.
55+
useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required.
56+
optionalfields:
57+
pointers:
58+
preference: WhenRequired # Always | WhenRequired # Whether to always require pointers, or only when required. Defaults to `Always`.
59+
policy: SuggestFix # SuggestFix | Warn # The policy for pointers in optional fields. Defaults to `SuggestFix`.
60+
omitempty:
61+
policy: SuggestFix # SuggestFix | Warn | Ignore # The policy for omitempty in optional fields. Defaults to `SuggestFix`.
62+
63+
exclusions:
64+
generated: strict
65+
paths:
66+
- zz_generated.*\.go$
67+
- ".*_test.go" # Exclude test files.
68+
rules:
69+
## KAL should only run on API folders.
70+
- path-except: "api//*"
71+
linters:
72+
- kubeapilinter
73+
74+
## Excludes for old apiVersions that can be removed once the apiVersions are dropped (we don't want to make any changes to these APIs).
75+
- path: "api/v1alpha1"
76+
linters:
77+
- kubeapilinter
78+
issues:
79+
max-same-issues: 0
80+
max-issues-per-linter: 0

.golangci.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,34 @@ linters:
3131
alias:
3232
- pkg: sigs.k8s.io/controller-runtime/pkg/log
3333
alias: logf
34-
- pkg: sigs.k8s.io/cluster-api/api/v1beta1
34+
- pkg: sigs.k8s.io/cluster-api/api/core/v1beta2
3535
alias: clusterv1
36-
- pkg: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha1
36+
- pkg: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
3737
alias: infrav1
3838
- pkg: k8s.io/apimachinery/pkg/api/errors
3939
alias: apierrors
4040
- pkg: k8s.io/apimachinery/pkg/util/errors
4141
alias: utilerrors
4242
- pkg: github.com/scaleway/cluster-api-provider-scaleway/internal/service/scaleway/lb/util
4343
alias: lbutil
44+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
45+
alias: metav1
4446
exclusions:
4547
generated: lax
4648
rules:
4749
- linters:
4850
- lll
4951
path: api/*
52+
- linters:
53+
- lll
54+
path: cmd/main.go
5055
- linters:
5156
- lll
5257
path: test/e2e/*
5358
- linters:
5459
- dupl
5560
- lll
5661
path: internal/*
57-
- linters:
58-
- staticcheck
59-
text: "ST1019"
6062
- linters:
6163
- staticcheck
6264
text: "ST1005"
@@ -73,11 +75,22 @@ linters:
7375
- examples$
7476
formatters:
7577
enable:
78+
- gci
7679
- gofmt
7780
- goimports
81+
settings:
82+
gci:
83+
sections:
84+
- standard
85+
- blank
86+
- dot
87+
- default
88+
- localmodule
89+
custom-order: true
7890
exclusions:
79-
generated: lax
91+
generated: strict
8092
paths:
93+
- zz_generated.*\.go$
8194
- third_party$
8295
- builtin$
8396
- examples$

Makefile

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ else
88
GOBIN=$(shell go env GOBIN)
99
endif
1010

11+
TOOLS_DIR := hack/tools
1112
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
1213

1314
# CONTAINER_TOOL defines the container tool to be used for building images.
@@ -48,10 +49,14 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
4849
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4950

5051
.PHONY: generate
51-
generate: controller-gen mockgen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
52+
generate: controller-gen generate-go-conversions mockgen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
5253
$(CONTROLLER_GEN) object paths="./..."
5354
go generate ./...
5455

56+
.PHONY: generate-go-conversions
57+
generate-go-conversions: conversion-gen ## Generate conversions go code
58+
$(CONVERSION_GEN) --output-file=zz_generated.conversion.go github.com/scaleway/cluster-api-provider-scaleway/api/...
59+
5560
.PHONY: fmt
5661
fmt: ## Run go fmt against code.
5762
go fmt ./...
@@ -70,7 +75,7 @@ KIND_KUBECONFIG ?= /tmp/caps-e2e-kubeconfig
7075
E2E_ARTIFACTS ?= $(ROOT_DIR)/_artifacts
7176
E2E_CONF_FILE ?= $(ROOT_DIR)/test/e2e/config/scaleway.yaml
7277
E2E_CONF_FILE_ENVSUBST := $(ROOT_DIR)/test/e2e/config/scaleway-envsubst.yaml
73-
E2E_V1BETA1_TEMPLATES := $(ROOT_DIR)/test/e2e/data/infrastructure-scaleway/v1beta1
78+
E2E_V1BETA2_TEMPLATES := $(ROOT_DIR)/test/e2e/data/infrastructure-scaleway/v1beta2
7479
E2E_FOCUS ?= ""
7580

7681
.PHONY: setup-test-e2e
@@ -83,9 +88,9 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
8388

8489
.PHONY: generate-e2e
8590
generate-e2e: kustomize ## Generate templates for e2e
86-
$(KUSTOMIZE) build $(E2E_V1BETA1_TEMPLATES)/cluster-template --load-restrictor LoadRestrictionsNone > $(E2E_V1BETA1_TEMPLATES)/cluster-template.yaml
87-
$(KUSTOMIZE) build $(E2E_V1BETA1_TEMPLATES)/cluster-template-private-network --load-restrictor LoadRestrictionsNone > $(E2E_V1BETA1_TEMPLATES)/cluster-template-private-network.yaml
88-
$(KUSTOMIZE) build $(E2E_V1BETA1_TEMPLATES)/cluster-template-managed --load-restrictor LoadRestrictionsNone > $(E2E_V1BETA1_TEMPLATES)/cluster-template-managed.yaml
91+
$(KUSTOMIZE) build $(E2E_V1BETA2_TEMPLATES)/cluster-template --load-restrictor LoadRestrictionsNone > $(E2E_V1BETA2_TEMPLATES)/cluster-template.yaml
92+
$(KUSTOMIZE) build $(E2E_V1BETA2_TEMPLATES)/cluster-template-private-network --load-restrictor LoadRestrictionsNone > $(E2E_V1BETA2_TEMPLATES)/cluster-template-private-network.yaml
93+
$(KUSTOMIZE) build $(E2E_V1BETA2_TEMPLATES)/cluster-template-managed --load-restrictor LoadRestrictionsNone > $(E2E_V1BETA2_TEMPLATES)/cluster-template-managed.yaml
8994

9095
.PHONY: test-e2e
9196
test-e2e: setup-test-e2e generate-e2e docker-build envsubst ginkgo build-installer fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
@@ -101,13 +106,17 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
101106
@$(KIND) delete cluster --name $(KIND_CLUSTER) --kubeconfig $(KIND_KUBECONFIG)
102107

103108
.PHONY: lint
104-
lint: lint-golangci-lint lint-nilaway ## Run linters
109+
lint: lint-api lint-golangci-lint lint-nilaway ## Run linters
105110
@echo "done"
106111

107112
.PHONY: lint-golangci-lint
108113
lint-golangci-lint: golangci-lint ## Run golangci-lint linter
109114
$(GOLANGCI_LINT) run
110115

116+
.PHONY: lint-api
117+
lint-api: golangci-lint-kube-api-linter ## Run golangci-lint-kube-api-linter linter
118+
$(GOLANGCI_LINT_KAL) run --config .golangci-kal.yml
119+
111120
.PHONY: lint-nilaway
112121
lint-nilaway: nilaway ## Run nilaway linter
113122
$(NILAWAY) -include-pkgs=github.com/scaleway/cluster-api-provider-scaleway ./...
@@ -217,19 +226,22 @@ NILAWAY = $(LOCALBIN)/nilaway
217226
MOCKGEN = $(LOCALBIN)/mockgen
218227
ENVSUBST = $(LOCALBIN)/envsubst
219228
GINKGO = $(LOCALBIN)/ginkgo
229+
GOLANGCI_LINT_KAL := $(LOCALBIN)/golangci-lint-kube-api-linter
230+
CONVERSION_GEN ?= $(LOCALBIN)/conversion-gen
220231

221232
## Tool Versions
222-
KUSTOMIZE_VERSION ?= v5.6.0
223-
CONTROLLER_TOOLS_VERSION ?= v0.18.0
233+
KUSTOMIZE_VERSION ?= v5.7.1
234+
CONTROLLER_TOOLS_VERSION ?= v0.19.0
224235
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
225236
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
226237
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
227238
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
228-
GOLANGCI_LINT_VERSION ?= v2.1.0
239+
GOLANGCI_LINT_VERSION ?= v2.6.2
229240
NILAWAY_VERSION ?= latest
230-
MOCKGEN_VERSION ?= v0.5.2
241+
MOCKGEN_VERSION ?= v0.6.0
231242
ENVSUBST_VERSION ?=latest
232-
GINKGO_VERSION ?= v2.23.4
243+
GINKGO_VERSION ?= v2.25.3
244+
CONVERSION_GEN_VERSION ?= v0.34.0
233245

234246
.PHONY: kustomize
235247
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -241,6 +253,11 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
241253
$(CONTROLLER_GEN): $(LOCALBIN)
242254
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
243255

256+
.PHONY: conversion-gen
257+
conversion-gen: $(CONVERSION_GEN) ## Download conversion-gen locally if necessary.
258+
$(CONVERSION_GEN): $(LOCALBIN)
259+
$(call go-install-tool,$(CONVERSION_GEN),k8s.io/code-generator/cmd/conversion-gen,$(CONVERSION_GEN_VERSION))
260+
244261
.PHONY: setup-envtest
245262
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
246263
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
@@ -279,6 +296,11 @@ ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
279296
$(GINKGO): $(LOCALBIN)
280297
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION))
281298

299+
.PHONY: golangci-lint-kube-api-linter
300+
golangci-lint-kube-api-linter: $(GOLANGCI_LINT_KAL) ## Build golangci-lint-kal from custom configuration.
301+
$(GOLANGCI_LINT_KAL): $(GOLANGCI_LINT)
302+
$(GOLANGCI_LINT) custom
303+
282304
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
283305
# $1 - target path with name of binary
284306
# $2 - package url which can be installed

PROJECT

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,96 @@ resources:
6969
kind: ScalewayManagedMachinePool
7070
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha1
7171
version: v1alpha1
72+
- api:
73+
crdVersion: v1
74+
namespaced: true
75+
domain: cluster.x-k8s.io
76+
group: infrastructure
77+
kind: ScalewayCluster
78+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
79+
version: v1alpha2
80+
webhooks:
81+
conversion: true
82+
spoke:
83+
- v1alpha1
84+
webhookVersion: v1
85+
- api:
86+
crdVersion: v1
87+
namespaced: true
88+
domain: cluster.x-k8s.io
89+
group: infrastructure
90+
kind: ScalewayMachine
91+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
92+
version: v1alpha2
93+
webhooks:
94+
conversion: true
95+
spoke:
96+
- v1alpha1
97+
webhookVersion: v1
98+
- api:
99+
crdVersion: v1
100+
namespaced: true
101+
domain: cluster.x-k8s.io
102+
group: infrastructure
103+
kind: ScalewayClusterTemplate
104+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
105+
version: v1alpha2
106+
webhooks:
107+
conversion: true
108+
spoke:
109+
- v1alpha1
110+
webhookVersion: v1
111+
- api:
112+
crdVersion: v1
113+
namespaced: true
114+
domain: cluster.x-k8s.io
115+
group: infrastructure
116+
kind: ScalewayMachineTemplate
117+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
118+
version: v1alpha2
119+
webhooks:
120+
conversion: true
121+
spoke:
122+
- v1alpha1
123+
webhookVersion: v1
124+
- api:
125+
crdVersion: v1
126+
namespaced: true
127+
domain: cluster.x-k8s.io
128+
group: infrastructure
129+
kind: ScalewayManagedCluster
130+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
131+
version: v1alpha2
132+
webhooks:
133+
conversion: true
134+
spoke:
135+
- v1alpha1
136+
webhookVersion: v1
137+
- api:
138+
crdVersion: v1
139+
namespaced: true
140+
domain: cluster.x-k8s.io
141+
group: infrastructure
142+
kind: ScalewayManagedControlPlane
143+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
144+
version: v1alpha2
145+
webhooks:
146+
conversion: true
147+
defaulting: true
148+
spoke:
149+
- v1alpha1
150+
webhookVersion: v1
151+
- api:
152+
crdVersion: v1
153+
namespaced: true
154+
domain: cluster.x-k8s.io
155+
group: infrastructure
156+
kind: ScalewayManagedMachinePool
157+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
158+
version: v1alpha2
159+
webhooks:
160+
conversion: true
161+
spoke:
162+
- v1alpha1
163+
webhookVersion: v1
72164
version: "3"

0 commit comments

Comments
 (0)