-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathhelm.go
96 lines (78 loc) · 2.97 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright The Helm Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tool
import (
"fmt"
"strings"
"github.com/helm/chart-testing/v3/pkg/exec"
)
type Helm struct {
exec exec.ProcessExecutor
extraArgs []string
lintExtraArgs []string
extraSetArgs []string
}
func NewHelm(exec exec.ProcessExecutor, extraArgs, lintExtraArgs, extraSetArgs []string) Helm {
return Helm{
exec: exec,
extraArgs: extraArgs,
lintExtraArgs: lintExtraArgs,
extraSetArgs: extraSetArgs,
}
}
func (h Helm) AddRepo(name string, url string, extraArgs []string) error {
const ociPrefix string = "oci://"
if strings.HasPrefix(url, ociPrefix) {
registryDomain := url[len(ociPrefix):]
return h.exec.RunProcess("helm", "registry", "login", registryDomain, extraArgs)
}
return h.exec.RunProcess("helm", "repo", "add", name, url, extraArgs)
}
func (h Helm) BuildDependencies(chart string) error {
return h.BuildDependenciesWithArgs(chart, []string{})
}
func (h Helm) BuildDependenciesWithArgs(chart string, extraArgs []string) error {
return h.exec.RunProcess("helm", "dependency", "build", chart, extraArgs)
}
func (h Helm) LintWithValues(chart string, valuesFile string) error {
var values []string
if valuesFile != "" {
values = []string{"--values", valuesFile}
}
return h.exec.RunProcess("helm", "lint", chart, values, h.lintExtraArgs)
}
func (h Helm) InstallWithValues(chart string, valuesFile string, namespace string, release string) error {
var values []string
if valuesFile != "" {
values = []string{"--values", valuesFile}
}
return h.exec.RunProcess("helm", "install", release, chart, "--namespace", namespace,
"--wait", values, h.extraArgs, h.extraSetArgs)
}
func (h Helm) Upgrade(chart string, namespace string, release string) error {
return h.exec.RunProcess("helm", "upgrade", release, chart, "--namespace", namespace,
"--reuse-values", "--wait", h.extraArgs, h.extraSetArgs)
}
func (h Helm) Test(namespace string, release string) error {
return h.exec.RunProcess("helm", "test", release, "--namespace", namespace, h.extraArgs)
}
func (h Helm) DeleteRelease(namespace string, release string) {
fmt.Printf("Deleting release %q...\n", release)
if err := h.exec.RunProcess("helm", "uninstall", release, "--namespace", namespace, h.extraArgs); err != nil {
fmt.Println("Error deleting Helm release:", err)
}
}
func (h Helm) Version() (string, error) {
return h.exec.RunProcessAndCaptureStdout("helm", "version", "--template", "{{ .Version }}")
}