@@ -47,52 +47,52 @@ type ConfigureInterface interface {
47
47
// Configure the plugin with the given NRI-supplied configuration.
48
48
// If a non-zero EventMask is returned, the plugin will be subscribed
49
49
// to the corresponding.
50
- Configure (config , runtime , version string ) (api.EventMask , error )
50
+ Configure (ctx context. Context , config , runtime , version string ) (api.EventMask , error )
51
51
}
52
52
53
53
// SynchronizeInterface handles Synchronize API requests.
54
54
type SynchronizeInterface interface {
55
55
// Synchronize the state of the plugin with the runtime.
56
56
// The plugin can request updates to containers in response.
57
- Synchronize ([]* api.PodSandbox , []* api.Container ) ([]* api.ContainerUpdate , error )
57
+ Synchronize (context. Context , []* api.PodSandbox , []* api.Container ) ([]* api.ContainerUpdate , error )
58
58
}
59
59
60
60
// ShutdownInterface handles a Shutdown API request.
61
61
type ShutdownInterface interface {
62
62
// Shutdown notifies the plugin about the runtime shutting down.
63
- Shutdown (* api. ShutdownRequest )
63
+ Shutdown (context. Context )
64
64
}
65
65
66
66
// RunPodInterface handles RunPodSandbox API events.
67
67
type RunPodInterface interface {
68
68
// RunPodSandbox relays a RunPodSandbox event to the plugin.
69
- RunPodSandbox (* api.PodSandbox ) error
69
+ RunPodSandbox (context. Context , * api.PodSandbox ) error
70
70
}
71
71
72
72
// StopPodInterface handles StopPodSandbox API events.
73
73
type StopPodInterface interface {
74
74
// StopPodSandbox relays a StopPodSandbox event to the plugin.
75
- StopPodSandbox (* api.PodSandbox ) error
75
+ StopPodSandbox (context. Context , * api.PodSandbox ) error
76
76
}
77
77
78
78
// RemovePodInterface handles RemovePodSandbox API events.
79
79
type RemovePodInterface interface {
80
80
// RemovePodSandbox relays a RemovePodSandbox event to the plugin.
81
- RemovePodSandbox (* api.PodSandbox ) error
81
+ RemovePodSandbox (context. Context , * api.PodSandbox ) error
82
82
}
83
83
84
84
// CreateContainerInterface handles CreateContainer API requests.
85
85
type CreateContainerInterface interface {
86
86
// CreateContainer relays a CreateContainer request to the plugin.
87
87
// The plugin can request adjustments to the container being created
88
88
// and updates to other unstopped containers in response.
89
- CreateContainer (* api.PodSandbox , * api.Container ) (* api.ContainerAdjustment , []* api.ContainerUpdate , error )
89
+ CreateContainer (context. Context , * api.PodSandbox , * api.Container ) (* api.ContainerAdjustment , []* api.ContainerUpdate , error )
90
90
}
91
91
92
92
// StartContainerInterface handles StartContainer API requests.
93
93
type StartContainerInterface interface {
94
94
// StartContainer relays a StartContainer event to the plugin.
95
- StartContainer (* api.PodSandbox , * api.Container ) error
95
+ StartContainer (context. Context , * api.PodSandbox , * api.Container ) error
96
96
}
97
97
98
98
// UpdateContainerInterface handles UpdateContainer API requests.
@@ -101,38 +101,38 @@ type UpdateContainerInterface interface {
101
101
// The plugin can request updates both to the container being updated
102
102
// (which then supersedes the original update) and to other unstopped
103
103
// containers in response.
104
- UpdateContainer (* api.PodSandbox , * api.Container ) ([]* api.ContainerUpdate , error )
104
+ UpdateContainer (context. Context , * api.PodSandbox , * api.Container ) ([]* api.ContainerUpdate , error )
105
105
}
106
106
107
107
// StopContainerInterface handles StopContainer API requests.
108
108
type StopContainerInterface interface {
109
109
// StopContainer relays a StopContainer request to the plugin.
110
110
// The plugin can request updates to unstopped containers in response.
111
- StopContainer (* api.PodSandbox , * api.Container ) ([]* api.ContainerUpdate , error )
111
+ StopContainer (context. Context , * api.PodSandbox , * api.Container ) ([]* api.ContainerUpdate , error )
112
112
}
113
113
114
114
// RemoveContainerInterface handles RemoveContainer API events.
115
115
type RemoveContainerInterface interface {
116
116
// RemoveContainer relays a RemoveContainer event to the plugin.
117
- RemoveContainer (* api.PodSandbox , * api.Container ) error
117
+ RemoveContainer (context. Context , * api.PodSandbox , * api.Container ) error
118
118
}
119
119
120
120
// PostCreateContainerInterface handles PostCreateContainer API events.
121
121
type PostCreateContainerInterface interface {
122
122
// PostCreateContainer relays a PostCreateContainer event to the plugin.
123
- PostCreateContainer (* api.PodSandbox , * api.Container ) error
123
+ PostCreateContainer (context. Context , * api.PodSandbox , * api.Container ) error
124
124
}
125
125
126
126
// PostStartContainerInterface handles PostStartContainer API events.
127
127
type PostStartContainerInterface interface {
128
128
// PostStartContainer relays a PostStartContainer event to the plugin.
129
- PostStartContainer (* api.PodSandbox , * api.Container ) error
129
+ PostStartContainer (context. Context , * api.PodSandbox , * api.Container ) error
130
130
}
131
131
132
132
// PostUpdateContainerInterface handles PostUpdateContainer API events.
133
133
type PostUpdateContainerInterface interface {
134
134
// PostUpdateContainer relays a PostUpdateContainer event to the plugin.
135
- PostUpdateContainer (* api.PodSandbox , * api.Container ) error
135
+ PostUpdateContainer (context. Context , * api.PodSandbox , * api.Container ) error
136
136
}
137
137
138
138
// Stub is the interface the stub provides for the plugin implementation.
@@ -253,20 +253,20 @@ type stub struct {
253
253
254
254
// Handlers for NRI plugin event and request.
255
255
type handlers struct {
256
- Configure func (string , string , string ) (api.EventMask , error )
257
- Synchronize func ([]* api.PodSandbox , []* api.Container ) ([]* api.ContainerUpdate , error )
258
- Shutdown func (* api. ShutdownRequest )
259
- RunPodSandbox func (* api.PodSandbox ) error
260
- StopPodSandbox func (* api.PodSandbox ) error
261
- RemovePodSandbox func (* api.PodSandbox ) error
262
- CreateContainer func (* api.PodSandbox , * api.Container ) (* api.ContainerAdjustment , []* api.ContainerUpdate , error )
263
- StartContainer func (* api.PodSandbox , * api.Container ) error
264
- UpdateContainer func (* api.PodSandbox , * api.Container ) ([]* api.ContainerUpdate , error )
265
- StopContainer func (* api.PodSandbox , * api.Container ) ([]* api.ContainerUpdate , error )
266
- RemoveContainer func (* api.PodSandbox , * api.Container ) error
267
- PostCreateContainer func (* api.PodSandbox , * api.Container ) error
268
- PostStartContainer func (* api.PodSandbox , * api.Container ) error
269
- PostUpdateContainer func (* api.PodSandbox , * api.Container ) error
256
+ Configure func (context. Context , string , string , string ) (api.EventMask , error )
257
+ Synchronize func (context. Context , []* api.PodSandbox , []* api.Container ) ([]* api.ContainerUpdate , error )
258
+ Shutdown func (context. Context )
259
+ RunPodSandbox func (context. Context , * api.PodSandbox ) error
260
+ StopPodSandbox func (context. Context , * api.PodSandbox ) error
261
+ RemovePodSandbox func (context. Context , * api.PodSandbox ) error
262
+ CreateContainer func (context. Context , * api.PodSandbox , * api.Container ) (* api.ContainerAdjustment , []* api.ContainerUpdate , error )
263
+ StartContainer func (context. Context , * api.PodSandbox , * api.Container ) error
264
+ UpdateContainer func (context. Context , * api.PodSandbox , * api.Container ) ([]* api.ContainerUpdate , error )
265
+ StopContainer func (context. Context , * api.PodSandbox , * api.Container ) ([]* api.ContainerUpdate , error )
266
+ RemoveContainer func (context. Context , * api.PodSandbox , * api.Container ) error
267
+ PostCreateContainer func (context. Context , * api.PodSandbox , * api.Container ) error
268
+ PostStartContainer func (context. Context , * api.PodSandbox , * api.Container ) error
269
+ PostUpdateContainer func (context. Context , * api.PodSandbox , * api.Container ) error
270
270
}
271
271
272
272
// New creates a stub with the given plugin and options.
@@ -552,7 +552,7 @@ func (stub *stub) Configure(ctx context.Context, req *api.ConfigureRequest) (rpl
552
552
if handler := stub .handlers .Configure ; handler == nil {
553
553
events = stub .events
554
554
} else {
555
- events , err = handler (req .Config , req .RuntimeName , req .RuntimeVersion )
555
+ events , err = handler (ctx , req .Config , req .RuntimeName , req .RuntimeVersion )
556
556
if err != nil {
557
557
log .Errorf (ctx , "Plugin configuration failed: %v" , err )
558
558
return nil , err
@@ -585,7 +585,7 @@ func (stub *stub) Synchronize(ctx context.Context, req *api.SynchronizeRequest)
585
585
if handler == nil {
586
586
return & api.SynchronizeResponse {}, nil
587
587
}
588
- update , err := handler (req .Pods , req .Containers )
588
+ update , err := handler (ctx , req .Pods , req .Containers )
589
589
return & api.SynchronizeResponse {
590
590
Update : update ,
591
591
}, err
@@ -595,7 +595,7 @@ func (stub *stub) Synchronize(ctx context.Context, req *api.SynchronizeRequest)
595
595
func (stub * stub ) Shutdown (ctx context.Context , req * api.ShutdownRequest ) (* api.ShutdownResponse , error ) {
596
596
handler := stub .handlers .Shutdown
597
597
if handler != nil {
598
- handler (req )
598
+ handler (ctx )
599
599
}
600
600
return & api.ShutdownResponse {}, nil
601
601
}
@@ -606,7 +606,7 @@ func (stub *stub) CreateContainer(ctx context.Context, req *api.CreateContainerR
606
606
if handler == nil {
607
607
return nil , nil
608
608
}
609
- adjust , update , err := handler (req .Pod , req .Container )
609
+ adjust , update , err := handler (ctx , req .Pod , req .Container )
610
610
return & api.CreateContainerResponse {
611
611
Adjust : adjust ,
612
612
Update : update ,
@@ -619,7 +619,7 @@ func (stub *stub) UpdateContainer(ctx context.Context, req *api.UpdateContainerR
619
619
if handler == nil {
620
620
return nil , nil
621
621
}
622
- update , err := handler (req .Pod , req .Container )
622
+ update , err := handler (ctx , req .Pod , req .Container )
623
623
return & api.UpdateContainerResponse {
624
624
Update : update ,
625
625
}, err
@@ -631,7 +631,7 @@ func (stub *stub) StopContainer(ctx context.Context, req *api.StopContainerReque
631
631
if handler == nil {
632
632
return nil , nil
633
633
}
634
- update , err := handler (req .Pod , req .Container )
634
+ update , err := handler (ctx , req .Pod , req .Container )
635
635
return & api.StopContainerResponse {
636
636
Update : update ,
637
637
}, err
@@ -643,35 +643,35 @@ func (stub *stub) StateChange(ctx context.Context, evt *api.StateChangeEvent) (*
643
643
switch evt .Event {
644
644
case api .Event_RUN_POD_SANDBOX :
645
645
if handler := stub .handlers .RunPodSandbox ; handler != nil {
646
- err = handler (evt .Pod )
646
+ err = handler (ctx , evt .Pod )
647
647
}
648
648
case api .Event_STOP_POD_SANDBOX :
649
649
if handler := stub .handlers .StopPodSandbox ; handler != nil {
650
- err = handler (evt .Pod )
650
+ err = handler (ctx , evt .Pod )
651
651
}
652
652
case api .Event_REMOVE_POD_SANDBOX :
653
653
if handler := stub .handlers .RemovePodSandbox ; handler != nil {
654
- err = handler (evt .Pod )
654
+ err = handler (ctx , evt .Pod )
655
655
}
656
656
case api .Event_POST_CREATE_CONTAINER :
657
657
if handler := stub .handlers .PostCreateContainer ; handler != nil {
658
- err = handler (evt .Pod , evt .Container )
658
+ err = handler (ctx , evt .Pod , evt .Container )
659
659
}
660
660
case api .Event_START_CONTAINER :
661
661
if handler := stub .handlers .StartContainer ; handler != nil {
662
- err = handler (evt .Pod , evt .Container )
662
+ err = handler (ctx , evt .Pod , evt .Container )
663
663
}
664
664
case api .Event_POST_START_CONTAINER :
665
665
if handler := stub .handlers .PostStartContainer ; handler != nil {
666
- err = handler (evt .Pod , evt .Container )
666
+ err = handler (ctx , evt .Pod , evt .Container )
667
667
}
668
668
case api .Event_POST_UPDATE_CONTAINER :
669
669
if handler := stub .handlers .PostUpdateContainer ; handler != nil {
670
- err = handler (evt .Pod , evt .Container )
670
+ err = handler (ctx , evt .Pod , evt .Container )
671
671
}
672
672
case api .Event_REMOVE_CONTAINER :
673
673
if handler := stub .handlers .RemoveContainer ; handler != nil {
674
- err = handler (evt .Pod , evt .Container )
674
+ err = handler (ctx , evt .Pod , evt .Container )
675
675
}
676
676
}
677
677
0 commit comments