mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
Fix: the new default values do not take effect when upgrading the vela core
Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
This commit is contained in:
@@ -140,20 +140,16 @@ func (h *Helper) UpgradeChart(ch *chart.Chart, releaseName, namespace string, va
|
||||
r.Info.Status == release.StatusPendingRollback {
|
||||
return nil, fmt.Errorf("previous installation (e.g., using vela install or helm upgrade) is still in progress. Please try again in %d minutes", timeoutInMinutes)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// merge un-existing values into the values as user-input, because the helm chart upgrade didn't handle the new default values in the chart.
|
||||
// the new default values <= the old custom values <= the new custom values
|
||||
if config.ReuseValues {
|
||||
// sort will sort the release by revision from old to new
|
||||
relutil.SortByRevision(releases)
|
||||
rel := releases[len(releases)-1]
|
||||
// merge new chart values into old values, the values of old chart has the high priority
|
||||
mergedWithNewValues := chartutil.CoalesceTables(rel.Chart.Values, ch.Values)
|
||||
// merge the chart with the released chart config but follow the old config
|
||||
mergeWithConfigs := chartutil.CoalesceTables(rel.Config, mergedWithNewValues)
|
||||
// merge new values as the user input, follow the new user input for --set
|
||||
values = chartutil.CoalesceTables(values, mergeWithConfigs)
|
||||
values = chartutil.CoalesceTables(values, rel.Config)
|
||||
}
|
||||
|
||||
// overwrite existing installation
|
||||
@@ -161,7 +157,8 @@ func (h *Helper) UpgradeChart(ch *chart.Chart, releaseName, namespace string, va
|
||||
install.Namespace = namespace
|
||||
install.Wait = config.Wait
|
||||
install.Timeout = time.Duration(timeoutInMinutes) * time.Minute
|
||||
install.ReuseValues = config.ReuseValues
|
||||
// use the new default value set.
|
||||
install.ReuseValues = false
|
||||
newRelease, err = install.Run(releaseName, ch, values)
|
||||
}
|
||||
// check if install/upgrade worked
|
||||
|
||||
@@ -49,7 +49,10 @@ var _ = Describe("Test helm helper", func() {
|
||||
helper := NewHelper()
|
||||
chart, err := helper.LoadCharts("./testdata/autoscalertrait-0.1.0.tgz", nil)
|
||||
Expect(err).Should(BeNil())
|
||||
release, err := helper.UpgradeChart(chart, "autoscalertrait", "default", nil, UpgradeChartOptions{
|
||||
release, err := helper.UpgradeChart(chart, "autoscalertrait", "default", map[string]interface{}{
|
||||
"replicaCount": 2,
|
||||
"image.tag": "0.1.0",
|
||||
}, UpgradeChartOptions{
|
||||
Config: cfg,
|
||||
Detail: false,
|
||||
Logging: util.IOStreams{Out: os.Stdout, ErrOut: os.Stderr},
|
||||
@@ -58,6 +61,42 @@ var _ = Describe("Test helm helper", func() {
|
||||
crds := GetCRDFromChart(release.Chart)
|
||||
Expect(cmp.Diff(len(crds), 1)).Should(BeEmpty())
|
||||
Expect(err).Should(BeNil())
|
||||
deployments := GetDeploymentsFromManifest(release.Manifest)
|
||||
Expect(cmp.Diff(len(deployments), 1)).Should(BeEmpty())
|
||||
Expect(cmp.Diff(*deployments[0].Spec.Replicas, int32(2))).Should(BeEmpty())
|
||||
containers := deployments[0].Spec.Template.Spec.Containers
|
||||
Expect(cmp.Diff(len(containers), 1)).Should(BeEmpty())
|
||||
|
||||
// add new default value
|
||||
Expect(cmp.Diff(containers[0].Image, "ghcr.io/oam-dev/catalog/autoscalertrait:0.1.0")).Should(BeEmpty())
|
||||
|
||||
chartNew, err := helper.LoadCharts("./testdata/autoscalertrait-0.2.0.tgz", nil)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
// the new custom values should override the last release custom values
|
||||
releaseNew, err := helper.UpgradeChart(chartNew, "autoscalertrait", "default", map[string]interface{}{
|
||||
"image.tag": "0.2.0",
|
||||
}, UpgradeChartOptions{
|
||||
Config: cfg,
|
||||
Detail: false,
|
||||
ReuseValues: true,
|
||||
Logging: util.IOStreams{Out: os.Stdout, ErrOut: os.Stderr},
|
||||
Wait: false,
|
||||
})
|
||||
Expect(err).Should(BeNil())
|
||||
deployments = GetDeploymentsFromManifest(releaseNew.Manifest)
|
||||
Expect(cmp.Diff(len(deployments), 1)).Should(BeEmpty())
|
||||
// keep the custom values
|
||||
Expect(cmp.Diff(*deployments[0].Spec.Replicas, int32(2))).Should(BeEmpty())
|
||||
containers = deployments[0].Spec.Template.Spec.Containers
|
||||
Expect(cmp.Diff(len(containers), 1)).Should(BeEmpty())
|
||||
|
||||
// change the default value
|
||||
Expect(cmp.Diff(containers[0].Image, "ghcr.io/oam-dev/catalog/autoscalertrait:0.2.0")).Should(BeEmpty())
|
||||
|
||||
// add new default value
|
||||
Expect(cmp.Diff(len(containers[0].Env), 1)).Should(BeEmpty())
|
||||
Expect(cmp.Diff(containers[0].Env[0].Name, "env1")).Should(BeEmpty())
|
||||
})
|
||||
|
||||
It("Test UninstallRelease", func() {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user