Fix: storage patch env (#4523)

* Fix: empty health policy do not check object existence

Signed-off-by: Somefive <yd219913@alibaba-inc.com>

* Fix: fix health check error

Signed-off-by: Somefive <yd219913@alibaba-inc.com>

* Fix: app use storage and env trait

Signed-off-by: Somefive <yd219913@alibaba-inc.com>
This commit is contained in:
Somefive
2022-08-02 19:17:16 +08:00
committed by GitHub
parent c8a16adfe8
commit 73f983e61e
4 changed files with 57 additions and 2 deletions

View File

@@ -115,6 +115,9 @@ func listMergeProcess(field *ast.Field, key string, baseList, patchList *ast.Lis
kmaps[fmt.Sprintf(key, blit.Value)] = patchList.Elts[i]
}
if !foundPatch {
if len(patchList.Elts) == 0 {
continue
}
return
}

View File

@@ -110,6 +110,19 @@ containers: [{noname: "x3"}]`,
base: `containers: [{name: "x1"},{name: "x2"},...]`,
patch: `
// +patchKey=name
containers: []`,
result: `// +patchKey=name
containers: [{
name: "x1"
}, {
name: "x2"
}, ...]
`,
},
{
base: `containers: [{name: "x1"},{name: "x2"},...]`,
patch: `
// +patchKey=name
containers: [{noname: "x3"},{name: "x1"}]`,
result: `// +patchKey=name
containers: [{
@@ -359,8 +372,10 @@ containers: [{
}
for i, tcase := range testCase {
v, _ := StrategyUnify(tcase.base, tcase.patch)
assert.Equal(t, v, tcase.result, fmt.Sprintf("testPatch for case(no:%d) %s", i, v))
t.Run(fmt.Sprintf("case-%d", i), func(t *testing.T) {
v, _ := StrategyUnify(tcase.base, tcase.patch)
assert.Equal(t, v, tcase.result, fmt.Sprintf("testPatch for case(no:%d) %s", i, v))
})
}
}

View File

@@ -590,5 +590,18 @@ var _ = Describe("Test multicluster scenario", func() {
g.Expect(k8sClient.Get(hubCtx, client.ObjectKeyFromObject(app), app)).Should(Satisfy(kerrors.IsNotFound))
}, 10*time.Second).Should(Succeed())
})
It("Test applications with env and storage trait", func() {
bs, err := ioutil.ReadFile("./testdata/app/app-with-env-and-storage.yaml")
Expect(err).Should(Succeed())
appYaml := strings.ReplaceAll(string(bs), "TEST_NAMESPACE", testNamespace)
app := &v1beta1.Application{}
Expect(yaml.Unmarshal([]byte(appYaml), app)).Should(Succeed())
Expect(k8sClient.Create(hubCtx, app)).Should(Succeed())
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(hubCtx, client.ObjectKeyFromObject(app), app)).Should(Succeed())
g.Expect(app.Status.Phase).Should(Equal(common.ApplicationRunning))
}, 20*time.Second).Should(Succeed())
})
})
})

View File

@@ -0,0 +1,24 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: app-with-env-and-storage
namespace: TEST_NAMESPACE
spec:
components:
- name: data-worker
type: worker
properties:
image: busybox
cmd:
- sleep
- '1000000'
traits:
- type: env
properties:
env:
TZ: Asia/Shanghai
- type: storage
properties:
emptyDir:
- name: jvm
mountPath: /jvm