diff --git a/pkg/target/kusttarget.go b/pkg/target/kusttarget.go index 6219581ca..6c2caf552 100644 --- a/pkg/target/kusttarget.go +++ b/pkg/target/kusttarget.go @@ -66,6 +66,13 @@ func NewKustTarget( return nil, err } k.DealWithDeprecatedFields() + msgs, 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")) + } tConfig, err := makeTransformerConfig(ldr, k.Configurations) if err != nil { return nil, err diff --git a/pkg/types/kustomization.go b/pkg/types/kustomization.go index e1badbc6d..fd3a3acc5 100644 --- a/pkg/types/kustomization.go +++ b/pkg/types/kustomization.go @@ -21,6 +21,11 @@ import ( "sigs.k8s.io/kustomize/pkg/patch" ) +const ( + KustomizationVersion = "v1" + KustomizationKind = "Kustomization" +) + // TypeMeta copies apimachinery/pkg/apis/meta/v1.TypeMeta type TypeMeta struct { // Kind copies apimachinery/pkg/apis/meta/v1.Typemeta.Kind @@ -146,6 +151,21 @@ func (k *Kustomization) DealWithDeprecatedFields() { } } +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 add apiVersion: "+KustomizationVersion) + } else if 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 add kind: "+KustomizationKind) + } else if k.Kind != KustomizationKind { + errs = append(errs, "kind should be "+KustomizationKind) + } + return msgs, errs +} + // GeneratorArgs contains arguments common to generators. type GeneratorArgs struct { // Namespace for the configmap, optional