@@ -140,102 +140,168 @@ spec:
140140 Not (ContainSubstring (`# SECURITY ADVISORY` )),
141141 ))
142142 })
143- })
144143
145- Describe ( "#WriteObjectsToFilesystem - MergeModeInformative" , func () {
146- It ( "should annotate operator-overridden scalar values with the GLK default and preserve user comments idempotently" , func ( ) {
147- initial := []byte (`apiVersion: v1
144+ DescribeTable ( "should annotate operator-overwritten values only in Informative mode" ,
145+ func ( mode configv1alpha1. MergeMode , expectAnnotation bool ) {
146+ initial := []byte (`apiVersion: v1
148147kind: ConfigMap
149148metadata:
150149 name: test
151150data:
152151 version: v1.0.0
153152` )
154- // First generate: establish defaults
155- Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : initial }, "/landscape" , "manifest" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
153+ Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : initial }, "/landscape" , "manifest" , fs , mode )).To (Succeed ())
156154
157- // Operator pins to a custom version with a comment explaining why
158- Expect (fs .WriteFile ("/landscape/manifest/test.yaml" , []byte (`apiVersion: v1
155+ // Operator pins to a custom version with a comment explaining why
156+ Expect (fs .WriteFile ("/landscape/manifest/test.yaml" , []byte (`apiVersion: v1
159157kind: ConfigMap
160158metadata:
161159 name: test
162160data:
163161 version: v1.0.5 # pinned for production
164162` ), 0600 )).To (Succeed ())
165163
166- // GLK ships a new default with a newer version
167- updated := []byte (`apiVersion: v1
164+ // GLK ships a new default with a newer version
165+ updated := []byte (`apiVersion: v1
168166kind: ConfigMap
169167metadata:
170168 name: test
171169data:
172170 version: v1.1.0
173171` )
174- Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : updated }, "/landscape" , "manifest" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
172+ Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : updated }, "/landscape" , "manifest" , fs , mode )).To (Succeed ())
173+
174+ content , err := fs .ReadFile ("/landscape/manifest/test.yaml" )
175+ Expect (err ).NotTo (HaveOccurred ())
176+ Expect (string (content )).To (ContainSubstring ("version: v1.0.5" ))
177+ Expect (string (content )).To (ContainSubstring ("pinned for production" ))
178+
179+ if expectAnnotation {
180+ Expect (string (content )).To (ContainSubstring (meta .GLKDefaultPrefix + "v1.1.0" ))
181+
182+ // Re-run with the same default — annotation persists because the user did not remove it.
183+ Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : updated }, "/landscape" , "manifest" , fs , mode )).To (Succeed ())
184+ content2 , err := fs .ReadFile ("/landscape/manifest/test.yaml" )
185+ Expect (err ).NotTo (HaveOccurred ())
186+ Expect (string (content2 )).To (Equal (string (content )))
187+ } else {
188+ Expect (string (content )).NotTo (ContainSubstring (meta .GLKDefaultPrefix ))
189+ }
190+ },
191+ Entry ("Silent" , configv1alpha1 .MergeModeSilent , false ),
192+ Entry ("Informative" , configv1alpha1 .MergeModeInformative , true ),
193+ )
175194
176- content , err := fs .ReadFile ("/landscape/manifest/test.yaml" )
177- Expect (err ).NotTo (HaveOccurred ())
178- // Operator's override is preserved
179- Expect (string (content )).To (ContainSubstring ("version: v1.0.5" ))
180- // User comment is preserved
181- Expect (string (content )).To (ContainSubstring ("pinned for production" ))
182- // GLK default annotation is added
183- Expect (string (content )).To (ContainSubstring ("# glk default: v1.1.0" ))
184- Expect (string (content )).To (ContainSubstring (meta .GLKManagedMarker ))
185-
186- // Re-run with the same inputs — annotation and user comment must not be doubled
187- Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : updated }, "/landscape" , "manifest" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
188-
189- content2 , err := fs .ReadFile ("/landscape/manifest/test.yaml" )
190- Expect (err ).NotTo (HaveOccurred ())
191- Expect (string (content2 )).To (Equal (string (content )))
192- })
195+ Context ("MergeMode Informative" , func () {
196+ It ("should not re-add the annotation after the user removed it, until the default changes again" , func () {
197+ initial := []byte (`apiVersion: v1
198+ kind: ConfigMap
199+ metadata:
200+ name: test
201+ data:
202+ version: v1.0.0
203+ ` )
204+ Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : initial }, "/landscape" , "manifest" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
205+
206+ // Operator pins to v1.0.5
207+ Expect (fs .WriteFile ("/landscape/manifest/test.yaml" , []byte (`apiVersion: v1
208+ kind: ConfigMap
209+ metadata:
210+ name: test
211+ data:
212+ version: v1.0.5
213+ ` ), 0600 )).To (Succeed ())
214+
215+ // GLK ships v1.1.0 — annotation appears
216+ v110 := []byte (`apiVersion: v1
217+ kind: ConfigMap
218+ metadata:
219+ name: test
220+ data:
221+ version: v1.1.0
222+ ` )
223+ Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : v110 }, "/landscape" , "manifest" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
224+ content , err := fs .ReadFile ("/landscape/manifest/test.yaml" )
225+ Expect (err ).NotTo (HaveOccurred ())
226+ Expect (string (content )).To (ContainSubstring (meta .GLKDefaultPrefix ))
227+
228+ // User acknowledges the annotation and removes it manually
229+ Expect (fs .WriteFile ("/landscape/manifest/test.yaml" , []byte (`apiVersion: v1
230+ kind: ConfigMap
231+ metadata:
232+ name: test
233+ data:
234+ version: v1.0.5
235+ ` ), 0600 )).To (Succeed ())
236+
237+ // Re-run with the same default — annotation stays removed
238+ Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : v110 }, "/landscape" , "manifest" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
239+ content , err = fs .ReadFile ("/landscape/manifest/test.yaml" )
240+ Expect (err ).NotTo (HaveOccurred ())
241+ Expect (string (content )).To (ContainSubstring ("version: v1.0.5" ))
242+ Expect (string (content )).NotTo (ContainSubstring (meta .GLKDefaultPrefix ))
193243
194- It ("should remove the annotation entirely when the GLK default reverts to the operator's value" , func () {
195- initial := []byte (`apiVersion: v1
244+ // GLK ships v1.2.0 — annotation re-appears because the default changed
245+ v120 := []byte (`apiVersion: v1
246+ kind: ConfigMap
247+ metadata:
248+ name: test
249+ data:
250+ version: v1.2.0
251+ ` )
252+ Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : v120 }, "/landscape" , "manifest" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
253+ content , err = fs .ReadFile ("/landscape/manifest/test.yaml" )
254+ Expect (err ).NotTo (HaveOccurred ())
255+ Expect (string (content )).To (ContainSubstring ("version: v1.0.5" ))
256+ Expect (string (content )).To (ContainSubstring (meta .GLKDefaultPrefix + "v1.2.0" ))
257+ })
258+
259+ It ("should remove the annotation entirely when the GLK default reverts to the operator's value" , func () {
260+ initial := []byte (`apiVersion: v1
196261kind: ConfigMap
197262metadata:
198263 name: test
199264data:
200265 version: v1.0.0
201266` )
202- Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : initial }, "/landscape" , "revert" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
267+ Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : initial }, "/landscape" , "revert" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
203268
204- // Operator pins to v1.0.5
205- Expect (fs .WriteFile ("/landscape/revert/test.yaml" , []byte (`apiVersion: v1
269+ // Operator pins to v1.0.5
270+ Expect (fs .WriteFile ("/landscape/revert/test.yaml" , []byte (`apiVersion: v1
206271kind: ConfigMap
207272metadata:
208273 name: test
209274data:
210275 version: v1.0.5
211276` ), 0600 )).To (Succeed ())
212277
213- // GLK ships v1.1.0 — annotation appears
214- updated := []byte (`apiVersion: v1
278+ // GLK ships v1.1.0 — annotation appears
279+ updated := []byte (`apiVersion: v1
215280kind: ConfigMap
216281metadata:
217282 name: test
218283data:
219284 version: v1.1.0
220285` )
221- Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : updated }, "/landscape" , "revert" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
222- content , err := fs .ReadFile ("/landscape/revert/test.yaml" )
223- Expect (err ).NotTo (HaveOccurred ())
224- Expect (string (content )).To (ContainSubstring (meta .GLKManagedMarker ))
286+ Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : updated }, "/landscape" , "revert" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
287+ content , err := fs .ReadFile ("/landscape/revert/test.yaml" )
288+ Expect (err ).NotTo (HaveOccurred ())
289+ Expect (string (content )).To (ContainSubstring (meta .GLKDefaultPrefix ))
225290
226- // GLK reverts to v1.0.5 — operator's value now matches the default, no annotation
227- reverted := []byte (`apiVersion: v1
291+ // GLK reverts to v1.0.5 — operator's value now matches the default, no annotation
292+ reverted := []byte (`apiVersion: v1
228293kind: ConfigMap
229294metadata:
230295 name: test
231296data:
232297 version: v1.0.5
233298` )
234- Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : reverted }, "/landscape" , "revert" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
235- content , err = fs .ReadFile ("/landscape/revert/test.yaml" )
236- Expect (err ).NotTo (HaveOccurred ())
237- Expect (string (content )).NotTo (ContainSubstring (meta .GLKManagedMarker ))
238- Expect (string (content )).NotTo (ContainSubstring ("# glk default:" ))
299+ Expect (files .WriteObjectsToFilesystem (map [string ][]byte {"test.yaml" : reverted }, "/landscape" , "revert" , fs , configv1alpha1 .MergeModeInformative )).To (Succeed ())
300+ content , err = fs .ReadFile ("/landscape/revert/test.yaml" )
301+ Expect (err ).NotTo (HaveOccurred ())
302+ Expect (string (content )).NotTo (ContainSubstring (meta .GLKDefaultPrefix ))
303+ Expect (string (content )).NotTo (ContainSubstring ("# Attention - new default:" ))
304+ })
239305 })
240306 })
241307
0 commit comments