Skip to content

Commit

Permalink
bugfix: avoid pod terminating in docker (#445)
Browse files Browse the repository at this point in the history
Signed-off-by: Yue Zhang <huaihuan.zy@alibaba-inc.com>
  • Loading branch information
ZYecho authored and hormes committed Aug 5, 2022
1 parent 1c44a0a commit f0daee1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions pkg/runtimeproxy/server/docker/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package docker
import (
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -212,8 +213,8 @@ func (d *RuntimeManagerDockerServer) HandleStopContainer(ctx context.Context, wr
runtimeHookPath = config.StopPodSandbox
podInfo := store.GetPodSandboxInfo(containerID)
if podInfo == nil {
// refuse the req
http.Error(wr, "Failed to get pod info", http.StatusInternalServerError)
// kubelet will not treat not found error as error, so we need to return err msg as same with docker server to avoid pod terminating
http.Error(wr, fmt.Sprintf("No such container: %s", containerID), http.StatusInternalServerError)
return
}
hookReq = podInfo.GetPodSandboxHookRequest()
Expand Down
24 changes: 12 additions & 12 deletions pkg/runtimeproxy/server/docker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package docker
import (
"bytes"
"context"
"fmt"
"net"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -140,24 +141,24 @@ func (d *RuntimeManagerDockerServer) failOver(dockerClient proxyDockerClient) er
}

for _, c := range containers {
podID := c.Labels[types.SandboxIDLabelKey]
podCheckPoint := store.GetPodSandboxInfo(podID)
if podCheckPoint == nil {
klog.Errorf("no pod info related to containerID %v", c.ID)
continue
}
store.WriteContainerInfo(c.ID, &store.ContainerInfo{
cInfo := &store.ContainerInfo{
ContainerResourceHookRequest: &v1alpha1.ContainerResourceHookRequest{
PodMeta: podCheckPoint.PodMeta,
ContainerResources: HostConfigToResource(c.ContainerJSON.HostConfig),
ContainerAnnotations: c.Labels,
ContainerMata: &v1alpha1.ContainerMetadata{
Name: c.Name,
Id: c.ID,
},
PodResources: podCheckPoint.Resources,
},
})
}
podID := c.Labels[types.SandboxIDLabelKey]
podCheckPoint := store.GetPodSandboxInfo(podID)
if podCheckPoint != nil {
cInfo.ContainerResourceHookRequest.PodMeta = podCheckPoint.PodMeta
cInfo.ContainerResourceHookRequest.PodResources = podCheckPoint.Resources
continue
}
store.WriteContainerInfo(c.ID, cInfo)
}
info, err := dockerClient.Info(context.TODO())
if err != nil {
Expand Down Expand Up @@ -191,8 +192,7 @@ func (d *RuntimeManagerDockerServer) Run() error {

err = d.failOver(dockerClient)
if err != nil {
//FIXME: need to panic?
klog.Errorf("Failed to backup container info from backend, err: %v", err)
panic(fmt.Sprintf("Failed to backup container info from backend, err: %v", err))
}

lis, err := net.Listen("unix", options.RuntimeProxyEndpoint)
Expand Down

0 comments on commit f0daee1

Please sign in to comment.