Skip to content

Commit c7183f0

Browse files
fix: #896 App of apps being overwritten by image-updater [release-0.15] (#920)
Signed-off-by: Pasha Kostohrys <pavel@codefresh.io> Signed-off-by: Cheng Fang <cfang@redhat.com> Co-authored-by: pasha-codefresh <pavel@codefresh.io>
1 parent e9c78e0 commit c7183f0

File tree

7 files changed

+49
-45
lines changed

7 files changed

+49
-45
lines changed

.github/workflows/create-release-draft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
run: |
4242
set -ex
4343
docker login --username "${DOCKER_USERNAME}" --password "${DOCKER_PASSWORD}" quay.io
44-
IMAGE_PUSH=yes make multiarch-image
44+
IMAGE_PUSH=yes IMAGE_TAG=v${{ steps.version.outputs.version }} make multiarch-image
4545
env:
4646
DOCKER_USERNAME: ${{ secrets.QUAY_USERNAME }}
4747
DOCKER_PASSWORD: ${{ secrets.QUAY_TOKEN }}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ release-binaries:
122122
BINNAME=argocd-image-updater-darwin_amd64 OUTDIR=dist/release OS=darwin ARCH=amd64 make controller
123123
BINNAME=argocd-image-updater-darwin_arm64 OUTDIR=dist/release OS=darwin ARCH=arm64 make controller
124124
BINNAME=argocd-image-updater-win64.exe OUTDIR=dist/release OS=windows ARCH=amd64 make controller
125+
rm -f dist/release/release-v${VERSION}.sha256 dist/release/release-v${VERSION}.sha256.asc
126+
for bin in dist/release/argocd-image-updater-*; do sha256sum "$$bin" >> dist/release/release-v${VERSION}.sha256; done
127+
gpg -a --detach-sign dist/release/release-v${VERSION}.sha256
128+
gpg -a --verify dist/release/release-v${VERSION}.sha256.asc
125129

126130
.PHONY: extract-binary
127131
extract-binary:

docs/contributing/releasing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Then create a release branch:
1717

1818
```
1919
git clone git@github.com:argoproj-labs/argocd-image-updater.git
20-
git branch -b release-0.13
20+
git checkout -b release-0.13
2121
git push origin release-0.13
2222
```
2323

pkg/argocd/argocd.go

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,20 @@ type k8sClient struct {
2929

3030
// GetApplication retrieves an application by name across all namespaces.
3131
func (client *k8sClient) GetApplication(ctx context.Context, appName string) (*v1alpha1.Application, error) {
32-
log.Debugf("Getting application %s across all namespaces", appName)
33-
3432
// List all applications across all namespaces (using empty labelSelector)
3533
appList, err := client.ListApplications(v1.NamespaceAll)
3634
if err != nil {
3735
return nil, fmt.Errorf("error listing applications: %w", err)
3836
}
3937

4038
// Filter applications by name using nameMatchesPattern
41-
app, err := findApplicationByName(appList, appName)
42-
if err != nil {
43-
log.Errorf("error getting application: %v", err)
44-
return nil, fmt.Errorf("error getting application: %w", err)
45-
}
46-
47-
// Retrieve the application in the specified namespace
48-
return app, nil
49-
}
50-
51-
// ListApplications lists all applications across all namespaces.
52-
func (client *k8sClient) ListApplications(labelSelector string) ([]v1alpha1.Application, error) {
53-
list, err := client.kubeClient.ApplicationsClientset.ArgoprojV1alpha1().Applications(v1.NamespaceAll).List(context.TODO(), v1.ListOptions{LabelSelector: labelSelector})
54-
if err != nil {
55-
return nil, fmt.Errorf("error listing applications: %w", err)
56-
}
57-
log.Debugf("Applications listed: %d", len(list.Items))
58-
return list.Items, nil
59-
}
60-
61-
// findApplicationByName filters the list of applications by name using nameMatchesPattern.
62-
func findApplicationByName(appList []v1alpha1.Application, appName string) (*v1alpha1.Application, error) {
63-
var matchedApps []*v1alpha1.Application
39+
var matchedApps []v1alpha1.Application
6440

6541
for _, app := range appList {
6642
log.Debugf("Found application: %s in namespace %s", app.Name, app.Namespace)
6743
if nameMatchesPattern(app.Name, []string{appName}) {
6844
log.Debugf("Application %s matches the pattern", app.Name)
69-
matchedApps = append(matchedApps, &app)
45+
matchedApps = append(matchedApps, app)
7046
}
7147
}
7248

@@ -78,7 +54,18 @@ func findApplicationByName(appList []v1alpha1.Application, appName string) (*v1a
7854
return nil, fmt.Errorf("multiple applications found matching %s", appName)
7955
}
8056

81-
return matchedApps[0], nil
57+
// Retrieve the application in the specified namespace
58+
return &matchedApps[0], nil
59+
}
60+
61+
// ListApplications lists all applications across all namespaces.
62+
func (client *k8sClient) ListApplications(labelSelector string) ([]v1alpha1.Application, error) {
63+
list, err := client.kubeClient.ApplicationsClientset.ArgoprojV1alpha1().Applications(v1.NamespaceAll).List(context.TODO(), v1.ListOptions{LabelSelector: labelSelector})
64+
if err != nil {
65+
return nil, fmt.Errorf("error listing applications: %w", err)
66+
}
67+
log.Debugf("Applications listed: %d", len(list.Items))
68+
return list.Items, nil
8269
}
8370

8471
func (client *k8sClient) UpdateSpec(ctx context.Context, spec *application.ApplicationUpdateSpecRequest) (*v1alpha1.ApplicationSpec, error) {

pkg/argocd/argocd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ func TestKubernetesClient(t *testing.T) {
10951095
// Test GetApplication with multiple matching applications
10961096
_, err = client.GetApplication(context.TODO(), "test-app")
10971097
assert.Error(t, err)
1098-
assert.EqualError(t, err, "error getting application: multiple applications found matching test-app")
1098+
assert.EqualError(t, err, "multiple applications found matching test-app")
10991099
})
11001100
}
11011101

