Add subcommand: edit fix

This commit is contained in:
Jingfang Liu
2018-12-13 11:38:29 -08:00
parent aeda4172e4
commit 986c85e728
5 changed files with 128 additions and 3 deletions

View File

@@ -151,15 +151,29 @@ func (k *Kustomization) DealWithDeprecatedFields() {
}
}
// DealWithMissingFields fills the missing fields
func (k *Kustomization) DealWithMissingFields() []string {
var msgs []string
if k.APIVersion == "" {
k.APIVersion = KustomizationVersion
msgs = append(msgs, "Fixed the missing field by adding apiVersion: "+KustomizationVersion)
}
if k.Kind == "" {
k.Kind = KustomizationKind
msgs = append(msgs, "Fixed the missing field by adding apiKind: "+KustomizationKind)
}
return msgs
}
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)
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)
}
if k.Kind == "" {
msgs = append(msgs, "kind is not defined. This will not be allowed in the next release.\nPlease add 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)
}