Skip to content

Commit 05599da

Browse files
authored
Merge pull request #579 from q384566678/hook-add-fix
validation: Increase err judgment
2 parents 963c1c0 + 86869d1 commit 05599da

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

validation/poststart.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ func main() {
2727
r.SetID(uuid.NewV4().String())
2828
g := util.GetDefaultGenerator()
2929
output = filepath.Join(r.BundleDir, g.Spec().Root.Path, "output")
30-
poststart := rspec.Hook{
30+
err := g.AddPostStartHook(rspec.Hook{
3131
Path: filepath.Join(r.BundleDir, g.Spec().Root.Path, "/bin/sh"),
3232
Args: []string{
3333
"sh", "-c", fmt.Sprintf("echo 'post-start called' >> %s", output),
3434
},
35+
})
36+
if err != nil {
37+
return err
3538
}
36-
37-
g.AddPostStartHook(poststart)
3839
g.SetProcessArgs([]string{"sh", "-c", fmt.Sprintf("echo 'process called' >> %s", "/output")})
3940
r.SetConfig(g)
4041
return nil

validation/poststop.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ func main() {
2828
r.SetID(uuid.NewV4().String())
2929
g := util.GetDefaultGenerator()
3030
output = filepath.Join(r.BundleDir, g.Spec().Root.Path, "output")
31-
poststop := rspec.Hook{
31+
err := g.AddPostStopHook(rspec.Hook{
3232
Path: filepath.Join(r.BundleDir, g.Spec().Root.Path, "/bin/sh"),
3333
Args: []string{
3434
"sh", "-c", fmt.Sprintf("echo 'post-stop called' >> %s", output),
3535
},
36+
})
37+
if err != nil {
38+
return err
3639
}
37-
38-
g.AddPostStopHook(poststop)
3940
g.SetProcessArgs([]string{"sh", "-c", fmt.Sprintf("echo 'process called' >> %s", "/output")})
4041
r.SetConfig(g)
4142
return nil

validation/prestart.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ func main() {
2626
r.SetID(uuid.NewV4().String())
2727
g := util.GetDefaultGenerator()
2828
output = filepath.Join(r.BundleDir, g.Spec().Root.Path, "output")
29-
prestart := rspec.Hook{
29+
err := g.AddPreStartHook(rspec.Hook{
3030
Path: filepath.Join(r.BundleDir, g.Spec().Root.Path, "/bin/sh"),
3131
Args: []string{
3232
"sh", "-c", fmt.Sprintf("echo 'pre-start called' >> %s", output),
3333
},
34+
})
35+
if err != nil {
36+
return err
3437
}
35-
36-
g.AddPreStartHook(prestart)
3738
g.SetProcessArgs([]string{"sh", "-c", fmt.Sprintf("echo 'process called' >> %s", "/output")})
3839
r.SetConfig(g)
3940
return nil

0 commit comments

Comments
 (0)