Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle pod delete with non-existent IPs #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions cmd/whereabouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"

"github.com/containernetworking/cni/pkg/skel"
cnitypes "github.com/containernetworking/cni/pkg/types"
"github.com/containernetworking/cni/pkg/types/current"
Expand Down Expand Up @@ -78,11 +77,18 @@ func cmdDel(args *skel.CmdArgs) error {
logging.Debugf("ContainerID: %v", args.ContainerID)

_, err = storage.IPManagement(types.Deallocate, *ipamConf, args.ContainerID)
if err != nil {
logging.Verbosef("WARNING: Problem deallocating IP: %s", err)
// return fmt.Errorf("Error deallocating IP: %s", err)
}

if err != nil {
re, ok := err.(*types.IPNotFoundError)

if ok {
logging.Debugf("Cannot deallocate IP, it might not have been assigned by us, so ignoring. %s", re)
} else {
logging.Errorf("Error deallocating IP: %s", err)
return fmt.Errorf("Error deallocating IP: %s", err)
}

}
return nil
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/allocate/allocate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package allocate

import (
//"errors"
"fmt"
"math/big"
"net"
Expand Down Expand Up @@ -59,7 +60,9 @@ func IterateForDeallocation(reservelist []types.IPReservation, containerID strin

// Check if it's a valid index
if foundidx < 0 {
return reservelist, fmt.Errorf("Did not find reserved IP for container %v", containerID)
return reservelist, &types.IPNotFoundError {
ContainerID: containerID,
}
}

updatedreservelist := removeIdxFromSlice(reservelist, foundidx)
Expand Down
12 changes: 11 additions & 1 deletion pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

import (
"net"

"fmt"
cnitypes "github.com/containernetworking/cni/pkg/types"
)

Expand Down Expand Up @@ -79,3 +79,13 @@ const (
// Deallocate operation identifier
Deallocate = 1
)


// IPNotFoundError represents an error finding a specific IP during the deallocation process for a container.
type IPNotFoundError struct {
ContainerID string
}

func (e *IPNotFoundError) Error() string {
return fmt.Sprintf("Did not find reserved IP for container %v", e.ContainerID)
}