From f1007e3eac5dea3f7f208fdfe543fb826f3373d7 Mon Sep 17 00:00:00 2001 From: liuwei Date: Sun, 27 Sep 2020 17:47:00 +0800 Subject: [PATCH] enhance agent recovery integration test --- test/integration/spokeagent_recovery_test.go | 25 +++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/test/integration/spokeagent_recovery_test.go b/test/integration/spokeagent_recovery_test.go index 3e008bc8a..cb706b530 100644 --- a/test/integration/spokeagent_recovery_test.go +++ b/test/integration/spokeagent_recovery_test.go @@ -3,6 +3,7 @@ package integration_test import ( "context" "path" + "reflect" "time" "github.com/onsi/ginkgo" @@ -14,6 +15,7 @@ import ( "github.com/openshift/library-go/pkg/controller/controllercmd" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" ) @@ -167,6 +169,16 @@ var _ = ginkgo.Describe("Agent Recovery", func() { err = util.ApproveSpokeClusterCSRWithExpiredCert(kubeClient, spokeClusterName) gomega.Expect(err).NotTo(gomega.HaveOccurred()) + var firstHubKubeConfigSecret *corev1.Secret + // the hub kubeconfig secret should be filled after the csr is approved + gomega.Eventually(func() bool { + firstHubKubeConfigSecret, err = util.GetFilledHubKubeConfigSecret(kubeClient, testNamespace, hubKubeconfigSecret) + if err != nil { + return false + } + return true + }, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue()) + // agent should bootstrap again due to the invalid hub config var secondCSRName string gomega.Eventually(func() bool { @@ -181,15 +193,22 @@ var _ = ginkgo.Describe("Agent Recovery", func() { // a new csr should be recreated gomega.Expect(firstCSRName).ShouldNot(gomega.BeEquivalentTo(secondCSRName)) - // approve the new csr + // approve the new csr with a valid hub config err = util.ApproveSpokeClusterCSR(kubeClient, spokeClusterName, time.Hour*24) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - // the hub kubeconfig secret should be filled after the csr is approved + // wait the hub kubeconfig secret is updated with the valid hub config gomega.Eventually(func() bool { - if _, err := util.GetFilledHubKubeConfigSecret(kubeClient, testNamespace, hubKubeconfigSecret); err != nil { + secondHubKubeConfigSecret, err := util.GetFilledHubKubeConfigSecret(kubeClient, testNamespace, hubKubeconfigSecret) + if err != nil { return false } + + // the hub kubeconfig secret should be updated + if reflect.DeepEqual(firstHubKubeConfigSecret.Data, secondHubKubeConfigSecret.Data) { + return false + } + return true }, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue())