-
Notifications
You must be signed in to change notification settings - Fork 356
fix(write-back): Duplicate image entries with different formats when updating two images #1037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1219,6 +1219,49 @@ kustomize: | |
| assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(yaml))) | ||
| }) | ||
|
|
||
| t.Run("Merge images param", func(t *testing.T) { | ||
| expected := ` | ||
| kustomize: | ||
| images: | ||
| - existing:latest | ||
| - updated:latest | ||
| - new | ||
| ` | ||
| app := v1alpha1.Application{ | ||
| ObjectMeta: v1.ObjectMeta{ | ||
| Name: "testapp", | ||
| Annotations: map[string]string{ | ||
| "argocd-image-updater.argoproj.io/image-list": "nginx", | ||
| }, | ||
| }, | ||
| Spec: v1alpha1.ApplicationSpec{ | ||
| Source: &v1alpha1.ApplicationSource{ | ||
| RepoURL: "https://example.com/example", | ||
| TargetRevision: "main", | ||
| Kustomize: &v1alpha1.ApplicationSourceKustomize{ | ||
| Images: v1alpha1.KustomizeImages{ | ||
| "new", | ||
| "updated:latest", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| Status: v1alpha1.ApplicationStatus{ | ||
| SourceType: v1alpha1.ApplicationSourceTypeKustomize, | ||
| }, | ||
| } | ||
| originalData := []byte(` | ||
| kustomize: | ||
| images: | ||
| - existing:latest | ||
| - updated:old | ||
| `) | ||
| yaml, err := marshalParamsOverride(&app, originalData) | ||
| require.NoError(t, err) | ||
| assert.NotEmpty(t, yaml) | ||
| assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(yaml))) | ||
| }) | ||
|
|
||
| t.Run("Empty Kustomize source", func(t *testing.T) { | ||
| app := v1alpha1.Application{ | ||
| ObjectMeta: v1.ObjectMeta{ | ||
|
|
@@ -3643,3 +3686,61 @@ func Test_GetRepositoryLock(t *testing.T) { | |
| require.NotNil(t, state.repositoryLocks[repo2]) | ||
| require.Equal(t, lock3, state.repositoryLocks[repo2]) | ||
| } | ||
|
|
||
| func Test_mergeKustomizeOverride(t *testing.T) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add a sub-test to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I see the call to marshalParamsOverride |
||
| tests := []struct { | ||
| name string | ||
| existing v1alpha1.KustomizeImages | ||
| new v1alpha1.KustomizeImages | ||
| expected v1alpha1.KustomizeImages | ||
| }{ | ||
| {"with-tag", []v1alpha1.KustomizeImage{"nginx:foo"}, | ||
| []v1alpha1.KustomizeImage{"nginx:foo"}, | ||
| []v1alpha1.KustomizeImage{"nginx:foo"}}, | ||
| {"no-tag", []v1alpha1.KustomizeImage{"nginx:foo"}, | ||
| []v1alpha1.KustomizeImage{"nginx"}, | ||
| []v1alpha1.KustomizeImage{"nginx:foo"}}, | ||
| {"with-tag-1", []v1alpha1.KustomizeImage{"nginx"}, | ||
| []v1alpha1.KustomizeImage{"nginx:latest"}, | ||
| []v1alpha1.KustomizeImage{"nginx:latest"}}, | ||
| {"with-tag-sha", []v1alpha1.KustomizeImage{"nginx:latest"}, | ||
| []v1alpha1.KustomizeImage{"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34"}, | ||
| []v1alpha1.KustomizeImage{"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34"}}, | ||
|
|
||
| {"2-images", []v1alpha1.KustomizeImage{"nginx:latest", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the sub-tests: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I rechecked this again and yeah, the first test |
||
| "bitnami/nginx:latest@sha256:1a2fe3f9f6d1d38d5a7ee35af732fdb7d15266ec3dbc79bbc0355742cd24d3ec"}, | ||
| []v1alpha1.KustomizeImage{"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34", | ||
| "bitnami/nginx@sha256:1a2fe3f9f6d1d38d5a7ee35af732fdb7d15266ec3dbc79bbc0355742cd24d3ec"}, | ||
| []v1alpha1.KustomizeImage{"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34", | ||
| "bitnami/nginx:latest@sha256:1a2fe3f9f6d1d38d5a7ee35af732fdb7d15266ec3dbc79bbc0355742cd24d3ec"}}, | ||
|
|
||
| {"with-registry", []v1alpha1.KustomizeImage{"quay.io/nginx:latest"}, | ||
| []v1alpha1.KustomizeImage{"quay.io/nginx:latest"}, | ||
| []v1alpha1.KustomizeImage{"quay.io/nginx:latest"}}, | ||
| {"with-registry-1", []v1alpha1.KustomizeImage{"quay.io/nginx:latest"}, | ||
| []v1alpha1.KustomizeImage{"docker.io/nginx:latest"}, | ||
| []v1alpha1.KustomizeImage{"docker.io/nginx:latest", "quay.io/nginx:latest"}}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| existingImages := kustomizeOverride{ | ||
| Kustomize: kustomizeImages{ | ||
| Images: &tt.existing, | ||
| }, | ||
| } | ||
| newImages := kustomizeOverride{ | ||
| Kustomize: kustomizeImages{ | ||
| Images: &tt.new, | ||
| }, | ||
| } | ||
| expectedImages := kustomizeOverride{ | ||
| Kustomize: kustomizeImages{ | ||
| Images: &tt.expected, | ||
| }, | ||
| } | ||
|
|
||
| mergeKustomizeOverride(&existingImages, &newImages) | ||
| assert.ElementsMatch(t, *expectedImages.Kustomize.Images, *existingImages.Kustomize.Images) | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RegistryURLhas 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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.