Skip to content

Commit

Permalink
Merge pull request #4333 from jwcesign/mcs-imp-e2e
Browse files Browse the repository at this point in the history
e2e: add mcs e2e with CrossCluster type
  • Loading branch information
karmada-bot authored Nov 30, 2023
2 parents 64d0873 + fb5993d commit 8ef8911
Show file tree
Hide file tree
Showing 4 changed files with 580 additions and 1 deletion.
72 changes: 72 additions & 0 deletions test/e2e/framework/mcs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright 2023 The Karmada 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 framework

import (
"context"
"fmt"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"

networkingv1alpha1 "github.com/karmada-io/karmada/pkg/apis/networking/v1alpha1"
karmada "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
)

// CreateMultiClusterService creates MultiClusterService with karmada client.
func CreateMultiClusterService(client karmada.Interface, mcs *networkingv1alpha1.MultiClusterService) {
ginkgo.By(fmt.Sprintf("Creating MultiClusterService(%s/%s)", mcs.Namespace, mcs.Name), func() {
_, err := client.NetworkingV1alpha1().MultiClusterServices(mcs.Namespace).Create(context.TODO(), mcs, metav1.CreateOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
}

// UpdateMultiClusterService updates MultiClusterService with karmada client.
func UpdateMultiClusterService(client karmada.Interface, mcs *networkingv1alpha1.MultiClusterService) {
ginkgo.By(fmt.Sprintf("Updating MultiClusterService(%s/%s)", mcs.Namespace, mcs.Name), func() {
gomega.Eventually(func() error {
mcsExist, err := client.NetworkingV1alpha1().MultiClusterServices(mcs.Namespace).Get(context.TODO(), mcs.Name, metav1.GetOptions{})
if err != nil {
return err
}
mcsExist.Spec = mcs.Spec
_, err = client.NetworkingV1alpha1().MultiClusterServices(mcsExist.Namespace).Update(context.TODO(), mcsExist, metav1.UpdateOptions{})
return err
}, pollTimeout, pollInterval).ShouldNot(gomega.HaveOccurred())
})
}

// RemoveMultiClusterService deletes MultiClusterService with karmada client.
func RemoveMultiClusterService(client karmada.Interface, namespace, name string) {
ginkgo.By(fmt.Sprintf("Removing MultiClusterService(%s/%s)", namespace, name), func() {
err := client.NetworkingV1alpha1().MultiClusterServices(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
}

// WaitMultiClusterServicePresentOnClustersFitWith waits MultiClusterService present on cluster sync with fit func.
func WaitMultiClusterServicePresentOnClustersFitWith(client karmada.Interface, namespace, name string, fit func(mcs *networkingv1alpha1.MultiClusterService) bool) {
klog.Infof("Waiting for MultiClusterService(%s/%s) fit", namespace, name)
gomega.Eventually(func() bool {
mcs, err := client.NetworkingV1alpha1().MultiClusterServices(namespace).Get(context.TODO(), name, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

return fit(mcs)
}, pollTimeout, pollInterval).Should(gomega.Equal(true))
}
Loading

0 comments on commit 8ef8911

Please sign in to comment.