Skip to content

Commit a3a64be

Browse files
committed
Adjust to CR not setting TypeMeta anymore
1 parent 3fa9487 commit a3a64be

File tree

17 files changed

+38
-89
lines changed

17 files changed

+38
-89
lines changed

cmd/clusterctl/client/cluster/upgrader_info_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,6 @@ func toSemanticVersions(versions []string) []version.Version {
491491

492492
func fakeProvider(name string, providerType clusterctlv1.ProviderType, version, targetNamespace string) clusterctlv1.Provider {
493493
return clusterctlv1.Provider{
494-
TypeMeta: metav1.TypeMeta{
495-
APIVersion: clusterctlv1.GroupVersion.String(),
496-
Kind: "Provider",
497-
},
498494
ObjectMeta: metav1.ObjectMeta{
499495
ResourceVersion: "999",
500496
Namespace: targetNamespace,

cmd/clusterctl/client/tree/discovery.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
corev1 "k8s.io/api/core/v1"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
25+
"k8s.io/apimachinery/pkg/runtime/schema"
2526
"sigs.k8s.io/controller-runtime/pkg/client"
2627

2728
addonsv1 "sigs.k8s.io/cluster-api/api/addons/v1beta2"
@@ -286,7 +287,7 @@ func addMachineDeploymentToObjectTree(ctx context.Context, c client.Client, clus
286287
tree.Add(templateParent, machineTemplateRefObject, ObjectMetaName("MachineInfrastructureTemplate"))
287288
}
288289

289-
machineSets := selectMachinesSetsControlledBy(machineSetList, md)
290+
machineSets := selectMachinesSetsControlledBy(machineSetList, md, clusterv1.GroupVersion.WithKind("MachineDeployment").GroupKind())
290291
for i := range machineSets {
291292
ms := machineSets[i]
292293

@@ -296,7 +297,7 @@ func addMachineDeploymentToObjectTree(ctx context.Context, c client.Client, clus
296297
parent = ms
297298
}
298299

299-
machines := selectMachinesControlledBy(machinesList, ms)
300+
machines := selectMachinesControlledBy(machinesList, ms, clusterv1.GroupVersion.WithKind("MachineSet").GroupKind())
300301
for _, w := range machines {
301302
addMachineFunc(parent, w)
302303
}
@@ -321,7 +322,7 @@ func addMachinePoolsToObjectTree(ctx context.Context, c client.Client, workers *
321322
}
322323
}
323324

324-
machines := selectMachinesControlledBy(machinesList, mp)
325+
machines := selectMachinesControlledBy(machinesList, mp, clusterv1.GroupVersion.WithKind("MachinePool").GroupKind())
325326
for _, m := range machines {
326327
addMachineFunc(mp, m)
327328
}
@@ -417,22 +418,22 @@ func selectControlPlaneMachines(machineList *clusterv1.MachineList) []*clusterv1
417418
return machines
418419
}
419420

420-
func selectMachinesSetsControlledBy(machineSetList *clusterv1.MachineSetList, controller client.Object) []*clusterv1.MachineSet {
421+
func selectMachinesSetsControlledBy(machineSetList *clusterv1.MachineSetList, controller client.Object, controllerGK schema.GroupKind) []*clusterv1.MachineSet {
421422
machineSets := []*clusterv1.MachineSet{}
422423
for i := range machineSetList.Items {
423424
m := &machineSetList.Items[i]
424-
if util.IsControlledBy(m, controller) {
425+
if util.IsControlledBy(m, controller, controllerGK) {
425426
machineSets = append(machineSets, m)
426427
}
427428
}
428429
return machineSets
429430
}
430431

431-
func selectMachinesControlledBy(machineList *clusterv1.MachineList, controller client.Object) []*clusterv1.Machine {
432+
func selectMachinesControlledBy(machineList *clusterv1.MachineList, controller client.Object, controllerGK schema.GroupKind) []*clusterv1.Machine {
432433
machines := []*clusterv1.Machine{}
433434
for i := range machineList.Items {
434435
m := &machineList.Items[i]
435-
if util.IsControlledBy(m, controller) {
436+
if util.IsControlledBy(m, controller, controllerGK) {
436437
machines = append(machines, m)
437438
}
438439
}

cmd/clusterctl/client/upgrade_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,6 @@ func fakeClientForUpgrade() *fakeClient {
365365

366366
func fakeProvider(name string, providerType clusterctlv1.ProviderType, version, targetNamespace string) clusterctlv1.Provider {
367367
return clusterctlv1.Provider{
368-
TypeMeta: metav1.TypeMeta{
369-
APIVersion: clusterctlv1.GroupVersion.String(),
370-
Kind: "Provider",
371-
},
372368
ObjectMeta: metav1.ObjectMeta{
373369
Namespace: targetNamespace,
374370
Name: clusterctlv1.ManifestLabel(name, providerType),

cmd/clusterctl/internal/test/fake_objects.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import (
2222

2323
corev1 "k8s.io/api/core/v1"
2424
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
25-
"k8s.io/apimachinery/pkg/api/meta"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2827
"k8s.io/apimachinery/pkg/types"
2928
"k8s.io/klog/v2"
3029
"k8s.io/utils/ptr"
3130
"sigs.k8s.io/controller-runtime/pkg/client"
31+
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
3232
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3333

3434
addonsv1 "sigs.k8s.io/cluster-api/api/addons/v1beta2"
@@ -1389,12 +1389,12 @@ func SelectClusterObj(objs []client.Object, namespace, name string) *clusterv1.C
13891389
// setUID assigns a UID to the object, so test objects are uniquely identified.
13901390
// NB. In order to make debugging easier we are using a human readable, deterministic string (instead of a random UID).
13911391
func setUID(obj client.Object) {
1392-
accessor, err := meta.Accessor(obj)
1392+
gvk, err := apiutil.GVKForObject(obj, FakeScheme)
13931393
if err != nil {
1394-
panic(fmt.Sprintf("failed to get accessor for test object: %v", err))
1394+
panic(fmt.Sprintf("failed to get GVK for test object: %v", err))
13951395
}
1396-
uid := fmt.Sprintf("%s, %s", obj.GetObjectKind().GroupVersionKind().String(), klog.KObj(accessor))
1397-
accessor.SetUID(types.UID(uid))
1396+
uid := fmt.Sprintf("%s, %s", gvk.String(), klog.KObj(obj))
1397+
obj.SetUID(types.UID(uid))
13981398
}
13991399

14001400
// FakeClusterCustomResourceDefinition returns a fake CRD object for the given group/versions/kind.

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ func (r *KubeadmControlPlaneReconciler) adoptOwnedSecrets(ctx context.Context, k
13871387

13881388
for i := range secrets.Items {
13891389
s := secrets.Items[i]
1390-
if !util.IsOwnedByObject(&s, currentOwner) {
1390+
if !util.IsOwnedByObject(&s, currentOwner, bootstrapv1.GroupVersion.WithKind("KubeadmConfig").GroupKind()) {
13911391
continue
13921392
}
13931393
// avoid taking ownership of the bootstrap data secret

controlplane/kubeadm/internal/controllers/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileKubeconfig(ctx context.Context,
9494
}
9595

9696
// only do rotation on owned secrets
97-
if !util.IsControlledBy(configSecret, controlPlane.KCP) {
97+
if !util.IsControlledBy(configSecret, controlPlane.KCP, controlplanev1.GroupVersion.WithKind("KubeadmControlPlane").GroupKind()) {
9898
return ctrl.Result{}, nil
9999
}
100100

controlplane/kubeadm/internal/workload_cluster_coredns_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,10 +1139,6 @@ func (m *fakeMigrator) Migrate(_, _, _ string, _ bool) (string, error) {
11391139

11401140
func newCoreDNSInfoDeploymentWithimage(image string) *appsv1.Deployment {
11411141
return &appsv1.Deployment{
1142-
TypeMeta: metav1.TypeMeta{
1143-
Kind: "Deployment",
1144-
APIVersion: "apps/v1",
1145-
},
11461142
ObjectMeta: metav1.ObjectMeta{
11471143
Name: coreDNSKey,
11481144
Namespace: metav1.NamespaceSystem,

internal/controllers/cluster/cluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ func (c *clusterDescendants) filterOwnedDescendants(cluster *clusterv1.Cluster)
631631
return nil //nolint:nilerr // We don't want to exit the EachListItem loop, just continue
632632
}
633633

634-
if util.IsOwnedByObject(acc, cluster) {
634+
if util.IsOwnedByObject(acc, cluster, clusterv1.GroupVersion.WithKind("Cluster").GroupKind()) {
635635
ownedDescendants = append(ownedDescendants, obj)
636636
}
637637

internal/controllers/cluster/cluster_controller_status.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func setWorkersReplicas(_ context.Context, cluster *clusterv1.Cluster, machinePo
246246
}
247247

248248
for _, ms := range machineSets.Items {
249-
if !util.IsOwnedByObject(&ms, cluster) {
249+
if !util.IsOwnedByObject(&ms, cluster, clusterv1.GroupVersion.WithKind("Cluster").GroupKind()) {
250250
continue
251251
}
252252
if ms.Spec.Replicas != nil {
@@ -267,7 +267,7 @@ func setWorkersReplicas(_ context.Context, cluster *clusterv1.Cluster, machinePo
267267
}
268268

269269
for _, m := range workerMachines.UnsortedList() {
270-
if !util.IsOwnedByObject(m, cluster) {
270+
if !util.IsOwnedByObject(m, cluster, clusterv1.GroupVersion.WithKind("Cluster").GroupKind()) {
271271
continue
272272
}
273273
currentReplicas = ptr.To(ptr.Deref(currentReplicas, 0) + 1)
@@ -973,7 +973,7 @@ func setScalingUpCondition(ctx context.Context, cluster *clusterv1.Cluster, cont
973973
ws = append(ws, aggregationWrapper{md: &md})
974974
}
975975
for _, ms := range machineSets.Items {
976-
if !util.IsOwnedByObject(&ms, cluster) {
976+
if !util.IsOwnedByObject(&ms, cluster, clusterv1.GroupVersion.WithKind("Cluster").GroupKind()) {
977977
continue
978978
}
979979
ws = append(ws, aggregationWrapper{ms: &ms})
@@ -1050,7 +1050,7 @@ func setScalingDownCondition(ctx context.Context, cluster *clusterv1.Cluster, co
10501050
ws = append(ws, aggregationWrapper{md: &md})
10511051
}
10521052
for _, ms := range machineSets.Items {
1053-
if !util.IsOwnedByObject(&ms, cluster) {
1053+
if !util.IsOwnedByObject(&ms, cluster, clusterv1.GroupVersion.WithKind("Cluster").GroupKind()) {
10541054
continue
10551055
}
10561056
ws = append(ws, aggregationWrapper{ms: &ms})

internal/controllers/clusterclass/clusterclass_controller_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,15 +1101,15 @@ func TestReconciler_reconcileVariables(t *testing.T) {
11011101
wantErrMessage: "failed to discover variables for ClusterClass class1: [" +
11021102
"patch1.variables[cpu].schema.openAPIV3Schema.properties[nestedField].default: Invalid value: \"integer\": failed rule: self >= 1, " +
11031103
"patch1.variables[anotherCPU].schema.openAPIV3Schema.x-kubernetes-validations[0].messageExpression: Invalid value: " +
1104-
"apiextensions.ValidationRule{Rule:\"self >= 1\", Message:\"\", MessageExpression:\"'Expected integer greater or equal to 1, got ' + this does not compile\", " +
1105-
"Reason:(*apiextensions.FieldValueErrorReason)(nil), FieldPath:\"\", OptionalOldSelf:(*bool)(nil)}: " +
1104+
"{\"Rule\":\"self \\u003e= 1\",\"Message\":\"\",\"MessageExpression\":\"'Expected integer greater or equal to 1, got ' + this does not compile\"," +
1105+
"\"Reason\":null,\"FieldPath\":\"\",\"OptionalOldSelf\":null}: " +
11061106
"messageExpression compilation failed: ERROR: <input>:1:55: Syntax error: mismatched input 'does' expecting <EOF>\n " +
11071107
"| 'Expected integer greater or equal to 1, got ' + this does not compile\n " +
11081108
"| ......................................................^]",
11091109
wantVariableDiscoveryErrorMessage: "VariableDiscovery failed: [patch1.variables[cpu].schema.openAPIV3Schema.properties[nestedField].default: Invalid value: \"integer\": failed rule: self >= 1, " +
11101110
"patch1.variables[anotherCPU].schema.openAPIV3Schema.x-kubernetes-validations[0].messageExpression: Invalid value: " +
1111-
"apiextensions.ValidationRule{Rule:\"self >= 1\", Message:\"\", MessageExpression:\"'Expected integer greater or equal to 1, got ' + this does not compile\", " +
1112-
"Reason:(*apiextensions.FieldValueErrorReason)(nil), FieldPath:\"\", OptionalOldSelf:(*bool)(nil)}: " +
1111+
"{\"Rule\":\"self \\u003e= 1\",\"Message\":\"\",\"MessageExpression\":\"'Expected integer greater or equal to 1, got ' + this does not compile\"," +
1112+
"\"Reason\":null,\"FieldPath\":\"\",\"OptionalOldSelf\":null}: " +
11131113
"messageExpression compilation failed: ERROR: <input>:1:55: Syntax error: mismatched input 'does' expecting <EOF>\n " +
11141114
"| 'Expected integer greater or equal to 1, got ' + this does not compile\n " +
11151115
"| ......................................................^]",
@@ -1150,15 +1150,15 @@ func TestReconciler_reconcileVariables(t *testing.T) {
11501150
},
11511151
wantErrMessage: "failed to discover variables for ClusterClass class1: " +
11521152
"patch1.variables[someIP].schema.openAPIV3Schema.x-kubernetes-validations[0].rule: Invalid value: " +
1153-
"apiextensions.ValidationRule{Rule:\"ip(self).family() == 6\", Message:\"\", MessageExpression:\"\", Reason:(*apiextensions.FieldValueErrorReason)(nil), FieldPath:\"\", OptionalOldSelf:(*bool)(nil)}: compilation failed: " +
1153+
"{\"Rule\":\"ip(self).family() == 6\",\"Message\":\"\",\"MessageExpression\":\"\",\"Reason\":null,\"FieldPath\":\"\",\"OptionalOldSelf\":null}: compilation failed: " +
11541154
"ERROR: <input>:1:3: undeclared reference to 'ip' (in container '')\n" +
11551155
" | ip(self).family() == 6\n" +
11561156
" | ..^\n" +
11571157
"ERROR: <input>:1:16: undeclared reference to 'family' (in container '')\n" +
11581158
" | ip(self).family() == 6\n" +
11591159
" | ...............^",
11601160
wantVariableDiscoveryErrorMessage: "VariableDiscovery failed: patch1.variables[someIP].schema.openAPIV3Schema.x-kubernetes-validations[0].rule: Invalid value: " +
1161-
"apiextensions.ValidationRule{Rule:\"ip(self).family() == 6\", Message:\"\", MessageExpression:\"\", Reason:(*apiextensions.FieldValueErrorReason)(nil), FieldPath:\"\", OptionalOldSelf:(*bool)(nil)}: compilation failed: " +
1161+
"{\"Rule\":\"ip(self).family() == 6\",\"Message\":\"\",\"MessageExpression\":\"\",\"Reason\":null,\"FieldPath\":\"\",\"OptionalOldSelf\":null}: compilation failed: " +
11621162
"ERROR: <input>:1:3: undeclared reference to 'ip' (in container '')\n" +
11631163
" | ip(self).family() == 6\n" +
11641164
" | ..^\n" +

0 commit comments

Comments
 (0)