fix the missing fields in all edit commands

This commit is contained in:
Jingfang Liu
2018-12-14 13:11:04 -08:00
parent f7414fec08
commit d0e4db74b7
3 changed files with 8 additions and 1 deletions

View File

@@ -153,6 +153,10 @@ func (mf *kustomizationFile) Read() (*types.Kustomization, error) {
return nil, err return nil, err
} }
k.DealWithDeprecatedFields() k.DealWithDeprecatedFields()
msgs := k.DealWithMissingFields()
if len(msgs) > 0 {
log.Printf(strings.Join(msgs, "\n"))
}
err = mf.parseCommentedFields(data) err = mf.parseCommentedFields(data)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -78,6 +78,7 @@ func TestWriteAndRead(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Couldn't read kustomization file: %v\n", err) t.Fatalf("Couldn't read kustomization file: %v\n", err)
} }
kustomization.DealWithMissingFields()
if !reflect.DeepEqual(kustomization, content) { if !reflect.DeepEqual(kustomization, content) {
t.Fatal("Read kustomization is different from written kustomization") t.Fatal("Read kustomization is different from written kustomization")
} }
@@ -172,6 +173,8 @@ func TestPreserveComments(t *testing.T) {
`# shem qing some comments `# shem qing some comments
# This is some comment we should preserve # This is some comment we should preserve
# don't delete it # don't delete it
apiVersion: v1
kind: Kustomization
resources: resources:
- pod.yaml - pod.yaml
- service.yaml - service.yaml

View File

@@ -160,7 +160,7 @@ func (k *Kustomization) DealWithMissingFields() []string {
} }
if k.Kind == "" { if k.Kind == "" {
k.Kind = KustomizationKind k.Kind = KustomizationKind
msgs = append(msgs, "Fixed the missing field by adding apiKind: "+KustomizationKind) msgs = append(msgs, "Fixed the missing field by adding kind: "+KustomizationKind)
} }
return msgs return msgs
} }