diff --git a/pkg/target/kusttarget.go b/pkg/target/kusttarget.go index 78dba3913..f0b4db87b 100644 --- a/pkg/target/kusttarget.go +++ b/pkg/target/kusttarget.go @@ -21,7 +21,6 @@ import ( "bytes" "encoding/json" "fmt" - "log" "strings" "github.com/ghodss/yaml" @@ -64,12 +63,9 @@ func NewKustTarget( if err != nil { return nil, err } - msgs, errs := k.EnforceFields() + errs := k.EnforceFields() if len(errs) > 0 { - return nil, fmt.Errorf(strings.Join(errs, "\n")) - } - if len(msgs) > 0 { - log.Printf(strings.Join(msgs, "\n")) + return nil, fmt.Errorf("Failed to read kustomization file under %s:\n"+strings.Join(errs, "\n"), ldr.Root()) } return &KustTarget{ kustomization: &k, diff --git a/pkg/types/kustomization.go b/pkg/types/kustomization.go index c78fb9f89..12d09820f 100644 --- a/pkg/types/kustomization.go +++ b/pkg/types/kustomization.go @@ -146,19 +146,15 @@ func (k *Kustomization) DealWithMissingFields() []string { return msgs } -func (k *Kustomization) EnforceFields() ([]string, []string) { - var msgs, errs []string - if k.APIVersion == "" { - msgs = append(msgs, "apiVersion is not defined. This will not be allowed in the next release.\nPlease run `kustomize edit fix`") - } else if k.APIVersion != KustomizationVersion { +func (k *Kustomization) EnforceFields() []string { + var errs []string + if k.APIVersion != "" && k.APIVersion != KustomizationVersion { errs = append(errs, "apiVersion should be "+KustomizationVersion) } - if k.Kind == "" { - msgs = append(msgs, "kind is not defined. This will not be allowed in the next release.\nPlease run `kustomize edit fix`") - } else if k.Kind != KustomizationKind { + if k.Kind != "" && k.Kind != KustomizationKind { errs = append(errs, "kind should be "+KustomizationKind) } - return msgs, errs + return errs } // DealWithDeprecatedFields should be called immediately after