@@ -548,6 +548,10 @@ func bringUpLoopback(netns string) error {
548
548
}
549
549
550
550
func (plugin * cniNetworkPlugin ) SetUpPod (podNetwork PodNetwork ) ([]NetResult , error ) {
551
+ return plugin .SetUpPodWithContext (context .Background (), podNetwork )
552
+ }
553
+
554
+ func (plugin * cniNetworkPlugin ) SetUpPodWithContext (ctx context.Context , podNetwork PodNetwork ) ([]NetResult , error ) {
551
555
if err := plugin .networksAvailable (& podNetwork ); err != nil {
552
556
return nil , err
553
557
}
@@ -563,7 +567,7 @@ func (plugin *cniNetworkPlugin) SetUpPod(podNetwork PodNetwork) ([]NetResult, er
563
567
564
568
results := make ([]NetResult , 0 )
565
569
if err := plugin .forEachNetwork (& podNetwork , false , func (network * cniNetwork , podNetwork * PodNetwork , rt * libcni.RuntimeConf ) error {
566
- result , err := network .addToNetwork (rt , plugin .cniConfig )
570
+ result , err := network .addToNetwork (ctx , rt , plugin .cniConfig )
567
571
if err != nil {
568
572
logrus .Errorf ("Error while adding pod to CNI network %q: %s" , network .name , err )
569
573
return err
@@ -668,6 +672,10 @@ func tearDownLoopback(netns string) error {
668
672
// TearDownPod tears down pod networks. Prefers cached pod attachment information
669
673
// but falls back to given network attachment information.
670
674
func (plugin * cniNetworkPlugin ) TearDownPod (podNetwork PodNetwork ) error {
675
+ return plugin .TearDownPodWithContext (context .Background (), podNetwork )
676
+ }
677
+
678
+ func (plugin * cniNetworkPlugin ) TearDownPodWithContext (ctx context.Context , podNetwork PodNetwork ) error {
671
679
if len (podNetwork .Networks ) == 0 {
672
680
attachments , err := plugin .getCachedNetworkInfo (podNetwork .ID )
673
681
if err == nil && len (attachments ) > 0 {
@@ -688,7 +696,7 @@ func (plugin *cniNetworkPlugin) TearDownPod(podNetwork PodNetwork) error {
688
696
}
689
697
690
698
return plugin .forEachNetwork (& podNetwork , true , func (network * cniNetwork , podNetwork * PodNetwork , rt * libcni.RuntimeConf ) error {
691
- if err := network .deleteFromNetwork (rt , plugin .cniConfig ); err != nil {
699
+ if err := network .deleteFromNetwork (ctx , rt , plugin .cniConfig ); err != nil {
692
700
logrus .Errorf ("Error while removing pod from CNI network %q: %s" , network .name , err )
693
701
return err
694
702
}
@@ -718,6 +726,12 @@ func checkLoopback(netns string) error {
718
726
// GetPodNetworkStatus returns IP addressing and interface details for all
719
727
// networks attached to the pod.
720
728
func (plugin * cniNetworkPlugin ) GetPodNetworkStatus (podNetwork PodNetwork ) ([]NetResult , error ) {
729
+ return plugin .GetPodNetworkStatusWithContext (context .Background (), podNetwork )
730
+ }
731
+
732
+ // GetPodNetworkStatusWithContext returns IP addressing and interface details for all
733
+ // networks attached to the pod.
734
+ func (plugin * cniNetworkPlugin ) GetPodNetworkStatusWithContext (ctx context.Context , podNetwork PodNetwork ) ([]NetResult , error ) {
721
735
plugin .podLock (podNetwork ).Lock ()
722
736
defer plugin .podUnlock (podNetwork )
723
737
@@ -728,7 +742,7 @@ func (plugin *cniNetworkPlugin) GetPodNetworkStatus(podNetwork PodNetwork) ([]Ne
728
742
729
743
results := make ([]NetResult , 0 )
730
744
if err := plugin .forEachNetwork (& podNetwork , true , func (network * cniNetwork , podNetwork * PodNetwork , rt * libcni.RuntimeConf ) error {
731
- result , err := network .checkNetwork (rt , plugin .cniConfig , plugin .nsManager , podNetwork .NetNS )
745
+ result , err := network .checkNetwork (ctx , rt , plugin .cniConfig , plugin .nsManager , podNetwork .NetNS )
732
746
if err != nil {
733
747
logrus .Errorf ("Error while checking pod to CNI network %q: %s" , network .name , err )
734
748
return err
@@ -750,9 +764,9 @@ func (plugin *cniNetworkPlugin) GetPodNetworkStatus(podNetwork PodNetwork) ([]Ne
750
764
return results , nil
751
765
}
752
766
753
- func (network * cniNetwork ) addToNetwork (rt * libcni.RuntimeConf , cni * libcni.CNIConfig ) (cnitypes.Result , error ) {
767
+ func (network * cniNetwork ) addToNetwork (ctx context. Context , rt * libcni.RuntimeConf , cni * libcni.CNIConfig ) (cnitypes.Result , error ) {
754
768
logrus .Infof ("About to add CNI network %s (type=%v)" , network .name , network .config .Plugins [0 ].Network .Type )
755
- res , err := cni .AddNetworkList (context . Background () , network .config , rt )
769
+ res , err := cni .AddNetworkList (ctx , network .config , rt )
756
770
if err != nil {
757
771
logrus .Errorf ("Error adding network: %v" , err )
758
772
return nil , err
@@ -761,7 +775,7 @@ func (network *cniNetwork) addToNetwork(rt *libcni.RuntimeConf, cni *libcni.CNIC
761
775
return res , nil
762
776
}
763
777
764
- func (network * cniNetwork ) checkNetwork (rt * libcni.RuntimeConf , cni * libcni.CNIConfig , nsManager * nsManager , netns string ) (cnitypes.Result , error ) {
778
+ func (network * cniNetwork ) checkNetwork (ctx context. Context , rt * libcni.RuntimeConf , cni * libcni.CNIConfig , nsManager * nsManager , netns string ) (cnitypes.Result , error ) {
765
779
logrus .Infof ("About to check CNI network %s (type=%v)" , network .name , network .config .Plugins [0 ].Network .Type )
766
780
767
781
gtet , err := cniversion .GreaterThanOrEqualTo (network .config .CNIVersion , "0.4.0" )
@@ -773,7 +787,7 @@ func (network *cniNetwork) checkNetwork(rt *libcni.RuntimeConf, cni *libcni.CNIC
773
787
774
788
// When CNIVersion supports Check, use it. Otherwise fall back on what was done initially.
775
789
if gtet {
776
- err = cni .CheckNetworkList (context . Background () , network .config , rt )
790
+ err = cni .CheckNetworkList (ctx , network .config , rt )
777
791
logrus .Infof ("Checking CNI network %s (config version=%v)" , network .name , network .config .CNIVersion )
778
792
if err != nil {
779
793
logrus .Errorf ("Error checking network: %v" , err )
@@ -833,9 +847,9 @@ func (network *cniNetwork) checkNetwork(rt *libcni.RuntimeConf, cni *libcni.CNIC
833
847
return converted , nil
834
848
}
835
849
836
- func (network * cniNetwork ) deleteFromNetwork (rt * libcni.RuntimeConf , cni * libcni.CNIConfig ) error {
850
+ func (network * cniNetwork ) deleteFromNetwork (ctx context. Context , rt * libcni.RuntimeConf , cni * libcni.CNIConfig ) error {
837
851
logrus .Infof ("About to del CNI network %s (type=%v)" , network .name , network .config .Plugins [0 ].Network .Type )
838
- if err := cni .DelNetworkList (context . Background () , network .config , rt ); err != nil {
852
+ if err := cni .DelNetworkList (ctx , network .config , rt ); err != nil {
839
853
logrus .Errorf ("Error deleting network: %v" , err )
840
854
return err
841
855
}
0 commit comments