Skip to content

Commit a275578

Browse files
author
Eidmantas Ivanauskas
committed
fix(git): guard batched writer for non-git/missing creds; test: strengthen batching test; docs: v100.0.5a changelog
1 parent ce42503 commit a275578

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ handling on your side.
3030
* refactor: make argocd-image-updater-config volume mapping optional (#145)
3131

3232

33+
## 2025-09-18 - Release v100.0.5a
34+
35+
### Fixes
36+
37+
- fix(git): Prevent panic in batched writer when `GetCreds` is nil or write-back method is not Git
38+
- Only enqueue batched writes when `wbc.Method == git`
39+
- Guard in `repoWriter.commitBatch` for missing `GetCreds` (skip with log)
40+
41+
### Tests
42+
43+
- test(git): Strengthen batched writer test to set `Method: WriteBackGit` and provide `GetCreds` stub, so missing-GetCreds would fail tests
44+
45+
### Notes
46+
47+
- No flags or defaults changed; safe upgrade from v100.0.4a
48+
3349
## 2025-09-18 - Release v100.0.4a
3450

3551
### Changes

pkg/argocd/git.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ func (rw *repoWriter) commitBatch(branch string, intents []writeIntent) {
229229
first := intents[0]
230230
logCtx := log.WithContext().AddField("repository", rw.repoURL)
231231

232+
// Only Git write-back is supported by the batched writer
233+
if first.wbc == nil || first.wbc.Method != WriteBackGit {
234+
logCtx.Warnf("skipping batched commit: non-git write-back method")
235+
return
236+
}
237+
238+
if first.wbc.GetCreds == nil {
239+
logCtx.Errorf("batched commit: missing GetCreds resolver; skipping")
240+
return
241+
}
232242
creds, err := first.wbc.GetCreds(first.app)
233243
if err != nil { logCtx.Errorf("could not get creds: %v", err); return }
234244

pkg/argocd/git_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func Test_repoWriter_BatchesPerBranch(t *testing.T) {
6464

6565
appMain := &v1alpha1.Application{}
6666
appDev := &v1alpha1.Application{ObjectMeta: appMain.ObjectMeta}
67-
wbcMain := &WriteBackConfig{GitRepo: "https://example/repo.git", GitWriteBranch: "main", GetCreds: func(a *v1alpha1.Application) (extgit.Creds, error) { return nil, nil }}
68-
wbcDev := &WriteBackConfig{GitRepo: "https://example/repo.git", GitWriteBranch: "dev", GetCreds: func(a *v1alpha1.Application) (extgit.Creds, error) { return nil, nil }}
67+
wbcMain := &WriteBackConfig{GitRepo: "https://example/repo.git", GitWriteBranch: "main", Method: WriteBackGit, GetCreds: func(a *v1alpha1.Application) (extgit.Creds, error) { return extgit.NopCreds{}, nil }}
68+
wbcDev := &WriteBackConfig{GitRepo: "https://example/repo.git", GitWriteBranch: "dev", Method: WriteBackGit, GetCreds: func(a *v1alpha1.Application) (extgit.Creds, error) { return extgit.NopCreds{}, nil }}
6969

7070
rw := &repoWriter{repoURL: wbcMain.GitRepo, intentsCh: make(chan writeIntent, 10), flushEvery: 0, maxBatch: 100, stopCh: make(chan struct{})}
7171
// Directly call flushBatch to avoid goroutine timing

pkg/argocd/update.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,15 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
410410
if needUpdate {
411411
logCtx := log.WithContext().AddField("application", app)
412412
log.Debugf("Using commit message: %s", wbc.GitCommitMessage)
413-
if !updateConf.DryRun {
414-
logCtx.Infof("Queuing %d parameter update(s) for application %s (git write pending)", result.NumImagesUpdated, app)
415-
// Enqueue batched write intent unless tests explicitly disable batching
413+
if !updateConf.DryRun {
414+
// If write-back is Git, we can batch; otherwise commit directly via Argo CD API
416415
var err error
417-
if env.GetBoolVal("GIT_BATCH_DISABLE", false) {
416+
if wbc.Method != WriteBackGit || env.GetBoolVal("GIT_BATCH_DISABLE", false) {
418417
err = commitChangesLocked(&updateConf.UpdateApp.Application, wbc, state, changeList)
419418
} else {
419+
logCtx.Infof("Queuing %d parameter update(s) for application %s (git write pending)", result.NumImagesUpdated, app)
420420
// Ensure Git credentials resolver is set for batched writer
421-
if wbc.Method == WriteBackGit && wbc.GetCreds == nil {
421+
if wbc.GetCreds == nil {
422422
if perr := parseGitConfig(&updateConf.UpdateApp.Application, updateConf.KubeClient, wbc, "repocreds"); perr != nil {
423423
logCtx.Warnf("could not prepare git credentials for batched write: %v", perr)
424424
}

0 commit comments

Comments
 (0)