Skip to content

Commit 95c1b7f

Browse files
authored
✨ Update controller runtime and cluster-api to the newest version (CAPI 1.10) (#1628)
1 parent 8852aed commit 95c1b7f

File tree

3,708 files changed

+224233
-168690
lines changed

Some content is hidden

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

3,708 files changed

+224233
-168690
lines changed

.github/actions/e2e/action.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ runs:
4343
- name: Install hcloud
4444
shell: bash
4545
env:
46-
hcloudctl_version: 1.40.0
46+
hcloudctl_version: v1.52.0
4747
run: |
48-
curl -fsSL https://github.com/hetznercloud/cli/releases/download/v${{ env.hcloudctl_version }}/hcloud-linux-amd64.tar.gz | tar -xzv hcloud
48+
curl -fsSL https://github.com/hetznercloud/cli/releases/download/${{ env.hcloudctl_version }}/hcloud-linux-amd64.tar.gz | tar -xzv hcloud
4949
mkdir -p hack/tools/bin/
5050
mv hcloud hack/tools/bin/hcloud
5151

.golangci.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ linters-settings:
8383
alias: bootstrapv1
8484
- pkg: sigs.k8s.io/controller-runtime/pkg/metrics/server
8585
alias: metricsserver
86-
- pkg: sigs.k8s.io/cluster-api/errors
87-
alias: capierrors
8886
- pkg: sigs.k8s.io/controller-runtime/pkg/client/fake
8987
alias: fakeclient
9088
nolintlint:

.mockery.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This config was choosen, so that the output matches to old structure (pre config file .mockery.yaml).
2+
# If you are here to copy this config to a new project, then it might
3+
# make sense to choose a structure which needs less config by using
4+
# the default values of Mockery.
5+
all: True
6+
filename: "{{.InterfaceName}}.go"
7+
mockname: "{{.InterfaceName}}"
8+
outpkg: mocks
9+
packages:
10+
github.com/syself/cluster-api-provider-hetzner/pkg/services/baremetal/client/ssh:
11+
config:
12+
dir: "{{.InterfaceDir}}/../mocks/ssh"
13+
github.com/syself/cluster-api-provider-hetzner/pkg/services/baremetal/client/robot:
14+
config:
15+
dir: "{{.InterfaceDir}}/../mocks/robot"
16+
github.com/syself/cluster-api-provider-hetzner/pkg/services/hcloud/client:
17+
config:
18+
dir: "{{.InterfaceDir}}/mocks"

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ install-essentials: ## This gets the secret and installs a CNI and the CCM. Usag
174174
$(MAKE) install-cilium-in-wl-cluster
175175
$(MAKE) install-ccm-in-wl-cluster
176176

177-
wait-and-get-secret:
177+
wait-and-get-secret: $(KUBECTL)
178178
./hack/ensure-env-variables.sh CLUSTER_NAME
179179
# Wait for the kubeconfig to become available.
180180
rm -f $(WORKER_CLUSTER_KUBECONFIG)
@@ -201,7 +201,7 @@ ifeq ($(BUILD_IN_CONTAINER),true)
201201
else
202202
helm repo add syself https://charts.syself.com
203203
helm repo update syself
204-
KUBECONFIG=$(WORKER_CLUSTER_KUBECONFIG) helm upgrade --install ccm syself/ccm-hetzner --version 1.1.10 \
204+
KUBECONFIG=$(WORKER_CLUSTER_KUBECONFIG) helm upgrade --install ccm syself/ccm-hetzner --version 2.0.1 \
205205
--namespace kube-system \
206206
--set privateNetwork.enabled=$(PRIVATE_NETWORK)
207207
@echo 'run "kubectl --kubeconfig=$(WORKER_CLUSTER_KUBECONFIG) ..." to work with the new target cluster'
@@ -241,6 +241,7 @@ create-workload-cluster-hcloud-network: env-vars-for-wl-cluster $(KUSTOMIZE) $(E
241241
$(MAKE) install-cilium-in-wl-cluster
242242
$(MAKE) install-ccm-in-wl-cluster PRIVATE_NETWORK=true
243243

244+
# Use that, if you want to test hcloud control-planes, hcloud worker and bm worker.
244245
create-workload-cluster-hetzner-hcloud-control-plane: env-vars-for-wl-cluster $(KUSTOMIZE) $(ENVSUBST) ## Creates a workload-cluster.
245246
# Create workload Cluster.
246247
./hack/ensure-env-variables.sh HCLOUD_TOKEN HETZNER_ROBOT_USER HETZNER_ROBOT_PASSWORD HETZNER_SSH_PRIV_PATH HETZNER_SSH_PUB_PATH SSH_KEY_NAME
@@ -782,8 +783,7 @@ ifeq ($(BUILD_IN_CONTAINER),true)
782783
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
783784
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
784785
else
785-
cd pkg/services/baremetal/client; go run github.com/vektra/mockery/[email protected]
786-
cd pkg/services/hcloud/client; go run github.com/vektra/mockery/[email protected] --all
786+
go run github.com/vektra/mockery/[email protected]
787787
endif
788788

789789
.PHONY: generate

api/v1beta1/hcloudmachine_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/hetznercloud/hcloud-go/v2/hcloud"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
23-
capierrors "sigs.k8s.io/cluster-api/errors"
23+
capierrors "sigs.k8s.io/cluster-api/errors" //nolint:staticcheck // we will handle that, when we update to capi v1.11
2424
)
2525

2626
const (

api/v1beta1/hcloudmachine_webhook.go

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

1919
import (
20+
"context"
2021
"fmt"
2122

2223
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -29,13 +30,18 @@ import (
2930
"github.com/syself/cluster-api-provider-hetzner/pkg/utils"
3031
)
3132

33+
type hcloudMachineWebhook struct{}
34+
3235
// log is for logging in this package.
3336
var hcloudmachinelog = utils.GetDefaultLogger("info").WithName("hcloudmachine-resource")
3437

3538
// SetupWebhookWithManager initializes webhook manager for HCloudMachine.
3639
func (r *HCloudMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
40+
w := new(hcloudMachineWebhook)
3741
return ctrl.NewWebhookManagedBy(mgr).
3842
For(r).
43+
WithDefaulter(w).
44+
WithValidator(w).
3945
Complete()
4046
}
4147

@@ -48,46 +54,59 @@ func (r *HCloudMachineList) SetupWebhookWithManager(mgr ctrl.Manager) error {
4854

4955
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-hcloudmachine,mutating=true,failurePolicy=fail,sideEffects=None,groups=infrastructure.cluster.x-k8s.io,resources=hcloudmachines,verbs=create;update,versions=v1beta1,name=mutation.hcloudmachine.infrastructure.cluster.x-k8s.io,admissionReviewVersions={v1,v1beta1}
5056

51-
var _ webhook.Defaulter = &HCloudMachine{}
57+
var _ webhook.CustomDefaulter = &hcloudMachineWebhook{}
5258

53-
// Default implements webhook.Defaulter so a webhook will be registered for the type.
54-
func (r *HCloudMachine) Default() {
59+
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
60+
func (*hcloudMachineWebhook) Default(_ context.Context, obj runtime.Object) error {
61+
r, ok := obj.(*HCloudMachine)
62+
if !ok {
63+
return fmt.Errorf("expected an HCloudMachine object but got %T", r)
64+
}
5565
if r.Spec.PublicNetwork == nil {
5666
r.Spec.PublicNetwork = &PublicNetworkSpec{
5767
EnableIPv4: true,
5868
EnableIPv6: true,
5969
}
6070
}
71+
return nil
6172
}
6273

6374
//+kubebuilder:webhook:path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-hcloudmachine,mutating=false,failurePolicy=fail,sideEffects=None,groups=infrastructure.cluster.x-k8s.io,resources=hcloudmachines,verbs=create;update,versions=v1beta1,name=validation.hcloudmachine.infrastructure.cluster.x-k8s.io,admissionReviewVersions={v1,v1beta1}
6475

65-
var _ webhook.Validator = &HCloudMachine{}
76+
var _ webhook.CustomValidator = &hcloudMachineWebhook{}
77+
78+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
79+
func (*hcloudMachineWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
80+
r, ok := obj.(*HCloudMachine)
81+
if !ok {
82+
return nil, fmt.Errorf("expected an HCloudMachine object but got %T", r)
83+
}
6684

67-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
68-
func (r *HCloudMachine) ValidateCreate() (admission.Warnings, error) {
6985
hcloudmachinelog.V(1).Info("validate create", "name", r.Name)
7086
var allErrs field.ErrorList
7187

7288
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
7389
}
7490

75-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
76-
func (r *HCloudMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
91+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
92+
func (*hcloudMachineWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
93+
r, ok := newObj.(*HCloudMachine)
94+
if !ok {
95+
return nil, fmt.Errorf("expected an HCloudMachine object but got %T", r)
96+
}
7797
hcloudmachinelog.V(1).Info("validate update", "name", r.Name)
7898

79-
oldM, ok := old.(*HCloudMachine)
99+
oldM, ok := oldObj.(*HCloudMachine)
80100
if !ok {
81-
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an HCloudMachine but got a %T", old))
101+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an HCloudMachine but got a %T", oldObj))
82102
}
83103

84104
allErrs := validateHCloudMachineSpecUpdate(oldM.Spec, r.Spec)
85105

86106
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
87107
}
88108

89-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
90-
func (r *HCloudMachine) ValidateDelete() (admission.Warnings, error) {
91-
hcloudmachinelog.V(1).Info("validate delete", "name", r.Name)
109+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
110+
func (r *hcloudMachineWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
92111
return nil, nil
93112
}

api/v1beta1/hcloudmachinetemplate_webhook.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,39 @@ import (
3030
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3131
)
3232

33-
// SetupWebhookWithManager initializes webhook manager for HetznerMachineTemplate.
34-
func (r *HCloudMachineTemplateWebhook) SetupWebhookWithManager(mgr ctrl.Manager) error {
33+
// SetupWebhookWithManager initializes webhook manager for HCloudMachineTemplate.
34+
func (r *HCloudMachineTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
35+
w := new(hcloudMachineTemplateWebhook)
3536
return ctrl.NewWebhookManagedBy(mgr).
36-
For(&HCloudMachineTemplate{}).
37-
WithValidator(r).
37+
For(r).
38+
WithValidator(w).
39+
WithDefaulter(w).
3840
Complete()
3941
}
4042

4143
// HCloudMachineTemplateWebhook implements a custom validation webhook for HCloudMachineTemplate.
4244
// +kubebuilder:object:generate=false
43-
type HCloudMachineTemplateWebhook struct{}
45+
type hcloudMachineTemplateWebhook struct{}
46+
47+
// Default implements admission.CustomDefaulter.
48+
func (*hcloudMachineTemplateWebhook) Default(_ context.Context, _ runtime.Object) error {
49+
return nil
50+
}
4451

4552
// +kubebuilder:webhook:path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-hcloudmachinetemplate,mutating=false,sideEffects=None,failurePolicy=fail,sideEffects=None,groups=infrastructure.cluster.x-k8s.io,resources=hcloudmachinetemplates,verbs=create;update,versions=v1beta1,name=validation.hcloudmachinetemplate.infrastructure.x-k8s.io,admissionReviewVersions=v1;v1beta1
4653

47-
var _ webhook.CustomValidator = &HCloudMachineTemplateWebhook{}
54+
var (
55+
_ webhook.CustomValidator = &hcloudMachineTemplateWebhook{}
56+
_ webhook.CustomDefaulter = &hcloudMachineTemplateWebhook{}
57+
)
4858

49-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
50-
func (r *HCloudMachineTemplateWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
59+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
60+
func (*hcloudMachineTemplateWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
5161
return nil, nil
5262
}
5363

54-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
55-
func (r *HCloudMachineTemplateWebhook) ValidateUpdate(ctx context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
64+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
65+
func (*hcloudMachineTemplateWebhook) ValidateUpdate(ctx context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
5666
newHCloudMachineTemplate, ok := newRaw.(*HCloudMachineTemplate)
5767
if !ok {
5868
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a HCloudMachineTemplate but got a %T", newRaw))
@@ -74,7 +84,7 @@ func (r *HCloudMachineTemplateWebhook) ValidateUpdate(ctx context.Context, oldRa
7484
return nil, aggregateObjErrors(newHCloudMachineTemplate.GroupVersionKind().GroupKind(), newHCloudMachineTemplate.Name, allErrs)
7585
}
7686

77-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
78-
func (r *HCloudMachineTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
87+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
88+
func (*hcloudMachineTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
7989
return nil, nil
8090
}

api/v1beta1/hcloudremediation_webhook.go

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

1919
import (
20+
"context"
21+
2022
"k8s.io/apimachinery/pkg/runtime"
2123
ctrl "sigs.k8s.io/controller-runtime"
2224
"sigs.k8s.io/controller-runtime/pkg/webhook"
2325
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2426
)
2527

28+
type hcloudRemediationWebhook struct{}
29+
2630
// SetupWebhookWithManager initializes webhook manager for HCloudRemediation.
2731
func (r *HCloudRemediation) SetupWebhookWithManager(mgr ctrl.Manager) error {
32+
w := new(hcloudRemediationWebhook)
2833
return ctrl.NewWebhookManagedBy(mgr).
2934
For(r).
35+
WithValidator(w).
36+
WithDefaulter(w).
3037
Complete()
3138
}
3239

3340
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-hcloudremediation,mutating=true,failurePolicy=fail,sideEffects=None,groups=infrastructure.cluster.x-k8s.io,resources=hcloudremediations,verbs=create;update,versions=v1beta1,name=mutation.hcloudremediation.infrastructure.cluster.x-k8s.io,admissionReviewVersions={v1,v1beta1}
3441

35-
var _ webhook.Defaulter = &HCloudRemediation{}
42+
var _ webhook.CustomDefaulter = &hcloudRemediationWebhook{}
3643

37-
// Default implements webhook.Defaulter so a webhook will be registered for the type.
38-
func (r *HCloudRemediation) Default() {
44+
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
45+
func (*hcloudRemediationWebhook) Default(_ context.Context, _ runtime.Object) error {
46+
return nil
3947
}
4048

4149
//+kubebuilder:webhook:path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-hcloudremediation,mutating=false,failurePolicy=fail,sideEffects=None,groups=infrastructure.cluster.x-k8s.io,resources=hcloudremediations,verbs=create;update,versions=v1beta1,name=validation.hcloudremediation.infrastructure.cluster.x-k8s.io,admissionReviewVersions={v1,v1beta1}
4250

43-
var _ webhook.Validator = &HCloudRemediation{}
51+
var _ webhook.CustomValidator = &hcloudRemediationWebhook{}
4452

45-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
46-
func (r *HCloudRemediation) ValidateCreate() (admission.Warnings, error) {
53+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
54+
func (*hcloudRemediationWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
4755
return nil, nil
4856
}
4957

50-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
51-
func (r *HCloudRemediation) ValidateUpdate(runtime.Object) (admission.Warnings, error) {
58+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
59+
func (*hcloudRemediationWebhook) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) {
5260
return nil, nil
5361
}
5462

55-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
56-
func (r *HCloudRemediation) ValidateDelete() (admission.Warnings, error) {
63+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
64+
func (*hcloudRemediationWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
5765
return nil, nil
5866
}

api/v1beta1/hcloudremediationtemplate_webhook.go

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

1919
import (
20+
"context"
21+
2022
"k8s.io/apimachinery/pkg/runtime"
2123
ctrl "sigs.k8s.io/controller-runtime"
2224
"sigs.k8s.io/controller-runtime/pkg/webhook"
2325
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2426
)
2527

28+
type hcloudRemediationTemplateWebhook struct{}
29+
2630
// SetupWebhookWithManager initializes webhook manager for HCloudRemediationTemplate.
2731
func (r *HCloudRemediationTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
32+
w := new(hcloudRemediationTemplateWebhook)
2833
return ctrl.NewWebhookManagedBy(mgr).
2934
For(r).
35+
WithValidator(w).
36+
WithDefaulter(w).
3037
Complete()
3138
}
3239

3340
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-hcloudremediationtemplate,mutating=true,failurePolicy=fail,sideEffects=None,groups=infrastructure.cluster.x-k8s.io,resources=hcloudremediationtemplates,verbs=create;update,versions=v1beta1,name=mhcloudremediationtemplate.kb.io,admissionReviewVersions=v1
3441

35-
var _ webhook.Defaulter = &HCloudRemediationTemplate{}
42+
var _ webhook.CustomDefaulter = &hcloudRemediationTemplateWebhook{}
3643

37-
// Default implements webhook.Defaulter so a webhook will be registered for the type.
38-
func (r *HCloudRemediationTemplate) Default() {
44+
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
45+
func (*hcloudRemediationTemplateWebhook) Default(_ context.Context, _ runtime.Object) error {
46+
return nil
3947
}
4048

4149
//+kubebuilder:webhook:path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-hcloudremediationtemplate,mutating=false,failurePolicy=fail,sideEffects=None,groups=infrastructure.cluster.x-k8s.io,resources=hcloudremediationtemplates,verbs=create;update,versions=v1beta1,name=vhcloudremediationtemplate.kb.io,admissionReviewVersions=v1
4250

43-
var _ webhook.Validator = &HCloudRemediationTemplate{}
51+
var _ webhook.CustomValidator = &hcloudRemediationTemplateWebhook{}
4452

45-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
46-
func (r *HCloudRemediationTemplate) ValidateCreate() (admission.Warnings, error) {
53+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
54+
func (*hcloudRemediationTemplateWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
4755
return nil, nil
4856
}
4957

50-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
51-
func (r *HCloudRemediationTemplate) ValidateUpdate(runtime.Object) (admission.Warnings, error) {
58+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
59+
func (*hcloudRemediationTemplateWebhook) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) {
5260
return nil, nil
5361
}
5462

55-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
56-
func (r *HCloudRemediationTemplate) ValidateDelete() (admission.Warnings, error) {
63+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
64+
func (*hcloudRemediationTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
5765
return nil, nil
5866
}

0 commit comments

Comments
 (0)