Skip to content

fix(write-back): Duplicate image entries with different formats when updating two images#1037

Merged
chengfang merged 1 commit into
argoproj-labs:masterfrom
chengfang:duplicate.entries.in.write
Feb 25, 2025
Merged

fix(write-back): Duplicate image entries with different formats when updating two images#1037
chengfang merged 1 commit into
argoproj-labs:masterfrom
chengfang:duplicate.entries.in.write

Conversation

@chengfang
Copy link
Copy Markdown
Collaborator

Fixes #1034

Modified mergeKustomizeOverride method to have more control over setting and adding parameters to .argocd-source-*.yaml target file.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.89%. Comparing base (add409e) to head (d235ae4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1037      +/-   ##
==========================================
+ Coverage   62.59%   62.89%   +0.29%     
==========================================
  Files          15       15              
  Lines        2259     2269      +10     
==========================================
+ Hits         1414     1427      +13     
+ Misses        755      753       -2     
+ Partials       90       89       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chengfang chengfang force-pushed the duplicate.entries.in.write branch from b6386e0 to 44f5996 Compare February 13, 2025 04:07
Comment thread pkg/argocd/update_test.go
[]v1alpha1.KustomizeImage{"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34"},
[]v1alpha1.KustomizeImage{"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34"}},

{"2-images", []v1alpha1.KustomizeImage{"nginx:latest",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheng, do you have an example where the new image tag replaces the old image tag to test out the conditional statements in your new code in update.go?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sub-tests: with-tag-1, with-tag-sha, and 2-images all replace the existing tag with the new tag.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rechecked this again and yeah, the first test with-tag, the existing and the new tag are the same. The next three tests, by definition of your test case struct, the tags are different.

Comment thread pkg/argocd/update.go Outdated
newContainerImage.RegistryURL == existingContainerImage.RegistryURL {
found = true
if existingContainerImage.ImageTag == nil ||
!(existingContainerImage.ImageTag).Equals(newContainerImage.ImageTag) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see, at least from the tests that I'm trying to run, the new image tag can be nil and so the newImage gets added

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In real applications, new image tag is unlikely to be nil. If it is, something already went wrong earlier.

But if the new tag is nil, it will cause nil pointer dereferece and panic. We could add a nil check to prevent that from happening:

if existingContainerImage.ImageTag == nil ||
(newContainerImage.ImageTag != nil && !(existingContainerImage.ImageTag).Equals(newContainerImage.ImageTag)) {

Comment thread pkg/argocd/update.go
for idx, existingImage := range *t.Kustomize.Images {
existingContainerImage := image.NewFromIdentifier(string(existingImage))
if newContainerImage.ImageName == existingContainerImage.ImageName &&
newContainerImage.RegistryURL == existingContainerImage.RegistryURL {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the tests that I performed, RegistryURL is nil all the time. Is there another test that will test this condition with non-nil values?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RegistryURL has a default value "" and should not be nil.

The first 4 sub-tests don't use any registry url, so they should be able to test this case.

Copy link
Copy Markdown

@keithchong keithchong Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see where the image RegistryURL is set. My comment can be resolved.

Comment thread pkg/argocd/update_test.go
require.Equal(t, lock3, state.repositoryLocks[repo2])
}

func Test_mergeKustomizeOverride(t *testing.T) {
Copy link
Copy Markdown

@keithchong keithchong Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to test the new function from a higher level, at calling marshalParamsOverride instead. Do you think it is worthwhile to do it from that? eg. see the first couple of scenarios from the existing test Test_MarshalParamsOverride

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add a sub-test to Test_MarshalParamsOverride by setting the new images in app spec, to test out the changes from that level.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see the call to marshalParamsOverride

…updating two images

Signed-off-by: Cheng Fang <cfang@redhat.com>
@chengfang chengfang force-pushed the duplicate.entries.in.write branch from 44f5996 to d235ae4 Compare February 14, 2025 16:14
Copy link
Copy Markdown

@keithchong keithchong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after re-review.

Copy link
Copy Markdown
Contributor

@jannfis jannfis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chengfang chengfang merged commit edabb0f into argoproj-labs:master Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate image entries with different formats when updating two images

4 participants