Skip to content

Commit 3666f7b

Browse files
Merge branch 'master' into add_rabbitmq_health
2 parents 73a56e6 + f775e7b commit 3666f7b

File tree

35 files changed

+1477
-519
lines changed

35 files changed

+1477
-519
lines changed

applicationset/generators/pull_request.go

+5
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ func (g *PullRequestGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha
109109
"author": pull.Author,
110110
}
111111

112+
err := appendTemplatedValues(appSetGenerator.PullRequest.Values, paramMap, applicationSetInfo.Spec.GoTemplate, applicationSetInfo.Spec.GoTemplateOptions)
113+
if err != nil {
114+
return nil, fmt.Errorf("failed to append templated values: %w", err)
115+
}
116+
112117
// PR lables will only be supported for Go Template appsets, since fasttemplate will be deprecated.
113118
if applicationSetInfo != nil && applicationSetInfo.Spec.GoTemplate {
114119
paramMap["labels"] = pull.Labels

applicationset/generators/pull_request_test.go

+43-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
1717
ctx := t.Context()
1818
cases := []struct {
1919
selectFunc func(context.Context, *argoprojiov1alpha1.PullRequestGenerator, *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error)
20+
values map[string]string
2021
expected []map[string]any
2122
expectedErr error
2223
applicationSet argoprojiov1alpha1.ApplicationSet
@@ -120,6 +121,45 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
120121
},
121122
expectedErr: nil,
122123
},
124+
{
125+
selectFunc: func(context.Context, *argoprojiov1alpha1.PullRequestGenerator, *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error) {
126+
return pullrequest.NewFakeService(
127+
ctx,
128+
[]*pullrequest.PullRequest{
129+
{
130+
Number: 1,
131+
Title: "title1",
132+
Branch: "my_branch",
133+
TargetBranch: "master",
134+
HeadSHA: "abcd",
135+
Author: "testName",
136+
},
137+
},
138+
nil,
139+
)
140+
},
141+
values: map[string]string{
142+
"foo": "bar",
143+
"pr_branch": "{{ branch }}",
144+
},
145+
expected: []map[string]any{
146+
{
147+
"number": "1",
148+
"title": "title1",
149+
"branch": "my_branch",
150+
"branch_slug": "my-branch",
151+
"target_branch": "master",
152+
"target_branch_slug": "master",
153+
"head_sha": "abcd",
154+
"head_short_sha": "abcd",
155+
"head_short_sha_7": "abcd",
156+
"author": "testName",
157+
"values.foo": "bar",
158+
"values.pr_branch": "my_branch",
159+
},
160+
},
161+
expectedErr: nil,
162+
},
123163
{
124164
selectFunc: func(context.Context, *argoprojiov1alpha1.PullRequestGenerator, *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error) {
125165
return pullrequest.NewFakeService(
@@ -219,7 +259,9 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
219259
selectServiceProviderFunc: c.selectFunc,
220260
}
221261
generatorConfig := argoprojiov1alpha1.ApplicationSetGenerator{
222-
PullRequest: &argoprojiov1alpha1.PullRequestGenerator{},
262+
PullRequest: &argoprojiov1alpha1.PullRequestGenerator{
263+
Values: c.values,
264+
},
223265
}
224266

225267
got, gotErr := gen.GenerateParams(&generatorConfig, &c.applicationSet, nil)

assets/swagger.json

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/operator-manual/applicationset/Generators-Pull-Request.md

+36
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,39 @@ For more information about each event, please refer to the [official documentati
480480
## Lifecycle
481481

482482
An Application will be generated when a Pull Request is discovered when the configured criteria is met - i.e. for GitHub when a Pull Request matches the specified `labels` and/or `pullRequestState`. Application will be removed when a Pull Request no longer meets the specified criteria.
483+
484+
## Pass additional key-value pairs via `values` field
485+
486+
You may pass additional, arbitrary string key-value pairs via the `values` field of any Pull Request generator. Values added via the `values` field are added as `values.(field)`.
487+
488+
```yaml
489+
apiVersion: argoproj.io/v1alpha1
490+
kind: ApplicationSet
491+
metadata:
492+
name: myapps
493+
spec:
494+
goTemplate: true
495+
goTemplateOptions: ["missingkey=error"]
496+
generators:
497+
- pullRequest:
498+
# ...
499+
values:
500+
pr_branch: '{{ .branch }}'
501+
template:
502+
metadata:
503+
name: '{{ .values.name }}'
504+
spec:
505+
source:
506+
repoURL: '{{ .url }}'
507+
targetRevision: '{{ .branch }}'
508+
path: kubernetes/
509+
project: default
510+
destination:
511+
server: https://kubernetes.default.svc
512+
namespace: default
513+
```
514+
515+
!!! note
516+
The `values.` prefix is always prepended to values provided via `generators.pullRequest.values` field. Ensure you include this prefix in the parameter name within the `template` when using it.
517+
518+
In `values` we can also interpolate all fields set by the Pull Request generator as mentioned above.

docs/operator-manual/argocd-cm.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,4 +428,4 @@ data:
428428
webhook.maxPayloadSizeMB: "50"
429429

430430
# application.sync.impersonation.enabled enables application sync to use a custom service account, via impersonation. This allows decoupling sync from control-plane service account.
431-
application.sync.impersonation.enabled: "false"
431+
application.sync.impersonation.enabled: "false"

docs/operator-manual/resource_actions_builtin.md

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/core-install-with-hydrator.yaml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/core-install.yaml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/crds/applicationset-crd.yaml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/ha/install-with-hydrator.yaml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/ha/install.yaml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/install-with-hydrator.yaml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/install.yaml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/application/v1alpha1/applicationset_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ type PullRequestGenerator struct {
612612
Bitbucket *PullRequestGeneratorBitbucket `json:"bitbucket,omitempty" protobuf:"bytes,8,opt,name=bitbucket"`
613613
// Additional provider to use and config for it.
614614
AzureDevOps *PullRequestGeneratorAzureDevOps `json:"azuredevops,omitempty" protobuf:"bytes,9,opt,name=azuredevops"`
615+
// Values contains key/value pairs which are passed directly as parameters to the template
616+
Values map[string]string `json:"values,omitempty" protobuf:"bytes,10,name=values"`
615617
// If you add a new SCM provider, update CustomApiUrl below.
616618
}
617619

0 commit comments

Comments
 (0)