Skip to content

Commit

Permalink
feat(cni): remove gc logic in cni (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
fioncat authored Jun 14, 2023
1 parent 6f1041e commit 8077463
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 57 deletions.
12 changes: 1 addition & 11 deletions cmd/cnivpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,11 @@ func assignPodIp(podName, podNS, netNS, sandboxId string) (*rpc.PodNetwork, bool
if err != nil {
return nil, false, fmt.Errorf("failed to init uapi client: %v", err)
}
ipAddr, macAddr, err := iputils.GetNodeAddress("")
macAddr, err := iputils.GetNodeMacAddress("")
if err != nil {
return nil, false, fmt.Errorf("failed to get addr: %v", err)
}

gc, err := iputils.NewGC(uapi, ipAddr, macAddr)
if err != nil {
ulog.Warnf("Init IP GC error: %v, we will use an empty one", err)
gc = iputils.EmptyGC(uapi, ipAddr, macAddr)
}
err = gc.Run(gc.NeedCollect(), nil)
if err != nil {
ulog.Warnf("Run GC error: %v", err)
}

// ipamd not available, directly call vpc to allocate IP
ip, err := allocateSecondaryIP(uapi, macAddr, podName, podNS, sandboxId)
if err != nil {
Expand Down
34 changes: 0 additions & 34 deletions pkg/ipamd/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ func (s *ipamServer) ipPoolWatermarkManager() {
ulog.Infof("Start ip pool watermark manager loop")
tk := time.Tick(10 * time.Second)
cooldownTk := time.Tick(time.Second * time.Duration(CooldownPeriodSeconds))
gcTk := time.Tick(time.Second * time.Duration(iputils.GCCollectSeconds))
healthSize := 0
for {
select {
Expand All @@ -255,9 +254,6 @@ func (s *ipamServer) ipPoolWatermarkManager() {
}
}

case <-gcTk:
s.runGC()

case r := <-chanAddPodIP:
pNet, err := s.getPodIp(r.Req)
r.Receiver <- &InnerAddPodNetworkResponse{
Expand Down Expand Up @@ -447,36 +443,6 @@ func (s *ipamServer) recycleCooldownIP() {
s.cooldownSet = newSet
}

func (s *ipamServer) runGC() {
ips, err := s.pool.List()
if err != nil {
ulog.Errorf("List ip error: %v", err)
return
}

pool := make([]string, len(ips))
for i, ip := range ips {
pool[i] = ip.VPCIP
}

for _, ip := range s.cooldownSet {
pool = append(pool, ip.vpcIP.VPCIP)
}

gc, err := iputils.NewGC(s.uapi, s.nodeName, s.hostMacAddr)
if err != nil {
ulog.Warnf("Init GC error: %v, we will use an empty one", err)
gc = iputils.EmptyGC(s.uapi, s.nodeName, s.hostMacAddr)
}
gc.SetKubeClient(s.kubeClient)

err = gc.Run(true, pool)
if err != nil {
ulog.Errorf("Run GC error: %v", err)
return
}
}

func (s *ipamServer) borrowIP() (*rpc.PodNetwork, error) {
ctx := context.Background()
val, err := s.crdClient.IpamdV1beta1().Ipamds("kube-system").List(ctx, metav1.ListOptions{})
Expand Down
23 changes: 11 additions & 12 deletions pkg/iputils/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,18 @@ func (gc *GarbageCollector) collectPodIPs() ([]*PodIP, error) {
if pod.Spec.HostNetwork {
continue
}
podIPs := pod.Status.PodIPs
for _, podIP := range podIPs {
if _, ok := ipSet[podIP.IP]; ok {
continue
}
ipSet[podIP.IP] = struct{}{}

ips = append(ips, &PodIP{
Namespace: pod.Namespace,
Name: pod.Name,
IP: podIP.IP,
})
podIP := pod.Status.PodIP
if _, ok := ipSet[podIP]; ok {
continue
}
ips = append(ips, &PodIP{
Namespace: pod.Namespace,
Name: pod.Name,
IP: podIP,
})
}
if len(ips) == 0 {
return nil, fmt.Errorf("unexpected ip length, should have at least one ip")
}
return ips, nil
}
Expand Down

0 comments on commit 8077463

Please sign in to comment.