mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
fix issue 5792
Signed-off-by: rokii <shangtaocn@gmail.com>
This commit is contained in:
parent
2a3b7b5395
commit
871b092f32
4 changed files with 74 additions and 11 deletions
|
|
@ -1,3 +1 @@
|
|||
Error: "helm upgrade" requires 2 arguments
|
||||
|
||||
Usage: helm upgrade [RELEASE] [CHART] [flags]
|
||||
Error: found in Chart.yaml, but missing in charts/ directory: reqsubchart2
|
||||
|
|
|
|||
7
cmd/helm/testdata/testcharts/upgradetest/templates/configmap.yaml
vendored
Normal file
7
cmd/helm/testdata/testcharts/upgradetest/templates/configmap.yaml
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: "{{ .Release.Name }}-configmap"
|
||||
data:
|
||||
myvalue: "Hello World"
|
||||
drink: {{ .Values.favoriteDrink }}
|
||||
|
|
@ -18,6 +18,8 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
|
@ -125,7 +127,7 @@ func TestUpgradeCmd(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "upgrade a release with missing dependencies",
|
||||
cmd: fmt.Sprintf("upgrade bonkers-bunny%s", missingDepsPath),
|
||||
cmd: fmt.Sprintf("upgrade bonkers-bunny %s", missingDepsPath),
|
||||
golden: "output/upgrade-with-missing-dependencies.txt",
|
||||
wantError: true,
|
||||
},
|
||||
|
|
@ -138,3 +140,61 @@ func TestUpgradeCmd(t *testing.T) {
|
|||
}
|
||||
runTestCmd(t, tests)
|
||||
}
|
||||
|
||||
func TestUpgradeWithValue(t *testing.T) {
|
||||
tmpChart := testTempDir(t)
|
||||
configmapData, err := ioutil.ReadFile("testdata/testcharts/upgradetest/templates/configmap.yaml")
|
||||
if err != nil {
|
||||
t.Fatalf("Error loading template yaml %v", err)
|
||||
}
|
||||
cfile := &chart.Chart{
|
||||
Metadata: &chart.Metadata{
|
||||
APIVersion: chart.APIVersionV1,
|
||||
Name: "testUpgradeChart",
|
||||
Description: "A Helm chart for Kubernetes",
|
||||
Version: "0.1.0",
|
||||
},
|
||||
Templates: []*chart.File{&chart.File{Name: "templates/configmap.yaml", Data: configmapData}},
|
||||
}
|
||||
chartPath := filepath.Join(tmpChart, cfile.Metadata.Name)
|
||||
if err := chartutil.SaveDir(cfile, tmpChart); err != nil {
|
||||
t.Fatalf("Error creating chart for upgrade: %v", err)
|
||||
}
|
||||
ch, err := loader.Load(chartPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Error loading chart: %v", err)
|
||||
}
|
||||
_ = release.Mock(&release.MockReleaseOptions{
|
||||
Name: "funny-bunny-v2",
|
||||
Chart: ch,
|
||||
})
|
||||
|
||||
|
||||
relMock := func(n string, v int, ch *chart.Chart) *release.Release {
|
||||
return release.Mock(&release.MockReleaseOptions{Name: n, Version: v, Chart: ch})
|
||||
}
|
||||
|
||||
defer resetEnv()()
|
||||
|
||||
store := storageFixture()
|
||||
|
||||
store.Create(relMock("funny-bunny-v2", 3, ch))
|
||||
|
||||
cmd := fmt.Sprintf("upgrade funny-bunny-v2 --set favoriteDrink=tea '%s'", chartPath)
|
||||
_, _, err = executeActionCommandC(store, cmd)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error, got '%v'", err)
|
||||
}
|
||||
|
||||
updatedRel, err := store.Get("funny-bunny-v2", 4)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error, got '%v'", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(updatedRel.Manifest, "drink: tea") {
|
||||
t.Errorf("The value is not set correctly. manifest: %s", updatedRel.Manifest)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -45,8 +45,6 @@ type Upgrade struct {
|
|||
Namespace string
|
||||
Timeout time.Duration
|
||||
Wait bool
|
||||
// Values is a string containing (unparsed) YAML values.
|
||||
Values map[string]interface{}
|
||||
DisableHooks bool
|
||||
DryRun bool
|
||||
Force bool
|
||||
|
|
@ -67,7 +65,7 @@ func NewUpgrade(cfg *Configuration) *Upgrade {
|
|||
|
||||
// Run executes the upgrade on the given release.
|
||||
func (u *Upgrade) Run(name string, chart *chart.Chart) (*release.Release, error) {
|
||||
if err := chartutil.ProcessDependencies(chart, u.Values); err != nil {
|
||||
if err := chartutil.ProcessDependencies(chart, u.rawValues); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +152,7 @@ func (u *Upgrade) prepareUpgrade(name string, chart *chart.Chart) (*release.Rele
|
|||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
valuesToRender, err := chartutil.ToRenderValues(chart, u.Values, options, caps)
|
||||
valuesToRender, err := chartutil.ToRenderValues(chart, u.rawValues, options, caps)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
@ -169,7 +167,7 @@ func (u *Upgrade) prepareUpgrade(name string, chart *chart.Chart) (*release.Rele
|
|||
Name: name,
|
||||
Namespace: currentRelease.Namespace,
|
||||
Chart: chart,
|
||||
Config: u.Values,
|
||||
Config: u.rawValues,
|
||||
Info: &release.Info{
|
||||
FirstDeployed: currentRelease.Info.FirstDeployed,
|
||||
LastDeployed: Timestamper(),
|
||||
|
|
@ -262,7 +260,7 @@ func (u *Upgrade) reuseValues(chart *chart.Chart, current *release.Release) erro
|
|||
return errors.Wrap(err, "failed to rebuild old values")
|
||||
}
|
||||
|
||||
u.Values = chartutil.CoalesceTables(current.Config, u.Values)
|
||||
u.rawValues = chartutil.CoalesceTables(current.Config, u.rawValues)
|
||||
|
||||
chart.Values = oldVals
|
||||
|
||||
|
|
@ -271,7 +269,7 @@ func (u *Upgrade) reuseValues(chart *chart.Chart, current *release.Release) erro
|
|||
|
||||
if len(u.Values) == 0 && len(current.Config) > 0 {
|
||||
u.cfg.Log("copying values from %s (v%d) to new release.", current.Name, current.Version)
|
||||
u.Values = current.Config
|
||||
u.rawValues = current.Config
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue