Skip to content

Commit

Permalink
Merge pull request #552 from l1b0k/fix/local_pod
Browse files Browse the repository at this point in the history
fix: check local pods before gc
  • Loading branch information
BSWANG authored Jan 18, 2024
2 parents 0df4bf1 + b1ffd5e commit 58d93a5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ func (n *networkService) gcPods(ctx context.Context) error {
if _, ok := exist[podID]; ok {
continue
}
// check kube-api again
ok, err := n.k8s.PodExist(podRes.PodInfo.Namespace, podRes.PodInfo.Name)
if err != nil || ok {
continue
}

// that is old logic ... keep it
if podRes.PodInfo.IPStickTime != 0 {
podRes.PodInfo.IPStickTime = 0
Expand Down
4 changes: 4 additions & 0 deletions pkg/eni/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,7 @@ func (f *FakeK8s) GetClient() client.Client {
//TODO implement me
panic("implement me")
}

func (f *FakeK8s) PodExist(namespace, name string) (bool, error) {
panic("implement me")
}
17 changes: 17 additions & 0 deletions pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ var (
type Kubernetes interface {
GetLocalPods() ([]*daemon.PodInfo, error)
GetPod(ctx context.Context, namespace, name string, cache bool) (*daemon.PodInfo, error)
PodExist(namespace, name string) (bool, error)

GetServiceCIDR() *types.IPNetSet
GetNodeCidr() *types.IPNetSet
SetNodeAllocatablePod(count int) error
Expand Down Expand Up @@ -380,6 +382,21 @@ func (k *k8s) GetPod(ctx context.Context, namespace, name string, cache bool) (*
return podInfo, nil
}

func (k *k8s) PodExist(namespace, name string) (bool, error) {
pod, err := getPod(context.Background(), k.client, namespace, name, false)
if err != nil {
if apierrors.IsNotFound(err) {
return false, nil
}
return false, err
}
if pod.Spec.NodeName != k.nodeName {
return false, nil
}

return true, nil
}

func (k *k8s) GetNodeCidr() *types.IPNetSet {
return k.nodeCIDR
}
Expand Down

0 comments on commit 58d93a5

Please sign in to comment.