Skip to content

Commit

Permalink
Merge pull request #23 from GMH233/feature/kubelet
Browse files Browse the repository at this point in the history
fix: 修复重复detach
  • Loading branch information
sjtuzc954 authored May 10, 2024
2 parents 0f444f8 + dfee8f3 commit 7685d5d
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions pkg/kubelet/runtime/runtime_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/docker/docker/api/types/mount"
"io"
"log"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -480,13 +479,21 @@ func (rm *runtimeManager) DeletePod(ID v1.UID) error {
defer rm.lock.Unlock()
containers, err := rm.getAllContainersIncludingPause()
if err != nil {
panic(err)
return err
}
for _, container := range containers {
if container.Labels["PodID"] == string(ID) {
err := rm.deleteContainer(container)
if _, ok := container.Labels["PauseType"]; ok {
// log.Printf("Container ID: %s\n", container.ID)
err = nw.Detach(container.ID)
if err != nil {
return err
}
delete(rm.IpMap, v1.UID(container.Labels["PodID"]))
}
err = rm.deleteContainer(container)
if err != nil {
panic(err)
return err
}
}
}
Expand All @@ -497,24 +504,24 @@ func (rm *runtimeManager) getAllContainersIncludingPause() ([]types.Container, e
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
return nil, err
}
defer cli.Close()

containers, err := cli.ContainerList(ctx, container.ListOptions{All: true})
if err != nil {
panic(err)
}
for _, container := range containers {
if _, ok := container.Labels["PauseType"]; ok {
log.Printf("Container ID: %s\n", container.ID)
err := nw.Detach(container.ID)
if err != nil {
panic(err)
}
delete(rm.IpMap, v1.UID(container.Labels["PodID"]))
}
}
return nil, err
}
//for _, container := range containers {
// if _, ok := container.Labels["PauseType"]; ok {
// log.Printf("Container ID: %s\n", container.ID)
// err := nw.Detach(container.ID)
// if err != nil {
// panic(err)
// }
// delete(rm.IpMap, v1.UID(container.Labels["PodID"]))
// }
//}

return containers, nil
}
Expand Down

0 comments on commit 7685d5d

Please sign in to comment.