Skip to content

Commit

Permalink
fix: check local pods before gc
Browse files Browse the repository at this point in the history
Signed-off-by: l1b0k <[email protected]>
  • Loading branch information
l1b0k committed Jan 17, 2024
1 parent 0df4bf1 commit 9ccaf84
Show file tree
Hide file tree
Showing 2 changed files with 23 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
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 9ccaf84

Please sign in to comment.