Skip to content
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
18 changes: 8 additions & 10 deletions pkg/controlloop/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,16 @@ func (pc *PodController) garbageCollectPodIPs(pod *v1.Pod) error {
if allocation.PodRef == podID(podNamespace, podName) {
logging.Verbosef("stale allocation to cleanup: %+v", allocation)

client := *wbclient.NewKubernetesClient(nil, pc.k8sClient)
wbClient := &wbclient.KubernetesIPAM{
Client: client,
Config: *ipamConfig,
client := *wbclient.NewKubernetesClient(pc.wbClient, pc.k8sClient)
k8sIPAM := &wbclient.KubernetesIPAM{
Config: *ipamConfig,
ContainerID: allocation.ContainerID,
IfName: allocation.IfName,
Namespace: pool.Namespace,
Client: client,
}

if err != nil {
logging.Debugf("error while generating the IPAM client: %v", err)
continue
}
if _, err := pc.cleanupFunc(context.TODO(), types.Deallocate, *ipamConfig, wbClient); err != nil {
if _, err := pc.cleanupFunc(context.TODO(), types.Deallocate, *ipamConfig, k8sIPAM); err != nil {
logging.Errorf("failed to cleanup allocation: %v", err)
}
if err := pc.addressGarbageCollected(pod, nad.GetName(), pool.Spec.Range, allocationIndex); err != nil {
Expand All @@ -244,7 +243,6 @@ func (pc *PodController) garbageCollectPodIPs(pod *v1.Pod) error {
}
}
}

return nil
}

Expand Down
34 changes: 17 additions & 17 deletions pkg/storage/kubernetes/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ const UnnamedNetwork string = ""
type KubernetesIPAM struct {
Client
Config whereaboutstypes.IPAMConfig
namespace string
containerID string
Namespace string
ContainerID string
IfName string
}

func newKubernetesIPAM(containerID, ifName string, ipamConf whereaboutstypes.IPAMConfig, namespace string, kubernetesClient Client) *KubernetesIPAM {
return &KubernetesIPAM{
Config: ipamConf,
containerID: containerID,
ContainerID: containerID,
IfName: ifName,
namespace: namespace,
Namespace: namespace,
Client: kubernetesClient,
}
}
Expand Down Expand Up @@ -76,7 +76,7 @@ func NewKubernetesIPAMWithNamespace(containerID, ifName string, ipamConf whereab
if err != nil {
return nil, err
}
k8sIPAM.namespace = namespace
k8sIPAM.Namespace = namespace
return k8sIPAM, nil
}

Expand Down Expand Up @@ -137,14 +137,14 @@ func (i *KubernetesIPAM) getPool(ctx context.Context, name string, iprange strin
ctxWithTimeout, cancel := context.WithTimeout(ctx, storage.RequestTimeout)
defer cancel()

pool, err := i.client.WhereaboutsV1alpha1().IPPools(i.namespace).Get(ctxWithTimeout, name, metav1.GetOptions{})
pool, err := i.client.WhereaboutsV1alpha1().IPPools(i.Namespace).Get(ctxWithTimeout, name, metav1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
// pool does not exist, create it
newPool := &whereaboutsv1alpha1.IPPool{}
newPool.ObjectMeta.Name = name
newPool.Spec.Range = iprange
newPool.Spec.Allocations = make(map[string]whereaboutsv1alpha1.IPAllocation)
_, err = i.client.WhereaboutsV1alpha1().IPPools(i.namespace).Create(ctxWithTimeout, newPool, metav1.CreateOptions{})
_, err = i.client.WhereaboutsV1alpha1().IPPools(i.Namespace).Create(ctxWithTimeout, newPool, metav1.CreateOptions{})
if err != nil && errors.IsAlreadyExists(err) {
// the pool was just created -- allow retry
return nil, &temporaryError{err}
Expand All @@ -162,7 +162,7 @@ func (i *KubernetesIPAM) getPool(ctx context.Context, name string, iprange strin

// Status tests connectivity to the kubernetes backend
func (i *KubernetesIPAM) Status(ctx context.Context) error {
_, err := i.client.WhereaboutsV1alpha1().IPPools(i.namespace).List(ctx, metav1.ListOptions{})
_, err := i.client.WhereaboutsV1alpha1().IPPools(i.Namespace).List(ctx, metav1.ListOptions{})
return err
}

Expand Down Expand Up @@ -276,7 +276,7 @@ type KubernetesOverlappingRangeStore struct {

// GetOverlappingRangeStore returns a clusterstore interface
func (i *KubernetesIPAM) GetOverlappingRangeStore() (storage.OverlappingRangeStore, error) {
return &KubernetesOverlappingRangeStore{i.client, i.namespace}, nil
return &KubernetesOverlappingRangeStore{i.client, i.Namespace}, nil
}

// IsAllocatedInOverlappingRange checks for IP addresses to see if they're allocated cluster wide, for overlapping
Expand Down Expand Up @@ -463,7 +463,7 @@ func IPManagement(ctx context.Context, mode int, ipamConf whereaboutstypes.IPAMC
}

// setup leader election
le, leader, deposed := newLeaderElector(ctx, client.clientSet, client.namespace, client)
le, leader, deposed := newLeaderElector(ctx, client.clientSet, client.Namespace, client)
var wg sync.WaitGroup
wg.Add(2)

Expand Down Expand Up @@ -517,10 +517,10 @@ func IPManagement(ctx context.Context, mode int, ipamConf whereaboutstypes.IPAMC
}

func GetNodeSlicePoolRange(ctx context.Context, ipam *KubernetesIPAM, nodeName string) (string, error) {
logging.Debugf("ipam namespace is %v", ipam.namespace)
nodeSlice, err := ipam.client.WhereaboutsV1alpha1().NodeSlicePools(ipam.namespace).Get(ctx, getNodeSliceName(ipam), metav1.GetOptions{})
logging.Debugf("ipam namespace is %v", ipam.Namespace)
nodeSlice, err := ipam.client.WhereaboutsV1alpha1().NodeSlicePools(ipam.Namespace).Get(ctx, getNodeSliceName(ipam), metav1.GetOptions{})
if err != nil {
logging.Errorf("error getting node slice %s/%s %v", ipam.namespace, getNodeSliceName(ipam), err)
logging.Errorf("error getting node slice %s/%s %v", ipam.Namespace, getNodeSliceName(ipam), err)
return "", err
}
for _, allocation := range nodeSlice.Status.Allocations {
Expand All @@ -542,7 +542,7 @@ func getNodeSliceName(ipam *KubernetesIPAM) string {

// IPManagementKubernetesUpdate manages k8s updates
func IPManagementKubernetesUpdate(ctx context.Context, mode int, ipam *KubernetesIPAM, ipamConf whereaboutstypes.IPAMConfig) ([]net.IPNet, error) {
logging.Debugf("IPManagement -- mode: %d / containerID: %q / podRef: %q / ifName: %q ", mode, ipam.containerID, ipamConf.GetPodRef(), ipam.IfName)
logging.Debugf("IPManagement -- mode: %d / containerID: %q / podRef: %q / ifName: %q ", mode, ipam.ContainerID, ipamConf.GetPodRef(), ipam.IfName)

var newips []net.IPNet
var newip net.IPNet
Expand Down Expand Up @@ -633,7 +633,7 @@ func IPManagementKubernetesUpdate(ctx context.Context, mode int, ipam *Kubernete
var updatedreservelist []whereaboutstypes.IPReservation
switch mode {
case whereaboutstypes.Allocate:
newip, updatedreservelist, err = allocate.AssignIP(ipRange, reservelist, ipam.containerID, ipamConf.GetPodRef(), ipam.IfName)
newip, updatedreservelist, err = allocate.AssignIP(ipRange, reservelist, ipam.ContainerID, ipamConf.GetPodRef(), ipam.IfName)
if err != nil {
logging.Errorf("Error assigning IP: %v", err)
return newips, err
Expand Down Expand Up @@ -664,10 +664,10 @@ func IPManagementKubernetesUpdate(ctx context.Context, mode int, ipam *Kubernete
}

case whereaboutstypes.Deallocate:
updatedreservelist, ipforoverlappingrangeupdate = allocate.DeallocateIP(reservelist, ipam.containerID, ipam.IfName)
updatedreservelist, ipforoverlappingrangeupdate = allocate.DeallocateIP(reservelist, ipam.ContainerID, ipam.IfName)
if ipforoverlappingrangeupdate == nil {
// Do not fail if allocation was not found.
logging.Debugf("Failed to find allocation for container ID: %s", ipam.containerID)
logging.Debugf("Failed to find allocation for container ID: %s", ipam.ContainerID)
return nil, nil
}
}
Expand Down