66 "github.com/christianh814/gokp/cmd/argo"
77 "github.com/christianh814/gokp/cmd/capi"
88 "github.com/christianh814/gokp/cmd/export"
9+ "github.com/christianh814/gokp/cmd/flux"
910
1011 "github.com/christianh814/gokp/cmd/github"
1112 "github.com/christianh814/gokp/cmd/kind"
@@ -48,6 +49,9 @@ doesn't create one for you).`,
4849 clusterName , _ := cmd .Flags ().GetString ("cluster-name" )
4950 privateRepo , _ := cmd .Flags ().GetBool ("private-repo" )
5051
52+ // Set GitOps Controller
53+ gitOpsController , _ := cmd .Flags ().GetString ("gitops-controller" )
54+
5155 // Grab AWS related flags
5256 awsRegion , _ := cmd .Flags ().GetString ("aws-region" )
5357 awsAccessKey , _ := cmd .Flags ().GetString ("aws-access-key" )
@@ -63,7 +67,7 @@ doesn't create one for you).`,
6367 tcpName := "gokp-bootstrapper"
6468
6569 // Run PreReq Checks
66- _ , err = utils .CheckPreReqs (gokpartifacts )
70+ _ , err = utils .CheckPreReqs (gokpartifacts , gitOpsController )
6771 if err != nil {
6872 log .Fatal (err )
6973 }
@@ -98,15 +102,26 @@ doesn't create one for you).`,
98102 log .Fatal (err )
99103 }
100104
101- // Create repo dir structure. Including Argo CD install YAMLs and base YAMLs. Push initial dir structure out
102- _ , err = templates .CreateRepoSkel (& clusterName , WorkDir , ghToken , gitopsrepo , & privateRepo )
103- if err != nil {
104- log .Fatal (err )
105+ // Create repo dir structure based on which gitops controller that was chosen
106+ if gitOpsController == "argocd" {
107+ // Create repo dir structure. Including Argo CD install YAMLs and base YAMLs. Push initial dir structure out
108+ _ , err = templates .CreateArgoRepoSkel (& clusterName , WorkDir , ghToken , gitopsrepo , & privateRepo )
109+ if err != nil {
110+ log .Fatal (err )
111+ }
112+ } else if gitOpsController == "fluxcd" {
113+ // Create repo dir structure. Including Flux CD install YAMLs and base YAMLs. Push initial dir structure out
114+ _ , err = templates .CreateFluxRepoSkel (& clusterName , WorkDir , ghToken , gitopsrepo , & privateRepo )
115+ if err != nil {
116+ log .Fatal (err )
117+ }
118+ } else {
119+ log .Fatal ("unknown gitops controller" )
105120 }
106121
107122 // Export/Create Cluster YAML to the Repo, Make sure kustomize is used for the core components
108123 log .Info ("Exporting Cluster YAML" )
109- _ , err = export .ExportClusterYaml (CapiCfg , WorkDir + "/" + clusterName )
124+ _ , err = export .ExportClusterYaml (CapiCfg , WorkDir + "/" + clusterName , gitOpsController )
110125 if err != nil {
111126 log .Fatal (err )
112127 }
@@ -118,16 +133,26 @@ doesn't create one for you).`,
118133 log .Fatal (err )
119134 }
120135
121- // Install Argo CD on the newly created cluster
122- // Deploy applications/applicationsets
123- log .Info ("Deploying Argo CD GitOps Controller" )
124- _ , err = argo .BootstrapArgoCD (& clusterName , WorkDir , CapiCfg )
125- if err != nil {
126- log .Fatal (err )
136+ // Deplopy the GitOps controller that was chosen
137+ if gitOpsController == "argocd" {
138+ // Install Argo CD on the newly created cluster with applications/applicationsets
139+ log .Info ("Deploying Argo CD GitOps Controller" )
140+ _ , err = argo .BootstrapArgoCD (& clusterName , WorkDir , CapiCfg )
141+ if err != nil {
142+ log .Fatal (err )
143+ }
144+ } else if gitOpsController == "fluxcd" {
145+ // Install Flux CD on the newly created cluster with all it's components
146+ log .Info ("Deploying Flux CD GitOps Controller" )
147+ _ , err = flux .BootstrapFluxCD (& clusterName , WorkDir , CapiCfg )
148+ if err != nil {
149+ log .Fatal (err )
150+ }
151+ } else {
152+ log .Fatal ("unknown gitops controller" )
127153 }
128154
129155 // MOVE from kind to capi instance
130- // uses the kubeconfig files of "src ~> dest"
131156 log .Info ("Moving CAPI Artifacts to: " + clusterName )
132157 _ , err = capi .MoveMgmtCluster (KindCfg , CapiCfg )
133158 if err != nil {
@@ -149,28 +174,20 @@ doesn't create one for you).`,
149174 log .Fatal (err )
150175 }
151176
152- notNeededDirs := []string {
177+ notNeeded := []string {
153178 "argocd-install-output" ,
154179 "capi-install-yamls-output" ,
155180 "cni-output" ,
156- }
157-
158- for _ , notNeededDir := range notNeededDirs {
159- err = os .RemoveAll (gokpartifacts + "/" + notNeededDir )
160- if err != nil {
161- log .Fatal (err )
162- }
163- }
164-
165- notNeededFiles := []string {
181+ "fluxcd-install-output" ,
166182 "argocd-install.yaml" ,
183+ "flux-install.yaml" ,
167184 "cni.yaml" ,
168185 "install-cluster.yaml" ,
169186 "kind.kubeconfig" ,
170187 }
171188
172- for _ , notNeededFile := range notNeededFiles {
173- err = os .Remove (gokpartifacts + "/" + notNeededFile )
189+ for _ , notNeededthing := range notNeeded {
190+ err = os .RemoveAll (gokpartifacts + "/" + notNeededthing )
174191 if err != nil {
175192 log .Fatal (err )
176193 }
@@ -185,6 +202,9 @@ doesn't create one for you).`,
185202func init () {
186203 createClusterCmd .AddCommand (awscreateCmd )
187204
205+ // GitOps Controller Flag
206+ awscreateCmd .Flags ().String ("gitops-controller" , "argocd" , "The GitOps Controller to use for this cluster." )
207+
188208 // Repo specific flags
189209 awscreateCmd .Flags ().String ("github-token" , "" , "GitHub token to use." )
190210 awscreateCmd .Flags ().String ("cluster-name" , "" , "Name of your cluster." )
0 commit comments