Skip to content

Commit

Permalink
Revert "fix locks"
Browse files Browse the repository at this point in the history
This reverts commit 96e148d.
  • Loading branch information
MikeZappa87 committed Nov 25, 2024
1 parent 106f527 commit d96cc3b
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func (c *libcni) Load(opts ...Opt) error {
func (c *libcni) Status() error {
c.RLock()
defer c.RUnlock()
if len(c.networks) < c.networkCount {
return ErrCNINotInitialized
if err := c.ready(); err != nil {
return err
}

// STATUS is only called for CNI Version 1.1.0 or greater. It is ignored for previous versions.
Expand All @@ -163,10 +163,8 @@ func (c *libcni) Networks() []*Network {

// Setup setups the network in the namespace and returns a Result
func (c *libcni) Setup(ctx context.Context, id string, path string, opts ...NamespaceOpts) (*Result, error) {
c.Lock()
defer c.Unlock()
if len(c.networks) < c.networkCount {
return nil, ErrCNINotInitialized
if err := c.ready(); err != nil {
return nil, err
}
ns, err := newNamespace(id, path, opts...)
if err != nil {
Expand All @@ -181,10 +179,8 @@ func (c *libcni) Setup(ctx context.Context, id string, path string, opts ...Name

// SetupSerially setups the network in the namespace and returns a Result
func (c *libcni) SetupSerially(ctx context.Context, id string, path string, opts ...NamespaceOpts) (*Result, error) {
c.Lock()
defer c.Unlock()
if len(c.networks) < c.networkCount {
return nil, ErrCNINotInitialized
if err := c.ready(); err != nil {
return nil, err
}
ns, err := newNamespace(id, path, opts...)
if err != nil {
Expand Down Expand Up @@ -246,10 +242,8 @@ func (c *libcni) attachNetworks(ctx context.Context, ns *Namespace) ([]*types100

// Remove removes the network config from the namespace
func (c *libcni) Remove(ctx context.Context, id string, path string, opts ...NamespaceOpts) error {
c.Lock()
defer c.Unlock()
if len(c.networks) < c.networkCount {
return ErrCNINotInitialized
if err := c.ready(); err != nil {
return err
}
ns, err := newNamespace(id, path, opts...)
if err != nil {
Expand All @@ -276,10 +270,8 @@ func (c *libcni) Remove(ctx context.Context, id string, path string, opts ...Nam

// Check checks if the network is still in desired state
func (c *libcni) Check(ctx context.Context, id string, path string, opts ...NamespaceOpts) error {
c.RLock()
defer c.RUnlock()
if len(c.networks) < c.networkCount {
return ErrCNINotInitialized
if err := c.ready(); err != nil {
return err
}
ns, err := newNamespace(id, path, opts...)
if err != nil {
Expand Down Expand Up @@ -328,3 +320,13 @@ func (c *libcni) GetConfig() *ConfigResult {
func (c *libcni) reset() {
c.networks = nil
}

func (c *libcni) ready() error {
c.RLock()
defer c.RUnlock()
if len(c.networks) < c.networkCount {
return ErrCNINotInitialized
}

return nil
}

0 comments on commit d96cc3b

Please sign in to comment.