Skip to content

Commit 962689c

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

File tree

123 files changed

+7275
-1834
lines changed

Some content is hidden

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

123 files changed

+7275
-1834
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.5.0
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-20250924094418-502783c08f9d

.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.5.0
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: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ 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:
@@ -54,9 +56,6 @@ linters:
5456
- dupl
5557
- lll
5658
path: internal/*
57-
- linters:
58-
- staticcheck
59-
text: "ST1019"
6059
- linters:
6160
- staticcheck
6261
text: "ST1005"
@@ -73,11 +72,22 @@ linters:
7372
- examples$
7473
formatters:
7574
enable:
75+
- gci
7676
- gofmt
7777
- goimports
78+
settings:
79+
gci:
80+
sections:
81+
- standard
82+
- blank
83+
- dot
84+
- default
85+
- localmodule
86+
custom-order: true
7887
exclusions:
79-
generated: lax
88+
generated: strict
8089
paths:
90+
- zz_generated.*\.go$
8191
- third_party$
8292
- builtin$
8393
- examples$

Makefile

Lines changed: 17 additions & 6 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.
@@ -101,13 +102,17 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
101102
@$(KIND) delete cluster --name $(KIND_CLUSTER) --kubeconfig $(KIND_KUBECONFIG)
102103

103104
.PHONY: lint
104-
lint: lint-golangci-lint lint-nilaway ## Run linters
105+
lint: lint-api lint-golangci-lint lint-nilaway ## Run linters
105106
@echo "done"
106107

107108
.PHONY: lint-golangci-lint
108109
lint-golangci-lint: golangci-lint ## Run golangci-lint linter
109110
$(GOLANGCI_LINT) run
110111

112+
.PHONY: lint-api
113+
lint-api: golangci-lint-kube-api-linter ## Run golangci-lint-kube-api-linter linter
114+
$(GOLANGCI_LINT_KAL) run --config .golangci-kal.yml
115+
111116
.PHONY: lint-nilaway
112117
lint-nilaway: nilaway ## Run nilaway linter
113118
$(NILAWAY) -include-pkgs=github.com/scaleway/cluster-api-provider-scaleway ./...
@@ -217,19 +222,20 @@ NILAWAY = $(LOCALBIN)/nilaway
217222
MOCKGEN = $(LOCALBIN)/mockgen
218223
ENVSUBST = $(LOCALBIN)/envsubst
219224
GINKGO = $(LOCALBIN)/ginkgo
225+
GOLANGCI_LINT_KAL := $(LOCALBIN)/golangci-lint-kube-api-linter
220226

221227
## Tool Versions
222-
KUSTOMIZE_VERSION ?= v5.6.0
223-
CONTROLLER_TOOLS_VERSION ?= v0.18.0
228+
KUSTOMIZE_VERSION ?= v5.7.1
229+
CONTROLLER_TOOLS_VERSION ?= v0.19.0
224230
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
225231
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
226232
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
227233
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
234+
GOLANGCI_LINT_VERSION ?= v2.5.0
229235
NILAWAY_VERSION ?= latest
230-
MOCKGEN_VERSION ?= v0.5.2
236+
MOCKGEN_VERSION ?= v0.6.0
231237
ENVSUBST_VERSION ?=latest
232-
GINKGO_VERSION ?= v2.23.4
238+
GINKGO_VERSION ?= v2.25.3
233239

234240
.PHONY: kustomize
235241
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -279,6 +285,11 @@ ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
279285
$(GINKGO): $(LOCALBIN)
280286
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION))
281287

288+
.PHONY: golangci-lint-kube-api-linter
289+
golangci-lint-kube-api-linter: $(GOLANGCI_LINT_KAL) ## Build golangci-lint-kal from custom configuration.
290+
$(GOLANGCI_LINT_KAL): $(GOLANGCI_LINT)
291+
$(GOLANGCI_LINT) custom
292+
282293
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
283294
# $1 - target path with name of binary
284295
# $2 - package url which can be installed

PROJECT

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,60 @@ 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+
- api:
81+
crdVersion: v1
82+
namespaced: true
83+
domain: cluster.x-k8s.io
84+
group: infrastructure
85+
kind: ScalewayMachine
86+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
87+
version: v1alpha2
88+
- api:
89+
crdVersion: v1
90+
namespaced: true
91+
domain: cluster.x-k8s.io
92+
group: infrastructure
93+
kind: ScalewayClusterTemplate
94+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
95+
version: v1alpha2
96+
- api:
97+
crdVersion: v1
98+
namespaced: true
99+
domain: cluster.x-k8s.io
100+
group: infrastructure
101+
kind: ScalewayMachineTemplate
102+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
103+
version: v1alpha2
104+
- api:
105+
crdVersion: v1
106+
namespaced: true
107+
domain: cluster.x-k8s.io
108+
group: infrastructure
109+
kind: ScalewayManagedCluster
110+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
111+
version: v1alpha2
112+
- api:
113+
crdVersion: v1
114+
namespaced: true
115+
domain: cluster.x-k8s.io
116+
group: infrastructure
117+
kind: ScalewayManagedControlPlane
118+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
119+
version: v1alpha2
120+
- api:
121+
crdVersion: v1
122+
namespaced: true
123+
domain: cluster.x-k8s.io
124+
group: infrastructure
125+
kind: ScalewayManagedMachinePool
126+
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha2
127+
version: v1alpha2
72128
version: "3"

api/v1alpha1/groupversion_info.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Package v1alpha1 contains API Schema definitions for the infrastructure v1alpha1 API group.
22
// +kubebuilder:object:generate=true
33
// +groupName=infrastructure.cluster.x-k8s.io
4+
//
5+
// Deprecated: This package is deprecated and is going to be removed when support for v1alpha1 will be dropped.
46
package v1alpha1
57

68
import (

api/v1alpha1/scalewaycluster_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package v1alpha1
22

33
import (
44
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
5+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1" //nolint:staticcheck
66
)
77

88
const ClusterFinalizer = "scalewaycluster.infrastructure.cluster.x-k8s.io/sc-protection"
@@ -223,7 +223,7 @@ type NetworkStatus struct {
223223
// +kubebuilder:printcolumn:name="Region",type="string",JSONPath=".spec.region",description="Region of the cluster"
224224
// +kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready",description="Ready is true when the cluster is fully provisioned"
225225
// +kubebuilder:resource:path=scalewayclusters,scope=Namespaced,categories=cluster-api,shortName=sc
226-
// +kubebuilder:storageversion
226+
// +kubebuilder:deprecatedversion
227227

228228
// ScalewayCluster is the Schema for the scalewayclusters API.
229229
// +kubebuilder:validation:XValidation:rule="self.metadata.name.size() <= 63",message="name must be between 1 and 63 characters"

api/v1alpha1/scalewayclustertemplate_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type ScalewayClusterTemplateResource struct {
1919

2020
// +kubebuilder:object:root=true
2121
// +kubebuilder:resource:path=scalewayclustertemplates,scope=Namespaced,categories=cluster-api,shortName=sct
22-
// +kubebuilder:storageversion
22+
// +kubebuilder:deprecatedversion
2323

2424
// ScalewayClusterTemplate is the Schema for the scalewayclustertemplates API.
2525
type ScalewayClusterTemplate struct {

0 commit comments

Comments
 (0)