Skip to content

Commit a02a64b

Browse files
committed
PCP-5293 Upgrade cluster-api version and code changes
1 parent b9ab904 commit a02a64b

File tree

5 files changed

+203
-345
lines changed

5 files changed

+203
-345
lines changed

controllers/locking/control_plane_init_mutex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (s *semaphore) setMetadata(cluster *clusterv1.Cluster) {
179179
Namespace: cluster.Namespace,
180180
Name: configMapName(cluster.Name),
181181
Labels: map[string]string{
182-
clusterv1.ClusterLabelName: cluster.Name,
182+
clusterv1.ClusterNameLabel: cluster.Name,
183183
},
184184
OwnerReferences: []metav1.OwnerReference{
185185
{

controllers/microk8sconfig_controller.go

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ import (
5858
"sigs.k8s.io/controller-runtime/pkg/client"
5959
"sigs.k8s.io/controller-runtime/pkg/handler"
6060
"sigs.k8s.io/controller-runtime/pkg/log"
61-
"sigs.k8s.io/controller-runtime/pkg/source"
61+
"sigs.k8s.io/controller-runtime/pkg/reconcile"
6262

6363
tokenpkg "github.com/canonical/cluster-api-bootstrap-provider-microk8s/pkg/token"
64+
"sigs.k8s.io/controller-runtime/pkg/builder"
6465
)
6566

6667
type InitLocker interface {
@@ -611,7 +612,7 @@ func (r *MicroK8sConfigReconciler) storeBootstrapData(ctx context.Context, scope
611612
Name: scope.Config.Name,
612613
Namespace: scope.Config.Namespace,
613614
Labels: map[string]string{
614-
clusterv1.ClusterLabelName: scope.Cluster.Name,
615+
clusterv1.ClusterNameLabel: scope.Cluster.Name,
615616
},
616617
OwnerReferences: []metav1.OwnerReference{
617618
{
@@ -792,38 +793,37 @@ func (r *MicroK8sConfigReconciler) SetupWithManager(ctx context.Context, mgr ctr
792793

793794
b := ctrl.NewControllerManagedBy(mgr).
794795
For(&bootstrapclusterxk8siov1beta1.MicroK8sConfig{}).
795-
Watches(&source.Kind{Type: &clusterv1.Machine{}},
796-
handler.EnqueueRequestsFromMapFunc(r.MachineToBootstrapMapFunc)).
797-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx),
798-
r.WatchFilterValue))
796+
Watches(
797+
&clusterv1.Machine{},
798+
handler.EnqueueRequestsFromMapFunc(r.MachineToBootstrapMapFunc),
799+
).
800+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), mgr.GetLogger(), r.WatchFilterValue))
799801

800802
if feature.Gates.Enabled(feature.MachinePool) {
801803
b = b.Watches(
802-
&source.Kind{Type: &expv1.MachinePool{}},
804+
&expv1.MachinePool{},
803805
handler.EnqueueRequestsFromMapFunc(r.MachineToBootstrapMapFunc),
804-
).WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue))
806+
).WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), mgr.GetLogger(), r.WatchFilterValue))
805807
}
806808

