/
converge.go
565 lines (467 loc) · 20.9 KB
/
converge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
package converge
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/spf13/cobra"
helm_v3 "helm.sh/helm/v3/cmd/helm"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/cli/values"
"helm.sh/helm/v3/pkg/postrender"
"github.com/werf/kubedog/pkg/kube"
"github.com/werf/logboek"
"github.com/werf/werf/cmd/werf/common"
"github.com/werf/werf/pkg/build"
"github.com/werf/werf/pkg/container_runtime"
"github.com/werf/werf/pkg/deploy/helm/chart_extender"
"github.com/werf/werf/pkg/deploy/helm/chart_extender/helpers"
"github.com/werf/werf/pkg/deploy/helm/command_helpers"
"github.com/werf/werf/pkg/deploy/helm/maintenance_helper"
"github.com/werf/werf/pkg/deploy/lock_manager"
"github.com/werf/werf/pkg/deploy/secrets_manager"
"github.com/werf/werf/pkg/git_repo"
"github.com/werf/werf/pkg/git_repo/gitdata"
"github.com/werf/werf/pkg/giterminism_manager"
"github.com/werf/werf/pkg/image"
"github.com/werf/werf/pkg/ssh_agent"
"github.com/werf/werf/pkg/storage/lrumeta"
"github.com/werf/werf/pkg/storage/manager"
"github.com/werf/werf/pkg/tmp_manager"
"github.com/werf/werf/pkg/true_git"
"github.com/werf/werf/pkg/werf"
"github.com/werf/werf/pkg/werf/global_warnings"
)
var cmdData struct {
Timeout int
AutoRollback bool
}
var commonCmdData common.CmdData
func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "converge",
Short: "Build and push images, then deploy application into Kubernetes",
Long: common.GetLongCommandDescription(`Build and push images, then deploy application into Kubernetes.
The result of converge command is an application deployed into Kubernetes for current git state. Command will create release and wait until all resources of the release will become ready.
Environment is a required param for the deploy by default, because it is needed to construct Helm Release name and Kubernetes Namespace. Either --env or $WERF_ENV should be specified for command.
Read more info about Helm chart structure, Helm Release name, Kubernetes Namespace and how to change it: https://werf.io/documentation/advanced/helm/releases/naming.html`),
Example: `# Build and deploy current application state into production environment
werf converge --repo registry.mydomain.com/web --env production`,
DisableFlagsInUseLine: true,
Annotations: map[string]string{
common.CmdEnvAnno: common.EnvsDescription(common.WerfDebugAnsibleArgs, common.WerfSecretKey),
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := common.BackgroundContext()
defer global_warnings.PrintGlobalWarnings(ctx)
if err := common.ProcessLogOptions(&commonCmdData); err != nil {
common.PrintHelp(cmd)
return err
}
common.LogVersion()
return common.LogRunningTime(func() error {
return runMain(ctx)
})
},
}
common.SetupDir(&commonCmdData, cmd)
common.SetupGitWorkTree(&commonCmdData, cmd)
common.SetupConfigTemplatesDir(&commonCmdData, cmd)
common.SetupConfigPath(&commonCmdData, cmd)
common.SetupEnvironment(&commonCmdData, cmd)
common.SetupGiterminismOptions(&commonCmdData, cmd)
common.SetupTmpDir(&commonCmdData, cmd)
common.SetupHomeDir(&commonCmdData, cmd)
common.SetupSSHKey(&commonCmdData, cmd)
common.SetupIntrospectAfterError(&commonCmdData, cmd)
common.SetupIntrospectBeforeError(&commonCmdData, cmd)
common.SetupIntrospectStage(&commonCmdData, cmd)
common.SetupSecondaryStagesStorageOptions(&commonCmdData, cmd)
common.SetupCacheStagesStorageOptions(&commonCmdData, cmd)
common.SetupStagesStorageOptions(&commonCmdData, cmd)
common.SetupFinalStagesStorageOptions(&commonCmdData, cmd)
common.SetupDockerConfig(&commonCmdData, cmd, "Command needs granted permissions to read, pull and push images into the specified repo, to pull base images")
common.SetupInsecureRegistry(&commonCmdData, cmd)
common.SetupInsecureHelmDependencies(&commonCmdData, cmd)
common.SetupSkipTlsVerifyRegistry(&commonCmdData, cmd)
common.SetupLogOptions(&commonCmdData, cmd)
common.SetupLogProjectDir(&commonCmdData, cmd)
common.SetupSynchronization(&commonCmdData, cmd)
common.SetupKubeConfig(&commonCmdData, cmd)
common.SetupKubeConfigBase64(&commonCmdData, cmd)
common.SetupKubeContext(&commonCmdData, cmd)
common.SetupStatusProgressPeriod(&commonCmdData, cmd)
common.SetupHooksStatusProgressPeriod(&commonCmdData, cmd)
common.SetupReleasesHistoryMax(&commonCmdData, cmd)
common.SetupRelease(&commonCmdData, cmd)
common.SetupNamespace(&commonCmdData, cmd)
common.SetupAddAnnotations(&commonCmdData, cmd)
common.SetupAddLabels(&commonCmdData, cmd)
common.SetupSetDockerConfigJsonValue(&commonCmdData, cmd)
common.SetupSet(&commonCmdData, cmd)
common.SetupSetString(&commonCmdData, cmd)
common.SetupSetFile(&commonCmdData, cmd)
common.SetupValues(&commonCmdData, cmd)
common.SetupSecretValues(&commonCmdData, cmd)
common.SetupIgnoreSecretKey(&commonCmdData, cmd)
common.SetupReportPath(&commonCmdData, cmd)
common.SetupReportFormat(&commonCmdData, cmd)
common.SetupUseCustomTag(&commonCmdData, cmd)
common.SetupVirtualMerge(&commonCmdData, cmd)
common.SetupVirtualMergeFromCommit(&commonCmdData, cmd)
common.SetupVirtualMergeIntoCommit(&commonCmdData, cmd)
common.SetupParallelOptions(&commonCmdData, cmd, common.DefaultBuildParallelTasksLimit)
common.SetupSkipBuild(&commonCmdData, cmd)
common.SetupPlatform(&commonCmdData, cmd)
common.SetupFollow(&commonCmdData, cmd)
common.SetupDisableAutoHostCleanup(&commonCmdData, cmd)
common.SetupAllowedDockerStorageVolumeUsage(&commonCmdData, cmd)
common.SetupAllowedDockerStorageVolumeUsageMargin(&commonCmdData, cmd)
common.SetupAllowedLocalCacheVolumeUsage(&commonCmdData, cmd)
common.SetupAllowedLocalCacheVolumeUsageMargin(&commonCmdData, cmd)
common.SetupDockerServerStoragePath(&commonCmdData, cmd)
defaultTimeout, err := common.GetIntEnvVar("WERF_TIMEOUT")
if err != nil || defaultTimeout == nil {
defaultTimeout = new(int64)
}
cmd.Flags().IntVarP(&cmdData.Timeout, "timeout", "t", int(*defaultTimeout), "Resources tracking timeout in seconds")
cmd.Flags().BoolVarP(&cmdData.AutoRollback, "auto-rollback", "R", common.GetBoolEnvironmentDefaultFalse("WERF_AUTO_ROLLBACK"), "Enable auto rollback of the failed release to the previous deployed release version when current deploy process have failed ($WERF_AUTO_ROLLBACK by default)")
cmd.Flags().BoolVarP(&cmdData.AutoRollback, "atomic", "", common.GetBoolEnvironmentDefaultFalse("WERF_ATOMIC"), "Enable auto rollback of the failed release to the previous deployed release version when current deploy process have failed ($WERF_ATOMIC by default)")
return cmd
}
func runMain(ctx context.Context) error {
global_warnings.PostponeMultiwerfNotUpToDateWarning()
if err := werf.Init(*commonCmdData.TmpDir, *commonCmdData.HomeDir); err != nil {
return fmt.Errorf("initialization error: %s", err)
}
containerRuntime, processCtx, err := common.InitProcessContainerRuntime(ctx, &commonCmdData)
if err != nil {
return err
}
ctx = processCtx
gitDataManager, err := gitdata.GetHostGitDataManager(ctx)
if err != nil {
return fmt.Errorf("error getting host git data manager: %s", err)
}
if err := git_repo.Init(gitDataManager); err != nil {
return err
}
if err := image.Init(); err != nil {
return err
}
if err := lrumeta.Init(); err != nil {
return err
}
if err := true_git.Init(true_git.Options{LiveGitOutput: *commonCmdData.LogVerbose || *commonCmdData.LogDebug}); err != nil {
return err
}
if err := common.DockerRegistryInit(ctx, &commonCmdData); err != nil {
return err
}
defer func() {
if err := common.RunAutoHostCleanup(ctx, &commonCmdData); err != nil {
logboek.Context(ctx).Error().LogF("Auto host cleanup failed: %s\n", err)
}
}()
giterminismManager, err := common.GetGiterminismManager(&commonCmdData)
if err != nil {
return err
}
common.ProcessLogProjectDir(&commonCmdData, giterminismManager.ProjectDir())
if err := ssh_agent.Init(ctx, common.GetSSHKey(&commonCmdData)); err != nil {
return fmt.Errorf("cannot initialize ssh agent: %s", err)
}
defer func() {
err := ssh_agent.Terminate()
if err != nil {
logboek.Warn().LogF("WARNING: ssh agent termination failed: %s\n", err)
}
}()
common.SetupOndemandKubeInitializer(*commonCmdData.KubeContext, *commonCmdData.KubeConfig, *commonCmdData.KubeConfigBase64, *commonCmdData.KubeConfigPathMergeList)
if err := common.GetOndemandKubeInitializer().Init(ctx); err != nil {
return err
}
if *commonCmdData.Follow {
logboek.LogOptionalLn()
return common.FollowGitHead(ctx, &commonCmdData, func(ctx context.Context, headCommitGiterminismManager giterminism_manager.Interface) error {
return run(ctx, containerRuntime, headCommitGiterminismManager)
})
} else {
return run(ctx, containerRuntime, giterminismManager)
}
}
func run(ctx context.Context, containerRuntime container_runtime.ContainerRuntime, giterminismManager giterminism_manager.Interface) error {
werfConfigPath, werfConfig, err := common.GetRequiredWerfConfig(ctx, &commonCmdData, giterminismManager, common.GetWerfConfigOptions(&commonCmdData, true))
if err != nil {
return fmt.Errorf("unable to load werf config: %s", err)
}
chartDir, err := common.GetHelmChartDir(werfConfigPath, werfConfig, giterminismManager)
if err != nil {
return fmt.Errorf("getting helm chart dir failed: %s", err)
}
projectName := werfConfig.Meta.Project
projectTmpDir, err := tmp_manager.CreateProjectDir(ctx)
if err != nil {
return fmt.Errorf("getting project tmp dir failed: %s", err)
}
defer tmp_manager.ReleaseProjectDir(projectTmpDir)
buildOptions, err := common.GetBuildOptions(&commonCmdData, giterminismManager, werfConfig)
if err != nil {
return err
}
var imagesInfoGetters []*image.InfoGetter
var imagesRepository string
if len(werfConfig.StapelImages) != 0 || len(werfConfig.ImagesFromDockerfile) != 0 {
stagesStorageAddress, err := common.GetStagesStorageAddress(&commonCmdData)
if err != nil {
return err
}
stagesStorage, err := common.GetStagesStorage(stagesStorageAddress, containerRuntime, &commonCmdData)
if err != nil {
return err
}
finalStagesStorage, err := common.GetOptionalFinalStagesStorage(containerRuntime, &commonCmdData)
if err != nil {
return err
}
logboek.LogOptionalLn()
synchronization, err := common.GetSynchronization(ctx, &commonCmdData, projectName, stagesStorage)
if err != nil {
return err
}
stagesStorageCache, err := common.GetStagesStorageCache(synchronization)
if err != nil {
return err
}
storageLockManager, err := common.GetStorageLockManager(ctx, synchronization)
if err != nil {
return err
}
secondaryStagesStorageList, err := common.GetSecondaryStagesStorageList(stagesStorage, containerRuntime, &commonCmdData)
if err != nil {
return err
}
cacheStagesStorageList, err := common.GetCacheStagesStorageList(containerRuntime, &commonCmdData)
if err != nil {
return err
}
storageManager := manager.NewStorageManager(projectName, stagesStorage, finalStagesStorage, secondaryStagesStorageList, cacheStagesStorageList, storageLockManager, stagesStorageCache)
imagesRepository = storageManager.StagesStorage.String()
conveyorOptions, err := common.GetConveyorOptionsWithParallel(&commonCmdData, buildOptions)
if err != nil {
return err
}
conveyorWithRetry := build.NewConveyorWithRetryWrapper(werfConfig, giterminismManager, nil, giterminismManager.ProjectDir(), projectTmpDir, ssh_agent.SSHAuthSock, containerRuntime, storageManager, storageLockManager, conveyorOptions)
defer conveyorWithRetry.Terminate()
if err := conveyorWithRetry.WithRetryBlock(ctx, func(c *build.Conveyor) error {
if *commonCmdData.SkipBuild {
shouldBeBuiltOptions, err := common.GetShouldBeBuiltOptions(&commonCmdData, giterminismManager, werfConfig)
if err != nil {
return err
}
if err := c.ShouldBeBuilt(ctx, shouldBeBuiltOptions); err != nil {
return err
}
} else {
if err := c.Build(ctx, buildOptions); err != nil {
return err
}
}
imagesInfoGetters = c.GetImageInfoGetters()
return nil
}); err != nil {
return err
}
logboek.LogOptionalLn()
}
secretsManager := secrets_manager.NewSecretsManager(secrets_manager.SecretsManagerOptions{DisableSecretsDecryption: *commonCmdData.IgnoreSecretKey})
releaseName, err := common.GetHelmRelease(*commonCmdData.Release, *commonCmdData.Environment, werfConfig)
if err != nil {
return err
}
namespace, err := common.GetKubernetesNamespace(*commonCmdData.Namespace, *commonCmdData.Environment, werfConfig)
if err != nil {
return err
}
kubeConfigOptions := kube.KubeConfigOptions{
Context: *commonCmdData.KubeContext,
ConfigPath: *commonCmdData.KubeConfig,
ConfigDataBase64: *commonCmdData.KubeConfigBase64,
}
userExtraAnnotations, err := common.GetUserExtraAnnotations(&commonCmdData)
if err != nil {
return err
}
userExtraLabels, err := common.GetUserExtraLabels(&commonCmdData)
if err != nil {
return err
}
var lockManager *lock_manager.LockManager
if m, err := lock_manager.NewLockManager(namespace); err != nil {
return fmt.Errorf("unable to create lock manager: %s", err)
} else {
lockManager = m
}
helmRegistryClientHandle, err := common.NewHelmRegistryClientHandle(ctx, &commonCmdData)
if err != nil {
return fmt.Errorf("unable to create helm registry client: %s", err)
}
wc := chart_extender.NewWerfChart(ctx, giterminismManager, secretsManager, chartDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.WerfChartOptions{
SecretValueFiles: common.GetSecretValues(&commonCmdData),
ExtraAnnotations: userExtraAnnotations,
ExtraLabels: userExtraLabels,
})
if err := wc.SetEnv(*commonCmdData.Environment); err != nil {
return err
}
if err := wc.SetWerfConfig(werfConfig); err != nil {
return err
}
useCustomTagFunc, err := common.GetUseCustomTagFunc(&commonCmdData, giterminismManager, werfConfig)
if err != nil {
return err
}
if vals, err := helpers.GetServiceValues(ctx, werfConfig.Meta.Project, imagesRepository, imagesInfoGetters, helpers.ServiceValuesOptions{
Namespace: namespace,
Env: *commonCmdData.Environment,
SetDockerConfigJsonValue: *commonCmdData.SetDockerConfigJsonValue,
DockerConfigPath: *commonCmdData.DockerConfig,
CustomTagFunc: useCustomTagFunc,
}); err != nil {
return fmt.Errorf("error creating service values: %s", err)
} else {
wc.SetServiceValues(vals)
}
loader.GlobalLoadOptions = &loader.LoadOptions{
ChartExtender: wc,
SubchartExtenderFactoryFunc: func() chart.ChartExtender { return chart_extender.NewWerfSubchart() },
}
valueOpts := &values.Options{
ValueFiles: common.GetValues(&commonCmdData),
StringValues: common.GetSetString(&commonCmdData),
Values: common.GetSet(&commonCmdData),
FileValues: common.GetSetFile(&commonCmdData),
}
actionConfig, err := common.NewActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, &commonCmdData, helmRegistryClientHandle)
if err != nil {
return err
}
maintenanceHelper := createMaintenanceHelper(ctx, actionConfig, kubeConfigOptions)
if err := migrateHelm2ToHelm3(ctx, releaseName, namespace, maintenanceHelper, wc.ChainPostRenderer, valueOpts, filepath.Join(giterminismManager.ProjectDir(), chartDir), helmRegistryClientHandle); err != nil {
return err
}
actionConfig, err = common.NewActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, &commonCmdData, helmRegistryClientHandle)
if err != nil {
return err
}
helmUpgradeCmd, _ := helm_v3.NewUpgradeCmd(actionConfig, logboek.OutStream(), helm_v3.UpgradeCmdOptions{
ChainPostRenderer: wc.ChainPostRenderer,
ValueOpts: valueOpts,
CreateNamespace: common.NewBool(true),
Install: common.NewBool(true),
Wait: common.NewBool(true),
Atomic: common.NewBool(cmdData.AutoRollback),
Timeout: common.NewDuration(time.Duration(cmdData.Timeout) * time.Second),
})
return command_helpers.LockReleaseWrapper(ctx, releaseName, lockManager, func() error {
if err := helmUpgradeCmd.RunE(helmUpgradeCmd, []string{releaseName, filepath.Join(giterminismManager.ProjectDir(), chartDir)}); err != nil {
return fmt.Errorf("helm upgrade have failed: %s", err)
}
return nil
})
}
func createMaintenanceHelper(ctx context.Context, actionConfig *action.Configuration, kubeConfigOptions kube.KubeConfigOptions) *maintenance_helper.MaintenanceHelper {
maintenanceOpts := maintenance_helper.MaintenanceHelperOptions{
KubeConfigOptions: kubeConfigOptions,
}
for _, val := range []string{
os.Getenv("WERF_HELM2_RELEASE_STORAGE_NAMESPACE"),
os.Getenv("WERF_HELM_RELEASE_STORAGE_NAMESPACE"),
os.Getenv("TILLER_NAMESPACE"),
} {
if val != "" {
maintenanceOpts.Helm2ReleaseStorageNamespace = val
break
}
}
for _, val := range []string{
os.Getenv("WERF_HELM2_RELEASE_STORAGE_TYPE"),
os.Getenv("WERF_HELM_RELEASE_STORAGE_TYPE"),
} {
if val != "" {
maintenanceOpts.Helm2ReleaseStorageType = val
break
}
}
return maintenance_helper.NewMaintenanceHelper(actionConfig, maintenanceOpts)
}
func migrateHelm2ToHelm3(ctx context.Context, releaseName, namespace string, maintenanceHelper *maintenance_helper.MaintenanceHelper, chainPostRenderer func(postrender.PostRenderer) postrender.PostRenderer, valueOpts *values.Options, fullChartDir string, helmRegistryClientHandle *helm_v3.RegistryClientHandle) error {
if helm2Exists, err := checkHelm2AvailableAndReleaseExists(ctx, releaseName, namespace, maintenanceHelper); err != nil {
return fmt.Errorf("error checking availability of helm 2 and existence of helm 2 release %q: %s", releaseName, err)
} else if !helm2Exists {
return nil
}
if helm3Exists, err := checkHelm3ReleaseExists(ctx, releaseName, namespace, maintenanceHelper); err != nil {
return fmt.Errorf("error checking existence of helm 3 release %q: %s", releaseName, err)
} else if helm3Exists {
// helm 2 exists and helm 3 exists
// migration not needed, but we should warn user that some helm 2 release with the same name exists
logboek.Context(ctx).Warn().LogF("### Helm 2 and helm 3 release %q exists at the same time ###\n", releaseName)
logboek.Context(ctx).Warn().LogLn()
logboek.Context(ctx).Warn().LogF("Found existing helm 2 release %q while there is existing helm 3 release %q in the %q namespace!\n", releaseName, releaseName, namespace)
logboek.Context(ctx).Warn().LogF("werf will continue deploy process into helm 3 release %q in the %q namespace\n", releaseName, namespace)
logboek.Context(ctx).Warn().LogF("To disable this warning please remove old helm 2 release %q metadata (fox example using: kubectl -n kube-system delete cm RELEASE_NAME.VERSION)\n", releaseName)
logboek.Context(ctx).Warn().LogLn()
return nil
}
logboek.Context(ctx).Warn().LogFDetails("Found existing helm 2 release %q, will try to render helm 3 templates and migrate existing release resources to helm 3\n", releaseName)
logboek.Context(ctx).Default().LogOptionalLn()
if err := logboek.Context(ctx).LogProcess("Rendering helm 3 templates for the current project state").DoError(func() error {
actionConfig, err := common.NewActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, &commonCmdData, helmRegistryClientHandle)
if err != nil {
return err
}
helmTemplateCmd, _ := helm_v3.NewTemplateCmd(actionConfig, ioutil.Discard, helm_v3.TemplateCmdOptions{
ChainPostRenderer: chainPostRenderer,
ValueOpts: valueOpts,
Validate: common.NewBool(true),
IncludeCrds: common.NewBool(true),
IsUpgrade: common.NewBool(true),
})
return helmTemplateCmd.RunE(helmTemplateCmd, []string{releaseName, fullChartDir})
}); err != nil {
return err
}
if err := logboek.Context(ctx).Default().LogProcess("Migrating helm 2 release %q to helm 3 in the %q namespace", releaseName, namespace).DoError(func() error {
if err := maintenance_helper.Migrate2To3(ctx, releaseName, releaseName, namespace, maintenanceHelper); err != nil {
return fmt.Errorf("error migrating existing helm 2 release %q to helm 3 release %q in the namespace %q: %s", releaseName, releaseName, namespace, err)
}
return nil
}); err != nil {
return err
}
return nil
}
func checkHelm2AvailableAndReleaseExists(ctx context.Context, releaseName, namespace string, maintenanceHelper *maintenance_helper.MaintenanceHelper) (bool, error) {
if available, err := maintenanceHelper.CheckHelm2StorageAvailable(ctx); err != nil {
return false, err
} else if available {
foundHelm2Release, err := maintenanceHelper.IsHelm2ReleaseExist(ctx, releaseName)
if err != nil {
return false, fmt.Errorf("error checking existence of helm 2 release %q: %s", releaseName, err)
}
return foundHelm2Release, nil
}
return false, nil
}
func checkHelm3ReleaseExists(ctx context.Context, releaseName, namespace string, maintenanceHelper *maintenance_helper.MaintenanceHelper) (bool, error) {
foundHelm3Release, err := maintenanceHelper.IsHelm3ReleaseExist(ctx, releaseName)
if err != nil {
return false, fmt.Errorf("error checking existence of helm 3 release %q: %s", releaseName, err)
}
return foundHelm3Release, nil
}