mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-08 00:37:27 +00:00
Merge pull request #5302 from maboehm/fix-multiple-kustomizations
flux diff: Reset target struct before decoding
This commit is contained in:
commit
0c73420ccf
3 changed files with 30 additions and 0 deletions
|
|
@ -464,6 +464,8 @@ func (b *Builder) unMarshallKustomization() (*kustomizev1.Kustomization, error)
|
|||
decoder := k8syaml.NewYAMLOrJSONDecoder(bytes.NewBuffer(data), len(data))
|
||||
// check for kustomization in yaml with the same name and namespace
|
||||
for {
|
||||
// ensure the target struct is emptied before decoding
|
||||
k = &kustomizev1.Kustomization{}
|
||||
err = decoder.Decode(k)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
|
|
|
|||
|
|
@ -226,6 +226,16 @@ func Test_unMarshallKustomization(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
t.Run("correct parsing of multiple documents", func(t *testing.T) {
|
||||
b.kustomizationFile = "testdata/local-kustomization/multi-doc-reset.yaml"
|
||||
ks, err := b.unMarshallKustomization()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected err '%s'", err)
|
||||
}
|
||||
if len(ks.Spec.Components) > 0 {
|
||||
t.Errorf("previous Kustomization in file leaked into subsequent Kustomizations")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_ResolveKustomization(t *testing.T) {
|
||||
|
|
|
|||
18
internal/build/testdata/local-kustomization/multi-doc-reset.yaml
vendored
Normal file
18
internal/build/testdata/local-kustomization/multi-doc-reset.yaml
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
||||
kind: Kustomization
|
||||
metadata:
|
||||
name: first
|
||||
namespace: flux-system
|
||||
spec:
|
||||
path: "./k8s/first"
|
||||
components:
|
||||
- foo
|
||||
---
|
||||
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
||||
kind: Kustomization
|
||||
metadata:
|
||||
name: podinfo
|
||||
namespace: flux-system
|
||||
spec:
|
||||
path: "./k8s/second"
|
||||
---
|
||||
Loading…
Reference in a new issue