Fix: Closure Bug In newValue (#2437)

* Fix: new value bug

* Fix: strategyUnify Bug

* Fix: e2e error
This commit is contained in:
Jian.Li
2021-10-12 19:05:03 +08:00
committed by GitHub
parent 287c895daf
commit 8935a87c59
4 changed files with 51 additions and 4 deletions
+40
View File
@@ -241,6 +241,46 @@ containers: [{
}
}, ...]
}, ...]
`},
{
base: `
containers: [{
volumeMounts: [{name: "k1", path: "p1"},{name: "k1", path: "p2"},...]
},...]
volumes: [{name: "x1",value: "v1"},{name: "x2",value: "v2"},...]
`,
patch: `
// +patchKey=name
volumes: [{name: "x1",value: "v1"},{name: "x3",value: "x2"}]
containers: [{
volumeMounts: [{name: "k1", path: "p1"},{name: "k1", path: "p2"},{ name:"k2", path: "p3"}]
},...]`,
result: `containers: [{
volumeMounts: [{
path: "p1"
name: "k1"
}, {
path: "p2"
name: "k1"
}, {
path: "p3"
name: "k2"
}]
}, ...]
// +patchKey=name
volumes: [{
name: "x1"
value: "v1"
}, {
name: "x2"
value: "v2"
}, {
name: "x3"
value: "x2"
}, ...]
`},
}
+4
View File
@@ -58,6 +58,10 @@ func (nwk *nodewalker) walk(node ast.Node) {
if n.Value != nil {
origin := nwk.pos
oriTags := nwk.tags
nwk.tags = map[string]string{}
for k, v := range oriTags {
nwk.tags[k] = v
}
nwk.pos = append(nwk.pos, labelStr(n.Label))
tags := findCommentTag(n.Comments())
for tk, tv := range tags {
+2 -2
View File
@@ -93,9 +93,9 @@ func NewValue(s string, pd *packages.PackageDiscover, tagTempl string, opts ...f
}
addImports := func(inst *build.Instance) error {
if pd != nil {
pd.ImportBuiltinPackagesFor(builder)
pd.ImportBuiltinPackagesFor(inst)
}
if err := stdlib.AddImportsFor(builder, tagTempl); err != nil {
if err := stdlib.AddImportsFor(inst, tagTempl); err != nil {
return err
}
return nil
+5 -2
View File
@@ -65,7 +65,7 @@ var _ = Describe("ComponentDefinition Normal tests", func() {
It("Test componentDefinition which only set type field", func() {
workDef := &v1beta1.WorkloadDefinition{
TypeMeta: metav1.TypeMeta{
Kind: "ComponentDefinition",
Kind: "WorkloadDefinition",
APIVersion: "core.oam.dev/v1beta1",
},
ObjectMeta: metav1.ObjectMeta{
@@ -91,7 +91,10 @@ var _ = Describe("ComponentDefinition Normal tests", func() {
cd.SetNamespace(namespace)
cd.SetName("test-componentdef")
cd.Spec.Schematic.CUE.Template = webServiceV1Template
Expect(k8sClient.Create(ctx, cd)).Should(Succeed())
Eventually(func() error {
return k8sClient.Create(ctx, cd)
}, 5*time.Second, time.Second).Should(BeNil())
defRev := new(v1beta1.DefinitionRevision)
Eventually(func() error {