/
helm.go
76 lines (63 loc) · 2.91 KB
/
helm.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
package common
import (
"context"
"time"
helm_v3 "helm.sh/helm/v3/cmd/helm"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/registry"
"github.com/werf/kubedog/pkg/kube"
"github.com/werf/logboek"
bundles_registry "github.com/werf/werf/pkg/deploy/bundles/registry"
"github.com/werf/werf/pkg/deploy/helm"
"github.com/werf/werf/pkg/docker"
"github.com/werf/werf/pkg/util"
)
func NewHelmRegistryClient(ctx context.Context, dockerConfig string, insecureHelmDependencies bool) (*registry.Client, error) {
client, err := NewHelmRegistryClientWithoutInit(ctx)
if err != nil {
return nil, err
}
InitHelmRegistryClient(client, dockerConfig, insecureHelmDependencies)
return client, nil
}
func NewHelmRegistryClientWithoutInit(ctx context.Context) (*registry.Client, error) {
return registry.NewClient(
registry.ClientOptDebug(logboek.Context(ctx).Debug().IsAccepted()),
registry.ClientOptWriter(logboek.Context(ctx).OutStream()),
)
}
func InitHelmRegistryClient(registryClient *registry.Client, dockerConfig string, insecureHelmDependencies bool) {
registry.ClientOptCredentialsFile(docker.GetDockerConfigCredentialsFile(dockerConfig))(registryClient)
registry.ClientOptInsecure(insecureHelmDependencies)(registryClient)
}
func NewBundlesRegistryClient(ctx context.Context, commonCmdData *CmdData) (*bundles_registry.Client, error) {
debug := logboek.Context(ctx).Debug().IsAccepted()
insecure := util.GetBoolEnvironmentDefaultFalse("WERF_BUNDLE_INSECURE_REGISTRY")
skipTlsVerify := util.GetBoolEnvironmentDefaultFalse("WERF_BUNDLE_SKIP_TLS_VERIFY_REGISTRY")
out := logboek.Context(ctx).OutStream()
return bundles_registry.NewClient(
bundles_registry.ClientOptCredentialsFile(docker.GetDockerConfigCredentialsFile(*commonCmdData.DockerConfig)),
bundles_registry.ClientOptDebug(debug),
bundles_registry.ClientOptInsecure(insecure),
bundles_registry.ClientOptSkipTlsVerify(skipTlsVerify),
bundles_registry.ClientOptWriter(out),
)
}
func NewActionConfig(ctx context.Context, kubeInitializer helm.KubeInitializer, namespace string, commonCmdData *CmdData, registryClient *registry.Client) (*action.Configuration, error) {
actionConfig := new(action.Configuration)
if err := helm.InitActionConfig(ctx, kubeInitializer, namespace, helm_v3.Settings, actionConfig, helm.InitActionConfigOptions{
StatusProgressPeriod: time.Duration(*commonCmdData.StatusProgressPeriodSeconds) * time.Second,
HooksStatusProgressPeriod: time.Duration(*commonCmdData.HooksStatusProgressPeriodSeconds) * time.Second,
KubeConfigOptions: kube.KubeConfigOptions{
Context: *commonCmdData.KubeContext,
ConfigPath: *commonCmdData.KubeConfig,
ConfigDataBase64: *commonCmdData.KubeConfigBase64,
ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList,
},
ReleasesHistoryMax: *commonCmdData.ReleasesHistoryMax,
RegistryClient: registryClient,
}); err != nil {
return nil, err
}
return actionConfig, nil
}