mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
allow apiVersion and Kind to be empty or specific values
This commit is contained in:
@@ -21,7 +21,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
@@ -64,12 +63,9 @@ func NewKustTarget(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
msgs, errs := k.EnforceFields()
|
errs := k.EnforceFields()
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
return nil, fmt.Errorf(strings.Join(errs, "\n"))
|
return nil, fmt.Errorf("Failed to read kustomization file under %s:\n"+strings.Join(errs, "\n"), ldr.Root())
|
||||||
}
|
|
||||||
if len(msgs) > 0 {
|
|
||||||
log.Printf(strings.Join(msgs, "\n"))
|
|
||||||
}
|
}
|
||||||
return &KustTarget{
|
return &KustTarget{
|
||||||
kustomization: &k,
|
kustomization: &k,
|
||||||
|
|||||||
@@ -146,19 +146,15 @@ func (k *Kustomization) DealWithMissingFields() []string {
|
|||||||
return msgs
|
return msgs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *Kustomization) EnforceFields() ([]string, []string) {
|
func (k *Kustomization) EnforceFields() []string {
|
||||||
var msgs, errs []string
|
var errs []string
|
||||||
if k.APIVersion == "" {
|
if k.APIVersion != "" && k.APIVersion != KustomizationVersion {
|
||||||
msgs = append(msgs, "apiVersion is not defined. This will not be allowed in the next release.\nPlease run `kustomize edit fix`")
|
|
||||||
} else if k.APIVersion != KustomizationVersion {
|
|
||||||
errs = append(errs, "apiVersion should be "+KustomizationVersion)
|
errs = append(errs, "apiVersion should be "+KustomizationVersion)
|
||||||
}
|
}
|
||||||
if k.Kind == "" {
|
if k.Kind != "" && k.Kind != KustomizationKind {
|
||||||
msgs = append(msgs, "kind is not defined. This will not be allowed in the next release.\nPlease run `kustomize edit fix`")
|
|
||||||
} else if k.Kind != KustomizationKind {
|
|
||||||
errs = append(errs, "kind should be "+KustomizationKind)
|
errs = append(errs, "kind should be "+KustomizationKind)
|
||||||
}
|
}
|
||||||
return msgs, errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
// DealWithDeprecatedFields should be called immediately after
|
// DealWithDeprecatedFields should be called immediately after
|
||||||
|
|||||||
Reference in New Issue
Block a user