Skip to content

Commit aa07b30

Browse files
committed
add singleargocd deprecation warning
1 parent 996912f commit aa07b30

5 files changed

Lines changed: 186 additions & 37 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ What upgrade does:
134134
- Otherwise: prepends `include Makefile-common` to the first line so your existing targets are preserved
135135
- Prints a deprecation warning if `values-global.yaml` still uses `main.clusterGroupName`, which the Validated Patterns operator deprecated in favor of `main.variant` in version 0.0.78 (`upgrade` does not modify the file; run `patternizer init` to migrate automatically)
136136
- Prints a deprecation warning if the pattern does not use the [variants folder structure](https://validatedpatterns.io/blog/2026-08-04-variants-folder-structure/) (introduced in operator version 0.0.78) — that is, if `variants/<variant>/values-<variant>.yaml` is missing for the configured variant (`upgrade` does not move any files; run `patternizer init` to migrate automatically)
137+
- Prints a warning if `global.singleArgoCD` is not set in `values-global.yaml`, recommending you set `global.singleArgoCD: true` if possible (see the [single ArgoCD instance](https://validatedpatterns.io/blog/2026-06-04-single-argocd-option/) blog post)
138+
139+
These warnings are written to stderr, grouped after the success message, so they stand out as a call to action.
137140
138141
### Understanding Secrets Management
139142

‎src/cmd/upgrade.go‎

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,58 @@ func runUpgrade(replaceMakefile bool) error {
7070
return fmt.Errorf("error installing skills: %w", err)
7171
}
7272

73+
warnings, err := collectUpgradeWarnings(repoRoot)
74+
if err != nil {
75+
return err
76+
}
77+
78+
fmt.Printf("Successfully upgraded pattern repository in %s\n", repoRoot)
79+
80+
emitUpgradeWarnings(warnings)
81+
return nil
82+
}
83+
84+
// collectUpgradeWarnings inspects the pattern's values-global.yaml and returns a list of
85+
// compact deprecation warnings that should be surfaced to the user as a call to action.
86+
func collectUpgradeWarnings(repoRoot string) ([]string, error) {
87+
var warnings []string
88+
7389
deprecated, err := pattern.UsesDeprecatedClusterGroupName(repoRoot)
7490
if err != nil {
75-
return fmt.Errorf("error checking for deprecated fields: %w", err)
91+
return nil, fmt.Errorf("error checking for deprecated fields: %w", err)
7692
}
7793
if deprecated {
78-
fmt.Println("Warning: values-global.yaml uses the deprecated 'main.clusterGroupName' field.")
79-
fmt.Println("The Validated Patterns operator deprecated 'main.clusterGroupName' in favor of 'main.variant' in version 0.0.78.")
80-
fmt.Println("Please update values-global.yaml to use 'main.variant'.")
94+
warnings = append(warnings, "WARNING: values-global.yaml uses deprecated 'main.clusterGroupName' (operator 0.0.78). Set 'main.variant' instead.")
8195
}
8296

8397
variant, folderMissing, err := pattern.VariantFolderFileMissing(repoRoot)
8498
if err != nil {
85-
return fmt.Errorf("error checking for variants folder structure: %w", err)
99+
return nil, fmt.Errorf("error checking for variants folder structure: %w", err)
86100
}
87101
if folderMissing {
88-
fmt.Printf("Warning: this pattern does not use the variants folder structure (variants/%s/values-%s.yaml not found).\n", variant, variant)
89-
fmt.Println("The Validated Patterns operator introduced the variants folder structure in version 0.0.78.")
90-
fmt.Println("See https://validatedpatterns.io/blog/2026-08-04-variants-folder-structure/ for migration guidance.")
102+
warnings = append(warnings, fmt.Sprintf("WARNING: not using the variants folder structure (variants/%s/values-%s.yaml not found; operator 0.0.78). See https://validatedpatterns.io/blog/2026-08-04-variants-folder-structure/", variant, variant))
91103
}
92104

93-
fmt.Printf("Successfully upgraded pattern repository in %s\n", repoRoot)
94-
return nil
105+
missingSingleArgoCD, err := pattern.MissingSingleArgoCD(repoRoot)
106+
if err != nil {
107+
return nil, fmt.Errorf("error checking for singleArgoCD: %w", err)
108+
}
109+
if missingSingleArgoCD {
110+
warnings = append(warnings, "WARNING: 'global.singleArgoCD' is not set. Set 'global.singleArgoCD: true' if possible. See https://validatedpatterns.io/blog/2026-06-04-single-argocd-option/")
111+
}
112+
113+
return warnings, nil
114+
}
115+
116+
// emitUpgradeWarnings prints deprecation warnings to stderr as a grouped block, separated
117+
// from the normal stdout logs so they stand out as a call to action.
118+
func emitUpgradeWarnings(warnings []string) {
119+
if len(warnings) == 0 {
120+
return
121+
}
122+
123+
fmt.Fprintln(os.Stderr)
124+
for _, warning := range warnings {
125+
fmt.Fprintln(os.Stderr, warning)
126+
}
95127
}

‎src/cmd/upgrade_test.go‎

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,15 @@ var _ = Describe("patternizer update (upgrade alias)", func() {
115115
})
116116
})
117117

