Skip to content

Commit ef0d20c

Browse files
Merge pull request #794 from salasberryfin/bump_capi_v1.11.4
✨ Bump to CAPI v1.11.5 and adopt `v1beta2` contract
2 parents d73fee2 + d1f7a6b commit ef0d20c

File tree

142 files changed

+12402
-2234
lines changed

Some content is hidden

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

142 files changed

+12402
-2234
lines changed

.github/workflows/e2e.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,29 @@ jobs:
3131
name: e2e-artifacts
3232
path: _artifacts
3333
if-no-files-found: ignore
34+
e2e-tests-upgrade:
35+
runs-on: runs-on,runner=4cpu-linux-x64,run-id=${{ github.run_id }}
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v6
39+
with:
40+
fetch-depth: 0
41+
- name: Install Go
42+
uses: actions/setup-go@v6
43+
with:
44+
go-version-file: go.mod
45+
- name: Setup kind
46+
uses: helm/[email protected]
47+
with:
48+
install_only: true
49+
- name: Run E2E tests
50+
env:
51+
GINKGO_LABEL_FILTER: upgrade
52+
run: make test-e2e
53+
- name: Archive artifacts
54+
if: always()
55+
uses: actions/[email protected]
56+
with:
57+
name: e2e-upgrade-artifacts
58+
path: _artifacts
59+
if-no-files-found: ignore

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ linters:
8686
path: _test\.go
8787
- linters:
8888
- lll
89-
source: '^//\+kubebuilder:'
89+
source: '^//\s*\+kubebuilder:'
9090
- linters:
9191
- dupl
9292
- wrapcheck

Makefile

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ ALL_GENERATE_MODULES = rke2-bootstrap rke2-control-plane
158158

159159
.PHONY: generate
160160
generate: ## Run all generate-manifests-*, generate-go-deepcopy-* targets
161-
# TODO: enable generate-go-conversions once v1beta2 is available and served.
162-
$(MAKE) generate-modules generate-manifests generate-go-deepcopy # generate-go-conversions -> remove this temporarily as there's only one version available after deprecating v1alpha1.
161+
$(MAKE) generate-modules generate-manifests generate-go-deepcopy generate-go-conversions
163162

164163
.PHONY: generate-manifests
165164
generate-manifests: $(addprefix generate-manifests-,$(ALL_GENERATE_MODULES)) ## Run all generate-manifests-* targets
@@ -177,7 +176,6 @@ generate-manifests-rke2-bootstrap: $(CONTROLLER_GEN) ## Generate manifests e.g.
177176
output:rbac:dir=./bootstrap/config/rbac \
178177
output:webhook:dir=./bootstrap/config/webhook \
179178
webhook
180-
rm ./bootstrap/config/crd/bases/_.yaml # this is temporarily used to delete the empty yaml definition that's generated for the non-served api `v1beta2`. This should be remove when `v1beta2` is promoted
181179

182180
.PHONY: generate-manifests-rke2-control-plane
183181
generate-manifests-rke2-control-plane: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc. for RKE2 control plane provider
@@ -193,7 +191,6 @@ generate-manifests-rke2-control-plane: $(CONTROLLER_GEN) ## Generate manifests e
193191
output:rbac:dir=./controlplane/config/rbac \
194192
output:webhook:dir=./controlplane/config/webhook \
195193
webhook
196-
rm ./controlplane/config/crd/bases/_.yaml # this is temporarily used to delete the empty yaml definition that's generated for the non-served api `v1beta2`. This should be remove when `v1beta2` is promoted
197194

198195
.PHONY: generate-go-deepcopy
199196
generate-go-deepcopy: ## Run all generate-go-deepcopy-* targets
@@ -220,19 +217,19 @@ generate-go-conversions: ## Run all generate-go-conversions-* targets
220217

