From b03866fb0527f5d69dfc9665dae25388a4f14595 Mon Sep 17 00:00:00 2001 From: Danil-Grigorev Date: Fri, 1 Nov 2024 11:07:19 +0100 Subject: [PATCH] Update references usage across the code Signed-off-by: Danil-Grigorev --- bootstrap/util/configowner.go | 2 +- cmd/clusterctl/client/tree/discovery.go | 16 ++++---- controllers/external/util.go | 4 +- controllers/external/util_test.go | 4 +- .../kubeadm/internal/control_plane.go | 2 +- .../internal/controllers/controller_test.go | 2 +- .../kubeadm/internal/controllers/helpers.go | 2 +- .../internal/controllers/helpers_test.go | 2 +- .../controllers/machinepool_controller.go | 4 +- .../machinepool_controller_phases.go | 4 +- .../machinepool_controller_phases_test.go | 4 +- .../cluster/cluster_controller_phases.go | 2 +- .../clusterclass/clusterclass_controller.go | 8 ++-- .../controllers/machine/machine_controller.go | 2 +- .../machine/machine_controller_phases.go | 2 +- .../machinedeployment_controller.go | 2 +- .../machinedeployment_controller_test.go | 2 +- .../machinehealthcheck_controller.go | 6 +-- .../machineset/machineset_controller.go | 6 +-- .../machineset/machineset_controller_test.go | 4 +- .../machineset/machineset_preflight.go | 2 +- internal/controllers/topology/cluster/util.go | 2 +- internal/webhooks/cluster.go | 2 +- test/e2e/clusterclass_changes.go | 24 +++++------ test/e2e/clusterclass_rollout.go | 40 +++++++++---------- test/e2e/clusterctl_upgrade.go | 2 +- 26 files changed, 76 insertions(+), 76 deletions(-) diff --git a/bootstrap/util/configowner.go b/bootstrap/util/configowner.go index 7ed7e2edbf24..39a411057f2b 100644 --- a/bootstrap/util/configowner.go +++ b/bootstrap/util/configowner.go @@ -176,7 +176,7 @@ func getConfigOwner(ctx context.Context, c client.Client, obj metav1.Object, get // GetOwnerByRef finds and returns the owner by looking at the object reference. func GetOwnerByRef(ctx context.Context, c client.Client, ref *corev1.ObjectReference) (*ConfigOwner, error) { - obj, err := external.Get(ctx, c, ref, ref.Namespace) + obj, err := external.Get(ctx, c, ref) if err != nil { return nil, err } diff --git a/cmd/clusterctl/client/tree/discovery.go b/cmd/clusterctl/client/tree/discovery.go index 09feb1960440..c86d3b573f69 100644 --- a/cmd/clusterctl/client/tree/discovery.go +++ b/cmd/clusterctl/client/tree/discovery.go @@ -84,7 +84,7 @@ func Discovery(ctx context.Context, c client.Client, namespace, name string, opt tree := NewObjectTree(cluster, options.toObjectTreeOptions()) // Adds cluster infra - clusterInfra, err := external.Get(ctx, c, cluster.Spec.InfrastructureRef, cluster.Namespace) + clusterInfra, err := external.Get(ctx, c, cluster.Spec.InfrastructureRef) if err != nil { return nil, errors.Wrap(err, "get InfraCluster reference from Cluster") } @@ -95,7 +95,7 @@ func Discovery(ctx context.Context, c client.Client, namespace, name string, opt } // Adds control plane - controlPlane, err := external.Get(ctx, c, cluster.Spec.ControlPlaneRef, cluster.Namespace) + controlPlane, err := external.Get(ctx, c, cluster.Spec.ControlPlaneRef) if err == nil { addControlPlane(cluster, controlPlane, tree, options) } @@ -112,13 +112,13 @@ func Discovery(ctx context.Context, c client.Client, namespace, name string, opt if visible { if (m.Spec.InfrastructureRef != corev1.ObjectReference{}) { - if machineInfra, err := external.Get(ctx, c, &m.Spec.InfrastructureRef, cluster.Namespace); err == nil { + if machineInfra, err := external.Get(ctx, c, &m.Spec.InfrastructureRef); err == nil { tree.Add(m, machineInfra, ObjectMetaName("MachineInfrastructure"), NoEcho(true)) } } if m.Spec.Bootstrap.ConfigRef != nil { - if machineBootstrap, err := external.Get(ctx, c, m.Spec.Bootstrap.ConfigRef, cluster.Namespace); err == nil { + if machineBootstrap, err := external.Get(ctx, c, m.Spec.Bootstrap.ConfigRef); err == nil { tree.Add(m, machineBootstrap, ObjectMetaName("BootstrapConfig"), NoEcho(true)) } } @@ -154,7 +154,7 @@ func Discovery(ctx context.Context, c client.Client, namespace, name string, opt if len(machinePoolList.Items) > 0 { // Add MachinePool objects tree.Add(cluster, workers) - addMachinePoolsToObjectTree(ctx, c, cluster.Namespace, workers, machinePoolList, machinesList, tree, addMachineFunc) + addMachinePoolsToObjectTree(ctx, c, workers, machinePoolList, machinesList, tree, addMachineFunc) } // Handles orphan machines. @@ -275,17 +275,17 @@ func addMachineDeploymentToObjectTree(ctx context.Context, c client.Client, clus return nil } -func addMachinePoolsToObjectTree(ctx context.Context, c client.Client, namespace string, workers *unstructured.Unstructured, machinePoolList *expv1.MachinePoolList, machinesList *clusterv1.MachineList, tree *ObjectTree, addMachineFunc func(parent client.Object, m *clusterv1.Machine)) { +func addMachinePoolsToObjectTree(ctx context.Context, c client.Client, workers *unstructured.Unstructured, machinePoolList *expv1.MachinePoolList, machinesList *clusterv1.MachineList, tree *ObjectTree, addMachineFunc func(parent client.Object, m *clusterv1.Machine)) { for i := range machinePoolList.Items { mp := &machinePoolList.Items[i] _, visible := tree.Add(workers, mp, GroupingObject(true)) if visible { - if machinePoolBootstrap, err := external.Get(ctx, c, mp.Spec.Template.Spec.Bootstrap.ConfigRef, namespace); err == nil { + if machinePoolBootstrap, err := external.Get(ctx, c, mp.Spec.Template.Spec.Bootstrap.ConfigRef); err == nil { tree.Add(mp, machinePoolBootstrap, ObjectMetaName("BootstrapConfig"), NoEcho(true)) } - if machinePoolInfra, err := external.Get(ctx, c, &mp.Spec.Template.Spec.InfrastructureRef, namespace); err == nil { + if machinePoolInfra, err := external.Get(ctx, c, &mp.Spec.Template.Spec.InfrastructureRef); err == nil { tree.Add(mp, machinePoolInfra, ObjectMetaName("MachinePoolInfrastructure"), NoEcho(true)) } } diff --git a/controllers/external/util.go b/controllers/external/util.go index c064885518cd..71009480b312 100644 --- a/controllers/external/util.go +++ b/controllers/external/util.go @@ -31,7 +31,7 @@ import ( ) // Get uses the client and reference to get an external, unstructured object. -func Get(ctx context.Context, c client.Reader, ref *corev1.ObjectReference, _ string) (*unstructured.Unstructured, error) { +func Get(ctx context.Context, c client.Reader, ref *corev1.ObjectReference) (*unstructured.Unstructured, error) { if ref == nil { return nil, errors.Errorf("cannot get object - object reference not set") } @@ -92,7 +92,7 @@ type CreateFromTemplateInput struct { // CreateFromTemplate uses the client and the reference to create a new object from the template. func CreateFromTemplate(ctx context.Context, in *CreateFromTemplateInput) (*corev1.ObjectReference, error) { - from, err := Get(ctx, in.Client, in.TemplateRef, in.Namespace) + from, err := Get(ctx, in.Client, in.TemplateRef) if err != nil { return nil, err } diff --git a/controllers/external/util_test.go b/controllers/external/util_test.go index f10eefab3687..3ef41d354f07 100644 --- a/controllers/external/util_test.go +++ b/controllers/external/util_test.go @@ -63,7 +63,7 @@ func TestGetResourceFound(t *testing.T) { } fakeClient := fake.NewClientBuilder().WithObjects(testResource.DeepCopy()).Build() - got, err := Get(ctx, fakeClient, testResourceReference, metav1.NamespaceDefault) + got, err := Get(ctx, fakeClient, testResourceReference) g.Expect(err).ToNot(HaveOccurred()) g.Expect(got).To(BeComparableTo(testResource)) } @@ -79,7 +79,7 @@ func TestGetResourceNotFound(t *testing.T) { } fakeClient := fake.NewClientBuilder().Build() - _, err := Get(ctx, fakeClient, testResourceReference, metav1.NamespaceDefault) + _, err := Get(ctx, fakeClient, testResourceReference) g.Expect(err).To(HaveOccurred()) g.Expect(apierrors.IsNotFound(errors.Cause(err))).To(BeTrue()) } diff --git a/controlplane/kubeadm/internal/control_plane.go b/controlplane/kubeadm/internal/control_plane.go index 41b1ed8ffed0..11fea608b91b 100644 --- a/controlplane/kubeadm/internal/control_plane.go +++ b/controlplane/kubeadm/internal/control_plane.go @@ -232,7 +232,7 @@ func (c *ControlPlane) UpToDateMachines() (collections.Machines, error) { func getInfraResources(ctx context.Context, cl client.Client, machines collections.Machines) (map[string]*unstructured.Unstructured, error) { result := map[string]*unstructured.Unstructured{} for _, m := range machines { - infraObj, err := external.Get(ctx, cl, &m.Spec.InfrastructureRef, m.Namespace) + infraObj, err := external.Get(ctx, cl, &m.Spec.InfrastructureRef) if err != nil { if apierrors.IsNotFound(errors.Cause(err)) { continue diff --git a/controlplane/kubeadm/internal/controllers/controller_test.go b/controlplane/kubeadm/internal/controllers/controller_test.go index 29f20b500319..125abfdbac09 100644 --- a/controlplane/kubeadm/internal/controllers/controller_test.go +++ b/controlplane/kubeadm/internal/controllers/controller_test.go @@ -1399,7 +1399,7 @@ kubernetesVersion: metav1.16.1 machine := machineList.Items[0] g.Expect(machine.Name).To(HavePrefix(kcp.Name)) // Newly cloned infra objects should have the infraref annotation. - infraObj, err := external.Get(ctx, r.Client, &machine.Spec.InfrastructureRef, machine.Spec.InfrastructureRef.Namespace) + infraObj, err := external.Get(ctx, r.Client, &machine.Spec.InfrastructureRef) g.Expect(err).ToNot(HaveOccurred()) g.Expect(infraObj.GetAnnotations()).To(HaveKeyWithValue(clusterv1.TemplateClonedFromNameAnnotation, genericInfrastructureMachineTemplate.GetName())) g.Expect(infraObj.GetAnnotations()).To(HaveKeyWithValue(clusterv1.TemplateClonedFromGroupKindAnnotation, genericInfrastructureMachineTemplate.GroupVersionKind().GroupKind().String())) diff --git a/controlplane/kubeadm/internal/controllers/helpers.go b/controlplane/kubeadm/internal/controllers/helpers.go index f7917e4a9e38..646d1c32a80b 100644 --- a/controlplane/kubeadm/internal/controllers/helpers.go +++ b/controlplane/kubeadm/internal/controllers/helpers.go @@ -151,7 +151,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileExternalReference(ctx context.C return err } - obj, err := external.Get(ctx, r.Client, ref, controlPlane.Cluster.Namespace) + obj, err := external.Get(ctx, r.Client, ref) if err != nil { if apierrors.IsNotFound(err) { controlPlane.InfraMachineTemplateIsNotFound = true diff --git a/controlplane/kubeadm/internal/controllers/helpers_test.go b/controlplane/kubeadm/internal/controllers/helpers_test.go index 311d202b7b8a..9554a8505f28 100644 --- a/controlplane/kubeadm/internal/controllers/helpers_test.go +++ b/controlplane/kubeadm/internal/controllers/helpers_test.go @@ -386,7 +386,7 @@ func TestCloneConfigsAndGenerateMachine(t *testing.T) { g.Expect(m.Name).NotTo(BeEmpty()) g.Expect(m.Name).To(HavePrefix(kcp.Name + namingTemplateKey)) - infraObj, err := external.Get(ctx, r.Client, &m.Spec.InfrastructureRef, m.Spec.InfrastructureRef.Namespace) + infraObj, err := external.Get(ctx, r.Client, &m.Spec.InfrastructureRef) g.Expect(err).ToNot(HaveOccurred()) g.Expect(infraObj.GetAnnotations()).To(HaveKeyWithValue(clusterv1.TemplateClonedFromNameAnnotation, genericInfrastructureMachineTemplate.GetName())) g.Expect(infraObj.GetAnnotations()).To(HaveKeyWithValue(clusterv1.TemplateClonedFromGroupKindAnnotation, genericInfrastructureMachineTemplate.GroupVersionKind().GroupKind().String())) diff --git a/exp/internal/controllers/machinepool_controller.go b/exp/internal/controllers/machinepool_controller.go index ee956dc0d7f2..4cd2ad82374d 100644 --- a/exp/internal/controllers/machinepool_controller.go +++ b/exp/internal/controllers/machinepool_controller.go @@ -340,10 +340,10 @@ func (r *MachinePoolReconciler) reconcileDeleteExternal(ctx context.Context, mac continue } - obj, err := external.Get(ctx, r.Client, ref, machinePool.Namespace) + obj, err := external.Get(ctx, r.Client, ref) if err != nil && !apierrors.IsNotFound(errors.Cause(err)) { return false, errors.Wrapf(err, "failed to get %s %q for MachinePool %q in namespace %q", - ref.GroupVersionKind(), ref.Name, machinePool.Name, machinePool.Namespace) + ref.GroupVersionKind(), ref.Name, machinePool.Name, ref.Namespace) } if obj != nil { objects = append(objects, obj) diff --git a/exp/internal/controllers/machinepool_controller_phases.go b/exp/internal/controllers/machinepool_controller_phases.go index 3a5474d05914..f56253ac9100 100644 --- a/exp/internal/controllers/machinepool_controller_phases.go +++ b/exp/internal/controllers/machinepool_controller_phases.go @@ -113,11 +113,11 @@ func (r *MachinePoolReconciler) reconcileExternal(ctx context.Context, cluster * return external.ReconcileOutput{}, err } - obj, err := external.Get(ctx, r.Client, ref, m.Namespace) + obj, err := external.Get(ctx, r.Client, ref) if err != nil { if apierrors.IsNotFound(errors.Cause(err)) { return external.ReconcileOutput{}, errors.Wrapf(err, "could not find %v %q for MachinePool %q in namespace %q, requeuing", - ref.GroupVersionKind(), ref.Name, m.Name, m.Namespace) + ref.GroupVersionKind(), ref.Name, m.Name, ref.Namespace) } return external.ReconcileOutput{}, err } diff --git a/exp/internal/controllers/machinepool_controller_phases_test.go b/exp/internal/controllers/machinepool_controller_phases_test.go index 162ba3ade556..837487ba252d 100644 --- a/exp/internal/controllers/machinepool_controller_phases_test.go +++ b/exp/internal/controllers/machinepool_controller_phases_test.go @@ -1469,7 +1469,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) { g.Expect(machineList.Items).To(HaveLen(2)) for i := range machineList.Items { machine := &machineList.Items[i] - _, err := external.Get(ctx, r.Client, &machine.Spec.InfrastructureRef, machine.Namespace) + _, err := external.Get(ctx, r.Client, &machine.Spec.InfrastructureRef) g.Expect(err).ToNot(HaveOccurred()) } }) @@ -1539,7 +1539,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) { g.Expect(machineList.Items).To(HaveLen(2)) for i := range machineList.Items { machine := &machineList.Items[i] - _, err := external.Get(ctx, r.Client, &machine.Spec.InfrastructureRef, machine.Namespace) + _, err := external.Get(ctx, r.Client, &machine.Spec.InfrastructureRef) g.Expect(err).ToNot(HaveOccurred()) } }) diff --git a/internal/controllers/cluster/cluster_controller_phases.go b/internal/controllers/cluster/cluster_controller_phases.go index 39a957a8a144..488c74a14086 100644 --- a/internal/controllers/cluster/cluster_controller_phases.go +++ b/internal/controllers/cluster/cluster_controller_phases.go @@ -90,7 +90,7 @@ func (r *Reconciler) reconcileExternal(ctx context.Context, cluster *clusterv1.C return nil, err } - obj, err := external.Get(ctx, r.Client, ref, cluster.Namespace) + obj, err := external.Get(ctx, r.Client, ref) if err != nil { return nil, err } diff --git a/internal/controllers/clusterclass/clusterclass_controller.go b/internal/controllers/clusterclass/clusterclass_controller.go index 14fdc9121c35..8d31cb28c59f 100644 --- a/internal/controllers/clusterclass/clusterclass_controller.go +++ b/internal/controllers/clusterclass/clusterclass_controller.go @@ -373,17 +373,17 @@ func refString(ref *corev1.ObjectReference) string { func (r *Reconciler) reconcileExternal(ctx context.Context, clusterClass *clusterv1.ClusterClass, ref *corev1.ObjectReference) error { log := ctrl.LoggerFrom(ctx) - obj, err := external.Get(ctx, r.Client, ref, clusterClass.Namespace) + obj, err := external.Get(ctx, r.Client, ref) if err != nil { if apierrors.IsNotFound(errors.Cause(err)) { - return errors.Wrapf(err, "Could not find external object for the ClusterClass. refGroupVersionKind: %s, refName: %s", ref.GroupVersionKind(), ref.Name) + return errors.Wrapf(err, "Could not find external object for the ClusterClass. refGroupVersionKind: %s, refName: %s, refNamespace: %s", ref.GroupVersionKind(), ref.Name, ref.Namespace) } - return errors.Wrapf(err, "failed to get the external object for the ClusterClass. refGroupVersionKind: %s, refName: %s", ref.GroupVersionKind(), ref.Name) + return errors.Wrapf(err, "failed to get the external object for the ClusterClass. refGroupVersionKind: %s, refName: %s, refNamespace: %s", ref.GroupVersionKind(), ref.Name, ref.Namespace) } // If referenced object is paused, return early. if annotations.HasPaused(obj) { - log.V(3).Info("External object referenced is paused", "refGroupVersionKind", ref.GroupVersionKind(), "refName", ref.Name) + log.V(3).Info("External object referenced is paused", "refGroupVersionKind", ref.GroupVersionKind(), "refName", ref.Name, "refNamespace", ref.Namespace) return nil } diff --git a/internal/controllers/machine/machine_controller.go b/internal/controllers/machine/machine_controller.go index 34675cf252f4..11723942ad73 100644 --- a/internal/controllers/machine/machine_controller.go +++ b/internal/controllers/machine/machine_controller.go @@ -732,7 +732,7 @@ func (r *Reconciler) isDeleteNodeAllowed(ctx context.Context, cluster *clusterv1 // controlPlaneRef is an optional field in the Cluster so skip the external // managed control plane check if it is nil if cluster.Spec.ControlPlaneRef != nil { - controlPlane, err := external.Get(ctx, r.Client, cluster.Spec.ControlPlaneRef, cluster.Spec.ControlPlaneRef.Namespace) + controlPlane, err := external.Get(ctx, r.Client, cluster.Spec.ControlPlaneRef) if apierrors.IsNotFound(err) { // If control plane object in the reference does not exist, log and skip check for // external managed control plane diff --git a/internal/controllers/machine/machine_controller_phases.go b/internal/controllers/machine/machine_controller_phases.go index f7e53d0ce232..8289c766d141 100644 --- a/internal/controllers/machine/machine_controller_phases.go +++ b/internal/controllers/machine/machine_controller_phases.go @@ -83,7 +83,7 @@ func (r *Reconciler) reconcileExternal(ctx context.Context, cluster *clusterv1.C func (r *Reconciler) ensureExternalOwnershipAndWatch(ctx context.Context, cluster *clusterv1.Cluster, m *clusterv1.Machine, ref *corev1.ObjectReference) (*unstructured.Unstructured, error) { log := ctrl.LoggerFrom(ctx) - obj, err := external.Get(ctx, r.Client, ref, m.Namespace) + obj, err := external.Get(ctx, r.Client, ref) if err != nil { return nil, err } diff --git a/internal/controllers/machinedeployment/machinedeployment_controller.go b/internal/controllers/machinedeployment/machinedeployment_controller.go index 0c8272508916..41184e4b69aa 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller.go @@ -513,7 +513,7 @@ func reconcileExternalTemplateReference(ctx context.Context, c client.Client, cl return errors.New(err.Error()) } - obj, err := external.Get(ctx, c, ref, cluster.Namespace) + obj, err := external.Get(ctx, c, ref) if err != nil { return err } diff --git a/internal/controllers/machinedeployment/machinedeployment_controller_test.go b/internal/controllers/machinedeployment/machinedeployment_controller_test.go index 0bcd742fedca..590d69bf5631 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller_test.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller_test.go @@ -204,7 +204,7 @@ func TestMachineDeploymentReconciler(t *testing.T) { t.Log("Verifying the linked infrastructure template has a cluster owner reference") g.Eventually(func() bool { - obj, err := external.Get(ctx, env, &deployment.Spec.Template.Spec.InfrastructureRef, deployment.Namespace) + obj, err := external.Get(ctx, env, &deployment.Spec.Template.Spec.InfrastructureRef) if err != nil { return false } diff --git a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go index bdbbc8a837c5..30f4e505dfd8 100644 --- a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go +++ b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go @@ -412,7 +412,7 @@ func (r *Reconciler) patchUnhealthyTargets(ctx context.Context, logger logr.Logg UID: t.Machine.UID, } - from, err := external.Get(ctx, r.Client, m.Spec.RemediationTemplate, t.Machine.Namespace) + from, err := external.Get(ctx, r.Client, m.Spec.RemediationTemplate) if err != nil { conditions.MarkFalse(m, clusterv1.ExternalRemediationTemplateAvailableCondition, clusterv1.ExternalRemediationTemplateNotFoundReason, clusterv1.ConditionSeverityError, err.Error()) @@ -420,7 +420,7 @@ func (r *Reconciler) patchUnhealthyTargets(ctx context.Context, logger logr.Logg Type: clusterv1.MachineExternallyRemediatedV1Beta2Condition, Status: metav1.ConditionFalse, Reason: clusterv1.MachineExternallyRemediatedRemediationTemplateNotFoundV1Beta2Reason, - Message: fmt.Sprintf("Error retrieving remediation template %s %s", m.Spec.RemediationTemplate.Kind, klog.KRef(t.Machine.Namespace, m.Spec.RemediationTemplate.Name)), + Message: fmt.Sprintf("Error retrieving remediation template %s %s", m.Spec.RemediationTemplate.Kind, klog.KRef(m.Spec.RemediationTemplate.Namespace, m.Spec.RemediationTemplate.Name)), }) errList = append(errList, errors.Wrapf(err, "error retrieving remediation template %v %q for machine %q in namespace %q within cluster %q", m.Spec.RemediationTemplate.GroupVersionKind(), m.Spec.RemediationTemplate.Name, t.Machine.Name, t.Machine.Namespace, m.Spec.ClusterName)) return errList @@ -691,7 +691,7 @@ func (r *Reconciler) getExternalRemediationRequest(ctx context.Context, m *clust Name: machineName, Namespace: m.Namespace, } - remediationReq, err := external.Get(ctx, r.Client, remediationRef, m.Namespace) + remediationReq, err := external.Get(ctx, r.Client, remediationRef) if err != nil { return nil, errors.Wrapf(err, "failed to retrieve external remediation request object") } diff --git a/internal/controllers/machineset/machineset_controller.go b/internal/controllers/machineset/machineset_controller.go index eadc30a22753..91b887a1f83b 100644 --- a/internal/controllers/machineset/machineset_controller.go +++ b/internal/controllers/machineset/machineset_controller.go @@ -526,7 +526,7 @@ func (r *Reconciler) syncMachines(ctx context.Context, s *scope) (ctrl.Result, e } machines[i] = updatedMachine - infraMachine, err := external.Get(ctx, r.Client, &updatedMachine.Spec.InfrastructureRef, updatedMachine.Namespace) + infraMachine, err := external.Get(ctx, r.Client, &updatedMachine.Spec.InfrastructureRef) if err != nil { return ctrl.Result{}, errors.Wrapf(err, "failed to get InfrastructureMachine %s", klog.KRef(updatedMachine.Spec.InfrastructureRef.Namespace, updatedMachine.Spec.InfrastructureRef.Name)) @@ -548,7 +548,7 @@ func (r *Reconciler) syncMachines(ctx context.Context, s *scope) (ctrl.Result, e } if updatedMachine.Spec.Bootstrap.ConfigRef != nil { - bootstrapConfig, err := external.Get(ctx, r.Client, updatedMachine.Spec.Bootstrap.ConfigRef, updatedMachine.Namespace) + bootstrapConfig, err := external.Get(ctx, r.Client, updatedMachine.Spec.Bootstrap.ConfigRef) if err != nil { return ctrl.Result{}, errors.Wrapf(err, "failed to get BootstrapConfig %s", klog.KRef(updatedMachine.Spec.Bootstrap.ConfigRef.Namespace, updatedMachine.Spec.Bootstrap.ConfigRef.Name)) @@ -1328,7 +1328,7 @@ func (r *Reconciler) reconcileExternalTemplateReference(ctx context.Context, clu return false, err } - obj, err := external.Get(ctx, r.Client, ref, cluster.Namespace) + obj, err := external.Get(ctx, r.Client, ref) if err != nil { if apierrors.IsNotFound(err) { if !ms.DeletionTimestamp.IsZero() { diff --git a/internal/controllers/machineset/machineset_controller_test.go b/internal/controllers/machineset/machineset_controller_test.go index a3b738d46f8c..f3c01bbc46c5 100644 --- a/internal/controllers/machineset/machineset_controller_test.go +++ b/internal/controllers/machineset/machineset_controller_test.go @@ -225,7 +225,7 @@ func TestMachineSetReconciler(t *testing.T) { t.Log("Verifying the linked bootstrap template has a cluster owner reference") g.Eventually(func() bool { - obj, err := external.Get(ctx, env, instance.Spec.Template.Spec.Bootstrap.ConfigRef, instance.Namespace) + obj, err := external.Get(ctx, env, instance.Spec.Template.Spec.Bootstrap.ConfigRef) if err != nil { return false } @@ -240,7 +240,7 @@ func TestMachineSetReconciler(t *testing.T) { t.Log("Verifying the linked infrastructure template has a cluster owner reference") g.Eventually(func() bool { - obj, err := external.Get(ctx, env, &instance.Spec.Template.Spec.InfrastructureRef, instance.Namespace) + obj, err := external.Get(ctx, env, &instance.Spec.Template.Spec.InfrastructureRef) if err != nil { return false } diff --git a/internal/controllers/machineset/machineset_preflight.go b/internal/controllers/machineset/machineset_preflight.go index ae959329e2f8..f20b098c6a97 100644 --- a/internal/controllers/machineset/machineset_preflight.go +++ b/internal/controllers/machineset/machineset_preflight.go @@ -66,7 +66,7 @@ func (r *Reconciler) runPreflightChecks(ctx context.Context, cluster *clusterv1. } // Get the control plane object. - controlPlane, err := external.Get(ctx, r.Client, cluster.Spec.ControlPlaneRef, cluster.Namespace) + controlPlane, err := external.Get(ctx, r.Client, cluster.Spec.ControlPlaneRef) if err != nil { return ctrl.Result{}, "", errors.Wrapf(err, "failed to perform %q: failed to perform preflight checks: failed to get ControlPlane %s", action, klog.KRef(cluster.Spec.ControlPlaneRef.Namespace, cluster.Spec.ControlPlaneRef.Name)) } diff --git a/internal/controllers/topology/cluster/util.go b/internal/controllers/topology/cluster/util.go index 3a2111713bea..643a4217fe66 100644 --- a/internal/controllers/topology/cluster/util.go +++ b/internal/controllers/topology/cluster/util.go @@ -33,7 +33,7 @@ func (r *Reconciler) getReference(ctx context.Context, ref *corev1.ObjectReferen return nil, errors.New("reference is not set") } - obj, err := external.Get(ctx, r.Client, ref, ref.Namespace) + obj, err := external.Get(ctx, r.Client, ref) if err != nil { return nil, errors.Wrapf(err, "failed to retrieve %s %s", ref.Kind, klog.KRef(ref.Namespace, ref.Name)) } diff --git a/internal/webhooks/cluster.go b/internal/webhooks/cluster.go index de51e7ab9d65..cc9b8974d19c 100644 --- a/internal/webhooks/cluster.go +++ b/internal/webhooks/cluster.go @@ -509,7 +509,7 @@ func (webhook *Cluster) validateTopologyVersion(ctx context.Context, fldPath *fi } func validateTopologyControlPlaneVersion(ctx context.Context, ctrlClient client.Reader, oldCluster *clusterv1.Cluster, oldVersion semver.Version) error { - cp, err := external.Get(ctx, ctrlClient, oldCluster.Spec.ControlPlaneRef, oldCluster.Namespace) + cp, err := external.Get(ctx, ctrlClient, oldCluster.Spec.ControlPlaneRef) if err != nil { return errors.Wrap(err, "failed to get ControlPlane object") } diff --git a/test/e2e/clusterclass_changes.go b/test/e2e/clusterclass_changes.go index f919a701ec92..454543f2a707 100644 --- a/test/e2e/clusterclass_changes.go +++ b/test/e2e/clusterclass_changes.go @@ -260,7 +260,7 @@ func modifyControlPlaneViaClusterClassAndWait(ctx context.Context, input modifyC // Get ControlPlaneTemplate object. controlPlaneTemplateRef := input.ClusterClass.Spec.ControlPlane.Ref - controlPlaneTemplate, err := external.Get(ctx, mgmtClient, controlPlaneTemplateRef, input.ClusterClass.Namespace) + controlPlaneTemplate, err := external.Get(ctx, mgmtClient, controlPlaneTemplateRef) Expect(err).ToNot(HaveOccurred()) // Create a new ControlPlaneTemplate object with a new name and ModifyControlPlaneFields set. @@ -287,7 +287,7 @@ func modifyControlPlaneViaClusterClassAndWait(ctx context.Context, input modifyC // Get the ControlPlane. controlPlaneRef := input.Cluster.Spec.ControlPlaneRef controlPlaneTopology := input.Cluster.Spec.Topology.ControlPlane - controlPlane, err := external.Get(ctx, mgmtClient, controlPlaneRef, input.ClusterClass.Namespace) + controlPlane, err := external.Get(ctx, mgmtClient, controlPlaneRef) g.Expect(err).ToNot(HaveOccurred()) // Verify that the fields from Cluster topology are set on the control plane. @@ -366,7 +366,7 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo // Retrieve BootstrapConfigTemplate object. bootstrapConfigTemplateRef = mdClass.Template.Bootstrap.Ref - bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, bootstrapConfigTemplateRef, input.Cluster.Namespace) + bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, bootstrapConfigTemplateRef) Expect(err).ToNot(HaveOccurred()) // Create a new BootstrapConfigTemplate object with a new name and ModifyBootstrapConfigTemplateFields set. newBootstrapConfigTemplate := bootstrapConfigTemplate.DeepCopy() @@ -383,7 +383,7 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo // Retrieve InfrastructureMachineTemplate object. infrastructureMachineTemplateRef := mdClass.Template.Infrastructure.Ref - infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, infrastructureMachineTemplateRef, input.Cluster.Namespace) + infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, infrastructureMachineTemplateRef) Expect(err).ToNot(HaveOccurred()) // Create a new InfrastructureMachineTemplate object with a new name and ModifyInfrastructureMachineTemplateFields set. newInfrastructureMachineTemplate := infrastructureMachineTemplate.DeepCopy() @@ -429,7 +429,7 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo if mdClass.Template.Bootstrap.Ref != nil { // Get the corresponding BootstrapConfigTemplate. bootstrapConfigTemplateRef := md.Spec.Template.Spec.Bootstrap.ConfigRef - bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, bootstrapConfigTemplateRef, input.Cluster.Namespace) + bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, bootstrapConfigTemplateRef) g.Expect(err).ToNot(HaveOccurred()) // Verify that ModifyBootstrapConfigTemplateFields have been set. @@ -443,7 +443,7 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo // Get the corresponding InfrastructureMachineTemplate. infrastructureMachineTemplateRef := md.Spec.Template.Spec.InfrastructureRef - infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, &infrastructureMachineTemplateRef, input.Cluster.Namespace) + infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, &infrastructureMachineTemplateRef) g.Expect(err).ToNot(HaveOccurred()) // Verify that ModifyInfrastructureMachineTemplateFields have been set. @@ -489,7 +489,7 @@ func modifyMachinePoolViaClusterClassAndWait(ctx context.Context, input modifyMa // Retrieve BootstrapConfigTemplate object. bootstrapConfigTemplateRef = mpClass.Template.Bootstrap.Ref - bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, bootstrapConfigTemplateRef, input.Cluster.Namespace) + bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, bootstrapConfigTemplateRef) Expect(err).ToNot(HaveOccurred()) // Create a new BootstrapConfigTemplate object with a new name and ModifyBootstrapConfigTemplateFields set. newBootstrapConfigTemplate := bootstrapConfigTemplate.DeepCopy() @@ -506,7 +506,7 @@ func modifyMachinePoolViaClusterClassAndWait(ctx context.Context, input modifyMa // Retrieve InfrastructureMachineTemplate object. infrastructureMachinePoolTemplateRef := mpClass.Template.Infrastructure.Ref - infrastructureMachinePoolTemplate, err := external.Get(ctx, mgmtClient, infrastructureMachinePoolTemplateRef, input.Cluster.Namespace) + infrastructureMachinePoolTemplate, err := external.Get(ctx, mgmtClient, infrastructureMachinePoolTemplateRef) Expect(err).ToNot(HaveOccurred()) // Create a new InfrastructureMachinePoolTemplate object with a new name and ModifyInfrastructureMachinePoolTemplateFields set. newInfrastructureMachinePoolTemplate := infrastructureMachinePoolTemplate.DeepCopy() @@ -552,7 +552,7 @@ func modifyMachinePoolViaClusterClassAndWait(ctx context.Context, input modifyMa if mpClass.Template.Bootstrap.Ref != nil { // Get the corresponding BootstrapConfig object. bootstrapConfigObjectRef := mp.Spec.Template.Spec.Bootstrap.ConfigRef - bootstrapConfigObject, err := external.Get(ctx, mgmtClient, bootstrapConfigObjectRef, input.Cluster.Namespace) + bootstrapConfigObject, err := external.Get(ctx, mgmtClient, bootstrapConfigObjectRef) g.Expect(err).ToNot(HaveOccurred()) // Verify that ModifyBootstrapConfigTemplateFields have been set and propagates to the BootstrapConfig. @@ -568,7 +568,7 @@ func modifyMachinePoolViaClusterClassAndWait(ctx context.Context, input modifyMa // Get the corresponding InfrastructureMachinePoolTemplate. infrastructureMachinePoolRef := mp.Spec.Template.Spec.InfrastructureRef - infrastructureMachinePool, err := external.Get(ctx, mgmtClient, &infrastructureMachinePoolRef, input.Cluster.Namespace) + infrastructureMachinePool, err := external.Get(ctx, mgmtClient, &infrastructureMachinePoolRef) g.Expect(err).ToNot(HaveOccurred()) // Verify that ModifyInfrastructureMachinePoolTemplateFields have been set. @@ -695,7 +695,7 @@ func rebaseClusterClassAndWait(ctx context.Context, input rebaseClusterClassAndW // Get the current ControlPlane, we will later verify that it has not changed. controlPlaneRef := input.Cluster.Spec.ControlPlaneRef - beforeControlPlane, err := external.Get(ctx, mgmtClient, controlPlaneRef, input.ClusterClass.Namespace) + beforeControlPlane, err := external.Get(ctx, mgmtClient, controlPlaneRef) Expect(err).ToNot(HaveOccurred()) // Rebase the Cluster to the new ClusterClass. @@ -741,7 +741,7 @@ func rebaseClusterClassAndWait(ctx context.Context, input rebaseClusterClassAndW // Verify that the ControlPlane has not been changed. // NOTE: MachineDeployments are rolled out before the ControlPlane. Thus, we know that the // ControlPlane would have been updated by now, if there have been any changes. - afterControlPlane, err := external.Get(ctx, mgmtClient, controlPlaneRef, input.ClusterClass.Namespace) + afterControlPlane, err := external.Get(ctx, mgmtClient, controlPlaneRef) Expect(err).ToNot(HaveOccurred()) Expect(afterControlPlane.GetGeneration()).To(Equal(beforeControlPlane.GetGeneration()), "ControlPlane generation should not be incremented during the rebase because ControlPlane should not be affected.") diff --git a/test/e2e/clusterclass_rollout.go b/test/e2e/clusterclass_rollout.go index 84a1233292b2..da8ea05788ab 100644 --- a/test/e2e/clusterclass_rollout.go +++ b/test/e2e/clusterclass_rollout.go @@ -1058,31 +1058,31 @@ func getClusterClassObjects(ctx context.Context, g Gomega, clusterProxy framewor } var err error - res.InfrastructureClusterTemplate, err = external.Get(ctx, mgmtClient, clusterClass.Spec.Infrastructure.Ref, clusterClass.Namespace) + res.InfrastructureClusterTemplate, err = external.Get(ctx, mgmtClient, clusterClass.Spec.Infrastructure.Ref) g.Expect(err).ToNot(HaveOccurred()) - res.ControlPlaneTemplate, err = external.Get(ctx, mgmtClient, clusterClass.Spec.ControlPlane.Ref, clusterClass.Namespace) + res.ControlPlaneTemplate, err = external.Get(ctx, mgmtClient, clusterClass.Spec.ControlPlane.Ref) g.Expect(err).ToNot(HaveOccurred()) - res.ControlPlaneInfrastructureMachineTemplate, err = external.Get(ctx, mgmtClient, clusterClass.Spec.ControlPlane.MachineInfrastructure.Ref, clusterClass.Namespace) + res.ControlPlaneInfrastructureMachineTemplate, err = external.Get(ctx, mgmtClient, clusterClass.Spec.ControlPlane.MachineInfrastructure.Ref) g.Expect(err).ToNot(HaveOccurred()) for _, mdClass := range clusterClass.Spec.Workers.MachineDeployments { - infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, mdClass.Template.Infrastructure.Ref, clusterClass.Namespace) + infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, mdClass.Template.Infrastructure.Ref) g.Expect(err).ToNot(HaveOccurred()) res.InfrastructureMachineTemplateByMachineDeploymentClass[mdClass.Class] = infrastructureMachineTemplate - bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, mdClass.Template.Bootstrap.Ref, clusterClass.Namespace) + bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, mdClass.Template.Bootstrap.Ref) g.Expect(err).ToNot(HaveOccurred()) res.BootstrapConfigTemplateByMachineDeploymentClass[mdClass.Class] = bootstrapConfigTemplate } for _, mpClass := range clusterClass.Spec.Workers.MachinePools { - infrastructureMachinePoolTemplate, err := external.Get(ctx, mgmtClient, mpClass.Template.Infrastructure.Ref, clusterClass.Namespace) + infrastructureMachinePoolTemplate, err := external.Get(ctx, mgmtClient, mpClass.Template.Infrastructure.Ref) g.Expect(err).ToNot(HaveOccurred()) res.InfrastructureMachinePoolTemplateByMachinePoolClass[mpClass.Class] = infrastructureMachinePoolTemplate - bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, mpClass.Template.Bootstrap.Ref, clusterClass.Namespace) + bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, mpClass.Template.Bootstrap.Ref) g.Expect(err).ToNot(HaveOccurred()) res.BootstrapConfigTemplateByMachinePoolClass[mpClass.Class] = bootstrapConfigTemplate } @@ -1133,15 +1133,15 @@ func getClusterObjects(ctx context.Context, g Gomega, clusterProxy framework.Clu var err error // InfrastructureCluster - res.InfrastructureCluster, err = external.Get(ctx, mgmtClient, cluster.Spec.InfrastructureRef, cluster.Namespace) + res.InfrastructureCluster, err = external.Get(ctx, mgmtClient, cluster.Spec.InfrastructureRef) g.Expect(err).ToNot(HaveOccurred()) // ControlPlane - res.ControlPlane, err = external.Get(ctx, mgmtClient, cluster.Spec.ControlPlaneRef, cluster.Namespace) + res.ControlPlane, err = external.Get(ctx, mgmtClient, cluster.Spec.ControlPlaneRef) g.Expect(err).ToNot(HaveOccurred()) controlPlaneInfrastructureMachineTemplateRef, err := contract.ControlPlane().MachineTemplate().InfrastructureRef().Get(res.ControlPlane) g.Expect(err).ToNot(HaveOccurred()) - res.ControlPlaneInfrastructureMachineTemplate, err = external.Get(ctx, mgmtClient, controlPlaneInfrastructureMachineTemplateRef, cluster.Namespace) + res.ControlPlaneInfrastructureMachineTemplate, err = external.Get(ctx, mgmtClient, controlPlaneInfrastructureMachineTemplateRef) g.Expect(err).ToNot(HaveOccurred()) controlPlaneMachineList := &clusterv1.MachineList{} g.Expect(mgmtClient.List(ctx, controlPlaneMachineList, client.InNamespace(cluster.Namespace), client.MatchingLabels{ @@ -1154,7 +1154,7 @@ func getClusterObjects(ctx context.Context, g Gomega, clusterProxy framework.Clu g.Expect(controlPlaneMachineList.Items).To(HaveLen(int(*replicas))) for _, machine := range controlPlaneMachineList.Items { res.ControlPlaneMachines = append(res.ControlPlaneMachines, &machine) - addMachineObjects(ctx, mgmtClient, workloadClient, g, res, cluster, &machine) + addMachineObjects(ctx, mgmtClient, workloadClient, g, res, &machine) } // MachineDeployments. @@ -1168,11 +1168,11 @@ func getClusterObjects(ctx context.Context, g Gomega, clusterProxy framework.Clu md := mdList.Items[0] res.MachineDeployments = append(res.MachineDeployments, &md) - bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, md.Spec.Template.Spec.Bootstrap.ConfigRef, cluster.Namespace) + bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, md.Spec.Template.Spec.Bootstrap.ConfigRef) g.Expect(err).ToNot(HaveOccurred()) res.BootstrapConfigTemplateByMachineDeployment[md.Name] = bootstrapConfigTemplate - infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, &md.Spec.Template.Spec.InfrastructureRef, cluster.Namespace) + infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, &md.Spec.Template.Spec.InfrastructureRef) g.Expect(err).ToNot(HaveOccurred()) res.InfrastructureMachineTemplateByMachineDeployment[md.Name] = infrastructureMachineTemplate @@ -1191,7 +1191,7 @@ func getClusterObjects(ctx context.Context, g Gomega, clusterProxy framework.Clu for _, machine := range machines { res.MachinesByMachineSet[machine.Labels[clusterv1.MachineSetNameLabel]] = append( res.MachinesByMachineSet[machine.Labels[clusterv1.MachineSetNameLabel]], &machine) - addMachineObjects(ctx, mgmtClient, workloadClient, g, res, cluster, &machine) + addMachineObjects(ctx, mgmtClient, workloadClient, g, res, &machine) } } @@ -1206,11 +1206,11 @@ func getClusterObjects(ctx context.Context, g Gomega, clusterProxy framework.Clu mp := mpList.Items[0] res.MachinePools = append(res.MachinePools, &mp) - bootstrapConfig, err := external.Get(ctx, mgmtClient, mp.Spec.Template.Spec.Bootstrap.ConfigRef, cluster.Namespace) + bootstrapConfig, err := external.Get(ctx, mgmtClient, mp.Spec.Template.Spec.Bootstrap.ConfigRef) g.Expect(err).ToNot(HaveOccurred()) res.BootstrapConfigByMachinePool[mp.Name] = bootstrapConfig - infrastructureMachinePool, err := external.Get(ctx, mgmtClient, &mp.Spec.Template.Spec.InfrastructureRef, cluster.Namespace) + infrastructureMachinePool, err := external.Get(ctx, mgmtClient, &mp.Spec.Template.Spec.InfrastructureRef) g.Expect(err).ToNot(HaveOccurred()) res.InfrastructureMachinePoolByMachinePool[mp.Name] = infrastructureMachinePool } @@ -1219,12 +1219,12 @@ func getClusterObjects(ctx context.Context, g Gomega, clusterProxy framework.Clu } // addMachineObjects adds objects related to the Machine (BootstrapConfig, InfraMachine, Node) to clusterObjects. -func addMachineObjects(ctx context.Context, mgmtClient, workloadClient client.Client, g Gomega, res clusterObjects, cluster *clusterv1.Cluster, machine *clusterv1.Machine) { - bootstrapConfig, err := external.Get(ctx, mgmtClient, machine.Spec.Bootstrap.ConfigRef, cluster.Namespace) +func addMachineObjects(ctx context.Context, mgmtClient, workloadClient client.Client, g Gomega, res clusterObjects, machine *clusterv1.Machine) { + bootstrapConfig, err := external.Get(ctx, mgmtClient, machine.Spec.Bootstrap.ConfigRef) g.Expect(err).ToNot(HaveOccurred()) res.BootstrapConfigByMachine[machine.Name] = bootstrapConfig - infrastructureMachine, err := external.Get(ctx, mgmtClient, &machine.Spec.InfrastructureRef, cluster.Namespace) + infrastructureMachine, err := external.Get(ctx, mgmtClient, &machine.Spec.InfrastructureRef) g.Expect(err).ToNot(HaveOccurred()) res.InfrastructureMachineByMachine[machine.Name] = infrastructureMachine @@ -1266,7 +1266,7 @@ func modifyControlPlaneViaClusterAndWait(ctx context.Context, input modifyContro // Get the ControlPlane. controlPlaneRef := input.Cluster.Spec.ControlPlaneRef controlPlaneTopology := input.Cluster.Spec.Topology.ControlPlane - controlPlane, err := external.Get(ctx, mgmtClient, controlPlaneRef, input.Cluster.Namespace) + controlPlane, err := external.Get(ctx, mgmtClient, controlPlaneRef) g.Expect(err).ToNot(HaveOccurred()) // Verify that the fields from Cluster topology are set on the control plane. diff --git a/test/e2e/clusterctl_upgrade.go b/test/e2e/clusterctl_upgrade.go index 7806eebfd36b..de179e9639f8 100644 --- a/test/e2e/clusterctl_upgrade.go +++ b/test/e2e/clusterctl_upgrade.go @@ -903,7 +903,7 @@ func calculateExpectedMachinePoolMachineCount(ctx context.Context, c client.Clie client.MatchingLabels{clusterv1.ClusterNameLabel: workloadClusterName}, ); err == nil { for _, mp := range machinePoolList.Items { - infraMachinePool, err := external.Get(ctx, c, &mp.Spec.Template.Spec.InfrastructureRef, workloadClusterNamespace) + infraMachinePool, err := external.Get(ctx, c, &mp.Spec.Template.Spec.InfrastructureRef) if err != nil { return 0, err }