Skip to content

Commit

Permalink
Added a function to determine if the attachedcluster was created in t…
Browse files Browse the repository at this point in the history
…he cluster (kurator-dev#598)

* Added a function to determine if the attachedcluster was created in the cluster

Signed-off-by: LiZhenCheng9527 <[email protected]>

* Reduced inspection intervals

Signed-off-by: LiZhenCheng9527 <[email protected]>

---------

Signed-off-by: LiZhenCheng9527 <[email protected]>
  • Loading branch information
LiZhenCheng9527 authored Feb 4, 2024
1 parent f81b410 commit fbb0ef7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion e2e/attachedcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down
12 changes: 12 additions & 0 deletions e2e/resources/attachedcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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))
}
26 changes: 26 additions & 0 deletions e2e/resources/constant.go
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit fbb0ef7

Please sign in to comment.