118+
func writeVariantFolderFile(dir, variant string) {
119+
variantDir := filepath.Join(dir, "variants", variant)
120+
Expect(os.MkdirAll(variantDir, 0o755)).To(Succeed())
121+
Expect(os.WriteFile(filepath.Join(variantDir, "values-"+variant+".yaml"), []byte("clusterGroup:\n name: "+variant+"\n"), 0o644)).To(Succeed())
122+
}
123+
118124
var _ = Describe("patternizer upgrade deprecation warning", func() {
119-
const legacyGlobal = "global:\n pattern: test-pattern\nmain:\n clusterGroupName: hub\n"
120-
const variantGlobal = "global:\n pattern: test-pattern\nmain:\n variant: hub\n"
125+
const legacyGlobal = "global:\n pattern: test-pattern\n singleArgoCD: true\nmain:\n clusterGroupName: hub\n"
126+
const upToDateGlobal = "global:\n pattern: test-pattern\n singleArgoCD: true\nmain:\n variant: hub\n"
121127

122128
Context("when values-global.yaml uses the deprecated main.clusterGroupName", func() {
123129
var tempDir string
@@ -129,11 +135,11 @@ var _ = Describe("patternizer upgrade deprecation warning", func() {
129135
session = runCLI(tempDir, "upgrade")
130136
})
131137

132-
It("should print a deprecation warning mentioning main.variant", func() {
133-
out := string(session.Out.Contents())
134-
Expect(out).To(ContainSubstring("main.clusterGroupName"))
135-
Expect(out).To(ContainSubstring("main.variant"))
136-
Expect(out).To(ContainSubstring("0.0.78"))
138+
It("should print a deprecation warning to stderr mentioning main.variant", func() {
139+
errOut := string(session.Err.Contents())
140+
Expect(errOut).To(ContainSubstring("main.clusterGroupName"))
141+
Expect(errOut).To(ContainSubstring("main.variant"))
142+
Expect(errOut).To(ContainSubstring("0.0.78"))
137143
})
138144

139145
It("should leave values-global.yaml unchanged", func() {
@@ -143,28 +149,25 @@ var _ = Describe("patternizer upgrade deprecation warning", func() {
143149
})
144150
})
145151

146-
Context("when values-global.yaml already uses main.variant and the variants folder", func() {
152+
Context("when values-global.yaml is fully up to date", func() {
147153
var tempDir string
148154
var session *gexec.Session
149155

150156
BeforeEach(func() {
151157
tempDir = createTestDir()
152-
Expect(os.WriteFile(filepath.Join(tempDir, "values-global.yaml"), []byte(variantGlobal), 0o644)).To(Succeed())
153-
variantDir := filepath.Join(tempDir, "variants", "hub")
154-
Expect(os.MkdirAll(variantDir, 0o755)).To(Succeed())
155-
Expect(os.WriteFile(filepath.Join(variantDir, "values-hub.yaml"), []byte("clusterGroup:\n name: hub\n"), 0o644)).To(Succeed())
158+
Expect(os.WriteFile(filepath.Join(tempDir, "values-global.yaml"), []byte(upToDateGlobal), 0o644)).To(Succeed())
159+
writeVariantFolderFile(tempDir, "hub")
156160
session = runCLI(tempDir, "upgrade")
157161
})
158162

159-
It("should not print any deprecation warning", func() {
160-
out := string(session.Out.Contents())
161-
Expect(out).NotTo(ContainSubstring("Warning:"))
163+
It("should not print any warnings to stderr", func() {
164+
Expect(string(session.Err.Contents())).NotTo(ContainSubstring("WARNING:"))
162165
})
163166
})
164167
})
165168

166169
var _ = Describe("patternizer upgrade variants folder warning", func() {
167-
const variantGlobal = "global:\n pattern: test-pattern\nmain:\n variant: hub\n"
170+
const variantGlobal = "global:\n pattern: test-pattern\n singleArgoCD: true\nmain:\n variant: hub\n"
168171

169172
Context("when the variants folder file is missing", func() {
170173
var tempDir string
@@ -176,12 +179,12 @@ var _ = Describe("patternizer upgrade variants folder warning", func() {
176179
session = runCLI(tempDir, "upgrade")
177180
})
178181

179-
It("should print a variants folder structure warning linking to the blog", func() {
180-
out := string(session.Out.Contents())
181-
Expect(out).To(ContainSubstring("variants folder structure"))
182-
Expect(out).To(ContainSubstring("variants/hub/values-hub.yaml"))
183-
Expect(out).To(ContainSubstring("0.0.78"))
184-
Expect(out).To(ContainSubstring("https://validatedpatterns.io/blog/2026-08-04-variants-folder-structure/"))
182+
It("should print a variants folder structure warning to stderr linking to the blog", func() {
183+
errOut := string(session.Err.Contents())
184+
Expect(errOut).To(ContainSubstring("variants folder structure"))
185+
Expect(errOut).To(ContainSubstring("variants/hub/values-hub.yaml"))
186+
Expect(errOut).To(ContainSubstring("0.0.78"))
187+
Expect(errOut).To(ContainSubstring("https://validatedpatterns.io/blog/2026-08-04-variants-folder-structure/"))
185188
})
186189
})
187190

@@ -192,15 +195,48 @@ var _ = Describe("patternizer upgrade variants folder warning", func() {
192195
BeforeEach(func() {
193196
tempDir = createTestDir()
194197
Expect(os.WriteFile(filepath.Join(tempDir, "values-global.yaml"), []byte(variantGlobal), 0o644)).To(Succeed())
195-
variantDir := filepath.Join(tempDir, "variants", "hub")
196-
Expect(os.MkdirAll(variantDir, 0o755)).To(Succeed())
197-
Expect(os.WriteFile(filepath.Join(variantDir, "values-hub.yaml"), []byte("clusterGroup:\n name: hub\n"), 0o644)).To(Succeed())
198+
writeVariantFolderFile(tempDir, "hub")
198199
session = runCLI(tempDir, "upgrade")
199200
})
200201

201202
It("should not print a variants folder structure warning", func() {
202-
out := string(session.Out.Contents())
203-
Expect(out).NotTo(ContainSubstring("variants folder structure"))
203+
Expect(string(session.Err.Contents())).NotTo(ContainSubstring("variants folder structure"))
204+
})
205+
})
206+
})
207+
208+
var _ = Describe("patternizer upgrade singleArgoCD warning", func() {
209+
Context("when global.singleArgoCD is not set", func() {
210+
var tempDir string
211+
var session *gexec.Session
212+
213+
BeforeEach(func() {
214+
tempDir = createTestDir()
215+
Expect(os.WriteFile(filepath.Join(tempDir, "values-global.yaml"), []byte("global:\n pattern: test-pattern\nmain:\n variant: hub\n"), 0o644)).To(Succeed())
216+
writeVariantFolderFile(tempDir, "hub")
217+
session = runCLI(tempDir, "upgrade")
218+
})
219+
220+
It("should print a singleArgoCD warning to stderr linking to the blog", func() {
221+
errOut := string(session.Err.Contents())
222+
Expect(errOut).To(ContainSubstring("global.singleArgoCD"))
223+
Expect(errOut).To(ContainSubstring("https://validatedpatterns.io/blog/2026-06-04-single-argocd-option/"))
224+
})
225+
})
226+
227+
Context("when global.singleArgoCD is set", func() {
228+
var tempDir string
229+
var session *gexec.Session
230+
231+
BeforeEach(func() {
232+
tempDir = createTestDir()
233+
Expect(os.WriteFile(filepath.Join(tempDir, "values-global.yaml"), []byte("global:\n pattern: test-pattern\n singleArgoCD: true\nmain:\n variant: hub\n"), 0o644)).To(Succeed())
234+
writeVariantFolderFile(tempDir, "hub")
235+
session = runCLI(tempDir, "upgrade")
236+
})
237+
238+
It("should not print a singleArgoCD warning", func() {
239+
Expect(string(session.Err.Contents())).NotTo(ContainSubstring("singleArgoCD"))
204240
})
205241
})
206242
})

‎src/internal/pattern/pattern.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,34 @@ func variantFolderValuesPath(repoRoot, variant string) string {
126126
return filepath.Join(repoRoot, "variants", variant, variantValuesFileName(variant))
127127
}
128128

129+
// MissingSingleArgoCD reports whether the pattern's values-global.yaml is missing the
130+
// 'global.singleArgoCD' field. It returns false without error when the file does not
131+
// exist (nothing to warn about).
132+
func MissingSingleArgoCD(repoRoot string) (bool, error) {
133+
globalValuesPath := filepath.Join(repoRoot, "values-global.yaml")
134+
135+
yamlFile, err := os.ReadFile(globalValuesPath)
136+
if err != nil {
137+
if os.IsNotExist(err) {
138+
return false, nil
139+
}
140+
return false, fmt.Errorf("failed to read %s: %w", globalValuesPath, err)
141+
}
142+
143+
var raw map[string]interface{}
144+
if err = yaml.Unmarshal(yamlFile, &raw); err != nil {
145+
return false, fmt.Errorf("failed to unmarshal YAML from %s: %w", globalValuesPath, err)
146+
}
147+
148+
global, ok := raw["global"].(map[string]interface{})
149+
if !ok {
150+
return true, nil
151+
}
152+
153+
_, ok = global["singleArgoCD"]
154+
return !ok, nil
155+
}
156+
129157
// ProcessClusterGroupValues processes the cluster group values YAML file.
130158
// The file is written to the variants folder structure at
131159
// variants/<variant>/values-<variant>.yaml. If a legacy flat-layout file exists at the

‎src/internal/pattern/pattern_test.go‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,53 @@ var _ = Describe("VariantFolderFileMissing", func() {
457457
Expect(missing).To(BeTrue())
458458
})
459459
})
460+
461+
var _ = Describe("MissingSingleArgoCD", func() {
462+
var tempDir string
463+
464+
BeforeEach(func() {
465+
tempDir = GinkgoT().TempDir()
466+
})
467+
468+
writeGlobal := func(content string) {
469+
Expect(os.WriteFile(filepath.Join(tempDir, "values-global.yaml"), []byte(content), 0o644)).To(Succeed())
470+
}
471+
472+
It("returns false when values-global.yaml does not exist", func() {
473+
missing, err := MissingSingleArgoCD(tempDir)
474+
Expect(err).NotTo(HaveOccurred())
475+
Expect(missing).To(BeFalse())
476+
})
477+
478+
It("returns false when global.singleArgoCD is set to true", func() {
479+
writeGlobal("global:\n pattern: test\n singleArgoCD: true\n")
480+
481+
missing, err := MissingSingleArgoCD(tempDir)
482+
Expect(err).NotTo(HaveOccurred())
483+
Expect(missing).To(BeFalse())
484+
})
485+
486+
It("returns false when global.singleArgoCD is set to false", func() {
487+
writeGlobal("global:\n pattern: test\n singleArgoCD: false\n")
488+
489+
missing, err := MissingSingleArgoCD(tempDir)
490+
Expect(err).NotTo(HaveOccurred())
491+
Expect(missing).To(BeFalse())
492+
})
493+
494+
It("returns true when global exists without singleArgoCD", func() {
495+
writeGlobal("global:\n pattern: test\n")
496+
497+
missing, err := MissingSingleArgoCD(tempDir)
498+
Expect(err).NotTo(HaveOccurred())
499+
Expect(missing).To(BeTrue())
500+
})
501+
502+
It("returns true when there is no global section", func() {
503+
writeGlobal("main:\n variant: hub\n")
504+
505+
missing, err := MissingSingleArgoCD(tempDir)
506+
Expect(err).NotTo(HaveOccurred())
507+
Expect(missing).To(BeTrue())
508+
})
509+
})

0 commit comments

Comments
 (0)