Skip to content

Commit 3bc72c8

Browse files
committed
Fix review findings
1 parent 94abd78 commit 3bc72c8

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

cmd/clusterctl/internal/test/fake_objects.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/api/meta"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
28+
"k8s.io/apimachinery/pkg/runtime/schema"
2829
"k8s.io/apimachinery/pkg/types"
2930
"k8s.io/klog/v2"
3031
"k8s.io/utils/ptr"
@@ -1562,6 +1563,9 @@ func (f *FakeClusterClass) Objs() []client.Object {
15621563
for o := range objMap {
15631564
setUID(o)
15641565
}
1566+
// GVK should be only set for setUID to avoid the wrong assumption that GVK is set on a
1567+
// ClusterClass in other parts of the code.
1568+
clusterClass.SetGroupVersionKind(schema.GroupVersionKind{})
15651569

15661570
for o, setOwnerReference := range objMap {
15671571
if setOwnerReference {

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func (r *KubeadmControlPlaneReconciler) initControlPlaneScope(ctx context.Contex
308308
return nil, true, r.adoptMachines(ctx, kcp, adoptableMachines, cluster)
309309
}
310310

311-
ownedMachines := controlPlaneMachines.Filter(collections.OwnedMachines(kcp))
311+
ownedMachines := controlPlaneMachines.Filter(collections.OwnedMachines(kcp, controlplanev1.GroupVersion.WithKind("KubeadmControlPlane").GroupKind()))
312312
if kcp.DeletionTimestamp.IsZero() && len(ownedMachines) != len(controlPlaneMachines) {
313313
err := errors.New("not all control plane machines are owned by this KubeadmControlPlane, refusing to operate in mixed management mode")
314314
log.Error(err, "KCP cannot reconcile")

controlplane/kubeadm/internal/controllers/scale_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestKubeadmControlPlaneReconciler_initializeControlPlane(t *testing.T) {
8888
g.Expect(env.GetAPIReader().List(ctx, machineList, client.InNamespace(cluster.Namespace))).To(Succeed())
8989
g.Expect(machineList.Items).To(HaveLen(1))
9090

91-
res, err := collections.GetFilteredMachinesForCluster(ctx, env.GetAPIReader(), cluster, collections.OwnedMachines(kcp))
91+
res, err := collections.GetFilteredMachinesForCluster(ctx, env.GetAPIReader(), cluster, collections.OwnedMachines(kcp, controlplanev1.GroupVersion.WithKind("KubeadmControlPlane").GroupKind()))
9292
g.Expect(res).To(HaveLen(1))
9393
g.Expect(err).ToNot(HaveOccurred())
9494

docs/book/src/developer/providers/migrations/v1.11-to-v1.12.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ maintainers of providers and consumers of our Go API.
55

66
## Go version
77

8-
- The Go version used by Cluster API is Go 1.24.x
8+
- The minimal Go version required to build Cluster API is v1.24.x
9+
- The Go version used by Cluster API is v1.24.x
10+
11+
## Dependencies
12+
13+
- The Controller Runtime version used by Cluster API is v0.22.x
14+
- The version of the Kubernetes libraries used by Cluster API is v1.34.x
915

1016
## Changes by Kind
1117

@@ -17,6 +23,9 @@ maintainers of providers and consumers of our Go API.
1723

1824
### Other
1925

26+
* `util.IsOwnedByObject`, `util.IsControlledBy` and `collections.OwnedMachines` now also require `schema.GroupKind` as input parameter.
27+
`schema.GroupKind` is needed for cases where typed objects are passed in because controller-runtime does not guarantee that GVK is set on typed objects.
28+
2029
### Suggested changes for providers
2130

2231
* For providers that copied the core Cluster API v1beta1 `APIEndpoint` struct and used it in their InfraCluster Go type

util/collections/machine_filters.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import (
2222
"github.com/blang/semver/v4"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
"k8s.io/apimachinery/pkg/labels"
25+
"k8s.io/apimachinery/pkg/runtime/schema"
2526
"k8s.io/apimachinery/pkg/selection"
27+
"sigs.k8s.io/controller-runtime/pkg/client"
2628

2729
controlplanev1 "sigs.k8s.io/cluster-api/api/controlplane/kubeadm/v1beta2"
2830
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
@@ -99,13 +101,13 @@ func InFailureDomains(failureDomains ...string) Func {
99101
}
100102

101103
// OwnedMachines returns a filter to find all machines owned by specified owner.
102-
// Usage: GetFilteredMachinesForCluster(ctx, client, cluster, OwnedMachines(controlPlane)).
103-
func OwnedMachines(owner *controlplanev1.KubeadmControlPlane) func(machine *clusterv1.Machine) bool {
104+
// Usage: GetFilteredMachinesForCluster(ctx, client, cluster, OwnedMachines(controlPlane, controlPlaneGK)).
105+
func OwnedMachines(owner client.Object, ownerGK schema.GroupKind) func(machine *clusterv1.Machine) bool {
104106
return func(machine *clusterv1.Machine) bool {
105107
if machine == nil {
106108
return false
107109
}
108-
return util.IsOwnedByObject(machine, owner, controlplanev1.GroupVersion.WithKind("KubeadmControlPlane").GroupKind())
110+
return util.IsOwnedByObject(machine, owner, ownerGK)
109111
}
110112
}
111113

0 commit comments

Comments
 (0)