Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions applicationset/controllers/applicationset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (r *ApplicationSetReconciler) generateApplications(applicationSetInfo argop
var applicationSetReason argoprojiov1alpha1.ApplicationSetReasonType

for _, requestedGenerator := range applicationSetInfo.Spec.Generators {
t, err := generators.Transform(requestedGenerator, r.Generators, applicationSetInfo.Spec.Template, &applicationSetInfo, map[string]string{})
t, err := generators.Transform(requestedGenerator, r.Generators, applicationSetInfo.Spec.Template, &applicationSetInfo, map[string]interface{}{})
if err != nil {
log.WithError(err).WithField("generator", requestedGenerator).
Error("error generating application from params")
Expand All @@ -445,7 +445,7 @@ func (r *ApplicationSetReconciler) generateApplications(applicationSetInfo argop
tmplApplication := getTempApplication(a.Template)

for _, p := range a.Params {
app, err := r.Renderer.RenderTemplateParams(tmplApplication, applicationSetInfo.Spec.SyncPolicy, p)
app, err := r.Renderer.RenderTemplateParams(tmplApplication, applicationSetInfo.Spec.SyncPolicy, p, applicationSetInfo.Spec.GoTemplate)
if err != nil {
log.WithError(err).WithField("params", a.Params).WithField("generator", requestedGenerator).
Error("error generating application from params")
Expand Down
29 changes: 15 additions & 14 deletions applicationset/controllers/applicationset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func (g *generatorMock) GetTemplate(appSetGenerator *argoprojiov1alpha1.Applicat
return args.Get(0).(*argoprojiov1alpha1.ApplicationSetTemplate)
}

func (g *generatorMock) GenerateParams(appSetGenerator *argoprojiov1alpha1.ApplicationSetGenerator, _ *argoprojiov1alpha1.ApplicationSet) ([]map[string]string, error) {
func (g *generatorMock) GenerateParams(appSetGenerator *argoprojiov1alpha1.ApplicationSetGenerator, _ *argoprojiov1alpha1.ApplicationSet) ([]map[string]interface{}, error) {
args := g.Called(appSetGenerator)

return args.Get(0).([]map[string]string), args.Error(1)
return args.Get(0).([]map[string]interface{}), args.Error(1)
}

type rendererMock struct {
Expand All @@ -61,8 +61,8 @@ func (g *generatorMock) GetRequeueAfter(appSetGenerator *argoprojiov1alpha1.Appl
return args.Get(0).(time.Duration)
}

func (r *rendererMock) RenderTemplateParams(tmpl *argov1alpha1.Application, syncPolicy *argoprojiov1alpha1.ApplicationSetSyncPolicy, params map[string]string) (*argov1alpha1.Application, error) {
args := r.Called(tmpl, params)
func (r *rendererMock) RenderTemplateParams(tmpl *argov1alpha1.Application, syncPolicy *argoprojiov1alpha1.ApplicationSetSyncPolicy, params map[string]interface{}, useGoTemplate bool) (*argov1alpha1.Application, error) {
args := r.Called(tmpl, params, useGoTemplate)

if args.Error(1) != nil {
return nil, args.Error(1)
Expand All @@ -82,7 +82,7 @@ func TestExtractApplications(t *testing.T) {

for _, c := range []struct {
name string
params []map[string]string
params []map[string]interface{}
template argoprojiov1alpha1.ApplicationSetTemplate
generateParamsError error
rendererError error
Expand All @@ -91,7 +91,7 @@ func TestExtractApplications(t *testing.T) {
}{
{
name: "Generate two applications",
params: []map[string]string{{"name": "app1"}, {"name": "app2"}},
params: []map[string]interface{}{{"name": "app1"}, {"name": "app2"}},
template: argoprojiov1alpha1.ApplicationSetTemplate{
ApplicationSetTemplateMeta: argoprojiov1alpha1.ApplicationSetTemplateMeta{
Name: "name",
Expand All @@ -110,7 +110,7 @@ func TestExtractApplications(t *testing.T) {
},
{
name: "Handles error from the render",
params: []map[string]string{{"name": "app1"}, {"name": "app2"}},
params: []map[string]interface{}{{"name": "app1"}, {"name": "app2"}},
template: argoprojiov1alpha1.ApplicationSetTemplate{
ApplicationSetTemplateMeta: argoprojiov1alpha1.ApplicationSetTemplateMeta{
Name: "name",
Expand Down Expand Up @@ -161,10 +161,10 @@ func TestExtractApplications(t *testing.T) {
for _, p := range cc.params {

if cc.rendererError != nil {
rendererMock.On("RenderTemplateParams", getTempApplication(cc.template), p).
rendererMock.On("RenderTemplateParams", getTempApplication(cc.template), p, false).
Return(nil, cc.rendererError)
} else {
rendererMock.On("RenderTemplateParams", getTempApplication(cc.template), p).
rendererMock.On("RenderTemplateParams", getTempApplication(cc.template), p, false).
Return(&app, nil)
expectedApps = append(expectedApps, app)
}
Expand Down Expand Up @@ -220,15 +220,15 @@ func TestMergeTemplateApplications(t *testing.T) {

for _, c := range []struct {
name string
params []map[string]string
params []map[string]interface{}
template argoprojiov1alpha1.ApplicationSetTemplate
overrideTemplate argoprojiov1alpha1.ApplicationSetTemplate
expectedMerged argoprojiov1alpha1.ApplicationSetTemplate
expectedApps []argov1alpha1.Application
}{
{
name: "Generate app",
params: []map[string]string{{"name": "app1"}},
params: []map[string]interface{}{{"name": "app1"}},
template: argoprojiov1alpha1.ApplicationSetTemplate{
ApplicationSetTemplateMeta: argoprojiov1alpha1.ApplicationSetTemplateMeta{
Name: "name",
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestMergeTemplateApplications(t *testing.T) {

rendererMock := rendererMock{}

rendererMock.On("RenderTemplateParams", getTempApplication(cc.expectedMerged), cc.params[0]).
rendererMock.On("RenderTemplateParams", getTempApplication(cc.expectedMerged), cc.params[0], false).
Return(&cc.expectedApps[0], nil)

r := ApplicationSetReconciler{
Expand Down Expand Up @@ -1792,6 +1792,7 @@ func TestReconcilerValidationErrorBehaviour(t *testing.T) {
Namespace: "argocd",
},
Spec: argoprojiov1alpha1.ApplicationSetSpec{
GoTemplate: true,
Generators: []argoprojiov1alpha1.ApplicationSetGenerator{
{
List: &argoprojiov1alpha1.ListGenerator{
Expand All @@ -1805,13 +1806,13 @@ func TestReconcilerValidationErrorBehaviour(t *testing.T) {
},
Template: argoprojiov1alpha1.ApplicationSetTemplate{
ApplicationSetTemplateMeta: argoprojiov1alpha1.ApplicationSetTemplateMeta{
Name: "{{cluster}}",
Name: "{{.cluster}}",
Namespace: "argocd",
},
Spec: argov1alpha1.ApplicationSpec{
Source: argov1alpha1.ApplicationSource{RepoURL: "https://github.com/argoproj/argocd-example-apps", Path: "guestbook"},
Project: "default",
Destination: argov1alpha1.ApplicationDestination{Server: "{{url}}"},
Destination: argov1alpha1.ApplicationDestination{Server: "{{.url}}"},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: guestbook
spec:
generators:
- clusters: {}
template:
metadata:
name: '{{name}}-guestbook'
spec:
project: "default"
source:
repoURL: https://github.com/argoproj/argocd-example-apps/
targetRevision: HEAD
path: guestbook
destination:
server: '{{server}}'
namespace: guestbook
5 changes: 3 additions & 2 deletions applicationset/examples/cluster/cluster-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ kind: ApplicationSet
metadata:
name: guestbook
spec:
goTemplate: true
generators:
- clusters: {}
template:
metadata:
name: '{{name}}-guestbook'
name: '{{.name}}-guestbook'
spec:
project: "default"
source:
repoURL: https://github.com/argoproj/argocd-example-apps/
targetRevision: HEAD
path: guestbook
destination:
server: '{{server}}'
server: '{{.server}}'
namespace: guestbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: book-import
spec:
generators:
- clusterDecisionResource:
configMapRef: ocm-placement
name: test-placement
requeueAfterSeconds: 30
template:
metadata:
name: '{{clusterName}}-book-import'
spec:
project: "default"
source:
repoURL: https://github.com/open-cluster-management/application-samples.git
targetRevision: HEAD
path: book-import
destination:
name: '{{clusterName}}'
namespace: bookimport
syncPolicy:
automated:
prune: true
syncOptions:
- CreateNamespace=true
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ kind: ApplicationSet
metadata:
name: book-import
spec:
goTemplate: true
generators:
- clusterDecisionResource:
configMapRef: ocm-placement
name: test-placement
requeueAfterSeconds: 30
template:
metadata:
name: '{{clusterName}}-book-import'
name: '{{.clusterName}}-book-import'
spec:
project: "default"
source:
repoURL: https://github.com/open-cluster-management/application-samples.git
targetRevision: HEAD
path: book-import
destination:
name: '{{clusterName}}'
name: '{{.clusterName}}'
namespace: bookimport
syncPolicy:
automated:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This is an example of a typical ApplicationSet which uses the cluster generator.
# An ApplicationSet is comprised with two stanzas:
# - spec.generator - producer of a list of values supplied as arguments to an app template
# - spec.template - an application template, which has been parameterized
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: guestbook
spec:
generators:
- clusters: {}
template:
metadata:
name: '{{name}}-guestbook'
spec:
source:
repoURL: https://github.com/infra-team/cluster-deployments.git
targetRevision: HEAD
chart: guestbook
destination:
server: '{{server}}'
namespace: guestbook
5 changes: 3 additions & 2 deletions applicationset/examples/design-doc/applicationset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ kind: ApplicationSet
metadata:
name: guestbook
spec:
goTemplate: true
generators:
- clusters: {}
template:
metadata:
name: '{{name}}-guestbook'
name: '{{.name}}-guestbook'
spec:
source:
repoURL: https://github.com/infra-team/cluster-deployments.git
targetRevision: HEAD
chart: guestbook
destination:
server: '{{server}}'
server: '{{.server}}'
namespace: guestbook
8 changes: 4 additions & 4 deletions applicationset/examples/design-doc/clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ spec:
project: default
template:
metadata:
name: '{{name}}-guestbook'
name: '{{.name}}-guestbook'
labels:
environment: '{{metadata.labels.environment}}'
environment: '{{.metadata.labels.environment}}'
spec:
project: '{{values.project}}'
project: '{{.values.project}}'
source:
repoURL: https://github.com/infra-team/cluster-deployments.git
targetRevision: HEAD
chart: guestbook
destination:
server: '{{server}}'
server: '{{.server}}'
namespace: guestbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This example demonstrates the git directory generator, which produces an items list
# based on discovery of directories in a git repo matching a specified pattern.
# Git generators automatically provide {{path}} and {{path.basename}} as available
# variables to the app template.
#
# Suppose the following git directory structure (note the use of different config tools):
#
# cluster-deployments
# └── add-ons
# ├── argo-rollouts
# │   ├── all.yaml
# │   └── kustomization.yaml
# ├── argo-workflows
# │   └── install.yaml
# ├── grafana
# │   ├── Chart.yaml
# │   └── values.yaml
# └── prometheus-operator
# ├── Chart.yaml
# └── values.yaml
#
# The following ApplicationSet would produce four applications (in different namespaces),
# using the directory basename as both the namespace and application name.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: cluster-addons
spec:
generators:
- git:
repoURL: https://github.com/infra-team/cluster-deployments.git
directories:
- path: add-ons/*
template:
metadata:
name: '{{path.basename}}'
spec:
source:
repoURL: https://github.com/infra-team/cluster-deployments.git
targetRevision: HEAD
path: '{{path.path}}'
destination:
server: http://kubernetes.default.svc
namespace: '{{path.basename}}'
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ kind: ApplicationSet
metadata:
name: cluster-addons
spec:
goTemplate: true
generators:
- git:
repoURL: https://github.com/infra-team/cluster-deployments.git
directories:
- path: add-ons/*
template:
metadata:
name: '{{path.basename}}'
name: '{{.path.basename}}'
spec:
source:
repoURL: https://github.com/infra-team/cluster-deployments.git
targetRevision: HEAD
path: '{{path}}'
path: '{{.path.path}}'
destination:
server: http://kubernetes.default.svc
namespace: '{{path.basename}}'
namespace: '{{.path.basename}}'
Loading