From 8e172091f697e948d700deed56fd682e54aa3df1 Mon Sep 17 00:00:00 2001 From: Tianxin Dong Date: Tue, 14 Sep 2021 10:26:57 +0800 Subject: [PATCH] Test: fix resource tracker e2e (#2281) --- pkg/appfile/appfile.go | 7 ++++++ pkg/appfile/template.go | 30 +++++++++++++++++++++++ test/e2e-test/definition_revision_test.go | 14 +++++------ test/e2e-test/definition_test.go | 2 +- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/pkg/appfile/appfile.go b/pkg/appfile/appfile.go index e3934e0a6..f9a80122c 100644 --- a/pkg/appfile/appfile.go +++ b/pkg/appfile/appfile.go @@ -411,6 +411,13 @@ func (af *Appfile) setWorkloadRefToTrait(wlRef corev1.ObjectReference, trait *un if traitType == definition.AuxiliaryWorkload { return nil } + if strings.Contains(traitType, "-") { + splitName := traitType[0:strings.LastIndex(traitType, "-")] + _, ok := af.RelatedTraitDefinitions[splitName] + if ok { + traitType = splitName + } + } traitDef, ok := af.RelatedTraitDefinitions[traitType] if !ok { return errors.Errorf("TraitDefinition %s not found in appfile", traitType) diff --git a/pkg/appfile/template.go b/pkg/appfile/template.go index 6bb1d0a2c..b8d4a4d90 100644 --- a/pkg/appfile/template.go +++ b/pkg/appfile/template.go @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "fmt" + "strings" "github.com/pkg/errors" kerrors "k8s.io/apimachinery/pkg/api/errors" @@ -153,6 +154,7 @@ func LoadTemplateFromRevision(capName string, capType types.CapType, apprev *v1b if apprev == nil { return nil, errors.Errorf("fail to find template for %s as app revision is empty", capName) } + capName = verifyRevisionName(capName, capType, apprev) switch capType { case types.TypeComponentDefinition: cd, ok := apprev.Spec.ComponentDefinitions[capName] @@ -231,6 +233,34 @@ func LoadTemplateFromRevision(capName string, capType types.CapType, apprev *v1b } } +func verifyRevisionName(capName string, capType types.CapType, apprev *v1beta1.ApplicationRevision) string { + if strings.Contains(capName, "@") { + splitName := capName[0:strings.LastIndex(capName, "@")] + ok := false + + switch capType { + case types.TypeComponentDefinition: + _, ok = apprev.Spec.ComponentDefinitions[splitName] + case types.TypeTrait: + _, ok = apprev.Spec.TraitDefinitions[splitName] + case types.TypePolicy: + _, ok = apprev.Spec.PolicyDefinitions[splitName] + case types.TypeWorkflowStep: + _, ok = apprev.Spec.WorkflowStepDefinitions[splitName] + case types.TypeScope: + _, ok = apprev.Spec.ScopeDefinitions[splitName] + default: + return capName + } + + if ok { + return splitName + } + } + + return capName +} + // DryRunTemplateLoader return a function that do the same work as // LoadTemplate, but load template from provided ones before loading from // cluster through LoadTemplate diff --git a/test/e2e-test/definition_revision_test.go b/test/e2e-test/definition_revision_test.go index bccc71c66..7001f6f9d 100644 --- a/test/e2e-test/definition_revision_test.go +++ b/test/e2e-test/definition_revision_test.go @@ -125,7 +125,7 @@ var _ = Describe("Test application of the specified definition version", func() Expect(k8sClient.Delete(ctx, &ns, client.PropagationPolicy(metav1.DeletePropagationForeground))).Should(Succeed()) }) - PIt("Test deploy application which containing cue rendering module", func() { + It("Test deploy application which containing cue rendering module", func() { var ( appName = "test-website-app" comp1Name = "front" @@ -322,7 +322,7 @@ var _ = Describe("Test application of the specified definition version", func() Expect(k8sClient.Patch(ctx, &app, client.Merge)).Should(HaveOccurred()) }) - PIt("Test deploy application which specify the name of component", func() { + It("Test deploy application which specify the name of component", func() { compName := "job" app := v1beta1.Application{ ObjectMeta: metav1.ObjectMeta{ @@ -352,7 +352,7 @@ var _ = Describe("Test application of the specified definition version", func() }, 30*time.Second, 3*time.Second).Should(Succeed()) }) - PIt("Test deploy application which containing helm module", func() { + It("Test deploy application which containing helm module", func() { var ( appName = "test-helm" compName = "worker" @@ -513,7 +513,7 @@ var _ = Describe("Test application of the specified definition version", func() }, 120*time.Second, 5*time.Second).Should(BeTrue()) }) - PIt("Test deploy application which containing kube module", func() { + It("Test deploy application which containing kube module", func() { var ( appName = "test-kube-app" compName = "worker" @@ -686,7 +686,7 @@ var _ = Describe("Test application of the specified definition version", func() }) // refer to https://github.com/oam-dev/kubevela/discussions/1810#discussioncomment-914295 - PIt("Test k8s resources created by application whether with correct label", func() { + It("Test k8s resources created by application whether with correct label", func() { var ( appName = "test-resources-labels" compName = "web" @@ -708,7 +708,7 @@ var _ = Describe("Test application of the specified definition version", func() if err != nil { return err } - exposeV2.Spec.Schematic.CUE.Template = exposeV2Templae + exposeV2.Spec.Schematic.CUE.Template = exposeV2Template return k8sClient.Update(ctx, exposeV2) }, 15*time.Second, time.Second).Should(BeNil()) @@ -1157,7 +1157,7 @@ parameter: { } ` -var exposeV2Templae = ` +var exposeV2Template = ` outputs: service: { apiVersion: "v1" kind: "Service" diff --git a/test/e2e-test/definition_test.go b/test/e2e-test/definition_test.go index ab312aec4..bbd55f86b 100644 --- a/test/e2e-test/definition_test.go +++ b/test/e2e-test/definition_test.go @@ -208,7 +208,7 @@ var _ = Describe("ComponentDefinition Normal tests", func() { }, 15*time.Second, time.Second).Should(BeNil()) newTd := oldTd.DeepCopy() - newTd.Spec.Schematic.CUE.Template = exposeV2Templae + newTd.Spec.Schematic.CUE.Template = exposeV2Template Expect(k8sClient.Create(ctx, newTd)).Should(HaveOccurred()) }) })