mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-14 18:10:21 +00:00
more useful vela system dry-run
This commit is contained in:
@@ -4,13 +4,11 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -21,6 +19,7 @@ import (
|
||||
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
|
||||
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||
"github.com/oam-dev/kubevela/pkg/utils/common"
|
||||
)
|
||||
|
||||
var _ = Describe("Versioning mechanism of components", func() {
|
||||
@@ -307,7 +306,7 @@ var _ = Describe("Versioning mechanism of components", func() {
|
||||
|
||||
By("Create trait definition")
|
||||
var td v1alpha2.TraitDefinition
|
||||
Expect(readYaml("testdata/revision/trait-def.yaml", &td)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/revision/trait-def.yaml", &td)).Should(BeNil())
|
||||
|
||||
var gtd v1alpha2.TraitDefinition
|
||||
if err := k8sClient.Get(ctx, client.ObjectKey{Name: td.Name, Namespace: td.Namespace}, >d); err != nil {
|
||||
@@ -319,12 +318,12 @@ var _ = Describe("Versioning mechanism of components", func() {
|
||||
|
||||
By("Create Component v1")
|
||||
var comp1 v1alpha2.Component
|
||||
Expect(readYaml("testdata/revision/comp-v1.yaml", &comp1)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/revision/comp-v1.yaml", &comp1)).Should(BeNil())
|
||||
Expect(k8sClient.Create(ctx, &comp1)).Should(Succeed())
|
||||
|
||||
By("Create AppConfig with component")
|
||||
var appconfig v1alpha2.ApplicationConfiguration
|
||||
Expect(readYaml("testdata/revision/app.yaml", &appconfig)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/revision/app.yaml", &appconfig)).Should(BeNil())
|
||||
Expect(k8sClient.Create(ctx, &appconfig)).Should(Succeed())
|
||||
|
||||
By("Get Component latest status after ControllerRevision created")
|
||||
@@ -351,7 +350,7 @@ var _ = Describe("Versioning mechanism of components", func() {
|
||||
|
||||
By("Create Component v2")
|
||||
var comp2 v1alpha2.Component
|
||||
Expect(readYaml("testdata/revision/comp-v2.yaml", &comp2)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/revision/comp-v2.yaml", &comp2)).Should(BeNil())
|
||||
comp2.ResourceVersion = comp1.ResourceVersion
|
||||
Expect(k8sClient.Update(ctx, &comp2)).Should(Succeed())
|
||||
|
||||
@@ -411,7 +410,7 @@ var _ = Describe("Versioning mechanism of components", func() {
|
||||
|
||||
By("Create trait definition")
|
||||
var td v1alpha2.TraitDefinition
|
||||
Expect(readYaml("testdata/revision/trait-def-no-revision.yaml", &td)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/revision/trait-def-no-revision.yaml", &td)).Should(BeNil())
|
||||
var gtd v1alpha2.TraitDefinition
|
||||
if err := k8sClient.Get(ctx, client.ObjectKey{Name: td.Name, Namespace: td.Namespace}, >d); err != nil {
|
||||
Expect(k8sClient.Create(ctx, &td)).Should(Succeed())
|
||||
@@ -422,12 +421,12 @@ var _ = Describe("Versioning mechanism of components", func() {
|
||||
|
||||
By("Create Component v1")
|
||||
var comp1 v1alpha2.Component
|
||||
Expect(readYaml("testdata/revision/comp-v1.yaml", &comp1)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/revision/comp-v1.yaml", &comp1)).Should(BeNil())
|
||||
Expect(k8sClient.Create(ctx, &comp1)).Should(Succeed())
|
||||
|
||||
By("Create AppConfig with component")
|
||||
var appconfig v1alpha2.ApplicationConfiguration
|
||||
Expect(readYaml("testdata/revision/app.yaml", &appconfig)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/revision/app.yaml", &appconfig)).Should(BeNil())
|
||||
Expect(k8sClient.Create(ctx, &appconfig)).Should(Succeed())
|
||||
|
||||
By("Workload created with component name")
|
||||
@@ -445,7 +444,7 @@ var _ = Describe("Versioning mechanism of components", func() {
|
||||
|
||||
By("Create Component v2")
|
||||
var comp2 v1alpha2.Component
|
||||
Expect(readYaml("testdata/revision/comp-v2.yaml", &comp2)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/revision/comp-v2.yaml", &comp2)).Should(BeNil())
|
||||
Eventually(func() error {
|
||||
tmp := &v1alpha2.Component{}
|
||||
k8sClient.Get(ctx, client.ObjectKey{Namespace: namespace, Name: componentName}, tmp)
|
||||
@@ -486,14 +485,6 @@ var _ = Describe("Versioning mechanism of components", func() {
|
||||
})
|
||||
})
|
||||
|
||||
func readYaml(path string, object runtime.Object) error {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return yaml.Unmarshal(data, object)
|
||||
}
|
||||
|
||||
var _ = Describe("Component revision", func() {
|
||||
ctx := context.Background()
|
||||
apiVersion := "core.oam.dev/v1alpha2"
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/oam-dev/kubevela/pkg/controller/utils"
|
||||
"github.com/oam-dev/kubevela/pkg/oam"
|
||||
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||
"github.com/oam-dev/kubevela/pkg/utils/common"
|
||||
)
|
||||
|
||||
var _ = Describe("Cloneset based rollout tests", func() {
|
||||
@@ -64,7 +65,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
CreateClonesetDef := func() {
|
||||
By("Install CloneSet based componentDefinition")
|
||||
var cd v1alpha2.ComponentDefinition
|
||||
Expect(readYaml("testdata/rollout/cloneset/clonesetDefinition.yaml", &cd)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/rollout/cloneset/clonesetDefinition.yaml", &cd)).Should(BeNil())
|
||||
// create the componentDefinition if not exist
|
||||
Eventually(
|
||||
func() error {
|
||||
@@ -104,7 +105,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
ApplySourceApp := func() {
|
||||
By("Apply an application")
|
||||
var newApp v1alpha2.Application
|
||||
Expect(readYaml("testdata/rollout/cloneset/app-source.yaml", &newApp)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/rollout/cloneset/app-source.yaml", &newApp)).Should(BeNil())
|
||||
newApp.Namespace = namespace
|
||||
Expect(k8sClient.Create(ctx, &newApp)).Should(Succeed())
|
||||
|
||||
@@ -141,7 +142,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
ApplyTargetApp := func() {
|
||||
By("Update the application to target spec during rolling")
|
||||
var targetApp v1alpha2.Application
|
||||
Expect(readYaml("testdata/rollout/cloneset/app-target.yaml", &targetApp)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/rollout/cloneset/app-target.yaml", &targetApp)).Should(BeNil())
|
||||
|
||||
Eventually(
|
||||
func() error {
|
||||
@@ -257,7 +258,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
|
||||
By("Revert the application back to source")
|
||||
var sourceApp v1alpha2.Application
|
||||
Expect(readYaml("testdata/rollout/cloneset/app-source.yaml", &sourceApp)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/rollout/cloneset/app-source.yaml", &sourceApp)).Should(BeNil())
|
||||
sourceApp.SetAnnotations(util.MergeMapOverrideWithDst(app.GetAnnotations(),
|
||||
map[string]string{oam.AnnotationRollingComponent: app.Spec.Components[0].Name,
|
||||
oam.AnnotationAppRollout: strconv.FormatBool(true)}))
|
||||
@@ -320,7 +321,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
ApplyTwoAppVersion()
|
||||
By("Apply the application rollout go directly to the target")
|
||||
var newAppRollout v1alpha2.AppRollout
|
||||
Expect(readYaml("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
newAppRollout.Namespace = namespace
|
||||
newAppRollout.Spec.SourceAppRevisionName = ""
|
||||
Expect(k8sClient.Create(ctx, &newAppRollout)).Should(Succeed())
|
||||
@@ -347,7 +348,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
|
||||
By("Apply the application rollout that stops after the first batch")
|
||||
var newAppRollout v1alpha2.AppRollout
|
||||
Expect(readYaml("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
newAppRollout.Namespace = namespace
|
||||
batchPartition := 0
|
||||
newAppRollout.Spec.RolloutPlan.BatchPartition = pointer.Int32Ptr(int32(batchPartition))
|
||||
@@ -407,7 +408,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
|
||||
By("Apply the application rollout")
|
||||
var newAppRollout v1alpha2.AppRollout
|
||||
Expect(readYaml("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
newAppRollout.Namespace = namespace
|
||||
Expect(k8sClient.Create(ctx, &newAppRollout)).Should(Succeed())
|
||||
|
||||
@@ -482,7 +483,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
|
||||
By("Apply the application rollout")
|
||||
var newAppRollout v1alpha2.AppRollout
|
||||
Expect(readYaml("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
newAppRollout.Namespace = namespace
|
||||
Expect(k8sClient.Create(ctx, &newAppRollout)).Should(Succeed())
|
||||
By("Wait for the rollout phase change to rolling in batches")
|
||||
@@ -508,7 +509,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
|
||||
By("Apply the application rollout that stops after the first batche")
|
||||
var newAppRollout v1alpha2.AppRollout
|
||||
Expect(readYaml("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
newAppRollout.Namespace = namespace
|
||||
batchPartition := 1
|
||||
newAppRollout.Spec.RolloutPlan.BatchPartition = pointer.Int32Ptr(int32(batchPartition))
|
||||
@@ -565,7 +566,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
MarkAppRolling(1)
|
||||
By("Apply the definition change")
|
||||
var cd, newCD v1alpha2.ComponentDefinition
|
||||
Expect(readYaml("testdata/rollout/cloneset/clonesetDefinitionModified.yaml.yaml", &newCD)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/rollout/cloneset/clonesetDefinitionModified.yaml.yaml", &newCD)).Should(BeNil())
|
||||
Eventually(
|
||||
func() error {
|
||||
k8sClient.Get(ctx, client.ObjectKey{Namespace: namespace, Name: newCD.Name}, &cd)
|
||||
@@ -576,7 +577,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
VerifyAppConfigTemplated(2)
|
||||
By("Apply the application rollout")
|
||||
var newAppRollout v1alpha2.AppRollout
|
||||
Expect(readYaml("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/rollout/cloneset/app-rollout.yaml", &newAppRollout)).Should(BeNil())
|
||||
newAppRollout.Namespace = namespace
|
||||
newAppRollout.Spec.RolloutPlan.BatchPartition = pointer.Int32Ptr(int32(len(newAppRollout.Spec.RolloutPlan.
|
||||
RolloutBatches) - 1))
|
||||
|
||||
@@ -44,6 +44,7 @@ import (
|
||||
core "github.com/oam-dev/kubevela/apis/core.oam.dev"
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
|
||||
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||
"github.com/oam-dev/kubevela/pkg/utils/common"
|
||||
// +kubebuilder:scaffold:imports
|
||||
)
|
||||
|
||||
@@ -100,15 +101,15 @@ var _ = BeforeSuite(func(done Done) {
|
||||
// TODO: Remove this after we get rid of the integration test dir
|
||||
By("Applying CRD of ComponentDefinition, WorkloadDefinition and TraitDefinition")
|
||||
var componentDefinitionCRD crdv1.CustomResourceDefinition
|
||||
Expect(readYaml("../../charts/vela-core/crds/core.oam.dev_componentdefinitions.yaml", &componentDefinitionCRD)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("../../charts/vela-core/crds/core.oam.dev_componentdefinitions.yaml", &componentDefinitionCRD)).Should(BeNil())
|
||||
Expect(k8sClient.Create(context.Background(), &componentDefinitionCRD)).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
var workloadDefinitionCRD crdv1.CustomResourceDefinition
|
||||
Expect(readYaml("../../charts/vela-core/crds/core.oam.dev_workloaddefinitions.yaml", &workloadDefinitionCRD)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("../../charts/vela-core/crds/core.oam.dev_workloaddefinitions.yaml", &workloadDefinitionCRD)).Should(BeNil())
|
||||
Expect(k8sClient.Create(context.Background(), &workloadDefinitionCRD)).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
|
||||
var traitDefinitionCRD crdv1.CustomResourceDefinition
|
||||
Expect(readYaml("../../charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml", &traitDefinitionCRD)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("../../charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml", &traitDefinitionCRD)).Should(BeNil())
|
||||
Expect(k8sClient.Create(context.Background(), &traitDefinitionCRD)).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
|
||||
By("Finished setting up test environment")
|
||||
|
||||
@@ -275,7 +276,7 @@ var _ = BeforeSuite(func(done Done) {
|
||||
|
||||
By("Create workload definition for revision mechanism test")
|
||||
var nwd v1alpha2.WorkloadDefinition
|
||||
Expect(readYaml("testdata/revision/workload-def.yaml", &nwd)).Should(BeNil())
|
||||
Expect(common.ReadYamlToObject("testdata/revision/workload-def.yaml", &nwd)).Should(BeNil())
|
||||
Eventually(
|
||||
func() error {
|
||||
return k8sClient.Create(context.Background(), &nwd)
|
||||
|
||||
Reference in New Issue
Block a user