Skip to content
This repository was archived by the owner on Jul 15, 2024. It is now read-only.

Commit ff41793

Browse files
committed
Implementation with two types of templates
Signed-off-by: Vlad <[email protected]>
1 parent ffe08d3 commit ff41793

20 files changed

+696
-599
lines changed

api/v1alpha1/applicationset_types.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ type ApplicationSet struct {
4949
// ApplicationSetSpec represents a class of application set state.
5050
type ApplicationSetSpec struct {
5151
Generators []ApplicationSetGenerator `json:"generators"`
52-
Template ApplicationSetTemplate `json:"template"`
52+
Template *ApplicationSetTemplate `json:"template,omitempty"`
53+
UntypedTemplate *ApplicationSetUntypedTemplate `json:"untypedTemplate,omitempty"`
5354
SyncPolicy *ApplicationSetSyncPolicy `json:"syncPolicy,omitempty"`
54-
TemplateOptions *ApplicationSetTemplateOptions `json:"templateOptions,omitempty"`
5555
}
5656

5757
// ApplicationSetSyncPolicy configures how generated Applications will relate to their
@@ -61,18 +61,15 @@ type ApplicationSetSyncPolicy struct {
6161
PreserveResourcesOnDeletion bool `json:"preserveResourcesOnDeletion,omitempty"`
6262
}
6363

64-
// ApplicationSetTemplateOptions configures how template rendering behaves
65-
type ApplicationSetTemplateOptions struct {
66-
// GotemplateEnabled will switch to Go template rendering engine.
67-
GotemplateEnabled bool `json:"gotemplateEnabled,omitempty"`
68-
}
69-
7064
// ApplicationSetTemplate represents argocd ApplicationSpec
7165
type ApplicationSetTemplate struct {
7266
ApplicationSetTemplateMeta `json:"metadata"`
7367
Spec v1alpha1.ApplicationSpec `json:"spec"`
7468
}
7569

70+
// ApplicationSetUntypedTemplate represents argocd ApplicationSpec without type check
71+
type ApplicationSetUntypedTemplate string
72+
7673
// ApplicationSetTemplateMeta represents the Argo CD application fields that may
7774
// be used for Applications generated from the ApplicationSet (based on metav1.ObjectMeta)
7875
type ApplicationSetTemplateMeta struct {

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 11 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/argoproj/applicationset
33
go 1.17
44

55
require (
6+
github.com/Masterminds/sprig/v3 v3.2.2
67
github.com/argoproj/argo-cd/v2 v2.3.0-rc5.0.20220225234205-31676e2aea6f
78
github.com/argoproj/gitops-engine v0.6.0
89
github.com/argoproj/pkg v0.11.1-0.20211203175135-36c59d8fafe0
@@ -29,6 +30,7 @@ require (
2930
cloud.google.com/go v0.81.0 // indirect
3031
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
3132
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd // indirect
33+
github.com/Masterminds/goutils v1.1.1 // indirect
3234
github.com/Masterminds/semver/v3 v3.1.1 // indirect
3335
github.com/PuerkitoBio/purell v1.1.1 // indirect
3436
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
@@ -76,6 +78,7 @@ require (
7678
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
7779
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
7880
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
81+
github.com/huandu/xstrings v1.3.1 // indirect
7982
github.com/inconshreveable/mousetrap v1.0.0 // indirect
8083
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
8184
github.com/jonboulle/clockwork v0.2.2 // indirect
@@ -87,8 +90,10 @@ require (
8790
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
8891
github.com/mailru/easyjson v0.7.6 // indirect
8992
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
93+
github.com/mitchellh/copystructure v1.0.0 // indirect
9094
github.com/mitchellh/go-homedir v1.1.0 // indirect
9195
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
96+
github.com/mitchellh/reflectwalk v1.0.0 // indirect
9297
github.com/moby/spdystream v0.2.0 // indirect
9398
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 // indirect
9499
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -107,6 +112,8 @@ require (
107112
github.com/robfig/cron v1.2.0 // indirect
108113
github.com/russross/blackfriday v1.5.2 // indirect
109114
github.com/sergi/go-diff v1.1.0 // indirect
115+
github.com/shopspring/decimal v1.2.0 // indirect
116+
github.com/spf13/cast v1.3.1 // indirect
110117
github.com/spf13/cobra v1.2.1 // indirect
111118
github.com/spf13/pflag v1.0.5 // indirect
112119
github.com/stretchr/objx v0.2.0 // indirect

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go
6565
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd h1:sjQovDkwrZp8u+gxLtPgKGjk5hCxuy2hrRejBTA9xFU=
6666
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E=
6767
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
68+
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
69+
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
6870
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
6971
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
7072
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
7173
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
74+
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
7275
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
76+
github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8=
77+
github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk=
7378
github.com/Microsoft/go-winio v0.4.15/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw=
7479
github.com/Microsoft/go-winio v0.4.17/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
7580
github.com/Microsoft/hcsshim v0.8.22/go.mod h1:91uVCVzvX2QD16sMCenoxxXo6L1wJnLMX2PSufFMtF0=
@@ -537,12 +542,15 @@ github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6/go.mod h1:xGMAM8JLi7U
537542
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs=
538543
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
539544
github.com/huandu/xstrings v1.3.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
545+
github.com/huandu/xstrings v1.3.1 h1:4jgBlKK6tLKFvO8u5pmYjG91cqytmDCDvGh7ECVFfFs=
546+
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
540547
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
541548
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
542549
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
543550
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
544551
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
545552
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
553+
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
546554
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
547555
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
548556
github.com/improbable-eng/grpc-web v0.0.0-20181111100011-16092bd1d58a/go.mod h1:6hRR09jOEG81ADP5wCQju1z71g6OL4eEvELdran/3cs=
@@ -661,6 +669,7 @@ github.com/minio/minio-go/v7 v7.0.2/go.mod h1:dJ80Mv2HeGkYLH1sqS/ksz07ON6csH3S6J
661669
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
662670
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfvcGfQ4ci2FwoAjKYxuo3Z4=
663671
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
672+
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
664673
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
665674
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
666675
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
@@ -673,6 +682,7 @@ github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0Qu
673682
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
674683
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
675684
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
685+
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
676686
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
677687
github.com/moby/ipvs v1.0.1/go.mod h1:2pngiyseZbIKXNv7hsKj3O9UEz30c53MT9005gt2hxQ=
678688
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
@@ -868,6 +878,7 @@ github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B
868878
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
869879
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
870880
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
881+
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
871882
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
872883
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
873884
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=

manifests/crds/argoproj.io_applicationsets.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6458,14 +6458,10 @@ spec:
64586458
- metadata
64596459
- spec
64606460
type: object
6461-
templateOptions:
6462-
properties:
6463-
gotemplateEnabled:
6464-
type: boolean
6465-
type: object
6461+
untypedTemplate:
6462+
type: string
64666463
required:
64676464
- generators
6468-
- template
64696465
type: object
64706466
status:
64716467
properties:

manifests/install.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6457,14 +6457,10 @@ spec:
64576457
- metadata
64586458
- spec
64596459
type: object
6460-
templateOptions:
6461-
properties:
6462-
gotemplateEnabled:
6463-
type: boolean
6464-
type: object
6460+
untypedTemplate:
6461+
type: string
64656462
required:
64666463
- generators
6467-
- template
64686464
type: object
64696465
status:
64706466
properties:

pkg/controllers/applicationset_controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,14 @@ func (r *ApplicationSetReconciler) generateApplications(applicationSetInfo argop
428428
var firstError error
429429
var applicationSetReason argoprojiov1alpha1.ApplicationSetReasonType
430430

431+
if (applicationSetInfo.Spec.Template == nil && applicationSetInfo.Spec.UntypedTemplate == nil) ||
432+
(applicationSetInfo.Spec.Template != nil && applicationSetInfo.Spec.UntypedTemplate != nil) {
433+
firstError = fmt.Errorf("application set spec should have either template or untypedTemplate defined")
434+
applicationSetReason = argoprojiov1alpha1.ApplicationSetReasonErrorOccurred
435+
436+
return res, applicationSetReason, firstError
437+
}
438+
431439
for _, requestedGenerator := range applicationSetInfo.Spec.Generators {
432440
t, err := generators.Transform(requestedGenerator, r.Generators, applicationSetInfo.Spec.Template, &applicationSetInfo)
433441
if err != nil {
@@ -444,7 +452,7 @@ func (r *ApplicationSetReconciler) generateApplications(applicationSetInfo argop
444452
tmplApplication := getTempApplication(a.Template)
445453

446454
for _, p := range a.Params {
447-
app, err := r.Renderer.RenderTemplateParams(tmplApplication, applicationSetInfo.Spec.SyncPolicy, applicationSetInfo.Spec.TemplateOptions, p)
455+
app, err := r.Renderer.RenderTemplateParams(tmplApplication, applicationSetInfo.Spec.UntypedTemplate, applicationSetInfo.Spec.SyncPolicy, p)
448456
if err != nil {
449457
log.WithError(err).WithField("params", a.Params).WithField("generator", requestedGenerator).
450458
Error("error generating application from params")

0 commit comments

Comments
 (0)