This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
upgrade.go
110 lines (91 loc) · 3.26 KB
/
upgrade.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
/*
Copyright © 2021 Bedag Informatik AG & 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.
*/
/* Lots of code straight from github.com/helm/helm and adapted to be used here */
package helm
import (
"github.com/sirupsen/logrus"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/storage/driver"
)
func (h *Helm) getUpgradeOptions(client *action.Upgrade) {
client.DryRun = h.options.DryRun
client.DisableHooks = h.options.NoHooks
client.Timeout = h.options.Timeout
client.Wait = h.options.Wait
client.WaitForJobs = h.options.WaitForJobs
client.DisableOpenAPIValidation = h.options.DisableOpenAPIValidation
client.Atomic = h.options.Atomic
client.SkipCRDs = h.options.SkipCRDs
client.SubNotes = h.options.RenderSubChartNotes
client.Force = h.options.Force
client.ResetValues = h.options.ResetValues
client.ReuseValues = h.options.ReuseValues
client.MaxHistory = h.options.HistoryMax
client.CleanupOnFail = h.options.CleanupOnFail
h.getChartPathOptions(&client.ChartPathOptions)
}
func (h *Helm) runUpgrade(args []string, vals map[string]interface{}, client *action.Upgrade, cfg *action.Configuration) (*release.Release, error) {
settings := h.settings
logFields := logrus.Fields{
"release": args[0],
"chart": args[1],
}
if client.Namespace == "" {
client.Namespace = settings.Namespace()
}
if client.Install {
// If a release does not exist, install it.
histClient := action.NewHistory(cfg)
histClient.Max = 1
if _, err := histClient.Run(args[0]); err == driver.ErrReleaseNotFound {
h.log.WithFields(logFields).Info("Release does not exist. Installing it now.")
instClient := action.NewInstall(cfg)
h.getInstallOptions(instClient)
instClient.Version = client.Version
instClient.Namespace = client.Namespace
instClient.ChartPathOptions.RepoURL = client.ChartPathOptions.RepoURL
return h.runInstall(args, vals, instClient)
} else if err != nil {
return nil, err
}
}
if client.Version == "" && client.Devel {
h.log.WithFields(logFields).Debug("setting version to >0.0.0-0")
client.Version = ">0.0.0-0"
}
chartPath, err := client.ChartPathOptions.LocateChart(args[1], settings)
if err != nil {
return nil, err
}
h.log.WithFields(logFields).Debugf("CHART PATH: %s", chartPath)
//vals, err := valueOpts.MergeValues(getter.All(settings))
//if err != nil {
// return err
//}
// Check chart dependencies to make sure all are present in /charts
ch, err := loader.Load(chartPath)
if err != nil {
return nil, err
}
if req := ch.Metadata.Dependencies; req != nil {
if err := action.CheckDependencies(ch, req); err != nil {
return nil, err
}
}
if ch.Metadata.Deprecated {
h.log.WithFields(logFields).Warn("This chart is deprecated")
}
return client.Run(args[0], ch, vals)
}