221218
.PHONY: generate-go-conversions-rke2-bootstrap
222219
generate-go-conversions-rke2-bootstrap: $(CONVERSION_GEN) ## Generate conversions go code for the rke2 bootstrap
223-
$(MAKE) clean-generated-conversions SRC_DIRS="./bootstrap/api/v1alpha1"
220+
$(MAKE) clean-generated-conversions SRC_DIRS="./bootstrap/api/v1beta1"
224221
$(CONVERSION_GEN) \
225222
--output-file=zz_generated.conversion.go $(ROOT_DIR)/$(CAPBPR_DIR) \
226223
--go-header-file=./hack/boilerplate.go.txt \
227-
./bootstrap/api/v1alpha1
224+
./bootstrap/api/v1beta1
228225

229226
.PHONY: generate-go-conversions-rke2-control-plane
230227
generate-go-conversions-rke2-control-plane: $(CONVERSION_GEN) ## Generate conversions go code for the rke2 control plane
231-
$(MAKE) clean-generated-conversions SRC_DIRS="./controlplane/api/v1alpha1"
228+
$(MAKE) clean-generated-conversions SRC_DIRS="./controlplane/api/v1beta1"
232229
$(CONVERSION_GEN) \
233230
--output-file=zz_generated.conversion.go $(ROOT_DIR)/$(CAPRKE2_DIR) \
234231
--go-header-file=./hack/boilerplate.go.txt \
235-
./controlplane/api/v1alpha1
232+
./controlplane/api/v1beta1
236233

237234
.PHONY: generate-modules
238235
generate-modules: ## Run go mod tidy to ensure modules are up to date
@@ -400,6 +397,7 @@ kubectl: # Download kubectl cli into tools bin folder
400397

401398
# Allow overriding the e2e configurations
402399
GINKGO_FOCUS ?=
400+
GINKGO_LABEL_FILTER ?= "default"
403401
GINKGO_SKIP ?= "Pivot" # See: https://github.com/rancher/cluster-api-provider-rke2/issues/691
404402
GINKGO_NODES ?= 1
405403
GINKGO_NOCOLOR ?= false
@@ -414,7 +412,7 @@ SKIP_CREATE_MGMT_CLUSTER ?= false
414412
.PHONY: test-e2e-run
415413
test-e2e-run: $(GINKGO) $(KUSTOMIZE) kubectl e2e-image inotify-check ## Run the end-to-end tests
416414
LOCAL_IMAGES="$(LOCAL_IMAGES)" CAPI_KUSTOMIZE_PATH="$(KUSTOMIZE)" $(GINKGO) -v -poll-progress-after=$(GINKGO_POLL_PROGRESS_AFTER) -poll-progress-interval=$(GINKGO_POLL_PROGRESS_INTERVAL) \
417-
--tags=e2e --focus="$(GINKGO_FOCUS)" --skip="$(GINKGO_SKIP)" --nodes=$(GINKGO_NODES) --no-color=$(GINKGO_NOCOLOR) \
415+
--tags=e2e --focus="$(GINKGO_FOCUS)" --label-filter="$(GINKGO_LABEL_FILTER)" --skip="$(GINKGO_SKIP)" --nodes=$(GINKGO_NODES) --no-color=$(GINKGO_NOCOLOR) \
418416
--timeout=$(GINKGO_TIMEOUT) --output-dir="$(ARTIFACTS)" --junit-report="junit.e2e_suite.1.xml" $(GINKGO_ARGS) ./test/e2e -- \
419417
-e2e.artifacts-folder="$(ARTIFACTS)" \
420418
-e2e.config="$(E2E_CONF_FILE)" \

bootstrap/api/v1beta1/condition_consts.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
20+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" // nolint:staticcheck
2121
)
2222

