Merge pull request #618 from Liujingfang1/version

Add enforcement message for apiVersion and kind
This commit is contained in:
Kubernetes Prow Robot
2018-12-13 10:10:21 -08:00
committed by GitHub
2 changed files with 27 additions and 0 deletions

View File

@@ -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

View File

@@ -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