Skip to content

Commit 0e04924

Browse files
refactor(WBC): Target field in the WriteBackConfig (argoproj-labs#380)
1 parent 6530702 commit 0e04924

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

pkg/argocd/git.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
247247
return nil
248248
}
249249

250-
func writeOverrides(app *v1alpha1.Application, _ *WriteBackConfig, gitC git.Client) (err error, skip bool) {
250+
func writeOverrides(app *v1alpha1.Application, wbc *WriteBackConfig, gitC git.Client) (err error, skip bool) {
251251
logCtx := log.WithContext().AddField("application", app.GetName())
252252
targetExists := true
253-
targetFile := path.Join(gitC.Root(), app.Spec.Source.Path, fmt.Sprintf(".argocd-source-%s.yaml", app.Name))
253+
targetFile := path.Join(gitC.Root(), wbc.Target)
254254
_, err = os.Stat(targetFile)
255255
if err != nil {
256256
if !os.IsNotExist(err) {

pkg/argocd/update.go

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type WriteBackConfig struct {
6767
GitCommitEmail string
6868
GitCommitMessage string
6969
KustomizeBase string
70+
Target string
7071
}
7172

7273
// The following are helper structs to only marshal the fields we require
@@ -415,6 +416,7 @@ func getWriteBackConfig(app *v1alpha1.Application, kubeClient *kube.KubernetesCl
415416
// Default write-back is to use Argo CD API
416417
wbc.Method = WriteBackApplication
417418
wbc.ArgoClient = argoClient
419+
wbc.Target = parseDefaultTarget(app.Name, app.Spec.Source.Path)
418420

419421
// If we have no update method, just return our default
420422
method, ok := app.Annotations[common.WriteBackMethodAnnotation]
@@ -446,6 +448,12 @@ func getWriteBackConfig(app *v1alpha1.Application, kubeClient *kube.KubernetesCl
446448
return wbc, nil
447449
}
448450

451+
func parseDefaultTarget(appName string, path string) string {
452+
defaultTargetFile := fmt.Sprintf(common.DefaultTargetFilePattern, appName)
453+
454+
return filepath.Join(path, defaultTargetFile)
455+
}
456+
449457
func parseTarget(target string, sourcePath string) (kustomizeBase string) {
450458
if target == common.KustomizationPrefix {
451459
return filepath.Join(sourcePath, ".")

pkg/common/constants.go

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ const (
5454
KustomizationPrefix = "kustomization"
5555
)
5656

57+
// DefaultTargetFilePattern configurations related to the write-back functionality
58+
const DefaultTargetFilePattern = ".argocd-source-%s.yaml"
59+
5760
// The default Git commit message's template
5861
const DefaultGitCommitMessage = `build: automatic update of {{ .AppName }}
5962

0 commit comments

Comments
 (0)