2323
const (
@@ -26,7 +26,7 @@ const (
2626
// NOTE: When the DataSecret generation starts the process completes immediately and within the
2727
// same reconciliation, so the user will always see a transition from Wait to Generated without having
2828
// to wait for the next reconciliation.
29-
DataSecretAvailableCondition clusterv1.ConditionType = "Available"
29+
DataSecretAvailableCondition clusterv1beta1.ConditionType = "Available"
3030
)
3131

3232
const (
@@ -44,7 +44,7 @@ const (
4444

4545
const (
4646
// CertificatesAvailableCondition documents the status of the certificates generation process.
47-
CertificatesAvailableCondition clusterv1.ConditionType = "CertificatesAvailable"
47+
CertificatesAvailableCondition clusterv1beta1.ConditionType = "CertificatesAvailable"
4848

4949
// CertificatesGenerationFailedReason documents a RKE2Config controller detecting
5050
// an error while generating certificates; those kind of errors are usually due to misconfigurations

bootstrap/api/v1beta1/conversion.go

Lines changed: 231 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,237 @@ limitations under the License.
1616

1717
package v1beta1
1818

19-
// Hub is a conversion hub for RKE2ConfigTemplate.
20-
func (*RKE2ConfigTemplate) Hub() {}
19+
import (
20+
"fmt"
21+
"reflect"
2122

22-
// Hub is a conversion hub for RKE2ConfigTemplateList.
23-
func (*RKE2ConfigTemplateList) Hub() {}
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
25+
"k8s.io/utils/ptr"
2426

25-
// Hub is a conversion hub for RKE2Config.
26-
func (*RKE2Config) Hub() {}
27+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" // nolint:staticcheck
28+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
29+
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
30+
"sigs.k8s.io/controller-runtime/pkg/conversion"
2731

28-
// Hub is a conversion hub for RKE2ConfigList.
29-
func (*RKE2ConfigList) Hub() {}
32+
bootstrapv1 "github.com/rancher/cluster-api-provider-rke2/bootstrap/api/v1beta2"
33+
)
34+
35+
// ConvertTo converts this RKE2Config to the Hub version (v1beta2).
36+
func (src *RKE2Config) ConvertTo(dstRaw conversion.Hub) error {
37+
dst, ok := dstRaw.(*bootstrapv1.RKE2Config)
38+
if !ok {
39+
return fmt.Errorf("not a RKE2Config: %v", dst)
40+
}
41+
42+
if err := Convert_v1beta1_RKE2Config_To_v1beta2_RKE2Config(src, dst, nil); err != nil {
43+
return err
44+
}
45+
46+
// Preserve Hub data on down-conversion.
47+
restored := &bootstrapv1.RKE2Config{}
48+
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
49+
return err
50+
}
51+
52+
// Recover intent for bool values converted to *bool.
53+
initialization := bootstrapv1.RKE2ConfigInitializationStatus{}
54+
restoredBootstrapDataSecretCreated := restored.Status.Initialization.DataSecretCreated
55+
clusterv1.Convert_bool_To_Pointer_bool(src.Status.Ready, ok, restoredBootstrapDataSecretCreated, &initialization.DataSecretCreated)
56+
if !reflect.DeepEqual(initialization, bootstrapv1.RKE2ConfigInitializationStatus{}) {
57+
dst.Status.Initialization = initialization
58+
}
59+
60+
return nil
61+
}
62+
63+
// ConvertFrom converts from the Hub version (v1beta2) to this version (v1beta1).
64+
func (dst *RKE2Config) ConvertFrom(srcRaw conversion.Hub) error {
65+
src, ok := srcRaw.(*bootstrapv1.RKE2Config)
66+
if !ok {
67+
return fmt.Errorf("not a RKE2Config: %v", src)
68+
}
69+
70+
if err := Convert_v1beta2_RKE2Config_To_v1beta1_RKE2Config(src, dst, nil); err != nil {
71+
return err
72+
}
73+
74+
// Preserve Hub data on down-conversion.
75+
if err := utilconversion.MarshalData(src, dst); err != nil {
76+
return err
77+
}
78+
79+
return nil
80+
}
81+
82+
// ConvertTo converts this RKE2ConfigList to the Hub version (v1beta2).
83+
func (src *RKE2ConfigList) ConvertTo(dstRaw conversion.Hub) error {
84+
dst, ok := dstRaw.(*bootstrapv1.RKE2ConfigList)
85+
if !ok {
86+
return fmt.Errorf("not a RKE2ConfigList: %v", dst)
87+
}
88+
89+
return Convert_v1beta1_RKE2ConfigList_To_v1beta2_RKE2ConfigList(src, dst, nil)
90+
}
91+
92+
// ConvertFrom converts from the Hub version (v1beta2) to this version (v1beta1).
93+
func (dst *RKE2ConfigList) ConvertFrom(srcRaw conversion.Hub) error {
94+
src, ok := srcRaw.(*bootstrapv1.RKE2ConfigList)
95+
if !ok {
96+
return fmt.Errorf("not a RKE2ConfigList: %v", src)
97+
}
98+
99+
return Convert_v1beta2_RKE2ConfigList_To_v1beta1_RKE2ConfigList(src, dst, nil)
100+
}
101+
102+
// ConvertTo converts this RKE2ConfigTemplate to the Hub version (v1beta2).
103+
func (src *RKE2ConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
104+
dst, ok := dstRaw.(*bootstrapv1.RKE2ConfigTemplate)
105+
if !ok {
106+
return fmt.Errorf("not a RKE2ConfigTemplate: %v", dst)
107+
}
108+
109+
if err := Convert_v1beta1_RKE2ConfigTemplate_To_v1beta2_RKE2ConfigTemplate(src, dst, nil); err != nil {
110+
return err
111+
}
112+
113+
// Preserve Hub data on down-conversion.
114+
restored := &bootstrapv1.RKE2ConfigTemplate{}
115+
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
116+
return err
117+
}
118+
119+
return nil
120+
}
121+
122+
// ConvertFrom converts from the Hub version (v1beta2) to this version (v1beta1).
123+
func (dst *RKE2ConfigTemplate) ConvertFrom(srcRaw conversion.Hub) error {
124+
src, ok := srcRaw.(*bootstrapv1.RKE2ConfigTemplate)
125+
if !ok {
126+
return fmt.Errorf("not a RKE2ConfigTemplate: %v", src)
127+
}
128+
129+
if err := Convert_v1beta2_RKE2ConfigTemplate_To_v1beta1_RKE2ConfigTemplate(src, dst, nil); err != nil {
130+
return err
131+
}
132+
133+
// Preserve Hub data on down-conversion.
134+
if err := utilconversion.MarshalData(src, dst); err != nil {
135+
return err
136+
}
137+
138+
return nil
139+
}
140+
141+
// ConvertTo converts this RKE2ConfigTemplateList to the Hub version (v1beta2).
142+
func (src *RKE2ConfigTemplateList) ConvertTo(dstRaw conversion.Hub) error {
143+
dst, ok := dstRaw.(*bootstrapv1.RKE2ConfigTemplateList)
144+
if !ok {
145+
return fmt.Errorf("not a RKE2ConfigTemplateList: %v", dst)
146+
}
147+
148+
return Convert_v1beta1_RKE2ConfigTemplateList_To_v1beta2_RKE2ConfigTemplateList(src, dst, nil)
149+
}
150+
151+
// ConvertFrom converts from the Hub version (v1beta2) to this version (v1beta1).
152+
func (dst *RKE2ConfigTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
153+
src, ok := srcRaw.(*bootstrapv1.RKE2ConfigTemplateList)
154+
if !ok {
155+
return fmt.Errorf("not a RKE2ConfigTemplateList: %v", src)
156+
}
157+
158+
return Convert_v1beta2_RKE2ConfigTemplateList_To_v1beta1_RKE2ConfigTemplateList(src, dst, nil)
159+
}
160+
161+
// Convert_v1beta1_RKE2ConfigStatus_To_v1beta2_RKE2ConfigStatus converts RKE2ConfigStatus from v1beta1 to v1beta2.
162+
func Convert_v1beta1_RKE2ConfigStatus_To_v1beta2_RKE2ConfigStatus(in *RKE2ConfigStatus, out *bootstrapv1.RKE2ConfigStatus, s apimachineryconversion.Scope) error {
163+
if err := autoConvert_v1beta1_RKE2ConfigStatus_To_v1beta2_RKE2ConfigStatus(in, out, s); err != nil {
164+
return err
165+
}
166+
167+
// Reset conditions from autogenerated conversions
168+
// NOTE: v1beta1 conditions should not be automatically be converted into v1beta2 conditions.
169+
out.Conditions = nil
170+
171+
// Retrieve new conditions (v1beta2) from the v1beta2 field.
172+
if in.V1Beta2 != nil {
173+
out.Conditions = in.V1Beta2.Conditions
174+
}
175+
176+
// Move legacy conditions (v1beta1), failureReason and failureMessage to the deprecated field.
177+
if out.Deprecated == nil {
178+
out.Deprecated = &bootstrapv1.RKE2ConfigDeprecatedStatus{}
179+
}
180+
if out.Deprecated.V1Beta1 == nil {
181+
out.Deprecated.V1Beta1 = &bootstrapv1.RKE2ConfigV1Beta1DeprecatedStatus{}
182+
}
183+
if in.Conditions != nil {
184+
clusterv1beta1.Convert_v1beta1_Conditions_To_v1beta2_Deprecated_V1Beta1_Conditions(&in.Conditions, &out.Deprecated.V1Beta1.Conditions)
185+
}
186+
out.Deprecated.V1Beta1.FailureReason = in.FailureReason
187+
out.Deprecated.V1Beta1.FailureMessage = in.FailureMessage
188+
189+
return nil
190+
}
191+
192+
// Convert_v1beta2_RKE2ConfigStatus_To_v1beta1_RKE2ConfigStatus converts RKE2ConfigStatus from v1beta2 to v1beta1.
193+
func Convert_v1beta2_RKE2ConfigStatus_To_v1beta1_RKE2ConfigStatus(in *bootstrapv1.RKE2ConfigStatus, out *RKE2ConfigStatus, s apimachineryconversion.Scope) error {
194+
if err := autoConvert_v1beta2_RKE2ConfigStatus_To_v1beta1_RKE2ConfigStatus(in, out, s); err != nil {
195+
return err
196+
}
197+
198+
// Reset conditions from autogenerated conversions
199+
// NOTE: v1beta2 conditions should not be automatically be converted into legacy conditions (v1beta1).
200+
out.Conditions = nil
201+
202+
// Retrieve legacy conditions (v1beta1), failureReason and failureMessage from the deprecated field.
203+
if in.Deprecated != nil && in.Deprecated.V1Beta1 != nil {
204+
if in.Deprecated.V1Beta1.Conditions != nil {
205+
clusterv1beta1.Convert_v1beta2_Deprecated_V1Beta1_Conditions_To_v1beta1_Conditions(&in.Deprecated.V1Beta1.Conditions, &out.Conditions)
206+
}
207+
out.FailureReason = in.Deprecated.V1Beta1.FailureReason
208+
out.FailureMessage = in.Deprecated.V1Beta1.FailureMessage
209+
}
210+
211+
// Move initialization to old fields
212+
out.Ready = ptr.Deref(in.Initialization.DataSecretCreated, false)
213+
214+
// Move new conditions (v1beta2) to the v1beta2 field.
215+
if in.Conditions == nil {
216+
return nil
217+
}
218+
out.V1Beta2 = &RKE2ConfigV1Beta2Status{}
219+
out.V1Beta2.Conditions = in.Conditions
220+
221+
return nil
222+
}
223+
224+
// Convert_v1beta1_RKE2AgentConfig_To_v1beta2_RKE2AgentConfig converts RKE2AgentConfig from v1beta1 to v1beta2.
225+
func Convert_v1beta1_RKE2AgentConfig_To_v1beta2_RKE2AgentConfig(in *RKE2AgentConfig, out *bootstrapv1.RKE2AgentConfig, s apimachineryconversion.Scope) error {
226+
return autoConvert_v1beta1_RKE2AgentConfig_To_v1beta2_RKE2AgentConfig(in, out, s)
227+
}
228+
229+
// Convert_v1beta2_RKE2AgentConfig_To_v1beta1_RKE2AgentConfig converts RKE2AgentConfig from v1beta2 to v1beta1.
230+
func Convert_v1beta2_RKE2AgentConfig_To_v1beta1_RKE2AgentConfig(in *bootstrapv1.RKE2AgentConfig, out *RKE2AgentConfig, s apimachineryconversion.Scope) error {
231+
return autoConvert_v1beta2_RKE2AgentConfig_To_v1beta1_RKE2AgentConfig(in, out, s)
232+
}
233+
234+
// Convert_v1beta1_RKE2ConfigSpec_To_v1beta2_RKE2ConfigSpec converts RKE2ConfigSpec from v1beta1 to v1beta2.
235+
func Convert_v1beta1_RKE2ConfigSpec_To_v1beta2_RKE2ConfigSpec(in *RKE2ConfigSpec, out *bootstrapv1.RKE2ConfigSpec, s apimachineryconversion.Scope) error {
236+
return autoConvert_v1beta1_RKE2ConfigSpec_To_v1beta2_RKE2ConfigSpec(in, out, s)
237+
}
238+
239+
// Convert_v1beta2_RKE2ConfigSpec_To_v1beta1_RKE2ConfigSpec converts RKE2ConfigSpec from v1beta2 to v1beta1.
240+
func Convert_v1beta2_RKE2ConfigSpec_To_v1beta1_RKE2ConfigSpec(in *bootstrapv1.RKE2ConfigSpec, out *RKE2ConfigSpec, s apimachineryconversion.Scope) error {
241+
return autoConvert_v1beta2_RKE2ConfigSpec_To_v1beta1_RKE2ConfigSpec(in, out, s)
242+
}
243+
244+
// Need to implement condition conversion between old CAPI-specific condition and the generic from apimachinery.
245+
// The logic is built in upstream CAPI but we need to have a convert function here so that controller-gen is aware of it.
246+
func Convert_v1beta1_Condition_To_v1_Condition(in *clusterv1beta1.Condition, out *metav1.Condition, s apimachineryconversion.Scope) error {
247+
return clusterv1beta1.Convert_v1beta1_Condition_To_v1_Condition(in, out, s)
248+
}
249+
250+
func Convert_v1_Condition_To_v1beta1_Condition(in *metav1.Condition, out *clusterv1beta1.Condition, s apimachineryconversion.Scope) error {
251+
return clusterv1beta1.Convert_v1_Condition_To_v1beta1_Condition(in, out, s)
252+
}

bootstrap/api/v1beta1/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ limitations under the License.
1616

1717
// Package v1beta1 contains a v1beta1 api for bootstrap resources.
1818
//
19+
// +k8s:conversion-gen=github.com/rancher/cluster-api-provider-rke2/bootstrap/api/v1beta2
1920
// +k8s:deepcopy-gen=package
2021
package v1beta1

bootstrap/api/v1beta1/groupversion_info.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ var (
3535
// AddToScheme adds the types in this group-version to the given scheme.
3636
AddToScheme = schemeBuilder.AddToScheme
3737

38+
// localSchemeBuilder is used for type conversions.
39+
localSchemeBuilder = &schemeBuilder
40+
3841
objectTypes = []runtime.Object{}
3942
)
4043

0 commit comments

Comments
 (0)