blob: d007ed2ef5760779e225008751cb5aa5cc668f0b [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
113 global := map[string]any{
114 "PCloudEnvName": bootstrapFlags.pcloudEnvName,
115 }
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 Lekveishvili7fb28bf2023-06-24 19:51:16 +0400379func installInfrastructureServices(repo installer.RepoIO, nsGen installer.NamespaceGenerator, nsCreator installer.NamespaceCreator, global map[string]any) 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 }
398 values := map[string]any{
399 "Global": global,
400 }
401 if len(namespaces) > 0 {
402 values["Release"] = map[string]any{
403 "Namespace": namespaces[0],
404 }
405 }
Giorgi Lekveishvili6e813182023-06-30 13:45:30 +0400406 return repo.InstallApp(*app, filepath.Join("/infrastructure", app.Name), values)
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400407 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400408 appsToInstall := []string{
409 "resource-renderer-controller",
410 "headscale-controller",
411 "csi-driver-smb",
412 "ingress-public",
413 "cert-manager",
414 "cert-manager-webhook-gandi",
415 "cert-manager-webhook-gandi-role",
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400416 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400417 for _, name := range appsToInstall {
418 if err := install(name); err != nil {
419 return err
420 }
Giorgi Lekveishvilid6e80cc2023-06-09 17:38:49 +0400421 }
422 return nil
423}
424
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400425func configurePCloudRepo(repo installer.RepoIO) error {
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400426 {
427 kust := installer.NewKustomization()
428 kust.AddResources("pcloud-flux", "infrastructure", "environments")
429 if err := repo.WriteKustomization("kustomization.yaml", kust); err != nil {
430 return err
431 }
432 {
433 out, err := repo.Writer("infrastructure/pcloud-charts.yaml")
434 if err != nil {
435 return err
436 }
437 defer out.Close()
438 _, err = out.Write([]byte(`
439apiVersion: source.toolkit.fluxcd.io/v1beta2
440kind: GitRepository
441metadata:
442 name: pcloud # TODO(giolekva): use more generic name
443 namespace: pcloud # TODO(giolekva): configurable
444spec:
445 interval: 1m0s
446 url: https://github.com/giolekva/pcloud
447 ref:
448 branch: main
449`))
450 if err != nil {
451 return err
452 }
453 }
454 infraKust := installer.NewKustomization()
455 infraKust.AddResources("pcloud-charts.yaml")
456 if err := repo.WriteKustomization("infrastructure/kustomization.yaml", infraKust); err != nil {
457 return err
458 }
459 if err := repo.WriteKustomization("environments/kustomization.yaml", installer.NewKustomization()); err != nil {
460 return err
461 }
462 if err := repo.CommitAndPush("initialize pcloud directory structure"); err != nil {
463 return err
464 }
465 }
466 return nil
467}
468
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400469func installEnvManager(ss *soft.Client, repo installer.RepoIO, nsGen installer.NamespaceGenerator, nsCreator installer.NamespaceCreator, global map[string]any) error {
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400470 keys, err := installer.NewSSHKeyPair()
471 if err != nil {
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400472 return err
473 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400474 user := fmt.Sprintf("%s-env-manager", bootstrapFlags.pcloudEnvName)
475 if err := ss.AddUser(user, keys.Public); err != nil {
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400476 return err
477 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400478 if err := ss.MakeUserAdmin(user); err != nil {
479 return err
480 }
481 appRepo := installer.NewInMemoryAppRepository(installer.CreateAllApps())
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400482 app, err := appRepo.Find("env-manager")
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400483 if err != nil {
484 return err
485 }
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400486 namespaces := make([]string, len(app.Namespaces))
487 for i, n := range app.Namespaces {
488 namespaces[i], err = nsGen.Generate(n)
489 if err != nil {
490 return err
491 }
492 }
493 for _, n := range namespaces {
494 if err := nsCreator.Create(n); err != nil {
495 return err
496 }
497 }
Giorgi Lekveishvili6e813182023-06-30 13:45:30 +0400498 return repo.InstallApp(*app, filepath.Join("/infrastructure", app.Name), map[string]any{
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400499 "Global": global,
500 "Values": map[string]any{
501 "RepoIP": bootstrapFlags.softServeIP,
502 "SSHPrivateKey": keys.Private,
503 },
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +0400504 "Release": map[string]any{
505 "Namespace": namespaces[0],
506 },
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +0400507 })
Giorgi Lekveishvili3550b432023-06-09 19:37:51 +0400508}
509
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400510func createActionConfig(namespace string) (*action.Configuration, error) {
giolekva8aa73e82022-07-09 11:34:39 +0400511 config := new(action.Configuration)
512 if err := config.Init(
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +0400513 kube.GetConfig(rootFlags.kubeConfig, "", namespace),
514 namespace,
giolekva8aa73e82022-07-09 11:34:39 +0400515 "",
516 func(fmtString string, args ...interface{}) {
517 fmt.Printf(fmtString, args...)
518 fmt.Println()
519 },
520 ); err != nil {
521 return nil, err
522 }
523 return config, nil
524}