pkg/argocd/git.go

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,6 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
158158
return err
159159
}
160160

161-
// Set username and e-mail address used to identify the commiter
162-
if wbc.GitCommitUser != "" && wbc.GitCommitEmail != "" {
163-
err = gitC.Config(wbc.GitCommitUser, wbc.GitCommitEmail)
164-
if err != nil {
165-
return err
166-
}
167-
}
168-
169161
// The branch to checkout is either a configured branch in the write-back
170162
// config, or taken from the application spec's targetRevision. If the
171163
// target revision is set to the special value HEAD, or is the empty
@@ -182,10 +174,6 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
182174
return err
183175
}
184176
}
185-
err = gitC.ShallowFetch(checkOutBranch, 1)
186-
if err != nil {
187-
return err
188-
}
189177

190178
// The push branch is by default the same as the checkout branch, unless
191179
// specified after a : separator git-branch annotation, in which case a
@@ -196,14 +184,30 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
196184
if wbc.GitWriteBranch != "" {
197185
logCtx.Debugf("Using branch template: %s", wbc.GitWriteBranch)
198186
pushBranch = TemplateBranchName(wbc.GitWriteBranch, changeList)
199-
if pushBranch != "" {
187+
if pushBranch == "" {
188+
return fmt.Errorf("Git branch name could not be created from the template: %s", wbc.GitWriteBranch)
189+
}
190+
}
191+
192+
// If the pushBranch already exists in the remote origin, directly use it.
193+
// Otherwise, create the new pushBranch from checkoutBranch
194+
if checkOutBranch != pushBranch {
195+
fetchErr := gitC.ShallowFetch(pushBranch, 1)
196+
if fetchErr != nil {
197+
err = gitC.ShallowFetch(checkOutBranch, 1)
198+
if err != nil {
199+
return err
200+
}
200201
logCtx.Debugf("Creating branch '%s' and using that for push operations", pushBranch)
201202
err = gitC.Branch(checkOutBranch, pushBranch)
202203
if err != nil {
203204
return err
204205
}
205-
} else {
206-
return fmt.Errorf("Git branch name could not be created from the template: %s", wbc.GitWriteBranch)
206+
}
207+
} else {
208+
err = gitC.ShallowFetch(checkOutBranch, 1)
209+
if err != nil {
210+
return err
207211
}
208212
}
209213

@@ -235,6 +239,14 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
235239
defer os.Remove(cm.Name())
236240
}
237241

242+
// Set username and e-mail address used to identify the commiter
243+
if wbc.GitCommitUser != "" && wbc.GitCommitEmail != "" {
244+
err = gitC.Config(wbc.GitCommitUser, wbc.GitCommitEmail)
245+
if err != nil {
246+
return err
247+
}
248+
}
249+
238250
if wbc.GitCommitSigningKey != "" {
239251
commitOpts.SigningKey = wbc.GitCommitSigningKey
240252
}

pkg/argocd/update_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3363,6 +3363,7 @@ replacements: []
33633363
app := app.DeepCopy()
33643364
gitMock := &gitmock.Client{}
33653365
gitMock.On("Init").Return(nil)
3366+
gitMock.On("Root").Return(t.TempDir())
33663367
gitMock.On("ShallowFetch", mock.Anything, mock.Anything).Return(nil)
33673368
gitMock.On("Checkout", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
33683369
args.Assert(t, "mydefaultbranch", false)

0 commit comments

Comments
 (0)