From d0e4db74b78f5c6c7e0340c5dfb4236bffd684a7 Mon Sep 17 00:00:00 2001 From: Jingfang Liu Date: Fri, 14 Dec 2018 13:11:04 -0800 Subject: [PATCH] fix the missing fields in all edit commands --- pkg/commands/kustfile/kustomizationfile.go | 4 ++++ pkg/commands/kustfile/kustomizationfile_test.go | 3 +++ pkg/types/kustomization.go | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/commands/kustfile/kustomizationfile.go b/pkg/commands/kustfile/kustomizationfile.go index cae3488de..abd9cfe0b 100644 --- a/pkg/commands/kustfile/kustomizationfile.go +++ b/pkg/commands/kustfile/kustomizationfile.go @@ -153,6 +153,10 @@ func (mf *kustomizationFile) Read() (*types.Kustomization, error) { return nil, err } k.DealWithDeprecatedFields() + msgs := k.DealWithMissingFields() + if len(msgs) > 0 { + log.Printf(strings.Join(msgs, "\n")) + } err = mf.parseCommentedFields(data) if err != nil { return nil, err diff --git a/pkg/commands/kustfile/kustomizationfile_test.go b/pkg/commands/kustfile/kustomizationfile_test.go index a7e77898a..9cfc89839 100644 --- a/pkg/commands/kustfile/kustomizationfile_test.go +++ b/pkg/commands/kustfile/kustomizationfile_test.go @@ -78,6 +78,7 @@ func TestWriteAndRead(t *testing.T) { if err != nil { t.Fatalf("Couldn't read kustomization file: %v\n", err) } + kustomization.DealWithMissingFields() if !reflect.DeepEqual(kustomization, content) { t.Fatal("Read kustomization is different from written kustomization") } @@ -172,6 +173,8 @@ func TestPreserveComments(t *testing.T) { `# shem qing some comments # This is some comment we should preserve # don't delete it +apiVersion: v1 +kind: Kustomization resources: - pod.yaml - service.yaml diff --git a/pkg/types/kustomization.go b/pkg/types/kustomization.go index 157628529..8cbeccaf8 100644 --- a/pkg/types/kustomization.go +++ b/pkg/types/kustomization.go @@ -160,7 +160,7 @@ func (k *Kustomization) DealWithMissingFields() []string { } if k.Kind == "" { 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 }