@@ -615,9 +615,16 @@ func (p *initProcess) start() (retErr error) {
615
615
if err := p .createNetworkInterfaces (); err != nil {
616
616
return fmt .Errorf ("error creating network interfaces: %w" , err )
617
617
}
618
- if err := p .updateSpecState (); err != nil {
619
- return fmt .Errorf ("error updating spec state: %w" , err )
618
+
619
+ // initConfig.SpecState is only needed to run hooks that are executed
620
+ // inside a container, i.e. CreateContainer and StartContainer.
621
+ if p .config .Config .HasHook (configs .CreateContainer , configs .StartContainer ) {
622
+ p .config .SpecState , err = p .container .currentOCIState ()
623
+ if err != nil {
624
+ return fmt .Errorf ("error getting current state: %w" , err )
625
+ }
620
626
}
627
+
621
628
if err := utils .WriteJSON (p .comm .initSockParent , p .config ); err != nil {
622
629
return fmt .Errorf ("error sending config to init process: %w" , err )
623
630
}
@@ -740,7 +747,7 @@ func (p *initProcess) start() (retErr error) {
740
747
return fmt .Errorf ("error setting Intel RDT config for procHooks process: %w" , err )
741
748
}
742
749
}
743
- if len ( p .config .Config .Hooks ) != 0 {
750
+ if p .config .Config .HasHook ( configs . Prestart , configs . CreateRuntime ) {
744
751
s , err := p .container .currentOCIState ()
745
752
if err != nil {
746
753
return err
@@ -779,16 +786,6 @@ func (p *initProcess) start() (retErr error) {
779
786
return nil
780
787
}
781
788
782
- func (p * initProcess ) updateSpecState () error {
783
- s , err := p .container .currentOCIState ()
784
- if err != nil {
785
- return err
786
- }
787
-
788
- p .config .SpecState = s
789
- return nil
790
- }
791
-
792
789
func (p * initProcess ) createNetworkInterfaces () error {
793
790
for _ , config := range p .config .Config .Networks {
794
791
strategy , err := getStrategy (config .Type )
0 commit comments