55// the same level of trust as the daemon itself, because they can make arbitrary
66// modifications to container settings.
77//
8- // The NRI framework is implemented by https:// github.com/containerd/nri - see that
8+ // The NRI framework is implemented by [ github.com/containerd/nri] - see that
99// package for more details about NRI and the framework.
1010//
1111// Plugins are long-running processed (not instantiated per-request like runtime shims,
@@ -47,8 +47,8 @@ type NRI struct {
4747 cfg Config
4848
4949 // mu protects nri - read lock for container operations, write lock for sync and shutdown.
50- mu sync.RWMutex
51- nri * adaptation.Adaptation
50+ mu sync.RWMutex
51+ adap * adaptation.Adaptation
5252}
5353
5454type ContainerLister interface {
@@ -79,11 +79,11 @@ func NewNRI(ctx context.Context, cfg Config) (*NRI, error) {
7979 nrilog .Set (& logShim {})
8080
8181 var err error
82- n .nri , err = adaptation .New ("docker" , dockerversion .Version , n .syncFn , n .updateFn , nriOptions (n .cfg .DaemonConfig )... )
82+ n .adap , err = adaptation .New ("docker" , dockerversion .Version , n .syncFn , n .updateFn , nriOptions (n .cfg .DaemonConfig )... )
8383 if err != nil {
8484 return nil , err
8585 }
86- if err := n .nri .Start (); err != nil {
86+ if err := n .adap .Start (); err != nil {
8787 return nil , err
8888 }
8989 return n , nil
@@ -93,20 +93,23 @@ func NewNRI(ctx context.Context, cfg Config) (*NRI, error) {
9393func (n * NRI ) Shutdown (ctx context.Context ) {
9494 n .mu .Lock ()
9595 defer n .mu .Unlock ()
96- if n .nri == nil {
96+ if n .adap == nil {
9797 return
9898 }
9999 log .G (ctx ).Info ("Shutting down NRI" )
100- n .nri .Stop ()
101- n .nri = nil
100+ n .adap .Stop ()
101+ n .adap = nil
102102}
103103
104104// CreateContainer notifies plugins of a "creation" NRI-lifecycle event for a container,
105105// allowing the plugin to adjust settings before the container is created.
106+ //
107+ // No lock is acquired on ctr, CreateContainer the caller must ensure it cannot be
108+ // accessed from other threads.
106109func (n * NRI ) CreateContainer (ctx context.Context , ctr * container.Container ) error {
107110 n .mu .RLock ()
108111 defer n .mu .RUnlock ()
109- if n .nri == nil {
112+ if n .adap == nil {
110113 return nil
111114 }
112115 // ctr.State can safely be locked here, but there's no need because it's expected
@@ -119,7 +122,7 @@ func (n *NRI) CreateContainer(ctx context.Context, ctr *container.Container) err
119122
120123 // TODO(robmry): call RunPodSandbox?
121124
122- resp , err := n .nri .CreateContainer (ctx , & adaptation.CreateContainerRequest {
125+ resp , err := n .adap .CreateContainer (ctx , & adaptation.CreateContainerRequest {
123126 Pod : nriPod ,
124127 Container : nriCtr ,
125128 })
0 commit comments