From adfb0a25481fd5734d72545b5c2acb5c045df1ff Mon Sep 17 00:00:00 2001 From: qiaozp Date: Sat, 3 Sep 2022 17:21:28 +0800 Subject: [PATCH] fix test Signed-off-by: qiaozp --- .../multicluster_test.go | 24 +++++++------------ test/e2e-multicluster-test/suite_test.go | 4 ++++ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/test/e2e-multicluster-test/multicluster_test.go b/test/e2e-multicluster-test/multicluster_test.go index 9174caccc..c22284263 100644 --- a/test/e2e-multicluster-test/multicluster_test.go +++ b/test/e2e-multicluster-test/multicluster_test.go @@ -21,32 +21,30 @@ import ( "encoding/json" "fmt" "io/ioutil" - v1 "k8s.io/api/authentication/v1" "os" "strings" "time" - "k8s.io/apimachinery/pkg/runtime" - - "github.com/oam-dev/kubevela/apis/core.oam.dev/common" - "github.com/oam-dev/kubevela/pkg/oam" - "github.com/oam-dev/kubevela/pkg/utils" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" + v1 "k8s.io/api/authentication/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/clientcmd" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/yaml" + "github.com/oam-dev/kubevela/apis/core.oam.dev/common" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha1" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" "github.com/oam-dev/kubevela/pkg/multicluster" + "github.com/oam-dev/kubevela/pkg/oam" + "github.com/oam-dev/kubevela/pkg/utils" ) func initializeContext() (hubCtx context.Context, workerCtx context.Context) { @@ -177,22 +175,16 @@ var _ = Describe("Test multicluster scenario", func() { }() serviceAccount = &corev1.ServiceAccount{} By("Generating a token for SA") - tr := &v1.TokenRequest{ - ObjectMeta: metav1.ObjectMeta{ - Name: serviceAccountName, - Namespace: serviceAccountNamespace, - }, - } - err := k8sClient.Create(workerCtx, tr, nil) + tr := &v1.TokenRequest{} + token, err := k8sCli.CoreV1().ServiceAccounts(serviceAccountNamespace).CreateToken(workerCtx, serviceAccountName, tr, metav1.CreateOptions{}) Expect(err).Should(BeNil()) - token := tr.Status.Token config, err := clientcmd.LoadFromFile(WorkerClusterKubeConfigPath) Expect(err).Should(Succeed()) currentContext, ok := config.Contexts[config.CurrentContext] Expect(ok).Should(BeTrue()) authInfo, ok := config.AuthInfos[currentContext.AuthInfo] Expect(ok).Should(BeTrue()) - authInfo.Token = string(token) + authInfo.Token = token.Status.Token authInfo.ClientKeyData = nil authInfo.ClientCertificateData = nil kubeconfigFilePath := fmt.Sprintf("/tmp/worker.sa-%d.kubeconfig", key) diff --git a/test/e2e-multicluster-test/suite_test.go b/test/e2e-multicluster-test/suite_test.go index 2d3d5427b..ae571779d 100644 --- a/test/e2e-multicluster-test/suite_test.go +++ b/test/e2e-multicluster-test/suite_test.go @@ -18,6 +18,7 @@ package e2e_multicluster_test import ( "context" + "k8s.io/client-go/kubernetes" "testing" "time" @@ -44,6 +45,7 @@ const ( var ( k8sClient client.Client + k8sCli kubernetes.Interface ) func execCommand(args ...string) (string, error) { @@ -70,6 +72,8 @@ var _ = BeforeSuite(func() { config.Wrap(multicluster.NewSecretModeMultiClusterRoundTripper) k8sClient, err = client.New(config, options) Expect(err).Should(Succeed()) + k8sCli, err = kubernetes.NewForConfig(config) + Expect(err).Should(Succeed()) // join worker cluster _, err = execCommand("cluster", "join", WorkerClusterKubeConfigPath, "--name", WorkerClusterName)