/
utils.go
79 lines (61 loc) · 2.19 KB
/
utils.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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors
// Package helm contains operations for working with helm charts.
package helm
import (
"fmt"
"github.com/defenseunicorns/pkg/helpers"
"github.com/defenseunicorns/zarf/src/pkg/message"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/cli/values"
"helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/chart/loader"
)
// loadChartFromTarball returns a helm chart from a tarball.
func (h *Helm) loadChartFromTarball() (*chart.Chart, error) {
// Get the path the temporary helm chart tarball
sourceFile := StandardName(h.chartPath, h.chart) + ".tgz"
// Load the loadedChart tarball
loadedChart, err := loader.Load(sourceFile)
if err != nil {
return nil, fmt.Errorf("unable to load helm chart archive: %w", err)
}
if err = loadedChart.Validate(); err != nil {
return nil, fmt.Errorf("unable to validate loaded helm chart: %w", err)
}
return loadedChart, nil
}
// parseChartValues reads the context of the chart values into an interface if it exists.
func (h *Helm) parseChartValues() (chartutil.Values, error) {
valueOpts := &values.Options{}
for idx := range h.chart.ValuesFiles {
path := StandardValuesName(h.valuesPath, h.chart, idx)
valueOpts.ValueFiles = append(valueOpts.ValueFiles, path)
}
httpProvider := getter.Provider{
Schemes: []string{"http", "https"},
New: getter.NewHTTPGetter,
}
providers := getter.Providers{httpProvider}
chartValues, err := valueOpts.MergeValues(providers)
if err != nil {
return chartValues, err
}
return helpers.MergeMapRecursive(chartValues, h.valuesOverrides), nil
}
func (h *Helm) createActionConfig(namespace string, spinner *message.Spinner) error {
// Initialize helm SDK
actionConfig := new(action.Configuration)
// Set the settings for the helm SDK
h.settings = cli.New()
// Set the namespace for helm
h.settings.SetNamespace(namespace)
// Setup K8s connection
err := actionConfig.Init(h.settings.RESTClientGetter(), namespace, "", spinner.Updatef)
// Set the actionConfig is the received Helm pointer
h.actionConfig = actionConfig
return err
}