@@ -137,8 +137,8 @@ func (c *libcni) Load(opts ...Opt) error {
137
137
func (c * libcni ) Status () error {
138
138
c .RLock ()
139
139
defer c .RUnlock ()
140
- if err := c . ready (); err != nil {
141
- return err
140
+ if len ( c . networks ) < c . networkCount {
141
+ return ErrCNINotInitialized
142
142
}
143
143
144
144
// STATUS is only called for CNI Version 1.1.0 or greater. It is ignored for previous versions.
@@ -163,8 +163,10 @@ func (c *libcni) Networks() []*Network {
163
163
164
164
// Setup setups the network in the namespace and returns a Result
165
165
func (c * libcni ) Setup (ctx context.Context , id string , path string , opts ... NamespaceOpts ) (* Result , error ) {
166
- if err := c .ready (); err != nil {
167
- return nil , err
166
+ c .Lock ()
167
+ defer c .Unlock ()
168
+ if len (c .networks ) < c .networkCount {
169
+ return nil , ErrCNINotInitialized
168
170
}
169
171
ns , err := newNamespace (id , path , opts ... )
170
172
if err != nil {
@@ -179,8 +181,10 @@ func (c *libcni) Setup(ctx context.Context, id string, path string, opts ...Name
179
181
180
182
// SetupSerially setups the network in the namespace and returns a Result
181
183
func (c * libcni ) SetupSerially (ctx context.Context , id string , path string , opts ... NamespaceOpts ) (* Result , error ) {
182
- if err := c .ready (); err != nil {
183
- return nil , err
184
+ c .Lock ()
185
+ defer c .Unlock ()
186
+ if len (c .networks ) < c .networkCount {
187
+ return nil , ErrCNINotInitialized
184
188
}
185
189
ns , err := newNamespace (id , path , opts ... )
186
190
if err != nil {
@@ -242,8 +246,10 @@ func (c *libcni) attachNetworks(ctx context.Context, ns *Namespace) ([]*types100
242
246
243
247
// Remove removes the network config from the namespace
244
248
func (c * libcni ) Remove (ctx context.Context , id string , path string , opts ... NamespaceOpts ) error {
245
- if err := c .ready (); err != nil {
246
- return err
249
+ c .Lock ()
250
+ defer c .Unlock ()
251
+ if len (c .networks ) < c .networkCount {
252
+ return ErrCNINotInitialized
247
253
}
248
254
ns , err := newNamespace (id , path , opts ... )
249
255
if err != nil {
@@ -270,8 +276,10 @@ func (c *libcni) Remove(ctx context.Context, id string, path string, opts ...Nam
270
276
271
277
// Check checks if the network is still in desired state
272
278
func (c * libcni ) Check (ctx context.Context , id string , path string , opts ... NamespaceOpts ) error {
273
- if err := c .ready (); err != nil {
274
- return err
279
+ c .RLock ()
280
+ defer c .RUnlock ()
281
+ if len (c .networks ) < c .networkCount {
282
+ return ErrCNINotInitialized
275
283
}
276
284
ns , err := newNamespace (id , path , opts ... )
277
285
if err != nil {
@@ -320,13 +328,3 @@ func (c *libcni) GetConfig() *ConfigResult {
320
328
func (c * libcni ) reset () {
321
329
c .networks = nil
322
330
}
323
-
324
- func (c * libcni ) ready () error {
325
- c .RLock ()
326
- defer c .RUnlock ()
327
- if len (c .networks ) < c .networkCount {
328
- return ErrCNINotInitialized
329
- }
330
-
331
- return nil
332
- }
0 commit comments