Skip to content

Commit

Permalink
revert back escaping hack
Browse files Browse the repository at this point in the history
  • Loading branch information
MChorfa committed Oct 20, 2020
1 parent a8bf7ab commit 64a6880
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 60 deletions.
29 changes: 1 addition & 28 deletions pkg/helm3/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 2 additions & 4 deletions pkg/helm3/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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",
Expand All @@ -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{
{
Expand Down
1 change: 0 additions & 1 deletion pkg/helm3/testdata/install-input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 1 addition & 25 deletions pkg/helm3/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions pkg/helm3/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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{
{
Expand Down

0 comments on commit 64a6880

Please sign in to comment.