mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-22 06:47:00 +00:00
Merge pull request #618 from Liujingfang1/version
Add enforcement message for apiVersion and kind
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user