Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sets the timeout for getting the attachecluster resource.
You can set it up here:

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, pollInterval).Should(gomega.Equal(true))
}

It will get the attachedcluster every time poolInterval until it succeeds or time over pollTimeout.

)
Loading