mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Add enforcement message for apiVersion and kind
This commit is contained in:
@@ -66,6 +66,13 @@ func NewKustTarget(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
k.DealWithDeprecatedFields()
|
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)
|
tConfig, err := makeTransformerConfig(ldr, k.Configurations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/pkg/patch"
|
"sigs.k8s.io/kustomize/pkg/patch"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
KustomizationVersion = "v1"
|
||||||
|
KustomizationKind = "Kustomization"
|
||||||
|
)
|
||||||
|
|
||||||
// TypeMeta copies apimachinery/pkg/apis/meta/v1.TypeMeta
|
// TypeMeta copies apimachinery/pkg/apis/meta/v1.TypeMeta
|
||||||
type TypeMeta struct {
|
type TypeMeta struct {
|
||||||
// Kind copies apimachinery/pkg/apis/meta/v1.Typemeta.Kind
|
// 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.
|
// GeneratorArgs contains arguments common to generators.
|
||||||
type GeneratorArgs struct {
|
type GeneratorArgs struct {
|
||||||
// Namespace for the configmap, optional
|
// Namespace for the configmap, optional
|
||||||
|
|||||||
Reference in New Issue
Block a user