Skip to content

Commit

Permalink
use apireader to deflake test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Jun 24, 2022
1 parent a498519 commit d3748ce
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions internal/controllers/topology/cluster/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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())
Expand All @@ -286,15 +286,15 @@ 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.
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
}
// Check if Cluster has relevant Infrastructure and ControlPlane and labels and annotations.
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand All @@ -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())
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit d3748ce

Please sign in to comment.