add check that kustomization is empty

This commit is contained in:
koba1t
2022-12-28 21:16:32 +09:00
parent d3184da4c6
commit 2c2b2ab825
5 changed files with 88 additions and 10 deletions

View File

@@ -298,6 +298,27 @@ func (k *Kustomization) FixKustomizationPreMarshalling(fSys filesys.FileSystem)
return nil
}
func (k *Kustomization) CheckEmpty() error {
// generate empty Kustomization
emptyKustomization := &Kustomization{}
emptyKustomization.FixKustomization()
// compare with yaml string
b, err := yaml.Marshal(k)
if err != nil {
return fmt.Errorf("kustomization marshal error: %w", err)
}
emptyb, err := yaml.Marshal(emptyKustomization)
if err != nil {
return fmt.Errorf("empty kustomization marshal error: %w", err)
}
if string(b) == string(emptyb) {
return fmt.Errorf("kustomization.yaml is empty")
}
return nil
}
func (k *Kustomization) EnforceFields() []string {
var errs []string
if k.Kind != "" && k.Kind != KustomizationKind && k.Kind != ComponentKind {