From 64a6880365d3fc0e707ae5dabcc51bbbfeb89a86 Mon Sep 17 00:00:00 2001 From: Mohamed Chorfa Date: Tue, 20 Oct 2020 00:16:22 -0400 Subject: [PATCH] revert back escaping hack --- pkg/helm3/install.go | 29 +-------------------------- pkg/helm3/install_test.go | 6 ++---- pkg/helm3/testdata/install-input.yaml | 1 - pkg/helm3/upgrade.go | 26 +----------------------- pkg/helm3/upgrade_test.go | 3 +-- 5 files changed, 5 insertions(+), 60 deletions(-) diff --git a/pkg/helm3/install.go b/pkg/helm3/install.go index e073010..114be4b 100644 --- a/pkg/helm3/install.go +++ b/pkg/helm3/install.go @@ -123,34 +123,7 @@ func HandleSettingChartValuesForInstall(step InstallStep, cmd *exec.Cmd) []strin sort.Strings(setKeys) for _, k := range setKeys { - //Hack unitl helm introduce `--set-literal` for complex keys - // see https://github.com/helm/helm/issues/4030 - // TODO : Fix this later upon `--set-literal` introduction - var complexKey bool - keySequences := strings.Split(k, ".") - keyAccumulator := make([]string, 0, len(keySequences)) - for _, ks := range keySequences { - - if strings.HasPrefix(ks, "\"") { - // Start Complex key - keyAccumulator = append(keyAccumulator, ks+"\\") - complexKey = true - - } else if !strings.HasPrefix(ks, "\"") && !strings.HasSuffix(ks, "\"") && complexKey { - // Still in the middle of complex key - keyAccumulator = append(keyAccumulator, strings.Replace(ks, "\"", "\"", -1)+"\\") - - } else if strings.HasSuffix(ks, "\"") && complexKey { - // We Reached the end of complex key so nothing to do. Reset complex sequence - keyAccumulator = append(keyAccumulator, strings.Replace(ks, "\"", "\"", -1)) - complexKey = false - } else { - // Do nothing - keyAccumulator = append(keyAccumulator, ks) - } - } - - cmd.Args = append(cmd.Args, "--set", fmt.Sprintf("%s=%s", strings.Join(keyAccumulator, "."), step.Set[k])) + cmd.Args = append(cmd.Args, "--set", fmt.Sprintf("%s=%s", k, step.Set[k])) } return cmd.Args } diff --git a/pkg/helm3/install_test.go b/pkg/helm3/install_test.go index 07caadf..3935189 100644 --- a/pkg/helm3/install_test.go +++ b/pkg/helm3/install_test.go @@ -42,7 +42,7 @@ func TestMixin_UnmarshalInstallStep(t *testing.T) { assert.Equal(t, "0.10.2", step.Version) assert.Equal(t, true, step.Replace) assert.Equal(t, map[string]string{"mysqlDatabase": "mydb", "mysqlUser": "myuser", - "livenessProbe.initialDelaySeconds": "30", "persistence.enabled": "true", "controller.nodeSelector.\"beta\\.kubernetes\\.io/os\"": "linux"}, step.Set) + "livenessProbe.initialDelaySeconds": "30", "persistence.enabled": "true"}, step.Set) } func TestMixin_Install(t *testing.T) { @@ -53,8 +53,6 @@ func TestMixin_Install(t *testing.T) { setArgs := map[string]string{ "foo": "bar", "baz": "qux", - "prop2.prop3.\"key1.key2.key3\"": "value2", - "prop1.prop2.\"key1.key2.key3\".prop1.prop2.\"key1.key2.key3\"": "value1", } values := []string{ "/tmp/val1.yaml", @@ -64,7 +62,7 @@ func TestMixin_Install(t *testing.T) { baseInstall := fmt.Sprintf(`helm3 install %s %s --namespace %s --version %s`, name, chart, namespace, version) baseInstallUpSert := fmt.Sprintf(`helm3 upgrade --install %s %s --namespace %s --version %s`, name, chart, namespace, version) baseValues := `--values /tmp/val1.yaml --values /tmp/val2.yaml` - baseSetArgs := `--set baz=qux --set foo=bar --set prop1.prop2."key1\.key2\.key3".prop1.prop2."key1\.key2\.key3"=value1 --set prop2.prop3."key1\.key2\.key3"=value2` + baseSetArgs := `--set baz=qux --set foo=bar` installTests := []InstallTest{ { diff --git a/pkg/helm3/testdata/install-input.yaml b/pkg/helm3/testdata/install-input.yaml index 8b67d34..b2c80e6 100644 --- a/pkg/helm3/testdata/install-input.yaml +++ b/pkg/helm3/testdata/install-input.yaml @@ -10,7 +10,6 @@ install: mysqlUser: myuser livenessProbe.initialDelaySeconds: 30 persistence.enabled: true - controller.nodeSelector."beta\.kubernetes\.io/os": linux outputs: - name: mysql-root-password diff --git a/pkg/helm3/upgrade.go b/pkg/helm3/upgrade.go index c49e2f6..1a08c7b 100644 --- a/pkg/helm3/upgrade.go +++ b/pkg/helm3/upgrade.go @@ -114,31 +114,7 @@ func HandleSettingChartValuesForUpgrade(step UpgradeStep, cmd *exec.Cmd) []strin sort.Strings(setKeys) for _, k := range setKeys { - //Hack unitl helm introduce `--set-literal` for complex keys - // see https://github.com/helm/helm/issues/4030 - // TODO : Fix this later upon `--set-literal` introduction - var complexKey bool - keySequences := strings.Split(k, ".") - escapedKeys := make([]string, 0, len(keySequences)) - for _, ks := range keySequences { - // Start Complex key - if strings.HasPrefix(ks, "\"") { - escapedKeys = append(escapedKeys, ks+"\\") - complexKey = true - // Still in the middle of complex key - } else if !strings.HasPrefix(ks, "\"") && !strings.HasSuffix(ks, "\"") && complexKey { - escapedKeys = append(escapedKeys, ks+"\\") - // Reach the end of complex key - } else if strings.HasSuffix(ks, "\"") && complexKey { - escapedKeys = append(escapedKeys, ks) - complexKey = false - // Do nothing - } else { - escapedKeys = append(escapedKeys, ks) - } - } - - cmd.Args = append(cmd.Args, "--set", fmt.Sprintf("%s=%s", strings.Join(escapedKeys, "."), step.Set[k])) + cmd.Args = append(cmd.Args, "--set", fmt.Sprintf("%s=%s", k, step.Set[k])) } return cmd.Args } diff --git a/pkg/helm3/upgrade_test.go b/pkg/helm3/upgrade_test.go index baf8efc..d44de12 100644 --- a/pkg/helm3/upgrade_test.go +++ b/pkg/helm3/upgrade_test.go @@ -49,7 +49,6 @@ func TestMixin_Upgrade(t *testing.T) { setArgs := map[string]string{ "foo": "bar", "baz": "qux", - "prop1.prop2.\"key1.key2.key3\".prop1.prop2.\"key1.key2.key3\"": "value1", } values := []string{ "/tmp/val1.yaml", @@ -58,7 +57,7 @@ func TestMixin_Upgrade(t *testing.T) { baseUpgrade := fmt.Sprintf(`helm3 upgrade --install %s %s --namespace %s --version %s`, name, chart, namespace, version) baseValues := `--values /tmp/val1.yaml --values /tmp/val2.yaml` - baseSetArgs := `--set baz=qux --set foo=bar --set prop1.prop2."key1\.key2\.key3".prop1.prop2."key1\.key2\.key3"=value1` + baseSetArgs := `--set baz=qux --set foo=bar` upgradeTests := []UpgradeTest{ {