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
This commit is contained in:
@@ -18,4 +18,4 @@ maintainers:
|
|||||||
name: common
|
name: common
|
||||||
sources: null
|
sources: null
|
||||||
type: library
|
type: library
|
||||||
version: 6.9.1
|
version: 6.9.2
|
||||||
|
|||||||
@@ -37,13 +37,11 @@ spec:
|
|||||||
containers:
|
containers:
|
||||||
- name: set-mount-permissions
|
- name: set-mount-permissions
|
||||||
image: alpine:3.3
|
image: alpine:3.3
|
||||||
command:
|
command: ["/bin/sh", "-c"]
|
||||||
- /bin/sh
|
args:
|
||||||
- -c
|
{{- range $_, $hpm := $hostPathMounts }}
|
||||||
- |
|
- chown -R {{ printf ":%d %s" (int $group) ( $hpm.mountPath | squote ) }}
|
||||||
{{- range $_, $hpm := $hostPathMounts }}
|
{{- end }}
|
||||||
chown -R {{ printf ":%d %s" (int $group) $hpm.mountPath }}
|
|
||||||
{{- end }}
|
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
{{- range $name, $hpm := $hostPathMounts }}
|
{{- range $name, $hpm := $hostPathMounts }}
|
||||||
- name: {{ printf "hostpathmounts-%s" $name }}
|
- name: {{ printf "hostpathmounts-%s" $name }}
|
||||||
|
|||||||
@@ -135,11 +135,15 @@ func (suite *PermissionsJobTestSuite) TestCommand() {
|
|||||||
tests := map[string]struct {
|
tests := map[string]struct {
|
||||||
values []string
|
values []string
|
||||||
expectedCommand []string
|
expectedCommand []string
|
||||||
|
expectedArgs []string
|
||||||
}{
|
}{
|
||||||
"DefaultPermissionsForMultipleMounts": {
|
"DefaultPermissionsForMultipleMounts": {
|
||||||
values: baseValues,
|
values: baseValues,
|
||||||
expectedCommand: []string{
|
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": {
|
"DefaultPermissionsForDisabledpodSecurityContext": {
|
||||||
@@ -147,7 +151,10 @@ func (suite *PermissionsJobTestSuite) TestCommand() {
|
|||||||
"podSecurityContext.allowPrivilegeEscalation=false",
|
"podSecurityContext.allowPrivilegeEscalation=false",
|
||||||
),
|
),
|
||||||
expectedCommand: []string{
|
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": {
|
"PermissionsForFsGroup": {
|
||||||
@@ -155,7 +162,10 @@ func (suite *PermissionsJobTestSuite) TestCommand() {
|
|||||||
"podSecurityContext.fsGroup=666",
|
"podSecurityContext.fsGroup=666",
|
||||||
),
|
),
|
||||||
expectedCommand: []string{
|
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": {
|
"PermissionsForPgid": {
|
||||||
@@ -163,7 +173,10 @@ func (suite *PermissionsJobTestSuite) TestCommand() {
|
|||||||
"env.PGID=666",
|
"env.PGID=666",
|
||||||
),
|
),
|
||||||
expectedCommand: []string{
|
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()
|
containers, _ := jobManifest.Path("spec.template.spec.containers").Children()
|
||||||
command, _ := containers[0].Path("command").Children()
|
command, _ := containers[0].Path("command").Children()
|
||||||
|
args, _ := containers[0].Path("args").Children()
|
||||||
if tc.expectedCommand != nil {
|
if tc.expectedCommand != nil {
|
||||||
actualCommand := []string{}
|
actualCommand := []string{}
|
||||||
|
|
||||||
@@ -190,6 +204,17 @@ func (suite *PermissionsJobTestSuite) TestCommand() {
|
|||||||
} else {
|
} else {
|
||||||
suite.Assertions.Empty(command)
|
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)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user