blob: 805a5a05e0e7a88c0806fe0e95093c9d1067474e [file] [log] [blame]
giolekva8aa73e82022-07-09 11:34:39 +04001package main
2
3import (
4 "context"
giolekva8aa73e82022-07-09 11:34:39 +04005 _ "embed"
giolekva8aa73e82022-07-09 11:34:39 +04006 "fmt"
giolekva8aa73e82022-07-09 11:34:39 +04007 "log"
8 "os"
9 "path/filepath"
10 "time"
11
giolekva8aa73e82022-07-09 11:34:39 +040012 "github.com/spf13/cobra"
13 "helm.sh/helm/v3/pkg/action"
14 "helm.sh/helm/v3/pkg/chart/loader"
15 "helm.sh/helm/v3/pkg/kube"
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +040016
17 "github.com/giolekva/pcloud/core/installer"
18 "github.com/giolekva/pcloud/core/installer/soft"
giolekva8aa73e82022-07-09 11:34:39 +040019)
20
21var bootstrapFlags struct {
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040022 pcloudEnvName string
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +040023 chartsDir string
24 adminPubKey string
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +040025 storageDir string
26 volumeDefaultReplicaCount int
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040027 softServeIP string // TODO(giolekva): reserve using metallb IPAddressPool
giolekva8aa73e82022-07-09 11:34:39 +040028}
29
30func bootstrapCmd() *cobra.Command {
31 cmd := &cobra.Command{
32 Use: "bootstrap",
33 RunE: bootstrapCmdRun,
34 }
35 cmd.Flags().StringVar(
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040036 &bootstrapFlags.pcloudEnvName,
37 "pcloud-env-name",
38 "pcloud",
39 "",
40 )
41 cmd.Flags().StringVar(
giolekva8aa73e82022-07-09 11:34:39 +040042 &bootstrapFlags.chartsDir,
43 "charts-dir",
44 "",
45 "",
46 )
47 cmd.Flags().StringVar(
48 &bootstrapFlags.adminPubKey,
49 "admin-pub-key",
50 "",
51 "",
52 )
53 cmd.Flags().StringVar(
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +040054 &bootstrapFlags.storageDir,
55 "storage-dir",
56 "",
57 "",
58 )
59 cmd.Flags().IntVar(
60 &bootstrapFlags.volumeDefaultReplicaCount,
61 "volume-default-replica-count",
62 3,
63 "",
64 )
65 cmd.Flags().StringVar(
66 &bootstrapFlags.softServeIP,
67 "soft-serve-ip",
68 "",
69 "",
70 )
giolekva8aa73e82022-07-09 11:34:39 +040071 return cmd
72}
73
74func bootstrapCmdRun(cmd *cobra.Command, args []string) error {
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040075 adminPubKey, err := os.ReadFile(bootstrapFlags.adminPubKey)
Giorgi Lekveishvili677b4572023-05-26 15:02:37 +040076 if err != nil {
77 return err
78 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040079 bootstrapJobKeys, err := installer.NewSSHKeyPair()
Giorgi Lekveishvili677b4572023-05-26 15:02:37 +040080 if err != nil {
81 return err
82 }
Giorgi Lekveishvili677b4572023-05-26 15:02:37 +040083 if err := installMetallb(); err != nil {
84 return err
85 }
Giorgi Lekveishvili677b4572023-05-26 15:02:37 +040086 if err := installLonghorn(); err != nil {
87 return err
88 }
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +040089 time.Sleep(2 * time.Minute) // TODO(giolekva): implement proper wait
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040090 if err := installSoftServe(bootstrapJobKeys.Public); err != nil {
Giorgi Lekveishvili677b4572023-05-26 15:02:37 +040091 return err
92 }
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +040093 time.Sleep(1 * time.Minute) // TODO(giolekva): implement proper wait
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040094 ss, err := soft.NewClient(bootstrapFlags.softServeIP, 22, []byte(bootstrapJobKeys.Private), log.Default())
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +040095 if err != nil {
96 return err
97 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040098 if ss.AddPublicKey("admin", string(adminPubKey)); err != nil {
99 return err
100 }
101 if err := installFluxcd(ss, bootstrapFlags.pcloudEnvName); err != nil {
102 return err
103 }
104 repo, err := ss.GetRepo(bootstrapFlags.pcloudEnvName)
Giorgi Lekveishvili677b4572023-05-26 15:02:37 +0400105 if err != nil {
106 return err
107 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400108 repoIO := installer.NewRepoIO(repo, ss.Signer)
109 if err := configurePCloudRepo(repoIO); err != nil {
Giorgi Lekveishvili677b4572023-05-26 15:02:37 +0400110 return err
111 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400112 // TODO(giolekva): commit this to the repo above
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400113 global := installer.Values{
114 PCloudEnvName: bootstrapFlags.pcloudEnvName,
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400115 }
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400116 nsCreator, err := newNSCreator()
117 if err != nil {
Giorgi Lekveishvili677b4572023-05-26 15:02:37 +0400118 return err
119 }
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400120 nsGen := installer.NewPrefixGenerator("pcloud-")
121 if err := installInfrastructureServices(repoIO, nsGen, nsCreator, global); err != nil {
122 return err
123 }
124 if err := installEnvManager(ss, repoIO, nsGen, nsCreator, global); err != nil {
Giorgi Lekveishvili677b4572023-05-26 15:02:37 +0400125 return err
126 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400127 if ss.RemovePublicKey("admin", bootstrapJobKeys.Public); err != nil {
Giorgi Lekveishvili677b4572023-05-26 15:02:37 +0400128 return err
129 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400130 return nil
131}
132
133func installMetallb() error {
134 if err := installMetallbNamespace(); err != nil {
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400135 return err
136 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400137 if err := installMetallbService(); err != nil {
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400138 return err
139 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400140 if err := installMetallbConfig(); err != nil {
Giorgi Lekveishvilid6e80cc2023-06-09 17:38:49 +0400141 return err
142 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400143 return nil
144}
145
146func installMetallbNamespace() error {
147 fmt.Println("Installing metallb namespace")
148 // config, err := createActionConfig("default")
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400149 config, err := createActionConfig(bootstrapFlags.pcloudEnvName)
giolekva8aa73e82022-07-09 11:34:39 +0400150 if err != nil {
151 return err
152 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400153 chart, err := loader.Load(filepath.Join(bootstrapFlags.chartsDir, "namespace"))
giolekva8aa73e82022-07-09 11:34:39 +0400154 if err != nil {
155 return err
156 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400157 values := map[string]interface{}{
158 // "namespace": "pcloud-metallb",
159 "namespace": "metallb-system",
160 "labels": []string{
161 "pod-security.kubernetes.io/audit: privileged",
162 "pod-security.kubernetes.io/enforce: privileged",
163 "pod-security.kubernetes.io/warn: privileged",
164 },
165 }
166 installer := action.NewInstall(config)
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400167 installer.Namespace = bootstrapFlags.pcloudEnvName
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400168 installer.ReleaseName = "metallb-ns"
169 installer.Wait = true
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400170 installer.WaitForJobs = true
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400171 if _, err := installer.RunWithContext(context.TODO(), chart, values); err != nil {
172 return err
173 }
174 return nil
175}
176
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400177func installMetallbService() error {
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400178 fmt.Println("Installing metallb")
179 // config, err := createActionConfig("default")
180 config, err := createActionConfig("metallb-system")
giolekva8aa73e82022-07-09 11:34:39 +0400181 if err != nil {
182 return err
183 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400184 chart, err := loader.Load(filepath.Join(bootstrapFlags.chartsDir, "metallb"))
giolekva8aa73e82022-07-09 11:34:39 +0400185 if err != nil {
186 return err
187 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400188 values := map[string]interface{}{ // TODO(giolekva): add loadBalancerClass?
189 "controller": map[string]interface{}{
190 "image": map[string]interface{}{
191 "repository": "quay.io/metallb/controller",
192 "tag": "v0.13.9",
193 "pullPolicy": "IfNotPresent",
194 },
195 "logLevel": "info",
196 },
197 "speaker": map[string]interface{}{
198 "image": map[string]interface{}{
199 "repository": "quay.io/metallb/speaker",
200 "tag": "v0.13.9",
201 "pullPolicy": "IfNotPresent",
202 },
203 "logLevel": "info",
204 },
205 }
206 installer := action.NewInstall(config)
207 installer.Namespace = "metallb-system" // "pcloud-metallb"
208 installer.CreateNamespace = true
209 installer.ReleaseName = "metallb"
210 installer.IncludeCRDs = true
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400211 installer.Wait = true
212 installer.WaitForJobs = true
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400213 installer.Timeout = 20 * time.Minute
214 if _, err := installer.RunWithContext(context.TODO(), chart, values); err != nil {
giolekva8aa73e82022-07-09 11:34:39 +0400215 return err
216 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400217 return nil
218}
219
220func installMetallbConfig() error {
221 fmt.Println("Installing metallb-config")
222 // config, err := createActionConfig("default")
223 config, err := createActionConfig("metallb-system")
224 if err != nil {
giolekva8aa73e82022-07-09 11:34:39 +0400225 return err
226 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400227 chart, err := loader.Load(filepath.Join(bootstrapFlags.chartsDir, "metallb-config"))
228 if err != nil {
giolekva8aa73e82022-07-09 11:34:39 +0400229 return err
230 }
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400231 values := map[string]interface{}{
232 "from": "192.168.0.210",
233 "to": "192.168.0.240",
234 }
235 installer := action.NewInstall(config)
236 installer.Namespace = "metallb-system" // "pcloud-metallb"
237 installer.CreateNamespace = true
238 installer.ReleaseName = "metallb-cfg"
239 installer.Wait = true
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400240 installer.WaitForJobs = true
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400241 installer.Timeout = 20 * time.Minute
242 if _, err := installer.RunWithContext(context.TODO(), chart, values); err != nil {
243 return err
244 }
245 return nil
246}
247
248func installLonghorn() error {
249 fmt.Println("Installing Longhorn")
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400250 config, err := createActionConfig(bootstrapFlags.pcloudEnvName)
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400251 if err != nil {
252 return err
253 }
254 chart, err := loader.Load(filepath.Join(bootstrapFlags.chartsDir, "longhorn"))
255 if err != nil {
256 return err
257 }
258 values := map[string]interface{}{
259 "defaultSettings": map[string]interface{}{
260 "defaultDataPath": bootstrapFlags.storageDir,
261 },
262 "persistence": map[string]interface{}{
263 "defaultClassReplicaCount": bootstrapFlags.volumeDefaultReplicaCount,
264 },
265 "service": map[string]interface{}{
266 "ui": map[string]interface{}{
267 "type": "LoadBalancer",
268 },
269 },
270 "ingress": map[string]interface{}{
271 "enabled": false,
272 },
273 }
274 installer := action.NewInstall(config)
275 installer.Namespace = "longhorn-system"
276 installer.CreateNamespace = true
277 installer.ReleaseName = "longhorn"
278 installer.Wait = true
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400279 installer.WaitForJobs = true
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400280 installer.Timeout = 20 * time.Minute
281 if _, err := installer.RunWithContext(context.TODO(), chart, values); err != nil {
giolekva8aa73e82022-07-09 11:34:39 +0400282 return err
283 }
284 return nil
285}
286
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400287func installSoftServe(adminPublicKey string) error {
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400288 fmt.Println("Installing SoftServe")
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400289 keys, err := installer.NewSSHKeyPair()
290 if err != nil {
291 return err
292 }
293 config, err := createActionConfig(bootstrapFlags.pcloudEnvName)
giolekva8aa73e82022-07-09 11:34:39 +0400294 if err != nil {
295 return err
296 }
297 chart, err := loader.Load(filepath.Join(bootstrapFlags.chartsDir, "soft-serve"))
298 if err != nil {
299 return err
300 }
301 values := map[string]interface{}{
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400302 "privateKey": keys.Private,
303 "publicKey": keys.Public,
304 "adminKey": adminPublicKey,
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400305 "reservedIP": bootstrapFlags.softServeIP,
giolekva8aa73e82022-07-09 11:34:39 +0400306 }
307 installer := action.NewInstall(config)
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400308 installer.Namespace = bootstrapFlags.pcloudEnvName
giolekva8aa73e82022-07-09 11:34:39 +0400309 installer.CreateNamespace = true
310 installer.ReleaseName = "soft-serve"
311 installer.Wait = true
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400312 installer.WaitForJobs = true
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400313 installer.Timeout = 20 * time.Minute
giolekva8aa73e82022-07-09 11:34:39 +0400314 if _, err := installer.RunWithContext(context.TODO(), chart, values); err != nil {
315 return err
316 }
317 return nil
318}
319
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400320func installFluxcd(ss *soft.Client, pcloudEnvName string) error {
321 keys, err := installer.NewSSHKeyPair()
322 if err != nil {
323 return err
324 }
325 if err := ss.AddUser("flux", keys.Public); err != nil {
326 return err
327 }
328 if err := ss.MakeUserAdmin("flux"); err != nil {
329 return err
330 }
331 fmt.Printf("Creating /%s repo", pcloudEnvName)
332 if err := ss.AddRepository(pcloudEnvName, "# PCloud Systems"); err != nil {
333 return err
334 }
335 fmt.Println("Installing Flux")
336 ssPublic, err := ss.GetPublicKey()
337 if err != nil {
338 return err
339 }
340 if err := installFluxBootstrap(
341 ss.GetRepoAddress(pcloudEnvName),
342 ss.IP,
343 string(ssPublic),
344 keys.Private,
345 ); err != nil {
346 return err
347 }
348 return nil
349}
350
351func installFluxBootstrap(repoAddr, repoHost, repoHostPubKey, privateKey string) error {
352 config, err := createActionConfig(bootstrapFlags.pcloudEnvName)
giolekva8aa73e82022-07-09 11:34:39 +0400353 if err != nil {
354 return err
355 }
356 chart, err := loader.Load(filepath.Join(bootstrapFlags.chartsDir, "flux-bootstrap"))
357 if err != nil {
358 return err
359 }
360 values := map[string]interface{}{
361 "repositoryAddress": repoAddr,
362 "repositoryHost": repoHost,
363 "repositoryHostPublicKey": repoHostPubKey,
364 "privateKey": privateKey,
365 }
366 installer := action.NewInstall(config)
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400367 installer.Namespace = bootstrapFlags.pcloudEnvName
giolekva8aa73e82022-07-09 11:34:39 +0400368 installer.CreateNamespace = true
369 installer.ReleaseName = "flux"
370 installer.Wait = true
371 installer.WaitForJobs = true
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400372 installer.Timeout = 20 * time.Minute
giolekva8aa73e82022-07-09 11:34:39 +0400373 if _, err := installer.RunWithContext(context.TODO(), chart, values); err != nil {
374 return err
375 }
376 return nil
377}
378
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400379func installInfrastructureServices(repo installer.RepoIO, nsGen installer.NamespaceGenerator, nsCreator installer.NamespaceCreator, global installer.Values) error {
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400380 appRepo := installer.NewInMemoryAppRepository(installer.CreateAllApps())
381 install := func(name string) error {
382 app, err := appRepo.Find(name)
383 if err != nil {
384 return err
385 }
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400386 namespaces := make([]string, len(app.Namespaces))
387 for i, n := range app.Namespaces {
388 namespaces[i], err = nsGen.Generate(n)
389 if err != nil {
390 return err
391 }
392 }
393 for _, n := range namespaces {
394 if err := nsCreator.Create(n); err != nil {
395 return err
396 }
397 }
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400398 derived := installer.Derived{
399 Global: global,
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400400 }
401 if len(namespaces) > 0 {
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400402 derived.Release.Namespace = namespaces[0]
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400403 }
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400404 return repo.InstallApp(*app, filepath.Join("/infrastructure", app.Name), map[string]any{}, derived)
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400405 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400406 appsToInstall := []string{
407 "resource-renderer-controller",
408 "headscale-controller",
409 "csi-driver-smb",
410 "ingress-public",
411 "cert-manager",
412 "cert-manager-webhook-gandi",
413 "cert-manager-webhook-gandi-role",
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400414 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400415 for _, name := range appsToInstall {
416 if err := install(name); err != nil {
417 return err
418 }
Giorgi Lekveishvilid6e80cc2023-06-09 17:38:49 +0400419 }
420 return nil
421}
422
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400423func configurePCloudRepo(repo installer.RepoIO) error {
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400424 {
425 kust := installer.NewKustomization()
426 kust.AddResources("pcloud-flux", "infrastructure", "environments")
427 if err := repo.WriteKustomization("kustomization.yaml", kust); err != nil {
428 return err
429 }
430 {
431 out, err := repo.Writer("infrastructure/pcloud-charts.yaml")
432 if err != nil {
433 return err
434 }
435 defer out.Close()
436 _, err = out.Write([]byte(`
437apiVersion: source.toolkit.fluxcd.io/v1beta2
438kind: GitRepository
439metadata:
440 name: pcloud # TODO(giolekva): use more generic name
441 namespace: pcloud # TODO(giolekva): configurable
442spec:
443 interval: 1m0s
444 url: https://github.com/giolekva/pcloud
445 ref:
446 branch: main
447`))
448 if err != nil {
449 return err
450 }
451 }
452 infraKust := installer.NewKustomization()
453 infraKust.AddResources("pcloud-charts.yaml")
454 if err := repo.WriteKustomization("infrastructure/kustomization.yaml", infraKust); err != nil {
455 return err
456 }
457 if err := repo.WriteKustomization("environments/kustomization.yaml", installer.NewKustomization()); err != nil {
458 return err
459 }
460 if err := repo.CommitAndPush("initialize pcloud directory structure"); err != nil {
461 return err
462 }
463 }
464 return nil
465}
466
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400467func installEnvManager(ss *soft.Client, repo installer.RepoIO, nsGen installer.NamespaceGenerator, nsCreator installer.NamespaceCreator, global installer.Values) error {
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400468 keys, err := installer.NewSSHKeyPair()
469 if err != nil {
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400470 return err
471 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400472 user := fmt.Sprintf("%s-env-manager", bootstrapFlags.pcloudEnvName)
473 if err := ss.AddUser(user, keys.Public); err != nil {
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400474 return err
475 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400476 if err := ss.MakeUserAdmin(user); err != nil {
477 return err
478 }
479 appRepo := installer.NewInMemoryAppRepository(installer.CreateAllApps())
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400480 app, err := appRepo.Find("env-manager")
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400481 if err != nil {
482 return err
483 }
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400484 namespaces := make([]string, len(app.Namespaces))
485 for i, n := range app.Namespaces {
486 namespaces[i], err = nsGen.Generate(n)
487 if err != nil {
488 return err
489 }
490 }
491 for _, n := range namespaces {
492 if err := nsCreator.Create(n); err != nil {
493 return err
494 }
495 }
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400496 derived := installer.Derived{
497 Global: global,
498 Values: map[string]any{
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400499 "RepoIP": bootstrapFlags.softServeIP,
500 "SSHPrivateKey": keys.Private,
501 },
Giorgi Lekveishvili4257b902023-07-07 17:08:42 +0400502 }
503 if len(namespaces) > 0 {
504 derived.Release.Namespace = namespaces[0]
505 }
506 return repo.InstallApp(*app, filepath.Join("/infrastructure", app.Name), derived.Values, derived)
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400507}
508
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400509func createActionConfig(namespace string) (*action.Configuration, error) {
giolekva8aa73e82022-07-09 11:34:39 +0400510 config := new(action.Configuration)
511 if err := config.Init(
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400512 kube.GetConfig(rootFlags.kubeConfig, "", namespace),
513 namespace,
giolekva8aa73e82022-07-09 11:34:39 +0400514 "",
515 func(fmtString string, args ...interface{}) {
516 fmt.Printf(fmtString, args...)
517 fmt.Println()
518 },
519 ); err != nil {
520 return nil, err
521 }
522 return config, nil
523}