Merge pull request #4949 from koba1t/fix/add_check_kustomization_is_empty

add check that kustomization is empty
This commit is contained in:
Kubernetes Prow Robot
2023-05-26 10:36:53 -07:00
committed by GitHub
5 changed files with 92 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/filesys"
@@ -300,6 +301,20 @@ func (k *Kustomization) FixKustomizationPreMarshalling(fSys filesys.FileSystem)
return nil
}
func (k *Kustomization) CheckEmpty() error {
// generate empty Kustomization
emptyKustomization := &Kustomization{}
// k.TypeMeta is metadata. It Isn't related to whether empty or not.
emptyKustomization.TypeMeta = k.TypeMeta
if reflect.DeepEqual(k, emptyKustomization) {
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 {