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

Return previous IP allocation for add cmd #471

Merged
merged 6 commits into from
Jun 11, 2024
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

bin/
/github.com/

.idea/
19 changes: 10 additions & 9 deletions cmd/whereabouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ func cmdAddFunc(args *skel.CmdArgs) error {
return err
}
logging.Debugf("ADD - IPAM configuration successfully read: %+v", *ipamConf)
ipam, err := kubernetes.NewKubernetesIPAM(args.ContainerID, *ipamConf)
ipam, err := kubernetes.NewKubernetesIPAM(args.ContainerID, args.IfName, *ipamConf)
if err != nil {
return logging.Errorf("failed to create Kubernetes IPAM manager: %v", err)
}
defer func() { safeCloseKubernetesBackendConnection(ipam) }()
return cmdAdd(args, ipam, confVersion)

logging.Debugf("Beginning IPAM for ContainerID: %q - podRef: %q - ifName: %q", args.ContainerID, ipamConf.GetPodRef(), args.IfName)
return cmdAdd(ipam, confVersion)
}

func cmdDelFunc(args *skel.CmdArgs) error {
Expand All @@ -40,12 +42,14 @@ func cmdDelFunc(args *skel.CmdArgs) error {
}
logging.Debugf("DEL - IPAM configuration successfully read: %+v", *ipamConf)

ipam, err := kubernetes.NewKubernetesIPAM(args.ContainerID, *ipamConf)
ipam, err := kubernetes.NewKubernetesIPAM(args.ContainerID, args.IfName, *ipamConf)
if err != nil {
return logging.Errorf("IPAM client initialization error: %v", err)
}
defer func() { safeCloseKubernetesBackendConnection(ipam) }()
return cmdDel(args, ipam)

logging.Debugf("Beginning delete for ContainerID: %q - podRef: %q - ifName: %q", args.ContainerID, ipamConf.GetPodRef(), args.IfName)
return cmdDel(ipam)
}

func main() {
Expand All @@ -69,13 +73,12 @@ func cmdCheck(args *skel.CmdArgs) error {
return fmt.Errorf("CNI CHECK method is not implemented")
}

func cmdAdd(args *skel.CmdArgs, client *kubernetes.KubernetesIPAM, cniVersion string) error {
func cmdAdd(client *kubernetes.KubernetesIPAM, cniVersion string) error {
// Initialize our result, and assign DNS & routing.
result := &current.Result{}
result.DNS = client.Config.DNS
result.Routes = client.Config.Routes

logging.Debugf("Beginning IPAM for ContainerID: %v", args.ContainerID)
var newips []net.IPNet

ctx, cancel := context.WithTimeout(context.Background(), types.AddTimeLimit)
Expand Down Expand Up @@ -103,9 +106,7 @@ func cmdAdd(args *skel.CmdArgs, client *kubernetes.KubernetesIPAM, cniVersion st
return cnitypes.PrintResult(result, cniVersion)
}

func cmdDel(args *skel.CmdArgs, client *kubernetes.KubernetesIPAM) error {
logging.Debugf("Beginning delete for ContainerID: %v", args.ContainerID)

func cmdDel(client *kubernetes.KubernetesIPAM) error {
ctx, cancel := context.WithTimeout(context.Background(), types.DelTimeLimit)
defer cancel()

Expand Down
Loading
Loading