From ce841212ced5bfcd2f8148a5dfaa1c1dd52702a2 Mon Sep 17 00:00:00 2001 From: jasonjung Date: Mon, 26 Dec 2022 15:42:53 -0800 Subject: [PATCH 1/3] warning comment on PROJECT file --- pkg/config/store/yaml/store.go | 9 +++++++++ pkg/config/store/yaml/store_test.go | 25 ++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/pkg/config/store/yaml/store.go b/pkg/config/store/yaml/store.go index 46223f1078d..bc6e728d9ae 100644 --- a/pkg/config/store/yaml/store.go +++ b/pkg/config/store/yaml/store.go @@ -31,6 +31,12 @@ import ( const ( // DefaultPath is the default path for the configuration file DefaultPath = "PROJECT" + + // Comment for 'PROJECT' config file + commentStr = `# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. +` ) // yamlStore implements store.Store using a YAML file as the storage backend @@ -133,6 +139,9 @@ func (s yamlStore) SaveTo(path string) error { return store.SaveError{Err: fmt.Errorf("unable to marshal to YAML: %w", err)} } + // Prepend warning comment for the 'PROJECT' file + content = append([]byte(commentStr), content...) + // Write the marshalled configuration err = afero.WriteFile(s.fs, path, content, 0600) if err != nil { diff --git a/pkg/config/store/yaml/store_test.go b/pkg/config/store/yaml/store_test.go index 42bf58d69ca..be831a489eb 100644 --- a/pkg/config/store/yaml/store_test.go +++ b/pkg/config/store/yaml/store_test.go @@ -86,7 +86,7 @@ layout: "" Context("Load", func() { It("should load the Config from an existing file at the default path", func() { - Expect(afero.WriteFile(s.fs, DefaultPath, []byte(v2File), os.ModePerm)).To(Succeed()) + Expect(afero.WriteFile(s.fs, DefaultPath, []byte(commentStr+v2File), os.ModePerm)).To(Succeed()) Expect(s.Load()).To(Succeed()) Expect(s.fs).NotTo(BeNil()) @@ -102,7 +102,7 @@ layout: "" }) It("should fail if unable to identify the version of the file at the default path", func() { - Expect(afero.WriteFile(s.fs, DefaultPath, []byte(unversionedFile), os.ModePerm)).To(Succeed()) + Expect(afero.WriteFile(s.fs, DefaultPath, []byte(commentStr+unversionedFile), os.ModePerm)).To(Succeed()) err := s.Load() Expect(err).To(HaveOccurred()) @@ -110,7 +110,7 @@ layout: "" }) It("should fail if unable to create a Config for the version of the file at the default path", func() { - Expect(afero.WriteFile(s.fs, DefaultPath, []byte(nonexistentVersionFile), os.ModePerm)).To(Succeed()) + Expect(afero.WriteFile(s.fs, DefaultPath, []byte(commentStr+nonexistentVersionFile), os.ModePerm)).To(Succeed()) err := s.Load() Expect(err).To(HaveOccurred()) @@ -118,7 +118,7 @@ layout: "" }) It("should fail if unable to unmarshal the file at the default path", func() { - Expect(afero.WriteFile(s.fs, DefaultPath, []byte(wrongFile), os.ModePerm)).To(Succeed()) + Expect(afero.WriteFile(s.fs, DefaultPath, []byte(commentStr+wrongFile), os.ModePerm)).To(Succeed()) err := s.Load() Expect(err).To(HaveOccurred()) @@ -128,7 +128,7 @@ layout: "" Context("LoadFrom", func() { It("should load the Config from an existing file from the specified path", func() { - Expect(afero.WriteFile(s.fs, path, []byte(v2File), os.ModePerm)).To(Succeed()) + Expect(afero.WriteFile(s.fs, path, []byte(commentStr+v2File), os.ModePerm)).To(Succeed()) Expect(s.LoadFrom(path)).To(Succeed()) Expect(s.fs).NotTo(BeNil()) @@ -144,7 +144,7 @@ layout: "" }) It("should fail if unable to identify the version of the file at the specified path", func() { - Expect(afero.WriteFile(s.fs, path, []byte(unversionedFile), os.ModePerm)).To(Succeed()) + Expect(afero.WriteFile(s.fs, path, []byte(commentStr+unversionedFile), os.ModePerm)).To(Succeed()) err := s.LoadFrom(path) Expect(err).To(HaveOccurred()) @@ -152,7 +152,7 @@ layout: "" }) It("should fail if unable to create a Config for the version of the file at the specified path", func() { - Expect(afero.WriteFile(s.fs, path, []byte(nonexistentVersionFile), os.ModePerm)).To(Succeed()) + Expect(afero.WriteFile(s.fs, path, []byte(commentStr+nonexistentVersionFile), os.ModePerm)).To(Succeed()) err := s.LoadFrom(path) Expect(err).To(HaveOccurred()) @@ -160,7 +160,7 @@ layout: "" }) It("should fail if unable to unmarshal the file at the specified path", func() { - Expect(afero.WriteFile(s.fs, path, []byte(wrongFile), os.ModePerm)).To(Succeed()) + Expect(afero.WriteFile(s.fs, path, []byte(commentStr+wrongFile), os.ModePerm)).To(Succeed()) err := s.LoadFrom(path) Expect(err).To(HaveOccurred()) @@ -175,7 +175,7 @@ layout: "" cfgBytes, err := afero.ReadFile(s.fs, DefaultPath) Expect(err).NotTo(HaveOccurred()) - Expect(string(cfgBytes)).To(Equal(v2File)) + Expect(string(cfgBytes)).To(Equal(commentStr + v2File)) }) It("should succeed for a valid config that must not exist", func() { @@ -185,7 +185,7 @@ layout: "" cfgBytes, err := afero.ReadFile(s.fs, DefaultPath) Expect(err).NotTo(HaveOccurred()) - Expect(string(cfgBytes)).To(Equal(v2File)) + Expect(string(cfgBytes)).To(Equal(commentStr + v2File)) }) It("should fail for an empty config", func() { @@ -212,8 +212,7 @@ layout: "" cfgBytes, err := afero.ReadFile(s.fs, path) Expect(err).NotTo(HaveOccurred()) - Expect(string(cfgBytes)).To(Equal(`version: "2" -`)) + Expect(string(cfgBytes)).To(Equal(commentStr + v2File)) }) It("should succeed for a valid config that must not exist", func() { @@ -223,7 +222,7 @@ layout: "" cfgBytes, err := afero.ReadFile(s.fs, path) Expect(err).NotTo(HaveOccurred()) - Expect(string(cfgBytes)).To(Equal(v2File)) + Expect(string(cfgBytes)).To(Equal(commentStr + v2File)) }) It("should fail for an empty config", func() { From d3e09335bbf244d8528694c05e0a16c28bd52464 Mon Sep 17 00:00:00 2001 From: jasonjung Date: Mon, 26 Dec 2022 16:10:37 -0800 Subject: [PATCH 2/3] make generate --- testdata/project-v2/PROJECT | 3 +++ testdata/project-v3-config/PROJECT | 3 +++ testdata/project-v3-declarative-v1/PROJECT | 3 +++ testdata/project-v3-multigroup/PROJECT | 3 +++ testdata/project-v3-with-deploy-image/PROJECT | 3 +++ testdata/project-v3-with-grafana/PROJECT | 3 +++ testdata/project-v3/PROJECT | 3 +++ testdata/project-v4-config/PROJECT | 3 +++ testdata/project-v4-declarative-v1/PROJECT | 3 +++ testdata/project-v4-multigroup/PROJECT | 3 +++ testdata/project-v4-with-deploy-image/PROJECT | 3 +++ testdata/project-v4-with-grafana/PROJECT | 3 +++ testdata/project-v4/PROJECT | 3 +++ 13 files changed, 39 insertions(+) diff --git a/testdata/project-v2/PROJECT b/testdata/project-v2/PROJECT index 36aacd80d5b..c27427db58a 100644 --- a/testdata/project-v2/PROJECT +++ b/testdata/project-v2/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. domain: testproject.org repo: sigs.k8s.io/kubebuilder/testdata/project-v2 resources: diff --git a/testdata/project-v3-config/PROJECT b/testdata/project-v3-config/PROJECT index 83e7f357591..bb1d89ab23c 100644 --- a/testdata/project-v3-config/PROJECT +++ b/testdata/project-v3-config/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. componentConfig: true domain: testproject.org layout: diff --git a/testdata/project-v3-declarative-v1/PROJECT b/testdata/project-v3-declarative-v1/PROJECT index 858f9f647d6..9bee7ba04f4 100644 --- a/testdata/project-v3-declarative-v1/PROJECT +++ b/testdata/project-v3-declarative-v1/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v3-multigroup/PROJECT b/testdata/project-v3-multigroup/PROJECT index 938072fdc06..2328824e5c0 100644 --- a/testdata/project-v3-multigroup/PROJECT +++ b/testdata/project-v3-multigroup/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v3-with-deploy-image/PROJECT b/testdata/project-v3-with-deploy-image/PROJECT index cdc2fa5c3ab..94c000611e1 100644 --- a/testdata/project-v3-with-deploy-image/PROJECT +++ b/testdata/project-v3-with-deploy-image/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v3-with-grafana/PROJECT b/testdata/project-v3-with-grafana/PROJECT index 329ffeaa527..886daf948a6 100644 --- a/testdata/project-v3-with-grafana/PROJECT +++ b/testdata/project-v3-with-grafana/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v3/PROJECT b/testdata/project-v3/PROJECT index 8ef4c5b14ac..ff0266c89a5 100644 --- a/testdata/project-v3/PROJECT +++ b/testdata/project-v3/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v4-config/PROJECT b/testdata/project-v4-config/PROJECT index 92f6555562e..94d29bb634e 100644 --- a/testdata/project-v4-config/PROJECT +++ b/testdata/project-v4-config/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. componentConfig: true domain: testproject.org layout: diff --git a/testdata/project-v4-declarative-v1/PROJECT b/testdata/project-v4-declarative-v1/PROJECT index 3acf97bc344..c83fdec823e 100644 --- a/testdata/project-v4-declarative-v1/PROJECT +++ b/testdata/project-v4-declarative-v1/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. domain: testproject.org layout: - go.kubebuilder.io/v4-alpha diff --git a/testdata/project-v4-multigroup/PROJECT b/testdata/project-v4-multigroup/PROJECT index ef652e90d9c..9492f5212f7 100644 --- a/testdata/project-v4-multigroup/PROJECT +++ b/testdata/project-v4-multigroup/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. domain: testproject.org layout: - go.kubebuilder.io/v4-alpha diff --git a/testdata/project-v4-with-deploy-image/PROJECT b/testdata/project-v4-with-deploy-image/PROJECT index ae6a0353e0a..b3f1bf971b3 100644 --- a/testdata/project-v4-with-deploy-image/PROJECT +++ b/testdata/project-v4-with-deploy-image/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. domain: testproject.org layout: - go.kubebuilder.io/v4-alpha diff --git a/testdata/project-v4-with-grafana/PROJECT b/testdata/project-v4-with-grafana/PROJECT index 07d11fc3467..bb491f11fd3 100644 --- a/testdata/project-v4-with-grafana/PROJECT +++ b/testdata/project-v4-with-grafana/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v4/PROJECT b/testdata/project-v4/PROJECT index 2fdc4c243f0..d04456774bd 100644 --- a/testdata/project-v4/PROJECT +++ b/testdata/project-v4/PROJECT @@ -1,3 +1,6 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. domain: testproject.org layout: - go.kubebuilder.io/v4-alpha From c90c039fde0094690381ba08774fadebb3db7be5 Mon Sep 17 00:00:00 2001 From: jasonjung Date: Fri, 30 Dec 2022 22:27:02 -0800 Subject: [PATCH 3/3] add link --- pkg/config/store/yaml/store.go | 1 + testdata/project-v2/PROJECT | 1 + testdata/project-v3-config/PROJECT | 1 + testdata/project-v3-declarative-v1/PROJECT | 1 + testdata/project-v3-multigroup/PROJECT | 1 + testdata/project-v3-with-deploy-image/PROJECT | 1 + testdata/project-v3-with-grafana/PROJECT | 1 + testdata/project-v3/PROJECT | 1 + testdata/project-v4-config/PROJECT | 1 + testdata/project-v4-declarative-v1/PROJECT | 1 + testdata/project-v4-multigroup/PROJECT | 1 + testdata/project-v4-with-deploy-image/PROJECT | 1 + testdata/project-v4-with-grafana/PROJECT | 1 + testdata/project-v4/PROJECT | 1 + 14 files changed, 14 insertions(+) diff --git a/pkg/config/store/yaml/store.go b/pkg/config/store/yaml/store.go index bc6e728d9ae..8f3531dc65b 100644 --- a/pkg/config/store/yaml/store.go +++ b/pkg/config/store/yaml/store.go @@ -36,6 +36,7 @@ const ( commentStr = `# Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html ` ) diff --git a/testdata/project-v2/PROJECT b/testdata/project-v2/PROJECT index c27427db58a..53085282124 100644 --- a/testdata/project-v2/PROJECT +++ b/testdata/project-v2/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: testproject.org repo: sigs.k8s.io/kubebuilder/testdata/project-v2 resources: diff --git a/testdata/project-v3-config/PROJECT b/testdata/project-v3-config/PROJECT index bb1d89ab23c..6ba744a8f09 100644 --- a/testdata/project-v3-config/PROJECT +++ b/testdata/project-v3-config/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html componentConfig: true domain: testproject.org layout: diff --git a/testdata/project-v3-declarative-v1/PROJECT b/testdata/project-v3-declarative-v1/PROJECT index 9bee7ba04f4..7853be9c396 100644 --- a/testdata/project-v3-declarative-v1/PROJECT +++ b/testdata/project-v3-declarative-v1/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v3-multigroup/PROJECT b/testdata/project-v3-multigroup/PROJECT index 2328824e5c0..0022d46f1b4 100644 --- a/testdata/project-v3-multigroup/PROJECT +++ b/testdata/project-v3-multigroup/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v3-with-deploy-image/PROJECT b/testdata/project-v3-with-deploy-image/PROJECT index 94c000611e1..970f41493fb 100644 --- a/testdata/project-v3-with-deploy-image/PROJECT +++ b/testdata/project-v3-with-deploy-image/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v3-with-grafana/PROJECT b/testdata/project-v3-with-grafana/PROJECT index 886daf948a6..d0e2feedf2f 100644 --- a/testdata/project-v3-with-grafana/PROJECT +++ b/testdata/project-v3-with-grafana/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v3/PROJECT b/testdata/project-v3/PROJECT index ff0266c89a5..8376173de79 100644 --- a/testdata/project-v3/PROJECT +++ b/testdata/project-v3/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v4-config/PROJECT b/testdata/project-v4-config/PROJECT index 94d29bb634e..dddcf4b57f7 100644 --- a/testdata/project-v4-config/PROJECT +++ b/testdata/project-v4-config/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html componentConfig: true domain: testproject.org layout: diff --git a/testdata/project-v4-declarative-v1/PROJECT b/testdata/project-v4-declarative-v1/PROJECT index c83fdec823e..28ef24efc50 100644 --- a/testdata/project-v4-declarative-v1/PROJECT +++ b/testdata/project-v4-declarative-v1/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: testproject.org layout: - go.kubebuilder.io/v4-alpha diff --git a/testdata/project-v4-multigroup/PROJECT b/testdata/project-v4-multigroup/PROJECT index 9492f5212f7..efe0381f3a0 100644 --- a/testdata/project-v4-multigroup/PROJECT +++ b/testdata/project-v4-multigroup/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: testproject.org layout: - go.kubebuilder.io/v4-alpha diff --git a/testdata/project-v4-with-deploy-image/PROJECT b/testdata/project-v4-with-deploy-image/PROJECT index b3f1bf971b3..3d0131505b5 100644 --- a/testdata/project-v4-with-deploy-image/PROJECT +++ b/testdata/project-v4-with-deploy-image/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: testproject.org layout: - go.kubebuilder.io/v4-alpha diff --git a/testdata/project-v4-with-grafana/PROJECT b/testdata/project-v4-with-grafana/PROJECT index bb491f11fd3..241a6cdefb9 100644 --- a/testdata/project-v4-with-grafana/PROJECT +++ b/testdata/project-v4-with-grafana/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: testproject.org layout: - go.kubebuilder.io/v3 diff --git a/testdata/project-v4/PROJECT b/testdata/project-v4/PROJECT index d04456774bd..c2e591df335 100644 --- a/testdata/project-v4/PROJECT +++ b/testdata/project-v4/PROJECT @@ -1,6 +1,7 @@ # Code generated by tool. DO NOT EDIT. # This file is used to track the info used to scaffold your project # and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: testproject.org layout: - go.kubebuilder.io/v4-alpha