1
0
mirror of synced 2026-02-13 13:06:56 +00:00

check for correct kustomization in multi-doc yaml

Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
Somtochi Onyekwere
2022-06-01 11:26:01 +01:00
parent 56c5e784fb
commit 355ed94852
6 changed files with 122 additions and 4 deletions

View File

@@ -23,6 +23,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
"sync"
"time"
@@ -250,12 +251,19 @@ func (b *Builder) unMarshallKustomization() (*kustomizev1.Kustomization, error)
if err != nil {
return nil, fmt.Errorf("failed to read kustomization file %s: %w", b.kustomizationFile, err)
}
k := &kustomizev1.Kustomization{}
decoder := k8syaml.NewYAMLOrJSONDecoder(bytes.NewBuffer(data), len(data))
err = decoder.Decode(k)
if err != nil {
return nil, fmt.Errorf("failed to unmarshall kustomization file %s: %w", b.kustomizationFile, err)
// check for kustomization in yaml with the same name and namespace
for !(k.Name == b.name && (k.Namespace == b.namespace || k.Namespace == "")) {
err = decoder.Decode(k)
if err != nil {
if err == io.EOF {
return nil, fmt.Errorf("failed find kustomization with name '%s' and namespace '%s' in file '%s'",
b.name, b.namespace, b.kustomizationFile)
} else {
return nil, fmt.Errorf("failed to unmarshall kustomization file %s: %w", b.kustomizationFile, err)
}
}
}
return k, nil
}