Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 00c55be

Browse files
committed
Use GetOwnerMachine
Signed-off-by: Chuck Ha <[email protected]>
1 parent 08dafc3 commit 00c55be

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

controllers/kubeadmconfig_controller.go

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,9 @@ func (r *KubeadmConfigReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
7676
return ctrl.Result{}, nil
7777
}
7878

79-
// Find the owner reference
80-
// The cluster-api machine controller set this value.
81-
var machineRef *v1.OwnerReference
82-
for _, ref := range config.OwnerReferences {
83-
if ref.Kind == machineKind.Kind && ref.APIVersion == machineKind.GroupVersion().String() {
84-
machineRef = &ref
85-
break
86-
}
87-
}
88-
if machineRef == nil {
89-
log.Info("did not find matching machine reference")
90-
return ctrl.Result{}, nil
91-
}
92-
93-
// Get the machine
94-
machine := &capiv1alpha2.Machine{}
95-
machineKey := client.ObjectKey{
96-
Namespace: req.Namespace,
97-
Name: machineRef.Name,
98-
}
99-
100-
if err := r.Get(ctx, machineKey, machine); err != nil {
101-
log.Error(err, "failed to get machine")
79+
machine, err := util.GetOwnerMachine(ctx, r.Client, config.ObjectMeta)
80+
if err != nil {
81+
log.Error(err, "could not get owner machine")
10282
return ctrl.Result{}, err
10383
}
10484

0 commit comments

Comments
 (0)