Skip to content

Commit d228c29

Browse files
committed
Adapt consumerRef/ownerRef checks to controller-runtime changes
Compare ownerRef/consumerRef groupversions, not TypeMeta, since controller runtime changes here kubernetes-sigs/controller-runtime#3229 Signed-off-by: Sunnatillo <[email protected]>
1 parent ef5aaa5 commit d228c29

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

baremetal/metal3machine_manager.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -917,19 +917,26 @@ func hostLabelSelectorForMachine(machine *infrav1.Metal3Machine, log logr.Logger
917917
// consumerRefMatches returns a boolean based on whether the consumer
918918
// reference and bare metal machine metadata match.
919919
func consumerRefMatches(consumer *corev1.ObjectReference, m3machine *infrav1.Metal3Machine) bool {
920+
if m3machine == nil || consumer == nil {
921+
return false
922+
}
920923
if consumer.Name != m3machine.Name {
921924
return false
922925
}
923926
if consumer.Namespace != m3machine.Namespace {
924927
return false
925928
}
926-
if consumer.Kind != m3machine.Kind {
929+
if consumer.Kind != "Metal3Machine" {
927930
return false
928931
}
929-
if consumer.GroupVersionKind().Group != m3machine.GroupVersionKind().Group {
932+
933+
// Parse and compare Group from consumer APIVersion
934+
gv, err := schema.ParseGroupVersion(consumer.APIVersion)
935+
if err != nil {
936+
// If we cannot parse it, it certainly does not match.
930937
return false
931938
}
932-
return true
939+
return gv.Group == infrav1.GroupVersion.Group
933940
}
934941

935942
// nodeReuseLabelMatches returns true if nodeReuseLabelName matches ControlPlane or MachineDeployment name on the host.
@@ -1855,10 +1862,14 @@ func (m *MachineManager) getMachineSet(ctx context.Context) (*clusterv1.MachineS
18551862
for index := range machineSets.Items {
18561863
machineset := &machineSets.Items[index]
18571864
for _, mOwnerRef := range m.Machine.ObjectMeta.OwnerReferences {
1858-
if mOwnerRef.Kind != machineset.Kind {
1865+
if mOwnerRef.Kind != "MachineSet" {
18591866
continue
18601867
}
1861-
if mOwnerRef.APIVersion != machineset.APIVersion {
1868+
gv, err := schema.ParseGroupVersion(mOwnerRef.APIVersion)
1869+
if err != nil {
1870+
return nil, errors.New("Failed to parse ownerRef Group of Machine")
1871+
}
1872+
if gv.Group != clusterv1.GroupVersion.Group {
18621873
machineSetError += fmt.Sprintf("MachineSet %s has different API version %s than Machine %s with API version %s",
18631874
machineset.Name, machineset.APIVersion, m.Machine.Name, mOwnerRef.APIVersion)
18641875
continue

baremetal/metal3machine_manager_test.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func consumerRef() *corev1.ObjectReference {
106106
return &corev1.ObjectReference{
107107
Name: metal3machineName,
108108
Namespace: namespaceName,
109-
Kind: "M3Machine",
109+
Kind: "Metal3Machine",
110110
APIVersion: infrav1.GroupVersion.String(),
111111
}
112112
}
@@ -115,7 +115,7 @@ func consumerRefSome() *corev1.ObjectReference {
115115
return &corev1.ObjectReference{
116116
Name: "someoneelsesmachine",
117117
Namespace: namespaceName,
118-
Kind: "M3Machine",
118+
Kind: "Metal3Machine",
119119
APIVersion: clusterv1beta1.GroupVersion.String(),
120120
}
121121
}
@@ -515,7 +515,7 @@ var _ = Describe("Metal3Machine manager", func() {
515515
ConsumerRef: &corev1.ObjectReference{
516516
Name: "someothermachine",
517517
Namespace: namespaceName,
518-
Kind: "M3Machine",
518+
Kind: "Metal3Machine",
519519
APIVersion: infrav1.GroupVersion.String(),
520520
},
521521
},
@@ -532,7 +532,7 @@ var _ = Describe("Metal3Machine manager", func() {
532532
ConsumerRef: &corev1.ObjectReference{
533533
Name: metal3machineName,
534534
Namespace: namespaceName,
535-
Kind: "M3Machine",
535+
Kind: "Metal3Machine",
536536
APIVersion: infrav1.GroupVersion.String(),
537537
},
538538
},
@@ -1010,7 +1010,7 @@ var _ = Describe("Metal3Machine manager", func() {
10101010
ConsumerRef: &corev1.ObjectReference{
10111011
Name: metal3machineName,
10121012
Namespace: namespaceName,
1013-
Kind: "M3Machine",
1013+
Kind: "Metal3Machine",
10141014
APIVersion: infrav1.GroupVersion.String(),
10151015
},
10161016
},
@@ -1027,7 +1027,7 @@ var _ = Describe("Metal3Machine manager", func() {
10271027
ConsumerRef: &corev1.ObjectReference{
10281028
Name: metal3machineName,
10291029
Namespace: namespaceName,
1030-
Kind: "M3Machine",
1030+
Kind: "Metal3Machine",
10311031
APIVersion: infrav1.GroupVersion.String(),
10321032
},
10331033
},
@@ -1044,7 +1044,7 @@ var _ = Describe("Metal3Machine manager", func() {
10441044
ConsumerRef: &corev1.ObjectReference{
10451045
Name: metal3machineName,
10461046
Namespace: namespaceName,
1047-
Kind: "M3Machine",
1047+
Kind: "Metal3Machine",
10481048
APIVersion: infrav1.GroupVersion.String(),
10491049
},
10501050
},
@@ -1113,7 +1113,7 @@ var _ = Describe("Metal3Machine manager", func() {
11131113
ConsumerRef: &corev1.ObjectReference{
11141114
Name: metal3machineName,
11151115
Namespace: namespaceName,
1116-
Kind: "M3Machine",
1116+
Kind: "Metal3Machine",
11171117
APIVersion: infrav1.GroupVersion.String(),
11181118
},
11191119
},
@@ -1131,7 +1131,7 @@ var _ = Describe("Metal3Machine manager", func() {
11311131
ConsumerRef: &corev1.ObjectReference{
11321132
Name: metal3machineName,
11331133
Namespace: namespaceName,
1134-
Kind: "M3Machine",
1134+
Kind: "Metal3Machine",
11351135
APIVersion: infrav1.GroupVersion.String(),
11361136
},
11371137
},
@@ -1149,7 +1149,7 @@ var _ = Describe("Metal3Machine manager", func() {
11491149
ConsumerRef: &corev1.ObjectReference{
11501150
Name: metal3machineName,
11511151
Namespace: namespaceName,
1152-
Kind: "M3Machine",
1152+
Kind: "Metal3Machine",
11531153
APIVersion: infrav1.GroupVersion.String(),
11541154
},
11551155
},
@@ -2358,7 +2358,7 @@ var _ = Describe("Metal3Machine manager", func() {
23582358
Namespace: namespaceName,
23592359
},
23602360
TypeMeta: metav1.TypeMeta{
2361-
Kind: "M3Machine",
2361+
Kind: "Metal3Machine",
23622362
APIVersion: clusterv1beta1.GroupVersion.String(),
23632363
},
23642364
Status: infrav1.Metal3MachineStatus{
@@ -2422,7 +2422,7 @@ var _ = Describe("Metal3Machine manager", func() {
24222422
Namespace: namespaceName,
24232423
},
24242424
TypeMeta: metav1.TypeMeta{
2425-
Kind: "M3Machine",
2425+
Kind: "Metal3Machine",
24262426
APIVersion: clusterv1beta1.GroupVersion.String(),
24272427
},
24282428
Status: infrav1.Metal3MachineStatus{
@@ -2470,7 +2470,7 @@ var _ = Describe("Metal3Machine manager", func() {
24702470
Namespace: namespaceName,
24712471
},
24722472
TypeMeta: metav1.TypeMeta{
2473-
Kind: "M3Machine",
2473+
Kind: "Metal3Machine",
24742474
APIVersion: clusterv1beta1.GroupVersion.String(),
24752475
},
24762476
Status: infrav1.Metal3MachineStatus{
@@ -3124,7 +3124,7 @@ var _ = Describe("Metal3Machine manager", func() {
31243124
M3Machine: *newMetal3Machine("myName", nil, nil, nil),
31253125
OwnerRefs: []metav1.OwnerReference{
31263126
{
3127-
Kind: "M3Machine",
3127+
Kind: "Metal3Machine",
31283128
APIVersion: infrav1.GroupVersion.String(),
31293129
Name: "myName",
31303130
UID: "adfasdf",
@@ -3149,7 +3149,7 @@ var _ = Describe("Metal3Machine manager", func() {
31493149
UID: "adfasdf",
31503150
},
31513151
{
3152-
Kind: "M3Machine",
3152+
Kind: "Metal3Machine",
31533153
APIVersion: infrav1.GroupVersion.String(),
31543154
Name: "myName",
31553155
UID: "adfasdf",
@@ -3168,7 +3168,7 @@ var _ = Describe("Metal3Machine manager", func() {
31683168
UID: "adfasdf",
31693169
},
31703170
{
3171-
Kind: "M3Machine",
3171+
Kind: "Metal3Machine",
31723172
APIVersion: "infrastructure.cluster.x-k8s.io/v1alpha1",
31733173
Name: "myName",
31743174
UID: "adfasdf",
@@ -3187,7 +3187,7 @@ var _ = Describe("Metal3Machine manager", func() {
31873187
UID: "adfasdf",
31883188
},
31893189
{
3190-
Kind: "M3Machine",
3190+
Kind: "Metal3Machine",
31913191
APIVersion: "nfrastructure.cluster.x-k8s.io/v1alpha1",
31923192
Name: "myName",
31933193
UID: "adfasdf",
@@ -3234,7 +3234,7 @@ var _ = Describe("Metal3Machine manager", func() {
32343234
M3Machine: *newMetal3Machine("myName", nil, nil, nil),
32353235
OwnerRefs: []metav1.OwnerReference{
32363236
{
3237-
Kind: "M3Machine",
3237+
Kind: "Metal3Machine",
32383238
APIVersion: infrav1.GroupVersion.String(),
32393239
Name: "myName",
32403240
UID: "adfasdf",
@@ -3257,7 +3257,7 @@ var _ = Describe("Metal3Machine manager", func() {
32573257
UID: "adfasdf",
32583258
},
32593259
{
3260-
Kind: "M3Machine",
3260+
Kind: "Metal3Machine",
32613261
APIVersion: infrav1.GroupVersion.String(),
32623262
Name: "myName",
32633263
UID: "adfasdf",
@@ -3268,7 +3268,7 @@ var _ = Describe("Metal3Machine manager", func() {
32683268
M3Machine: *newMetal3Machine("myName", nil, nil, nil),
32693269
OwnerRefs: []metav1.OwnerReference{
32703270
{
3271-
Kind: "M3Machine",
3271+
Kind: "Metal3Machine",
32723272
APIVersion: infrav1.GroupVersion.String(),
32733273
Name: "myName",
32743274
UID: "adfasdf",
@@ -3309,7 +3309,7 @@ var _ = Describe("Metal3Machine manager", func() {
33093309
M3Machine: *newMetal3Machine("myName", nil, nil, nil),
33103310
OwnerRefs: []metav1.OwnerReference{
33113311
{
3312-
Kind: "M3Machine",
3312+
Kind: "Metal3Machine",
33133313
APIVersion: infrav1.GroupVersion.String(),
33143314
Name: "myName",
33153315
UID: "adfasdf",
@@ -3332,7 +3332,7 @@ var _ = Describe("Metal3Machine manager", func() {
33323332
UID: "adfasdf",
33333333
},
33343334
{
3335-
Kind: "M3Machine",
3335+
Kind: "Metal3Machine",
33363336
APIVersion: infrav1.GroupVersion.String(),
33373337
Name: "myName",
33383338
UID: "adfasdf",
@@ -3429,7 +3429,7 @@ var _ = Describe("Metal3Machine manager", func() {
34293429
OwnerReferences: []metav1.OwnerReference{
34303430
{
34313431
Name: "myName",
3432-
Kind: "M3Machine",
3432+
Kind: "Metal3Machine",
34333433
APIVersion: infrav1.GroupVersion.String(),
34343434
},
34353435
},
@@ -3457,7 +3457,7 @@ var _ = Describe("Metal3Machine manager", func() {
34573457
OwnerReferences: []metav1.OwnerReference{
34583458
{
34593459
Name: "myName",
3460-
Kind: "M3Machine",
3460+
Kind: "Metal3Machine",
34613461
APIVersion: infrav1.GroupVersion.String(),
34623462
},
34633463
},
@@ -4711,7 +4711,7 @@ func newConfig(userDataNamespace string,
47114711

47124712
infrastructureRef := &clusterv1.ContractVersionedObjectReference{
47134713
Name: "someothermachine",
4714-
Kind: "M3Machine",
4714+
Kind: "Metal3Machine",
47154715
APIGroup: infrav1.GroupVersion.Group,
47164716
}
47174717
return &config, infrastructureRef
@@ -4763,7 +4763,7 @@ func newMetal3Machine(name string,
47634763
}
47644764

47654765
typeMeta := &metav1.TypeMeta{
4766-
Kind: "M3Machine",
4766+
Kind: "Metal3Machine",
47674767
APIVersion: infrav1.GroupVersion.String(),
47684768
}
47694769

0 commit comments

Comments
 (0)