Skip to content

fix(applicationset): use pointer type for generator Template fields to honor omitempty#26632

Open
HsiuChuanHsu wants to merge 6 commits intoargoproj:masterfrom
HsiuChuanHsu:fix-24647-omitempty
Open

fix(applicationset): use pointer type for generator Template fields to honor omitempty#26632
HsiuChuanHsu wants to merge 6 commits intoargoproj:masterfrom
HsiuChuanHsu:fix-24647-omitempty

Conversation

@HsiuChuanHsu
Copy link

WHY

The Problem: Users have a generator in ApplicationSet without a generator-level template, but an empty template structure would be automatically added.

What

The Template fields in ApplicationSet generator structs were defined as value types. Because of this, omitempty in the JSON tags had no effect.

type PullRequestGenerator struct {
// Which provider to use and config for it.
Github *PullRequestGeneratorGithub `json:"github,omitempty" protobuf:"bytes,1,opt,name=github"`
GitLab *PullRequestGeneratorGitLab `json:"gitlab,omitempty" protobuf:"bytes,2,opt,name=gitlab"`
Gitea *PullRequestGeneratorGitea `json:"gitea,omitempty" protobuf:"bytes,3,opt,name=gitea"`
BitbucketServer *PullRequestGeneratorBitbucketServer `json:"bitbucketServer,omitempty" protobuf:"bytes,4,opt,name=bitbucketServer"`
// Filters for which pull requests should be considered.
Filters []PullRequestGeneratorFilter `json:"filters,omitempty" protobuf:"bytes,5,rep,name=filters"`
// Standard parameters.
RequeueAfterSeconds *int64 `json:"requeueAfterSeconds,omitempty" protobuf:"varint,6,opt,name=requeueAfterSeconds"`
Template ApplicationSetTemplate `json:"template,omitempty" protobuf:"bytes,7,opt,name=template"`
Bitbucket *PullRequestGeneratorBitbucket `json:"bitbucket,omitempty" protobuf:"bytes,8,opt,name=bitbucket"`
// Additional provider to use and config for it.
AzureDevOps *PullRequestGeneratorAzureDevOps `json:"azuredevops,omitempty" protobuf:"bytes,9,opt,name=azuredevops"`
// Values contains key/value pairs which are passed directly as parameters to the template
Values map[string]string `json:"values,omitempty" protobuf:"bytes,10,name=values"`
// ContinueOnRepoNotFoundError is a flag to continue the ApplicationSet Pull Request generator parameters generation even if the repository is not found.
ContinueOnRepoNotFoundError bool `json:"continueOnRepoNotFoundError,omitempty" protobuf:"varint,11,opt,name=continueOnRepoNotFoundError"`
// If you add a new SCM provider, update CustomApiUrl below.
}

This means that even when a generator had no template configured, an empty template object was still being merged into the final Application spec

How

This PR changes the Template fields to pointer types (*ApplicationSetTemplate). When a template is not set, the field becomes nil, which Go correctly treats as empty. This allows omitempty to work as intended and prevents unintended merges.

Changes:

  • Changed 9 Template fields in generator structs from value types to pointer types in pkg/apis/application/v1alpha1/applicationset_types.go
  • Updated GetTemplate() to handle the new pointer types safely
    • applicationset/generators/list.go
    • applicationset/generators/matrix.go
    • applicationset/generators/merge.go
    • applicationset/generators/cluster.go
    • applicationset/generators/duck_type.go
    • applicationset/generators/git.go
    • applicationset/generators/scm_provider.go
    • applicationset/generators/pull_request.go
    • applicationset/generators/plugin.go
  • Updated mergeGeneratorTemplate() to handle the new pointer types safely
    • applicationset/generators/generator_spec_processor.go
  • Updated unit tests across affected generators to reflect the pointer-based changes

Fix: #24647

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Title of the PR
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

…o honor omitempty

Signed-off-by: HsiuChuanHsu <hchsu2106@gmail.com>
…for pointer Template

Signed-off-by: HsiuChuanHsu <hchsu2106@gmail.com>
Signed-off-by: HsiuChuanHsu <hchsu2106@gmail.com>
Signed-off-by: HsiuChuanHsu <hchsu2106@gmail.com>
@HsiuChuanHsu HsiuChuanHsu requested a review from a team as a code owner February 27, 2026 02:59
@bunnyshell
Copy link

bunnyshell bot commented Feb 27, 2026

🔴 Preview Environment stopped on Bunnyshell

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔵 /bns:start to start the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@HsiuChuanHsu HsiuChuanHsu changed the title Fix 24647 omitempty fix(applicationset): use pointer type for generator Template fields to honor omitempty Feb 27, 2026
@HsiuChuanHsu
Copy link
Author

Test

Apply applicationset with list generator

  apiVersion: argoproj.io/v1alpha1
  kind: ApplicationSet
  metadata:
    name: test-appset
    namespace: argocd
  spec:
    goTemplate: true
    generators:
    - list:
        elements:
        - env: staging
    template:
      metadata:
        name: 'test-app-{{.env}}'
      spec:
        project: default
        source:
          repoURL: https://github.com/argoproj/argocd-example-apps
          targetRevision: HEAD
          path: guestbook
        destination:
          server: https://kubernetes.default.svc
          namespace: default

Master branch
Deploy

Screenshot 2026-02-25 at 10 34 39 PM

Resutl

Screenshot 2026-02-25 at 10 34 50 PM

This PR

Deploy & Result

Screenshot 2026-02-25 at 10 56 52 PM

Signed-off-by: HsiuChuanHsu <hchsu2106@gmail.com>
Signed-off-by: HsiuChuanHsu <hchsu2106@gmail.com>
@HsiuChuanHsu HsiuChuanHsu requested a review from a team as a code owner February 27, 2026 15:51
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.

Template section is automatically appended to AppSet generators section

1 participant