diff --git a/e2e/attachedcluster_test.go b/e2e/attachedcluster_test.go index 4b5810cc..34606591 100644 --- a/e2e/attachedcluster_test.go +++ b/e2e/attachedcluster_test.go @@ -93,8 +93,10 @@ var _ = ginkgo.Describe("[AttachedClusters] AttachedClusters testing", func() { // step 2.create attachedclusters attachedCreateErr := resources.CreateAttachedCluster(kuratorClient, attachedcluster) gomega.Expect(attachedCreateErr).ShouldNot(gomega.HaveOccurred()) + resources.WaitAttachedClusterFitWith(kuratorClient, namespace, memberClusterName, func(attachedCluster *clusterv1a1.AttachedCluster) bool { + return attachedCluster.Status.Ready + }) - time.Sleep(3 * time.Second) // step 3.create fleet clusters := []*corev1.ObjectReference{ { diff --git a/e2e/resources/attachedcluster.go b/e2e/resources/attachedcluster.go index cc1bf72b..7eadd4a7 100644 --- a/e2e/resources/attachedcluster.go +++ b/e2e/resources/attachedcluster.go @@ -19,6 +19,7 @@ package resources import ( "context" + "github.com/onsi/gomega" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -75,3 +76,14 @@ func RemoveAttachedCluster(client kurator.Interface, namespace, name string) err } return nil } + +// WaitAttachedClusterFitWith wait attachedCluster sync with fit func. +func WaitAttachedClusterFitWith(client kurator.Interface, namespace, name string, fit func(attachedCluster *clusterv1a1.AttachedCluster) bool) { + gomega.Eventually(func() bool { + attachedClusterPresentOnCluster, err := client.ClusterV1alpha1().AttachedClusters(namespace).Get(context.TODO(), name, metav1.GetOptions{}) + if err != nil { + return false + } + return fit(attachedClusterPresentOnCluster) + }, pollTimeout, pollIntervalInHostCluster).Should(gomega.Equal(true)) +} diff --git a/e2e/resources/constant.go b/e2e/resources/constant.go new file mode 100644 index 00000000..1faeb185 --- /dev/null +++ b/e2e/resources/constant.go @@ -0,0 +1,26 @@ +/* +Copyright Kurator Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package resources + +import "time" + +const ( + // pollIntervalInHostCluster defines the interval time for a poll operation. + pollIntervalInHostCluster = 3 * time.Second + // pollTimeout defines the time after which the poll operation times out. + pollTimeout = 420 * time.Second +)