Skip to content

fix(kustomize): mergeKustomizeOverride is alias-blind, clobbers entries when two aliases share an image name #1769

Description

@chengfang

Problem

mergeKustomizeOverride in pkg/argocd/update.go matches kustomize image entries using sameImageNameAndRegistry, which compares only ImageName + RegistryURL and ignores ImageAlias. When two aliases (e.g. service-a, service-b) target the same image name (jannfis/foobar) with distinct tags, the merge loop matches the wrong slot and clobbers one alias's update with the other's.

This is the git write-back path instance of the same bug class fixed at other layers by:

Neither PR addresses mergeKustomizeOverride.

Steps to reproduce

  1. Configure an ImageUpdater CR with two aliases that share the same image name but use distinct manifestTargets.kustomize.name values (e.g. service-a=jannfis/foobar, service-b=jannfis/foobar).
  2. Use git write-back (WriteBackGit).
  3. Trigger an update for both aliases.

Expected: each alias's kustomize image entry is updated independently.
Actual: processing service-b's new entry matches service-a's slot first (same ImageName), overwrites it, and the old service-b entry at its original index is never updated. One alias's update is silently lost.

Relevant code

https://github.com/argoproj-labs/argocd-image-updater/blob/master/pkg/argocd/update.go#L690-L716

func mergeKustomizeOverride(t *kustomizeOverride, o *kustomizeOverride) {
    // ...
    for _, newImage := range *o.Kustomize.Images {
        newContainerImage := image.NewFromIdentifier(string(newImage))
        for idx, existingImage := range *t.Kustomize.Images {
            existingContainerImage := image.NewFromIdentifier(string(existingImage))
            if sameImageNameAndRegistry(newContainerImage, existingContainerImage) {
                // ^^^ ignores ImageAlias — matches the wrong slot
            }
        }
    }
}

Suggested fix

Add alias-awareness to the matching logic in mergeKustomizeOverride, consistent with the approach in #1763: when both the new and existing entries carry a non-empty ImageAlias, require alias equality in addition to name+registry equality.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions