-
Notifications
You must be signed in to change notification settings - Fork 785
/
helmops.go
126 lines (111 loc) · 3.71 KB
/
helmops.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
package apps
import (
"fmt"
"strings"
"github.com/jenkins-x/jx/pkg/helm"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/util"
"github.com/pkg/errors"
)
// HelmOpsOptions is the options used for Helm Operations for apps
type HelmOpsOptions struct {
*InstallOptions
}
// AddApp adds the app with a version and releaseName from the chart from the repository with username and password.
// A values file or a slice of name=value pairs can be passed in to configure the chart
func (o *HelmOpsOptions) AddApp(app string, chart string, name string, version string, values []byte, repository string,
username string, password string, releaseName string, setValues []string, helmUpdate bool) error {
parsedSetValues := make([]string, 0)
for _, vs := range setValues {
parsedSetValues = append(parsedSetValues, strings.Split(vs, ",")...)
}
err := helm.InstallFromChartOptions(helm.InstallChartOptions{
ReleaseName: releaseName,
Chart: chart,
Version: version,
Ns: o.Namespace,
HelmUpdate: helmUpdate,
SetValues: parsedSetValues,
ValueFiles: o.valuesFiles.Items,
Repository: repository,
Username: username,
Password: password,
}, o.Helmer, o.KubeClient, o.InstallTimeout)
if err != nil {
return errors.Wrapf(err, "failed to install app %s", app)
}
// Attach the current values.yaml
appCRDName := fmt.Sprintf("%s-%s", releaseName, name)
err = StashValues(values, appCRDName, o.JxClient, o.Namespace, chart, repository)
if err != nil {
return errors.Wrapf(err, "attaching values.yaml to %s", appCRDName)
}
log.Infof("Successfully installed %s %s\n", util.ColorInfo(name), util.ColorInfo(version))
return nil
}
//DeleteApp deletes the app, optionally allowing the user to set the releaseName
func (o *HelmOpsOptions) DeleteApp(app string, releaseName string, purge bool) error {
if releaseName == "" {
releaseName = app
}
return o.Helmer.DeleteRelease(o.Namespace, releaseName, purge)
}
//UpgradeApp upgrades the app with releaseName (or all apps if the app name is empty) to the specified version (
// or the latest version if the version is empty) using the repository with username and password
func (o *HelmOpsOptions) UpgradeApp(app string, version string, repository string, username string, password string,
releaseName string, alias string, helmUpdate bool) error {
// TODO implement this!
/*var branchNameText string
var title string
var message string
all := true
if app != "" {
all = false
if version == "" {
version = "latest"
}
branchNameText = fmt.Sprintf("upgrade-app-%s-%s", app, version)
}
branchNameText = fmt.Sprintf("upgrade-all-apps")
title = fmt.Sprintf("Upgrade all apps")
message = fmt.Sprintf("Upgrade all apps:\n")
for _, d := range requirements.Dependencies {
upgrade := false
// We need to ignore the platform
if d.Name == "jenkins-x-platform" {
upgrade = false
} else if all {
upgrade = true
} else {
if d.Name == app && d.Alias == alias {
upgrade = true
}
}
if upgrade {
upgraded = true
if all || version == "" {
var err error
version, err = helm.GetLatestVersion(d.Name, repository, username, password, o.Helmer)
if err != nil {
return err
}
if o.Verbose {
log.Infof("No version specified so using latest version which is %s\n", util.ColorInfo(version))
}
}
// Do the upgrade
oldVersion := d.Version
d.Version = version
if !all {
title = fmt.Sprintf("Upgrade %s to %s", app, version)
message = fmt.Sprintf("Upgrade %s from %s to %s", app, oldVersion, version)
} else {
message = fmt.Sprintf("%s\n* %s from %s to %s", message, d.Name, oldVersion, version)
}
}
}
if !upgraded {
log.Infof("No upgrades available\n")
}*/
return nil
}