807-
c, err := b.Build(r)
808-
if err != nil {
809-
return errors.Wrap(err, "failed setting up with a controller manager")
810-
}
811-
err = c.Watch(
812-
&source.Kind{Type: &clusterv1.Cluster{}},
809+
b = b.Watches(
810+
&clusterv1.Cluster{},
813811
handler.EnqueueRequestsFromMapFunc(r.ClusterToMicroK8sConfigs),
814-
predicates.All(ctrl.LoggerFrom(ctx),
815-
predicates.ClusterUnpausedAndInfrastructureReady(ctrl.LoggerFrom(ctx)),
816-
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
812+
builder.WithPredicates(
813+
predicates.ClusterUnpausedAndInfrastructureReady(mgr.GetScheme(), mgr.GetLogger()),
814+
predicates.ResourceHasFilterLabel(mgr.GetScheme(), mgr.GetLogger(), r.WatchFilterValue),
817815
),
818816
)
817+
818+
_, err := b.Build(r)
819819
if err != nil {
820-
return errors.Wrap(err, "failed adding Watch for Clusters to controller manager")
820+
return errors.Wrap(err, "failed setting up with a controller manager")
821821
}
822822

823823
return nil
824824
}
825825

826-
func (r *MicroK8sConfigReconciler) ClusterToMicroK8sConfigs(o client.Object) []ctrl.Request {
826+
func (r *MicroK8sConfigReconciler) ClusterToMicroK8sConfigs(ctx context.Context, o client.Object) []ctrl.Request {
827827
result := []ctrl.Request{}
828828

829829
c, ok := o.(*clusterv1.Cluster)
@@ -834,45 +834,48 @@ func (r *MicroK8sConfigReconciler) ClusterToMicroK8sConfigs(o client.Object) []c
834834
selectors := []client.ListOption{
835835
client.InNamespace(c.Namespace),
836836
client.MatchingLabels{
837-
clusterv1.ClusterLabelName: c.Name,
837+
clusterv1.ClusterNameLabel: c.Name,
838838
},
839839
}
840840

841841
machineList := &clusterv1.MachineList{}
842-
if err := r.Client.List(context.TODO(), machineList, selectors...); err != nil {
842+
if err := r.Client.List(ctx, machineList, selectors...); err != nil {
843843
return nil
844844
}
845845

846846
for _, m := range machineList.Items {
847847
if m.Spec.Bootstrap.ConfigRef != nil &&
848848
m.Spec.Bootstrap.ConfigRef.GroupVersionKind().GroupKind() == v1beta1.GroupVersion.WithKind("MicroK8sConfig").GroupKind() {
849849
name := client.ObjectKey{Namespace: m.Namespace, Name: m.Spec.Bootstrap.ConfigRef.Name}
850-
result = append(result, ctrl.Request{NamespacedName: name})
850+
result = append(result, reconcile.Request{NamespacedName: name})
851851
}
852852
}
853853

854854
if feature.Gates.Enabled(feature.MachinePool) {
855855
machinePoolList := &expv1.MachinePoolList{}
856-
if err := r.Client.List(context.TODO(), machinePoolList, selectors...); err != nil {
856+
if err := r.Client.List(ctx, machinePoolList, selectors...); err != nil {
857857
return nil
858858
}
859859

860860
for _, mp := range machinePoolList.Items {
861861
if mp.Spec.Template.Spec.Bootstrap.ConfigRef != nil &&
862862
mp.Spec.Template.Spec.Bootstrap.ConfigRef.GroupVersionKind().GroupKind() == v1beta1.GroupVersion.WithKind("MicroK8sConfig").GroupKind() {
863863
name := client.ObjectKey{Namespace: mp.Namespace, Name: mp.Spec.Template.Spec.Bootstrap.ConfigRef.Name}
864-
result = append(result, ctrl.Request{NamespacedName: name})
864+
result = append(result, reconcile.Request{NamespacedName: name})
865865
}
866866
}
867867
}
868868

869869
return result
870870
}
871871

872-
func (r *MicroK8sConfigReconciler) MachineToBootstrapMapFunc(o client.Object) []ctrl.Request {
872+
func (r *MicroK8sConfigReconciler) MachineToBootstrapMapFunc(ctx context.Context, o client.Object) []ctrl.Request {
873873
m, ok := o.(*clusterv1.Machine)
874874
if !ok {
875-
panic(fmt.Sprintf("Expected a Machine but got a %T", o))
875+
_, ok = o.(*expv1.MachinePool)
876+
if !ok {
877+
panic(fmt.Sprintf("Expected a Machine or MachinePool but got a %T", o))
878+
}
876879
}
877880

878881
result := []ctrl.Request{}
@@ -886,8 +889,8 @@ func (r *MicroK8sConfigReconciler) MachineToBootstrapMapFunc(o client.Object) []
886889
func (r *MicroK8sConfigReconciler) getControlPlaneMachinesForCluster(ctx context.Context,
887890
cluster client.ObjectKey) ([]clusterv1.Machine, error) {
888891
selector := map[string]string{
889-
clusterv1.ClusterLabelName: cluster.Name,
890-
clusterv1.MachineControlPlaneLabelName: "",
892+
clusterv1.ClusterNameLabel: cluster.Name,
893+
clusterv1.MachineControlPlaneNameLabel: "",
891894
}
892895

893896
machineList := clusterv1.MachineList{}

go.mod

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/canonical/cluster-api-bootstrap-provider-microk8s
22

3-
go 1.23.0
3+
go 1.24.0
44

55
toolchain go1.24.3
66

@@ -9,75 +9,69 @@ require (
99
github.com/onsi/gomega v1.36.1
1010
github.com/pkg/errors v0.9.1
1111
gopkg.in/yaml.v2 v2.4.0
12-
k8s.io/api v0.32.1
13-
k8s.io/apimachinery v0.32.1
14-
k8s.io/client-go v0.32.1
12+
k8s.io/api v0.33.0
13+
k8s.io/apimachinery v0.33.0
14+
k8s.io/client-go v0.33.0
1515
k8s.io/klog/v2 v2.130.1
1616
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
17-
sigs.k8s.io/cluster-api v1.2.4
17+
sigs.k8s.io/cluster-api v1.9.4
1818
sigs.k8s.io/controller-runtime v0.20.4
1919
)
2020

2121
require (
2222
github.com/beorn7/perks v1.0.1 // indirect
23-
github.com/blang/semver v3.5.1+incompatible // indirect
2423
github.com/blang/semver/v4 v4.0.0 // indirect
2524
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2625
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
27-
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
28-
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
26+
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
2927
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
3028
github.com/fsnotify/fsnotify v1.7.0 // indirect
3129
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
3230
github.com/go-logr/zapr v1.3.0 // indirect
3331
github.com/go-openapi/jsonpointer v0.21.0 // indirect
3432
github.com/go-openapi/jsonreference v0.20.2 // indirect
3533
github.com/go-openapi/swag v0.23.0 // indirect
36-
github.com/gobuffalo/flect v0.3.0 // indirect
34+
github.com/gobuffalo/flect v1.0.3 // indirect
3735
github.com/gogo/protobuf v1.3.2 // indirect
38-
github.com/golang/protobuf v1.5.4 // indirect
3936
github.com/google/btree v1.1.3 // indirect
40-
github.com/google/gnostic-models v0.6.8 // indirect
41-
github.com/google/go-cmp v0.6.0 // indirect
42-
github.com/google/gofuzz v1.2.0 // indirect
37+
github.com/google/gnostic-models v0.6.9 // indirect
38+
github.com/google/go-cmp v0.7.0 // indirect
4339
github.com/google/uuid v1.6.0 // indirect
44-
github.com/imdario/mergo v0.3.13 // indirect
45-
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4640
github.com/josharian/intern v1.0.0 // indirect
4741
github.com/json-iterator/go v1.1.12 // indirect
4842
github.com/mailru/easyjson v0.7.7 // indirect
4943
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5044
github.com/modern-go/reflect2 v1.0.2 // indirect
5145
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
52-
github.com/prometheus/client_golang v1.19.1 // indirect
46+
github.com/prometheus/client_golang v1.22.0 // indirect
5347
github.com/prometheus/client_model v0.6.1 // indirect
54-
github.com/prometheus/common v0.55.0 // indirect
48+
github.com/prometheus/common v0.62.0 // indirect
5549
github.com/prometheus/procfs v0.15.1 // indirect
56-
github.com/spf13/cobra v1.8.1 // indirect
5750
github.com/spf13/pflag v1.0.5 // indirect
5851
github.com/x448/float16 v0.8.4 // indirect
59-
go.opentelemetry.io/otel v1.28.0 // indirect
60-
go.opentelemetry.io/otel/trace v1.28.0 // indirect
52+
go.opentelemetry.io/otel v1.33.0 // indirect
53+
go.opentelemetry.io/otel/trace v1.33.0 // indirect
6154
go.uber.org/multierr v1.11.0 // indirect
6255
go.uber.org/zap v1.27.0 // indirect
63-
golang.org/x/net v0.33.0 // indirect
64-
golang.org/x/oauth2 v0.23.0 // indirect
65-
golang.org/x/sync v0.10.0 // indirect
66-
golang.org/x/sys v0.28.0 // indirect
67-
golang.org/x/term v0.27.0 // indirect
68-
golang.org/x/text v0.21.0 // indirect
69-
golang.org/x/time v0.7.0 // indirect
56+
golang.org/x/net v0.38.0 // indirect
57+
golang.org/x/oauth2 v0.27.0 // indirect
58+
golang.org/x/sync v0.12.0 // indirect
59+
golang.org/x/sys v0.31.0 // indirect
60+
golang.org/x/term v0.30.0 // indirect
61+
golang.org/x/text v0.23.0 // indirect
62+
golang.org/x/time v0.9.0 // indirect
7063
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
71-
google.golang.org/protobuf v1.35.1 // indirect
64+
google.golang.org/protobuf v1.36.5 // indirect
7265
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
7366
gopkg.in/inf.v0 v0.9.1 // indirect
7467
gopkg.in/yaml.v3 v3.0.1 // indirect
75-
k8s.io/apiextensions-apiserver v0.32.1 // indirect
76-
k8s.io/apiserver v0.32.1 // indirect
77-
k8s.io/cluster-bootstrap v0.24.0 // indirect
78-
k8s.io/component-base v0.32.1 // indirect
79-
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
68+
k8s.io/apiextensions-apiserver v0.33.0 // indirect
69+
k8s.io/apiserver v0.33.0 // indirect
70+
k8s.io/cluster-bootstrap v0.31.3 // indirect
71+
k8s.io/component-base v0.33.0 // indirect
72+
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
8073
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
81-
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
74+
sigs.k8s.io/randfill v1.0.0 // indirect
75+
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
8276
sigs.k8s.io/yaml v1.4.0 // indirect
8377
)

0 commit comments

Comments
 (0)