@@ -744,29 +744,39 @@ func (g *Generator) ClearPreStartHooks() {
744744func (g * Generator ) AddPreStartHook (path string , args []string ) {
745745 g .initSpecHooks ()
746746 hook := rspec.Hook {Path : path , Args : args }
747+ for i , hook := range g .spec .Hooks .Prestart {
748+ if hook .Path == path {
749+ g .spec .Hooks .Prestart [i ] = hook
750+ return
751+ }
752+ }
747753 g .spec .Hooks .Prestart = append (g .spec .Hooks .Prestart , hook )
748754}
749755
750756// AddPreStartHookEnv adds envs of a prestart hook into g.spec.Hooks.Prestart.
751757func (g * Generator ) AddPreStartHookEnv (path string , envs []string ) {
752- g .initSpec ()
758+ g .initSpecHooks ()
753759 for i , hook := range g .spec .Hooks .Prestart {
754760 if hook .Path == path {
755761 g .spec .Hooks .Prestart [i ].Env = envs
756762 return
757763 }
758764 }
765+ hook := rspec.Hook {Path : path , Env : envs }
766+ g .spec .Hooks .Prestart = append (g .spec .Hooks .Prestart , hook )
759767}
760768
761769// AddPreStartHookTimeout adds timeout of a prestart hook into g.spec.Hooks.Prestart.
762770func (g * Generator ) AddPreStartHookTimeout (path string , timeout int ) {
763- g .initSpec ()
771+ g .initSpecHooks ()
764772 for i , hook := range g .spec .Hooks .Prestart {
765773 if hook .Path == path {
766774 g .spec .Hooks .Prestart [i ].Timeout = & timeout
767775 return
768776 }
769777 }
778+ hook := rspec.Hook {Path : path , Timeout : & timeout }
779+ g .spec .Hooks .Prestart = append (g .spec .Hooks .Prestart , hook )
770780}
771781
772782// ClearPostStopHooks clear g.spec.Hooks.Poststop.
@@ -784,29 +794,39 @@ func (g *Generator) ClearPostStopHooks() {
784794func (g * Generator ) AddPostStopHook (path string , args []string ) {
785795 g .initSpecHooks ()
786796 hook := rspec.Hook {Path : path , Args : args }
797+ for i , hook := range g .spec .Hooks .Poststop {
798+ if hook .Path == path {
799+ g .spec .Hooks .Poststop [i ] = hook
800+ return
801+ }
802+ }
787803 g .spec .Hooks .Poststop = append (g .spec .Hooks .Poststop , hook )
788804}
789805
790806// AddPostStopHookEnv adds envs of a poststop hook into g.spec.Hooks.Poststop.
791807func (g * Generator ) AddPostStopHookEnv (path string , envs []string ) {
792- g .initSpec ()
808+ g .initSpecHooks ()
793809 for i , hook := range g .spec .Hooks .Poststop {
794810 if hook .Path == path {
795811 g .spec .Hooks .Poststop [i ].Env = envs
796812 return
797813 }
798814 }
815+ hook := rspec.Hook {Path : path , Env : envs }
816+ g .spec .Hooks .Poststop = append (g .spec .Hooks .Poststop , hook )
799817}
800818
801819// AddPostStopHookTimeout adds timeout of a poststop hook into g.spec.Hooks.Poststop.
802820func (g * Generator ) AddPostStopHookTimeout (path string , timeout int ) {
803- g .initSpec ()
821+ g .initSpecHooks ()
804822 for i , hook := range g .spec .Hooks .Poststop {
805823 if hook .Path == path {
806824 g .spec .Hooks .Poststop [i ].Timeout = & timeout
807825 return
808826 }
809827 }
828+ hook := rspec.Hook {Path : path , Timeout : & timeout }
829+ g .spec .Hooks .Poststop = append (g .spec .Hooks .Poststop , hook )
810830}
811831
812832// ClearPostStartHooks clear g.spec.Hooks.Poststart.
@@ -824,29 +844,39 @@ func (g *Generator) ClearPostStartHooks() {
824844func (g * Generator ) AddPostStartHook (path string , args []string ) {
825845 g .initSpecHooks ()
826846 hook := rspec.Hook {Path : path , Args : args }
847+ for i , hook := range g .spec .Hooks .Poststart {
848+ if hook .Path == path {
849+ g .spec .Hooks .Poststart [i ] = hook
850+ return
851+ }
852+ }
827853 g .spec .Hooks .Poststart = append (g .spec .Hooks .Poststart , hook )
828854}
829855
830856// AddPostStartHookEnv adds envs of a poststart hook into g.spec.Hooks.Poststart.
831857func (g * Generator ) AddPostStartHookEnv (path string , envs []string ) {
832- g .initSpec ()
858+ g .initSpecHooks ()
833859 for i , hook := range g .spec .Hooks .Poststart {
834860 if hook .Path == path {
835861 g .spec .Hooks .Poststart [i ].Env = envs
836862 return
837863 }
838864 }
865+ hook := rspec.Hook {Path : path , Env : envs }
866+ g .spec .Hooks .Poststart = append (g .spec .Hooks .Poststart , hook )
839867}
840868
841869// AddPostStartHookTimeout adds timeout of a poststart hook into g.spec.Hooks.Poststart.
842870func (g * Generator ) AddPostStartHookTimeout (path string , timeout int ) {
843- g .initSpec ()
871+ g .initSpecHooks ()
844872 for i , hook := range g .spec .Hooks .Poststart {
845873 if hook .Path == path {
846874 g .spec .Hooks .Poststart [i ].Timeout = & timeout
847875 return
848876 }
849877 }
878+ hook := rspec.Hook {Path : path , Timeout : & timeout }
879+ g .spec .Hooks .Poststart = append (g .spec .Hooks .Poststart , hook )
850880}
851881
852882// AddTmpfsMount adds a tmpfs mount into g.spec.Mounts.
0 commit comments