mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
CodeQL / Analyze (go) (push) Failing after 6m23s
Definition-Lint / definition-doc (push) Failing after 3m8s
E2E MultiCluster Test / detect-noop (push) Successful in 6s
E2E Test / detect-noop (push) Successful in 3s
Go / detect-noop (push) Successful in 2s
license / Check for unapproved licenses (push) Failing after 18s
Registry / publish-core-images (push) Failing after 1m4s
Unit-Test / detect-noop (push) Successful in 20s
Sync SDK / sync_sdk (push) Failing after 3m9s
Go / staticcheck (push) Successful in 6m17s
Go / check-diff (push) Failing after 19m4s
Go / check-core-image-build (push) Failing after 5m44s
Go / check-cli-image-build (push) Failing after 3m31s
Unit-Test / unit-tests (push) Failing after 13m54s
Go / lint (push) Failing after 1h53m27s
Scorecards supply-chain security / Scorecards analysis (push) Failing after 1m27s
E2E MultiCluster Test / e2e-multi-cluster-tests (v1.29) (push) Has been cancelled
E2E Test / e2e-tests (v1.29) (push) Has been cancelled
Go / check-windows (push) Has been cancelled
* chore: update k8s to 1.29 Signed-off-by: phantomnat <w.nattadej@gmail.com> * fix: unit test Signed-off-by: phantomnat <w.nattadej@gmail.com> * fix: lint Signed-off-by: phantomnat <w.nattadej@gmail.com> * fix: lint Signed-off-by: phantomnat <w.nattadej@gmail.com> * fix: e2e Signed-off-by: phantomnat <w.nattadej@gmail.com> * fix: lint and e2e test Signed-off-by: phantomnat <w.nattadej@gmail.com> * test(e2e): increase timeout Signed-off-by: phantomnat <w.nattadej@gmail.com> * fix e2e and scripts Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com> * make reviewable Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com> * rollback a unnecessary ut change Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com> * update go.mod to import merged workflow Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com> --------- Signed-off-by: phantomnat <w.nattadej@gmail.com> Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com> Co-authored-by: phantomnat <w.nattadej@gmail.com>
123 lines
4.2 KiB
Go
123 lines
4.2 KiB
Go
/*
|
|
Copyright 2021 The KubeVela 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 e2e_multicluster_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/kubernetes"
|
|
"k8s.io/klog/v2/textlogger"
|
|
"k8s.io/utils/strings/slices"
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/client/config"
|
|
|
|
"github.com/kubevela/pkg/multicluster"
|
|
|
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
|
"github.com/oam-dev/kubevela/apis/types"
|
|
multicluster2 "github.com/oam-dev/kubevela/pkg/multicluster"
|
|
oamutil "github.com/oam-dev/kubevela/pkg/oam/util"
|
|
"github.com/oam-dev/kubevela/pkg/utils/common"
|
|
"github.com/oam-dev/kubevela/pkg/utils/util"
|
|
"github.com/oam-dev/kubevela/references/cli"
|
|
)
|
|
|
|
const (
|
|
WorkerClusterName = "cluster-worker"
|
|
WorkerClusterKubeConfigPath = "/tmp/worker.kubeconfig"
|
|
)
|
|
|
|
var (
|
|
k8sClient client.Client
|
|
k8sCli kubernetes.Interface
|
|
)
|
|
|
|
func execCommand(args ...string) (string, error) {
|
|
ioStream, buf := util.NewTestIOStreams()
|
|
command := cli.NewCommandWithIOStreams(ioStream)
|
|
command.SetArgs(args)
|
|
command.SetOut(buf)
|
|
command.SetErr(buf)
|
|
err := command.Execute()
|
|
return buf.String(), err
|
|
}
|
|
|
|
func TestMulticluster(t *testing.T) {
|
|
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
|
|
RegisterFailHandler(Fail)
|
|
RunSpecs(t, "KubeVela MultiCluster Test Suite")
|
|
}
|
|
|
|
var _ = BeforeSuite(func() {
|
|
var err error
|
|
|
|
// initialize clients
|
|
options := client.Options{Scheme: common.Scheme}
|
|
config := config.GetConfigOrDie()
|
|
config.Wrap(multicluster.NewTransportWrapper())
|
|
k8sClient, err = multicluster.NewClient(config, multicluster.ClientOptions{Options: options})
|
|
Expect(err).Should(Succeed())
|
|
k8sCli, err = kubernetes.NewForConfig(config)
|
|
Expect(err).Should(Succeed())
|
|
|
|
// join worker cluster
|
|
_, err = execCommand("cluster", "join", WorkerClusterKubeConfigPath, "--name", WorkerClusterName, "-y")
|
|
Expect(err).Should(Succeed())
|
|
cv, err := multicluster2.GetVersionInfoFromCluster(context.Background(), WorkerClusterName, config)
|
|
Expect(err).Should(Succeed())
|
|
Expect(cv.Minor).Should(Not(BeEquivalentTo("")))
|
|
Expect(cv.Major).Should(BeEquivalentTo("1"))
|
|
ocv := multicluster2.GetVersionInfoFromObject(context.Background(), k8sClient, WorkerClusterName)
|
|
Expect(ocv).Should(BeEquivalentTo(cv))
|
|
})
|
|
|
|
var _ = AfterSuite(func() {
|
|
holdAddons := []string{"addon-terraform", "addon-fluxcd"}
|
|
Eventually(func(g Gomega) {
|
|
apps := &v1beta1.ApplicationList{}
|
|
g.Expect(k8sClient.List(context.Background(), apps)).Should(Succeed())
|
|
for _, app := range apps.Items {
|
|
if slices.Contains(holdAddons, app.Name) {
|
|
continue
|
|
}
|
|
g.Expect(k8sClient.Delete(context.Background(), app.DeepCopy())).Should(Succeed())
|
|
}
|
|
}, 3*time.Minute).Should(Succeed())
|
|
Eventually(func(g Gomega) {
|
|
// Delete terraform and fluxcd in order
|
|
app := &v1beta1.Application{}
|
|
apps := &v1beta1.ApplicationList{}
|
|
for _, addon := range holdAddons {
|
|
g.Expect(k8sClient.Delete(context.Background(), &v1beta1.Application{ObjectMeta: v1.ObjectMeta{Name: addon, Namespace: types.DefaultKubeVelaNS}})).Should(SatisfyAny(Succeed(), oamutil.NotFoundMatcher{}))
|
|
g.Expect(k8sClient.Get(context.Background(), client.ObjectKey{Name: addon, Namespace: types.DefaultKubeVelaNS}, app)).Should(SatisfyAny(Succeed(), oamutil.NotFoundMatcher{}))
|
|
}
|
|
err := k8sClient.List(context.Background(), apps)
|
|
g.Expect(err, nil)
|
|
g.Expect(len(apps.Items)).Should(Equal(0))
|
|
}, 5*time.Minute).Should(Succeed())
|
|
Eventually(func(g Gomega) {
|
|
_, err := execCommand("cluster", "detach", WorkerClusterName)
|
|
g.Expect(err).Should(Succeed())
|
|
}, time.Minute).Should(Succeed())
|
|
})
|