diff --git a/internal/controllers/topology/cluster/cluster_controller_test.go b/internal/controllers/topology/cluster/cluster_controller_test.go index e0d92dc43097..ec04af07bef5 100644 --- a/internal/controllers/topology/cluster/cluster_controller_test.go +++ b/internal/controllers/topology/cluster/cluster_controller_test.go @@ -121,7 +121,7 @@ func TestClusterReconciler_reconcileMultipleClustersFromOneClass(t *testing.T) { for _, name := range []string{clusterName1, clusterName2} { // Get the cluster object. actualCluster := &clusterv1.Cluster{} - if err := env.Get(ctx, client.ObjectKey{Name: name, Namespace: ns.Name}, actualCluster); err != nil { + if err := env.GetAPIReader().Get(ctx, client.ObjectKey{Name: name, Namespace: ns.Name}, actualCluster); err != nil { return err } @@ -167,7 +167,7 @@ func TestClusterReconciler_reconcileUpdateOnClusterTopology(t *testing.T) { // First ensure that the initial cluster and other objects are created and populated as expected. g.Eventually(func(g Gomega) error { // Get the cluster object now including the updated replica number for the Machine deployment. - if err := env.Get(ctx, client.ObjectKey{Name: clusterName1, Namespace: ns.Name}, actualCluster); err != nil { + if err := env.GetAPIReader().Get(ctx, client.ObjectKey{Name: clusterName1, Namespace: ns.Name}, actualCluster); err != nil { return err } @@ -200,7 +200,7 @@ func TestClusterReconciler_reconcileUpdateOnClusterTopology(t *testing.T) { g.Eventually(func(g Gomega) error { // Get the cluster object. updatedCluster := &clusterv1.Cluster{} - if err := env.Get(ctx, client.ObjectKey{Name: clusterName1, Namespace: ns.Name}, updatedCluster); err != nil { + if err := env.GetAPIReader().Get(ctx, client.ObjectKey{Name: clusterName1, Namespace: ns.Name}, updatedCluster); err != nil { return err } @@ -250,7 +250,7 @@ func TestClusterReconciler_reconcileUpdatesOnClusterClass(t *testing.T) { g.Eventually(func(g Gomega) error { for _, name := range []string{clusterName1, clusterName2} { // Get the cluster object. - if err := env.Get(ctx, client.ObjectKey{Name: name, Namespace: ns.Name}, actualCluster); err != nil { + if err := env.GetAPIReader().Get(ctx, client.ObjectKey{Name: name, Namespace: ns.Name}, actualCluster); err != nil { return err } @@ -274,7 +274,7 @@ func TestClusterReconciler_reconcileUpdatesOnClusterClass(t *testing.T) { // Get the clusterClass to update and check if clusterClass updates are being correctly reconciled. clusterClass := &clusterv1.ClusterClass{} - g.Expect(env.Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: actualCluster.Spec.Topology.Class}, clusterClass)).To(Succeed()) + g.Expect(env.GetAPIReader().Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: actualCluster.Spec.Topology.Class}, clusterClass)).To(Succeed()) patchHelper, err := patch.NewHelper(clusterClass, env.Client) g.Expect(err).ToNot(HaveOccurred()) @@ -286,7 +286,7 @@ func TestClusterReconciler_reconcileUpdatesOnClusterClass(t *testing.T) { // Check that the clusterClass has been correctly updated to use the new infrastructure template. // This is necessary as sometimes the cache can take a little time to update. class := &clusterv1.ClusterClass{} - g.Expect(env.Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: actualCluster.Spec.Topology.Class}, class)).To(Succeed()) + g.Expect(env.GetAPIReader().Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: actualCluster.Spec.Topology.Class}, class)).To(Succeed()) g.Expect(class.Spec.Workers.MachineDeployments[0].Template.Infrastructure.Ref.Name).To(Equal(infrastructureMachineTemplateName2)) // For each cluster check that the clusterClass changes have been correctly reconciled. @@ -294,7 +294,7 @@ func TestClusterReconciler_reconcileUpdatesOnClusterClass(t *testing.T) { // Get the cluster object. actualCluster = &clusterv1.Cluster{} - if err := env.Get(ctx, client.ObjectKey{Name: name, Namespace: ns.Name}, actualCluster); err != nil { + if err := env.GetAPIReader().Get(ctx, client.ObjectKey{Name: name, Namespace: ns.Name}, actualCluster); err != nil { return err } // Check if Cluster has relevant Infrastructure and ControlPlane and labels and annotations. @@ -340,7 +340,7 @@ func TestClusterReconciler_reconcileClusterClassRebase(t *testing.T) { // First ensure that the initial cluster and other objects are created and populated as expected. g.Eventually(func(g Gomega) error { // Get the cluster object. - if err := env.Get(ctx, client.ObjectKey{Name: clusterName1, Namespace: ns.Name}, actualCluster); err != nil { + if err := env.GetAPIReader().Get(ctx, client.ObjectKey{Name: clusterName1, Namespace: ns.Name}, actualCluster); err != nil { return err } @@ -369,7 +369,7 @@ func TestClusterReconciler_reconcileClusterClassRebase(t *testing.T) { g.Eventually(func(g Gomega) error { // Get the cluster object. updatedCluster := &clusterv1.Cluster{} - if err := env.Get(ctx, client.ObjectKey{Name: clusterName1, Namespace: ns.Name}, updatedCluster); err != nil { + if err := env.GetAPIReader().Get(ctx, client.ObjectKey{Name: clusterName1, Namespace: ns.Name}, updatedCluster); err != nil { return err } // Check to ensure the spec.topology.class has been successfully updated in the API server and cache. @@ -415,7 +415,7 @@ func TestClusterReconciler_deleteClusterClass(t *testing.T) { g.Eventually(func(g Gomega) error { for _, name := range []string{clusterName1, clusterName2} { // Get the cluster object. - if err := env.Get(ctx, client.ObjectKey{Name: name, Namespace: ns.Name}, actualCluster); err != nil { + if err := env.GetAPIReader().Get(ctx, client.ObjectKey{Name: name, Namespace: ns.Name}, actualCluster); err != nil { return err } @@ -436,7 +436,7 @@ func TestClusterReconciler_deleteClusterClass(t *testing.T) { // Ensure the clusterClass is available in the API server . clusterClass := &clusterv1.ClusterClass{} - g.Expect(env.Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: actualCluster.Spec.Topology.Class}, clusterClass)).To(Succeed()) + g.Expect(env.GetAPIReader().Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: actualCluster.Spec.Topology.Class}, clusterClass)).To(Succeed()) // Attempt to delete the ClusterClass. Expect an error here as the ClusterClass deletion is blocked by the webhook. g.Expect(env.Delete(ctx, clusterClass)).NotTo(Succeed()) @@ -732,7 +732,7 @@ func assertControlPlaneReconcile(cluster *clusterv1.Cluster) error { } } clusterClass := &clusterv1.ClusterClass{} - if err := env.Get(ctx, client.ObjectKey{Namespace: cluster.Namespace, Name: cluster.Spec.Topology.Class}, clusterClass); err != nil { + if err := env.GetAPIReader().Get(ctx, client.ObjectKey{Namespace: cluster.Namespace, Name: cluster.Spec.Topology.Class}, clusterClass); err != nil { return err } // Check for the ControlPlaneInfrastructure if it's referenced in the clusterClass. @@ -860,7 +860,7 @@ func getAndAssertLabelsAndAnnotations(template corev1.ObjectReference, clusterNa got.SetKind(template.Kind) got.SetAPIVersion(template.APIVersion) - if err := env.Get(ctx, client.ObjectKey{Name: template.Name, Namespace: template.Namespace}, got); err != nil { + if err := env.GetAPIReader().Get(ctx, client.ObjectKey{Name: template.Name, Namespace: template.Namespace}, got); err != nil { return nil, err }