Merge pull request #30781 from AkihiroSuda/fix-stack-env
compose: fix environment interpolation from the client
This commit is contained in:
@ -394,11 +394,16 @@ func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortC
|
||||
}, nil
|
||||
}
|
||||
|
||||
func convertEnvironment(source map[string]string) []string {
|
||||
func convertEnvironment(source map[string]*string) []string {
|
||||
var output []string
|
||||
|
||||
for name, value := range source {
|
||||
output = append(output, fmt.Sprintf("%s=%s", name, value))
|
||||
switch value {
|
||||
case nil:
|
||||
output = append(output, name)
|
||||
default:
|
||||
output = append(output, fmt.Sprintf("%s=%s", name, *value))
|
||||
}
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
@ -43,10 +43,14 @@ func TestConvertRestartPolicyFromFailure(t *testing.T) {
|
||||
assert.DeepEqual(t, policy, expected)
|
||||
}
|
||||
|
||||
func strPtr(val string) *string {
|
||||
return &val
|
||||
}
|
||||
|
||||
func TestConvertEnvironment(t *testing.T) {
|
||||
source := map[string]string{
|
||||
"foo": "bar",
|
||||
"key": "value",
|
||||
source := map[string]*string{
|
||||
"foo": strPtr("bar"),
|
||||
"key": strPtr("value"),
|
||||
}
|
||||
env := convertEnvironment(source)
|
||||
sort.Strings(env)
|
||||
|
||||
Reference in New Issue
Block a user