Skip to content

Commit bc644f0

Browse files
authored
✨ warning comment on PROJECT file (#3137)
* warning comment on PROJECT file * make generate * add link
1 parent e118741 commit bc644f0

File tree

15 files changed

+74
-13
lines changed

15 files changed

+74
-13
lines changed

pkg/config/store/yaml/store.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ import (
3131
const (
3232
// DefaultPath is the default path for the configuration file
3333
DefaultPath = "PROJECT"
34+
35+
// Comment for 'PROJECT' config file
36+
commentStr = `# Code generated by tool. DO NOT EDIT.
37+
# This file is used to track the info used to scaffold your project
38+
# and allow the plugins properly work.
39+
# More info: https://book.kubebuilder.io/reference/project-config.html
40+
`
3441
)
3542

3643
// yamlStore implements store.Store using a YAML file as the storage backend
@@ -133,6 +140,9 @@ func (s yamlStore) SaveTo(path string) error {
133140
return store.SaveError{Err: fmt.Errorf("unable to marshal to YAML: %w", err)}
134141
}
135142

143+
// Prepend warning comment for the 'PROJECT' file
144+
content = append([]byte(commentStr), content...)
145+
136146
// Write the marshalled configuration
137147
err = afero.WriteFile(s.fs, path, content, 0600)
138148
if err != nil {

pkg/config/store/yaml/store_test.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ layout: ""
8686

8787
Context("Load", func() {
8888
It("should load the Config from an existing file at the default path", func() {
89-
Expect(afero.WriteFile(s.fs, DefaultPath, []byte(v2File), os.ModePerm)).To(Succeed())
89+
Expect(afero.WriteFile(s.fs, DefaultPath, []byte(commentStr+v2File), os.ModePerm)).To(Succeed())
9090

9191
Expect(s.Load()).To(Succeed())
9292
Expect(s.fs).NotTo(BeNil())
@@ -102,23 +102,23 @@ layout: ""
102102
})
103103

104104
It("should fail if unable to identify the version of the file at the default path", func() {
105-
Expect(afero.WriteFile(s.fs, DefaultPath, []byte(unversionedFile), os.ModePerm)).To(Succeed())
105+
Expect(afero.WriteFile(s.fs, DefaultPath, []byte(commentStr+unversionedFile), os.ModePerm)).To(Succeed())
106106

107107
err := s.Load()
108108
Expect(err).To(HaveOccurred())
109109
Expect(errors.As(err, &store.LoadError{})).To(BeTrue())
110110
})
111111

112112
It("should fail if unable to create a Config for the version of the file at the default path", func() {
113-
Expect(afero.WriteFile(s.fs, DefaultPath, []byte(nonexistentVersionFile), os.ModePerm)).To(Succeed())
113+
Expect(afero.WriteFile(s.fs, DefaultPath, []byte(commentStr+nonexistentVersionFile), os.ModePerm)).To(Succeed())
114114

115115
err := s.Load()
116116
Expect(err).To(HaveOccurred())
117117
Expect(errors.As(err, &store.LoadError{})).To(BeTrue())
118118
})
119119

120120
It("should fail if unable to unmarshal the file at the default path", func() {
121-
Expect(afero.WriteFile(s.fs, DefaultPath, []byte(wrongFile), os.ModePerm)).To(Succeed())
121+
Expect(afero.WriteFile(s.fs, DefaultPath, []byte(commentStr+wrongFile), os.ModePerm)).To(Succeed())
122122

123123
err := s.Load()
124124
Expect(err).To(HaveOccurred())
@@ -128,7 +128,7 @@ layout: ""
128128

129129
Context("LoadFrom", func() {
130130
It("should load the Config from an existing file from the specified path", func() {
131-
Expect(afero.WriteFile(s.fs, path, []byte(v2File), os.ModePerm)).To(Succeed())
131+
Expect(afero.WriteFile(s.fs, path, []byte(commentStr+v2File), os.ModePerm)).To(Succeed())
132132

133133
Expect(s.LoadFrom(path)).To(Succeed())
134134
Expect(s.fs).NotTo(BeNil())
@@ -144,23 +144,23 @@ layout: ""
144144
})
145145

146146
It("should fail if unable to identify the version of the file at the specified path", func() {
147-
Expect(afero.WriteFile(s.fs, path, []byte(unversionedFile), os.ModePerm)).To(Succeed())
147+
Expect(afero.WriteFile(s.fs, path, []byte(commentStr+unversionedFile), os.ModePerm)).To(Succeed())
148148

149149
err := s.LoadFrom(path)
150150
Expect(err).To(HaveOccurred())
151151
Expect(errors.As(err, &store.LoadError{})).To(BeTrue())
152152
})
153153

154154
It("should fail if unable to create a Config for the version of the file at the specified path", func() {
155-
Expect(afero.WriteFile(s.fs, path, []byte(nonexistentVersionFile), os.ModePerm)).To(Succeed())
155+
Expect(afero.WriteFile(s.fs, path, []byte(commentStr+nonexistentVersionFile), os.ModePerm)).To(Succeed())
156156

157157
err := s.LoadFrom(path)
158158
Expect(err).To(HaveOccurred())
159159
Expect(errors.As(err, &store.LoadError{})).To(BeTrue())
160160
})
161161

162162
It("should fail if unable to unmarshal the file at the specified path", func() {
163-
Expect(afero.WriteFile(s.fs, path, []byte(wrongFile), os.ModePerm)).To(Succeed())
163+
Expect(afero.WriteFile(s.fs, path, []byte(commentStr+wrongFile), os.ModePerm)).To(Succeed())
164164

165165
err := s.LoadFrom(path)
166166
Expect(err).To(HaveOccurred())
@@ -175,7 +175,7 @@ layout: ""
175175

176176
cfgBytes, err := afero.ReadFile(s.fs, DefaultPath)
177177
Expect(err).NotTo(HaveOccurred())
178-
Expect(string(cfgBytes)).To(Equal(v2File))
178+
Expect(string(cfgBytes)).To(Equal(commentStr + v2File))
179179
})
180180

181181
It("should succeed for a valid config that must not exist", func() {
@@ -185,7 +185,7 @@ layout: ""
185185

186186
cfgBytes, err := afero.ReadFile(s.fs, DefaultPath)
187187
Expect(err).NotTo(HaveOccurred())
188-
Expect(string(cfgBytes)).To(Equal(v2File))
188+
Expect(string(cfgBytes)).To(Equal(commentStr + v2File))
189189
})
190190

191191
It("should fail for an empty config", func() {
@@ -212,8 +212,7 @@ layout: ""
212212

213213
cfgBytes, err := afero.ReadFile(s.fs, path)
214214
Expect(err).NotTo(HaveOccurred())
215-
Expect(string(cfgBytes)).To(Equal(`version: "2"
216-
`))
215+
Expect(string(cfgBytes)).To(Equal(commentStr + v2File))
217216
})
218217

219218
It("should succeed for a valid config that must not exist", func() {
@@ -223,7 +222,7 @@ layout: ""
223222

224223
cfgBytes, err := afero.ReadFile(s.fs, path)
225224
Expect(err).NotTo(HaveOccurred())
226-
Expect(string(cfgBytes)).To(Equal(v2File))
225+
Expect(string(cfgBytes)).To(Equal(commentStr + v2File))
227226
})
228227

229228
It("should fail for an empty config", func() {

testdata/project-v2/PROJECT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: testproject.org
26
repo: sigs.k8s.io/kubebuilder/testdata/project-v2
37
resources:

testdata/project-v3-config/PROJECT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
componentConfig: true
26
domain: testproject.org
37
layout:

testdata/project-v3-declarative-v1/PROJECT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: testproject.org
26
layout:
37
- go.kubebuilder.io/v3

testdata/project-v3-multigroup/PROJECT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: testproject.org
26
layout:
37
- go.kubebuilder.io/v3

testdata/project-v3-with-deploy-image/PROJECT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: testproject.org
26
layout:
37
- go.kubebuilder.io/v3

testdata/project-v3-with-grafana/PROJECT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: testproject.org
26
layout:
37
- go.kubebuilder.io/v3

testdata/project-v3/PROJECT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: testproject.org
26
layout:
37
- go.kubebuilder.io/v3

testdata/project-v4-config/PROJECT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
componentConfig: true
26
domain: testproject.org
37
layout:

0 commit comments

Comments
 (0)