2021-10-14 18:27:50 +08:00
|
|
|
/*
|
|
|
|
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"
|
|
|
|
"fmt"
|
2022-12-29 19:34:45 +08:00
|
|
|
"os"
|
2021-10-14 18:27:50 +08:00
|
|
|
"time"
|
|
|
|
|
2023-05-15 16:07:51 +08:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2021-10-14 18:27:50 +08:00
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
|
|
|
appsv1 "k8s.io/api/apps/v1"
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
"k8s.io/apimachinery/pkg/types"
|
|
|
|
|
|
|
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
|
|
|
"github.com/oam-dev/kubevela/apis/standard.oam.dev/v1alpha1"
|
|
|
|
"github.com/oam-dev/kubevela/pkg/oam/util"
|
|
|
|
|
|
|
|
"sigs.k8s.io/yaml"
|
|
|
|
)
|
|
|
|
|
2023-04-18 19:03:13 +08:00
|
|
|
var _ = PDescribe("Test MultiCluster Rollout", func() {
|
2021-10-14 18:27:50 +08:00
|
|
|
Context("Test Runtime Cluster Rollout", func() {
|
|
|
|
var namespace string
|
|
|
|
var hubCtx context.Context
|
|
|
|
var workerCtx context.Context
|
|
|
|
var rollout v1alpha1.Rollout
|
|
|
|
var componentName string
|
|
|
|
var targetDeploy appsv1.Deployment
|
|
|
|
var sourceDeploy appsv1.Deployment
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
hubCtx, workerCtx, namespace = initializeContextAndNamespace()
|
|
|
|
componentName = "hello-world-server"
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
cleanUpNamespace(hubCtx, workerCtx, namespace)
|
|
|
|
ns := v1.Namespace{}
|
2021-11-05 17:29:05 +08:00
|
|
|
Eventually(func() error { return k8sClient.Get(hubCtx, types.NamespacedName{Name: namespace}, &ns) }, 300*time.Second).Should(util.NotFoundMatcher{})
|
2021-10-14 18:27:50 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
verifySucceed := func(componentRevision string) {
|
|
|
|
By("check rollout status have succeed")
|
|
|
|
Eventually(func() error {
|
|
|
|
rolloutKey := types.NamespacedName{Namespace: namespace, Name: componentName}
|
|
|
|
if err := k8sClient.Get(workerCtx, rolloutKey, &rollout); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if rollout.Spec.TargetRevisionName != componentRevision {
|
|
|
|
return fmt.Errorf("rollout have not point to right targetRevision")
|
|
|
|
}
|
|
|
|
if rollout.Status.RollingState != v1alpha1.RolloutSucceedState {
|
|
|
|
return fmt.Errorf("error rollout status state %s", rollout.Status.RollingState)
|
|
|
|
}
|
|
|
|
compRevName := rollout.Spec.TargetRevisionName
|
|
|
|
deployKey := types.NamespacedName{Namespace: namespace, Name: compRevName}
|
|
|
|
if err := k8sClient.Get(workerCtx, deployKey, &targetDeploy); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if *targetDeploy.Spec.Replicas != *rollout.Spec.RolloutPlan.TargetSize {
|
|
|
|
return fmt.Errorf("targetDeploy replicas missMatch %d, %d", targetDeploy.Spec.Replicas, rollout.Spec.RolloutPlan.TargetSize)
|
|
|
|
}
|
|
|
|
if targetDeploy.Status.UpdatedReplicas != *targetDeploy.Spec.Replicas {
|
|
|
|
return fmt.Errorf("update not finish")
|
|
|
|
}
|
|
|
|
if rollout.Status.LastSourceRevision == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
deployKey = types.NamespacedName{Namespace: namespace, Name: rollout.Status.LastSourceRevision}
|
|
|
|
if err := k8sClient.Get(workerCtx, deployKey, &sourceDeploy); err == nil || !apierrors.IsNotFound(err) {
|
|
|
|
return fmt.Errorf("source deploy still exist")
|
|
|
|
}
|
|
|
|
return nil
|
2021-12-10 15:00:03 +08:00
|
|
|
}, time.Second*60).Should(BeNil())
|
2021-10-14 18:27:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
It("Test Rollout whole feature in runtime cluster ", func() {
|
|
|
|
app := &v1beta1.Application{}
|
2022-12-29 19:34:45 +08:00
|
|
|
appYaml, err := os.ReadFile("./testdata/app/app-rollout-envbinding.yaml")
|
2021-10-14 18:27:50 +08:00
|
|
|
Expect(err).Should(Succeed())
|
|
|
|
Expect(yaml.Unmarshal([]byte(appYaml), app)).Should(Succeed())
|
|
|
|
app.SetNamespace(namespace)
|
|
|
|
err = k8sClient.Create(hubCtx, app)
|
|
|
|
Expect(err).Should(Succeed())
|
|
|
|
verifySucceed(componentName + "-v1")
|
|
|
|
|
|
|
|
By("update application to v2")
|
|
|
|
checkApp := &v1beta1.Application{}
|
|
|
|
Eventually(func() error {
|
|
|
|
if err := k8sClient.Get(hubCtx, types.NamespacedName{Namespace: namespace, Name: app.Name}, checkApp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
checkApp.Spec.Components[0].Properties.Raw = []byte(`{"image": "stefanprodan/podinfo:5.0.2"}`)
|
|
|
|
if err := k8sClient.Update(hubCtx, checkApp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2021-11-05 17:29:05 +08:00
|
|
|
}, 30*time.Second).Should(BeNil())
|
2021-10-14 18:27:50 +08:00
|
|
|
verifySucceed(componentName + "-v2")
|
|
|
|
|
|
|
|
By("revert to v1, should guarantee compRev v1 still exist")
|
2022-12-29 19:34:45 +08:00
|
|
|
appYaml, err = os.ReadFile("./testdata/app/revert-app-envbinding.yaml")
|
2021-10-14 18:27:50 +08:00
|
|
|
Expect(err).Should(Succeed())
|
|
|
|
|
|
|
|
Expect(k8sClient.Get(hubCtx, types.NamespacedName{Namespace: namespace, Name: app.Name}, checkApp)).Should(BeNil())
|
|
|
|
revertApp := &v1beta1.Application{}
|
|
|
|
Expect(yaml.Unmarshal([]byte(appYaml), revertApp)).Should(Succeed())
|
|
|
|
revertApp.SetNamespace(namespace)
|
|
|
|
revertApp.SetResourceVersion(checkApp.ResourceVersion)
|
|
|
|
|
|
|
|
Eventually(func() error {
|
|
|
|
if err := k8sClient.Update(hubCtx, revertApp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2021-11-05 17:29:05 +08:00
|
|
|
}, 30*time.Second).Should(BeNil())
|
2021-10-14 18:27:50 +08:00
|
|
|
verifySucceed(componentName + "-v1")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|