Skip to content

Commit

Permalink
Add enforcement message for apiVersion and kind
Browse files Browse the repository at this point in the history
  • Loading branch information
Liujingfang1 committed Dec 12, 2018
1 parent f0f8aad commit 0759136
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/target/kusttarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions pkg/types/kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0759136

Please sign in to comment.