Skip to content
This repository was archived by the owner on Jun 16, 2021. It is now read-only.

Commit e1a58e2

Browse files
restart: no gets interpreted as restart: false
The yaml parser seems to turn `restart: no` into `restart: false` and false is not a valid restart policy. This patch manually fixes up the value to be `no` if it is read as `false`. Signed-off-by: Darren Shepherd <darren@rancher.com>
1 parent 26d8c30 commit e1a58e2

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

project/merge.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,21 @@ func Merge(p *Project, bytes []byte) (map[string]*ServiceConfig, error) {
5050
datas[name] = data
5151
}
5252

53-
err = utils.Convert(datas, &configs)
54-
return configs, err
53+
if err := utils.Convert(datas, &configs); err != nil {
54+
return nil, err
55+
}
56+
57+
adjustValues(configs)
58+
return configs, nil
59+
}
60+
61+
func adjustValues(configs map[string]*ServiceConfig) {
62+
// yaml parser turns "no" into "false" but that is not valid for retart policy
63+
for _, v := range configs {
64+
if v.Restart == "false" {
65+
v.Restart = "no"
66+
}
67+
}
5568
}
5669

5770
func readEnvFile(configLookup ConfigLookup, inFile string, serviceData rawService) (rawService, error) {

project/merge_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,47 @@ child:
146146
t.Fatal("Invalid image", child.Image)
147147
}
148148
}
149+
150+
func TestRestartNo(t *testing.T) {
151+
p := NewProject(&Context{
152+
ConfigLookup: &NullLookup{},
153+
})
154+
155+
config, err := Merge(p, []byte(`
156+
test:
157+
restart: no
158+
image: foo
159+
`))
160+
161+
if err != nil {
162+
t.Fatal(err)
163+
}
164+
165+
test := config["test"]
166+
167+
if test.Restart != "no" {
168+
t.Fatal("Invalid restart policy", test.Restart)
169+
}
170+
}
171+
172+
func TestRestartAlways(t *testing.T) {
173+
p := NewProject(&Context{
174+
ConfigLookup: &NullLookup{},
175+
})
176+
177+
config, err := Merge(p, []byte(`
178+
test:
179+
restart: always
180+
image: foo
181+
`))
182+
183+
if err != nil {
184+
t.Fatal(err)
185+
}
186+
187+
test := config["test"]
188+
189+
if test.Restart != "always" {
190+
t.Fatal("Invalid restart policy", test.Restart)
191+
}
192+
}

0 commit comments

Comments
 (0)