Skip to content

Commit e905704

Browse files
committed
allow apiVersion and Kind to be empty or specific values
1 parent d858533 commit e905704

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

pkg/target/kusttarget.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"bytes"
2222
"encoding/json"
2323
"fmt"
24-
"log"
2524
"strings"
2625

2726
"github.com/ghodss/yaml"
@@ -64,12 +63,9 @@ func NewKustTarget(
6463
if err != nil {
6564
return nil, err
6665
}
67-
msgs, errs := k.EnforceFields()
66+
errs := k.EnforceFields()
6867
if len(errs) > 0 {
69-
return nil, fmt.Errorf(strings.Join(errs, "\n"))
70-
}
71-
if len(msgs) > 0 {
72-
log.Printf(strings.Join(msgs, "\n"))
68+
return nil, fmt.Errorf("Failed to read kustomization file under %s:\n"+strings.Join(errs, "\n"), ldr.Root())
7369
}
7470
return &KustTarget{
7571
kustomization: &k,

pkg/types/kustomization.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,15 @@ func (k *Kustomization) DealWithMissingFields() []string {
146146
return msgs
147147
}
148148

149-
func (k *Kustomization) EnforceFields() ([]string, []string) {
150-
var msgs, errs []string
151-
if k.APIVersion == "" {
152-
msgs = append(msgs, "apiVersion is not defined. This will not be allowed in the next release.\nPlease run `kustomize edit fix`")
153-
} else if k.APIVersion != KustomizationVersion {
149+
func (k *Kustomization) EnforceFields() []string {
150+
var errs []string
151+
if k.APIVersion != "" && k.APIVersion != KustomizationVersion {
154152
errs = append(errs, "apiVersion should be "+KustomizationVersion)
155153
}
156-
if k.Kind == "" {
157-
msgs = append(msgs, "kind is not defined. This will not be allowed in the next release.\nPlease run `kustomize edit fix`")
158-
} else if k.Kind != KustomizationKind {
154+
if k.Kind != "" && k.Kind != KustomizationKind {
159155
errs = append(errs, "kind should be "+KustomizationKind)
160156
}
161-
return msgs, errs
157+
return errs
162158
}
163159

164160
// DealWithDeprecatedFields should be called immediately after

0 commit comments

Comments
 (0)