From 5ad61348ddee421a6545b5974c76ab82fec03664 Mon Sep 17 00:00:00 2001 From: pasha-codefresh Date: Wed, 23 Oct 2024 14:23:00 +0300 Subject: [PATCH 1/6] fix: pass image tag into build image command (#893) Signed-off-by: Pasha Kostohrys --- .github/workflows/create-release-draft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-release-draft.yaml b/.github/workflows/create-release-draft.yaml index eb35d62d..c66338e0 100644 --- a/.github/workflows/create-release-draft.yaml +++ b/.github/workflows/create-release-draft.yaml @@ -41,7 +41,7 @@ jobs: run: | set -ex docker login --username "${DOCKER_USERNAME}" --password "${DOCKER_PASSWORD}" quay.io - IMAGE_PUSH=yes make multiarch-image + IMAGE_PUSH=yes IMAGE_TAG=v${{ steps.version.outputs.version }} make multiarch-image env: DOCKER_USERNAME: ${{ secrets.QUAY_USERNAME }} DOCKER_PASSWORD: ${{ secrets.QUAY_TOKEN }} From da331df74ed5ccb43461f45dc72bc2b5fbbc8f82 Mon Sep 17 00:00:00 2001 From: pasha-codefresh Date: Wed, 23 Oct 2024 14:54:51 +0300 Subject: [PATCH 2/6] fix: wrong checkout command in documentation (#894) Signed-off-by: Pasha Kostohrys --- docs/contributing/releasing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/contributing/releasing.md b/docs/contributing/releasing.md index 0c32c45a..0fb0f3e6 100644 --- a/docs/contributing/releasing.md +++ b/docs/contributing/releasing.md @@ -17,7 +17,7 @@ Then create a release branch: ``` git clone git@github.com:argoproj-labs/argocd-image-updater.git -git branch -b release-0.13 +git checkout -b release-0.13 git push origin release-0.13 ``` From e73a8722b2b390d7f250818d2cdf121a5a67e27d Mon Sep 17 00:00:00 2001 From: Cheng Fang Date: Wed, 30 Oct 2024 03:58:58 -0400 Subject: [PATCH 3/6] fix: add build steps to create binary checksum and signature files (#901) Signed-off-by: Cheng Fang --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index decc81c7..6c36f8d9 100644 --- a/Makefile +++ b/Makefile @@ -122,6 +122,10 @@ release-binaries: BINNAME=argocd-image-updater-darwin_amd64 OUTDIR=dist/release OS=darwin ARCH=amd64 make controller BINNAME=argocd-image-updater-darwin_arm64 OUTDIR=dist/release OS=darwin ARCH=arm64 make controller BINNAME=argocd-image-updater-win64.exe OUTDIR=dist/release OS=windows ARCH=amd64 make controller + rm -f dist/release/release-v${VERSION}.sha256 dist/release/release-v${VERSION}.sha256.asc + for bin in dist/release/argocd-image-updater-*; do sha256sum "$$bin" >> dist/release/release-v${VERSION}.sha256; done + gpg -a --detach-sign dist/release/release-v${VERSION}.sha256 + gpg -a --verify dist/release/release-v${VERSION}.sha256.asc .PHONY: extract-binary extract-binary: From 3ac067a74fcd33db8d11f857c886a8eb92f5ed81 Mon Sep 17 00:00:00 2001 From: Cheng Fang Date: Fri, 1 Nov 2024 13:39:19 -0400 Subject: [PATCH 4/6] fix: #895 Image Updater continuously force-pushes new commits when checkout branch is specified (#911) Signed-off-by: Cheng Fang --- pkg/argocd/git.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/argocd/git.go b/pkg/argocd/git.go index 13e62b66..7d30cec3 100644 --- a/pkg/argocd/git.go +++ b/pkg/argocd/git.go @@ -182,10 +182,6 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis return err } } - err = gitC.ShallowFetch(checkOutBranch, 1) - if err != nil { - return err - } // The push branch is by default the same as the checkout branch, unless // specified after a : separator git-branch annotation, in which case a @@ -196,14 +192,30 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis if wbc.GitWriteBranch != "" { logCtx.Debugf("Using branch template: %s", wbc.GitWriteBranch) pushBranch = TemplateBranchName(wbc.GitWriteBranch, changeList) - if pushBranch != "" { + if pushBranch == "" { + return fmt.Errorf("Git branch name could not be created from the template: %s", wbc.GitWriteBranch) + } + } + + // If the pushBranch already exists in the remote origin, directly use it. + // Otherwise, create the new pushBranch from checkoutBranch + if checkOutBranch != pushBranch { + fetchErr := gitC.ShallowFetch(pushBranch, 1) + if fetchErr != nil { + err = gitC.ShallowFetch(checkOutBranch, 1) + if err != nil { + return err + } logCtx.Debugf("Creating branch '%s' and using that for push operations", pushBranch) err = gitC.Branch(checkOutBranch, pushBranch) if err != nil { return err } - } else { - return fmt.Errorf("Git branch name could not be created from the template: %s", wbc.GitWriteBranch) + } + } else { + err = gitC.ShallowFetch(checkOutBranch, 1) + if err != nil { + return err } } From 589df0fd254bebdf4b98d4953bccca279cdc3f97 Mon Sep 17 00:00:00 2001 From: Cheng Fang Date: Fri, 8 Nov 2024 09:46:40 -0500 Subject: [PATCH 5/6] fix: #896 App of apps being overwritten by image-updater (#918) Signed-off-by: Cheng Fang --- pkg/argocd/argocd.go | 41 +++++++++++++-------------------------- pkg/argocd/argocd_test.go | 2 +- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/pkg/argocd/argocd.go b/pkg/argocd/argocd.go index 63ac7a79..f064eaaa 100644 --- a/pkg/argocd/argocd.go +++ b/pkg/argocd/argocd.go @@ -29,8 +29,6 @@ type k8sClient struct { // GetApplication retrieves an application by name across all namespaces. func (client *k8sClient) GetApplication(ctx context.Context, appName string) (*v1alpha1.Application, error) { - log.Debugf("Getting application %s across all namespaces", appName) - // List all applications across all namespaces (using empty labelSelector) appList, err := client.ListApplications(v1.NamespaceAll) if err != nil { @@ -38,35 +36,13 @@ func (client *k8sClient) GetApplication(ctx context.Context, appName string) (*v } // Filter applications by name using nameMatchesPattern - app, err := findApplicationByName(appList, appName) - if err != nil { - log.Errorf("error getting application: %v", err) - return nil, fmt.Errorf("error getting application: %w", err) - } - - // Retrieve the application in the specified namespace - return app, nil -} - -// ListApplications lists all applications across all namespaces. -func (client *k8sClient) ListApplications(labelSelector string) ([]v1alpha1.Application, error) { - list, err := client.kubeClient.ApplicationsClientset.ArgoprojV1alpha1().Applications(v1.NamespaceAll).List(context.TODO(), v1.ListOptions{LabelSelector: labelSelector}) - if err != nil { - return nil, fmt.Errorf("error listing applications: %w", err) - } - log.Debugf("Applications listed: %d", len(list.Items)) - return list.Items, nil -} - -// findApplicationByName filters the list of applications by name using nameMatchesPattern. -func findApplicationByName(appList []v1alpha1.Application, appName string) (*v1alpha1.Application, error) { - var matchedApps []*v1alpha1.Application + var matchedApps []v1alpha1.Application for _, app := range appList { log.Debugf("Found application: %s in namespace %s", app.Name, app.Namespace) if nameMatchesPattern(app.Name, []string{appName}) { log.Debugf("Application %s matches the pattern", app.Name) - matchedApps = append(matchedApps, &app) + matchedApps = append(matchedApps, app) } } @@ -78,7 +54,18 @@ func findApplicationByName(appList []v1alpha1.Application, appName string) (*v1a return nil, fmt.Errorf("multiple applications found matching %s", appName) } - return matchedApps[0], nil + // Retrieve the application in the specified namespace + return &matchedApps[0], nil +} + +// ListApplications lists all applications across all namespaces. +func (client *k8sClient) ListApplications(labelSelector string) ([]v1alpha1.Application, error) { + list, err := client.kubeClient.ApplicationsClientset.ArgoprojV1alpha1().Applications(v1.NamespaceAll).List(context.TODO(), v1.ListOptions{LabelSelector: labelSelector}) + if err != nil { + return nil, fmt.Errorf("error listing applications: %w", err) + } + log.Debugf("Applications listed: %d", len(list.Items)) + return list.Items, nil } func (client *k8sClient) UpdateSpec(ctx context.Context, spec *application.ApplicationUpdateSpecRequest) (*v1alpha1.ApplicationSpec, error) { diff --git a/pkg/argocd/argocd_test.go b/pkg/argocd/argocd_test.go index ce565f21..28124f0c 100644 --- a/pkg/argocd/argocd_test.go +++ b/pkg/argocd/argocd_test.go @@ -1095,7 +1095,7 @@ func TestKubernetesClient(t *testing.T) { // Test GetApplication with multiple matching applications _, err = client.GetApplication(context.TODO(), "test-app") assert.Error(t, err) - assert.EqualError(t, err, "error getting application: multiple applications found matching test-app") + assert.EqualError(t, err, "multiple applications found matching test-app") }) } From 990602adc13c6952090138016b8b0a48ac416dd8 Mon Sep 17 00:00:00 2001 From: Cheng Fang Date: Fri, 8 Nov 2024 09:47:10 -0500 Subject: [PATCH 6/6] fix: delay setting git.username and git.email config till commit time (#912) Signed-off-by: Cheng Fang --- pkg/argocd/git.go | 16 ++++++++-------- pkg/argocd/update_test.go | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/argocd/git.go b/pkg/argocd/git.go index 7d30cec3..71422c2e 100644 --- a/pkg/argocd/git.go +++ b/pkg/argocd/git.go @@ -158,14 +158,6 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis return err } - // Set username and e-mail address used to identify the commiter - if wbc.GitCommitUser != "" && wbc.GitCommitEmail != "" { - err = gitC.Config(wbc.GitCommitUser, wbc.GitCommitEmail) - if err != nil { - return err - } - } - // The branch to checkout is either a configured branch in the write-back // config, or taken from the application spec's targetRevision. If the // target revision is set to the special value HEAD, or is the empty @@ -247,6 +239,14 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis defer os.Remove(cm.Name()) } + // Set username and e-mail address used to identify the commiter + if wbc.GitCommitUser != "" && wbc.GitCommitEmail != "" { + err = gitC.Config(wbc.GitCommitUser, wbc.GitCommitEmail) + if err != nil { + return err + } + } + if wbc.GitCommitSigningKey != "" { commitOpts.SigningKey = wbc.GitCommitSigningKey } diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go index 416de5d3..1bd1d3e2 100644 --- a/pkg/argocd/update_test.go +++ b/pkg/argocd/update_test.go @@ -3363,6 +3363,7 @@ replacements: [] app := app.DeepCopy() gitMock := &gitmock.Client{} gitMock.On("Init").Return(nil) + gitMock.On("Root").Return(t.TempDir()) gitMock.On("ShallowFetch", mock.Anything, mock.Anything).Return(nil) gitMock.On("Checkout", mock.Anything, mock.Anything).Run(func(args mock.Arguments) { args.Assert(t, "mydefaultbranch", false)