From 579887ccf6d7605e7b5dbc2d556ad7e5eeafc630 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Thu, 26 Aug 2021 21:20:31 +0200 Subject: [PATCH] try to fix pre-install quoting errors (#819) * try to fix pre-install quoting errors * split command and args * expected command * sh-bash mistake * some work on permissions and quoting * fix test mistake * another test mistake * again --- charts/library/common/Chart.yaml | 2 +- .../templates/classes/_mountPermissions.tpl | 12 +++---- .../common/tests/permissions_job_test.go | 33 ++++++++++++++++--- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index da0b474dce5..1a4deb5bd59 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -18,4 +18,4 @@ maintainers: name: common sources: null type: library -version: 6.9.1 +version: 6.9.2 diff --git a/charts/library/common/templates/classes/_mountPermissions.tpl b/charts/library/common/templates/classes/_mountPermissions.tpl index 24b5ca3e0ad..0f2e7d2ef4c 100644 --- a/charts/library/common/templates/classes/_mountPermissions.tpl +++ b/charts/library/common/templates/classes/_mountPermissions.tpl @@ -37,13 +37,11 @@ spec: containers: - name: set-mount-permissions image: alpine:3.3 - command: - - /bin/sh - - -c - - | - {{- range $_, $hpm := $hostPathMounts }} - chown -R {{ printf ":%d %s" (int $group) $hpm.mountPath }} - {{- end }} + command: ["/bin/sh", "-c"] + args: + {{- range $_, $hpm := $hostPathMounts }} + - chown -R {{ printf ":%d %s" (int $group) ( $hpm.mountPath | squote ) }} + {{- end }} volumeMounts: {{- range $name, $hpm := $hostPathMounts }} - name: {{ printf "hostpathmounts-%s" $name }} diff --git a/charts/library/common/tests/permissions_job_test.go b/charts/library/common/tests/permissions_job_test.go index 7154c0ba566..9943250e967 100644 --- a/charts/library/common/tests/permissions_job_test.go +++ b/charts/library/common/tests/permissions_job_test.go @@ -135,11 +135,15 @@ func (suite *PermissionsJobTestSuite) TestCommand() { tests := map[string]struct { values []string expectedCommand []string + expectedArgs []string }{ "DefaultPermissionsForMultipleMounts": { values: baseValues, expectedCommand: []string{ - "/bin/sh", "-c", "chown -R :568 /config\nchown -R :568 /data\n", + "/bin/sh", "-c", + }, + expectedArgs: []string{ + "chown -R :568 '/config'", "chown -R :568 '/data'", }, }, "DefaultPermissionsForDisabledpodSecurityContext": { @@ -147,7 +151,10 @@ func (suite *PermissionsJobTestSuite) TestCommand() { "podSecurityContext.allowPrivilegeEscalation=false", ), expectedCommand: []string{ - "/bin/sh", "-c", "chown -R :568 /config\nchown -R :568 /data\n", + "/bin/sh", "-c", + }, + expectedArgs: []string{ + "chown -R :568 '/config'", "chown -R :568 '/data'", }, }, "PermissionsForFsGroup": { @@ -155,7 +162,10 @@ func (suite *PermissionsJobTestSuite) TestCommand() { "podSecurityContext.fsGroup=666", ), expectedCommand: []string{ - "/bin/sh", "-c", "chown -R :666 /config\nchown -R :666 /data\n", + "/bin/sh", "-c", + }, + expectedArgs: []string{ + "chown -R :666 '/config'", "chown -R :666 '/data'", }, }, "PermissionsForPgid": { @@ -163,7 +173,10 @@ func (suite *PermissionsJobTestSuite) TestCommand() { "env.PGID=666", ), expectedCommand: []string{ - "/bin/sh", "-c", "chown -R :666 /config\nchown -R :666 /data\n", + "/bin/sh", "-c", + }, + expectedArgs: []string{ + "chown -R :666 '/config'", "chown -R :666 '/data'", }, }, } @@ -179,6 +192,7 @@ func (suite *PermissionsJobTestSuite) TestCommand() { containers, _ := jobManifest.Path("spec.template.spec.containers").Children() command, _ := containers[0].Path("command").Children() + args, _ := containers[0].Path("args").Children() if tc.expectedCommand != nil { actualCommand := []string{} @@ -190,6 +204,17 @@ func (suite *PermissionsJobTestSuite) TestCommand() { } else { suite.Assertions.Empty(command) } + if tc.expectedArgs != nil { + actualArgs := []string{} + + for _, v := range args { + actualArgs = append(actualArgs, v.Data().(string)) + } + + suite.Assertions.EqualValues(tc.expectedArgs, actualArgs) + } else { + suite.Assertions.Empty(args) + } }) } }