Skip to content

Commit

Permalink
Merge pull request #8334 from killianmuldoon/pr-flaky-clusterresource…
Browse files Browse the repository at this point in the history
…set-test

🐛 Fix flaky wait in CRS test
  • Loading branch information
k8s-ci-robot authored Mar 22, 2023
2 parents 54503f5 + e7d0ab8 commit 03eb136
Showing 1 changed file with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -916,14 +916,6 @@ metadata:
ns := setup(t, g)
defer teardown(t, g, ns)

kubernetesAPIServerService := &corev1.Service{
TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "v1"},
ObjectMeta: metav1.ObjectMeta{
Name: "kubernetes",
Namespace: metav1.NamespaceDefault,
},
}

fakeService := &corev1.Service{
TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "v1"},
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -941,8 +933,9 @@ metadata:
},
}

kubernetesAPIServerService := &corev1.Service{}
t.Log("Verifying Kubernetes API Server Service has been created")
g.Expect(env.Get(ctx, client.ObjectKeyFromObject(kubernetesAPIServerService), kubernetesAPIServerService)).To(Succeed())
g.Expect(env.Get(ctx, client.ObjectKey{Name: "kubernetes", Namespace: metav1.NamespaceDefault}, kubernetesAPIServerService)).To(Succeed())

fakeService.Spec.ClusterIP = kubernetesAPIServerService.Spec.ClusterIP

Expand All @@ -958,7 +951,7 @@ metadata:
}
return nil
}, timeout).Should(Succeed())
g.Expect(apierrors.IsNotFound(env.Get(ctx, client.ObjectKeyFromObject(kubernetesAPIServerService), kubernetesAPIServerService))).To(BeTrue())
g.Expect(apierrors.IsNotFound(env.Get(ctx, client.ObjectKeyFromObject(kubernetesAPIServerService), &corev1.Service{}))).To(BeTrue())

clusterResourceSetInstance := &addonsv1.ClusterResourceSet{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -978,28 +971,27 @@ metadata:
g.Expect(env.Update(ctx, testCluster)).To(Succeed())

// ClusterResourceSetBinding for the Cluster is not created because the Kubernetes API Server Service doesn't exist.
clusterResourceSetBindingKey := client.ObjectKey{
Namespace: testCluster.Namespace,
Name: testCluster.Name,
}
clusterResourceSetBindingKey := client.ObjectKey{Namespace: testCluster.Namespace, Name: testCluster.Name}
g.Consistently(func() bool {
binding := &addonsv1.ClusterResourceSetBinding{}

err := env.Get(ctx, clusterResourceSetBindingKey, binding)
return apierrors.IsNotFound(err)
}, timeout).Should(BeTrue())

t.Log("Make sure Kubernetes API Server Service has been created")
t.Log("Create Kubernetes API Server Service")
g.Expect(env.Delete(ctx, fakeService)).Should(Succeed())
g.Eventually(func() bool {
err := env.Get(ctx, client.ObjectKeyFromObject(kubernetesAPIServerService), kubernetesAPIServerService)
return err == nil
}, timeout).Should(BeTrue())
kubernetesAPIServerService.ResourceVersion = ""
g.Expect(env.Create(ctx, kubernetesAPIServerService)).Should(Succeed())

// Label the CRS to trigger reconciliation.
labels["new"] = ""
clusterResourceSetInstance.SetLabels(labels)
g.Expect(env.Patch(ctx, clusterResourceSetInstance, client.MergeFrom(clusterResourceSetInstance.DeepCopy()))).To(Succeed())

// Wait until ClusterResourceSetBinding is created for the Cluster
g.Eventually(func() bool {
binding := &addonsv1.ClusterResourceSetBinding{}

err := env.Get(ctx, clusterResourceSetBindingKey, binding)
return err == nil
}, timeout).Should(BeTrue())
Expand Down

0 comments on commit 03eb136

Please sign in to comment.