From 81a724c3ac752cad7f0995305ca542054d7a13a1 Mon Sep 17 00:00:00 2001 From: Jason Jung Date: Sat, 31 Dec 2022 02:59:29 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20warning=20comment=20on=20PROJECT=20?= =?UTF-8?q?file=20(#3137)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * warning comment on PROJECT file * make generate * add link --- pkg/config/store/yaml/store.go | 10 ++++++++ pkg/config/store/yaml/store_test.go | 25 +++++++++---------- testdata/project-v2/PROJECT | 4 +++ testdata/project-v3-config/PROJECT | 4 +++ testdata/project-v3-declarative-v1/PROJECT | 4 +++ testdata/project-v3-multigroup/PROJECT | 4 +++ testdata/project-v3-with-deploy-image/PROJECT | 4 +++ testdata/project-v3-with-grafana/PROJECT | 4 +++ testdata/project-v3/PROJECT | 4 +++ testdata/project-v4-config/PROJECT | 4 +++ testdata/project-v4-declarative-v1/PROJECT | 4 +++ testdata/project-v4-multigroup/PROJECT | 4 +++ testdata/project-v4-with-deploy-image/PROJECT | 4 +++ testdata/project-v4-with-grafana/PROJECT | 4 +++ testdata/project-v4/PROJECT | 4 +++ 15 files changed, 74 insertions(+), 13 deletions(-) diff --git a/pkg/config/store/yaml/store.go b/pkg/config/store/yaml/store.go index 46223f1078d..8f3531dc65b 100644 --- a/pkg/config/store/yaml/store.go +++ b/pkg/config/store/yaml/store.go @@ -31,6 +31,13 @@ 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. +# More info: https://book.kubebuilder.io/reference/project-config.html +` ) // yamlStore implements store.Store using a YAML file as the storage backend @@ -133,6 +140,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() { diff --git a/testdata/project-v2/PROJECT b/testdata/project-v2/PROJECT index 36aacd80d5b..53085282124 100644 --- a/testdata/project-v2/PROJECT +++ b/testdata/project-v2/PROJECT @@ -1,3 +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 83e7f357591..6ba744a8f09 100644 --- a/testdata/project-v3-config/PROJECT +++ b/testdata/project-v3-config/PROJECT @@ -1,3 +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 858f9f647d6..7853be9c396 100644 --- a/testdata/project-v3-declarative-v1/PROJECT +++ b/testdata/project-v3-declarative-v1/PROJECT @@ -1,3 +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 938072fdc06..0022d46f1b4 100644 --- a/testdata/project-v3-multigroup/PROJECT +++ b/testdata/project-v3-multigroup/PROJECT @@ -1,3 +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 cdc2fa5c3ab..970f41493fb 100644 --- a/testdata/project-v3-with-deploy-image/PROJECT +++ b/testdata/project-v3-with-deploy-image/PROJECT @@ -1,3 +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 329ffeaa527..d0e2feedf2f 100644 --- a/testdata/project-v3-with-grafana/PROJECT +++ b/testdata/project-v3-with-grafana/PROJECT @@ -1,3 +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 8ef4c5b14ac..8376173de79 100644 --- a/testdata/project-v3/PROJECT +++ b/testdata/project-v3/PROJECT @@ -1,3 +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 92f6555562e..dddcf4b57f7 100644 --- a/testdata/project-v4-config/PROJECT +++ b/testdata/project-v4-config/PROJECT @@ -1,3 +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 3acf97bc344..28ef24efc50 100644 --- a/testdata/project-v4-declarative-v1/PROJECT +++ b/testdata/project-v4-declarative-v1/PROJECT @@ -1,3 +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 ef652e90d9c..efe0381f3a0 100644 --- a/testdata/project-v4-multigroup/PROJECT +++ b/testdata/project-v4-multigroup/PROJECT @@ -1,3 +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 ae6a0353e0a..3d0131505b5 100644 --- a/testdata/project-v4-with-deploy-image/PROJECT +++ b/testdata/project-v4-with-deploy-image/PROJECT @@ -1,3 +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 07d11fc3467..241a6cdefb9 100644 --- a/testdata/project-v4-with-grafana/PROJECT +++ b/testdata/project-v4-with-grafana/PROJECT @@ -1,3 +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 2fdc4c243f0..c2e591df335 100644 --- a/testdata/project-v4/PROJECT +++ b/testdata/project-v4/PROJECT @@ -1,3 +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