Skip to content
This repository was archived by the owner on Mar 9, 2025. It is now read-only.

Commit 6bb49fc

Browse files
committed
Bugfix: fixing invalidation error introduced in gimletd-dash merging
1 parent f665776 commit 6bb49fc

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

pkg/dashboard/worker/gitops.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func processRollbackEvent(
424424
logrus.Errorf("could not push to git with native command: %s", err)
425425
return nil, fmt.Errorf("could not push to git. Check server logs")
426426
}
427-
gitopsRepoCache.Invalidate(repoName)
427+
gitopsRepoCache.InvalidateNow(repoName)
428428

429429
rollbackResults := []model.Result{}
430430

@@ -612,14 +612,15 @@ func cloneTemplateWriteAndPush(
612612

613613
if sha != "" || kustomizationSha != "" { // if there is a change to push
614614
operation := func() error {
615-
return nativeGit.PushWithToken(repo, githubChartAccessToken)
615+
head, _ := repo.Head()
616+
return nativeGit.NativePushWithToken(repoTmpPath, repoName, githubChartAccessToken, head.Name().Short())
616617
}
617618
backoffStrategy := backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 5)
618619
err := backoff.Retry(operation, backoffStrategy)
619620
if err != nil {
620621
return "", err
621622
}
622-
gitopsRepoCache.Invalidate(repoName)
623+
gitopsRepoCache.InvalidateNow(repoName)
623624
}
624625

625626
perf.WithLabelValues("gitops_cloneTemplateWriteAndPush").Observe(float64(time.Since(t0).Seconds()))
@@ -669,11 +670,12 @@ func cloneTemplateDeleteAndPush(
669670
sha, err := nativeGit.Commit(repo, gitMessage)
670671

671672
if sha != "" { // if there is a change to push
672-
err = nativeGit.PushWithToken(repo, nonImpersonatedToken)
673+
head, _ := repo.Head()
674+
err = nativeGit.NativePushWithToken(repoTmpPath, repoName, nonImpersonatedToken, head.Name().Short())
673675
if err != nil {
674676
return "", err
675677
}
676-
gitopsRepoCache.Invalidate(repoName)
678+
gitopsRepoCache.InvalidateNow(repoName)
677679
}
678680

679681
return sha, nil

pkg/git/nativeGit/repoCache.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (r *RepoCache) InstanceForWrite(repoName string) (*git.Repository, string,
205205
_, err = r.clone(repoName)
206206
go r.registerWebhook(repoName)
207207
}
208-
r.lock.Unlock()
208+
defer r.lock.Unlock()
209209
if err != nil {
210210
return nil, "", err
211211
}
@@ -232,6 +232,11 @@ func (r *RepoCache) Invalidate(repoName string) {
232232
r.invalidateCh <- repoName
233233
}
234234

235+
func (r *RepoCache) InvalidateNow(repoName string) {
236+
logrus.Infof("invalidating repocace now for %s", repoName)
237+
r.syncGitRepo(repoName)
238+
}
239+
235240
func (r *RepoCache) clone(repoName string) (*git.Repository, error) {
236241
if repoName == "" {
237242
return nil, fmt.Errorf("repo name is mandatory")

0 commit comments

Comments
 (0)