Skip to content

Commit 6955f86

Browse files
committed
bugfix: avoid pod terminating in docker
Signed-off-by: Yue Zhang <huaihuan.zy@alibaba-inc.com>
1 parent f133061 commit 6955f86

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

pkg/runtimeproxy/server/docker/handler.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package docker
1919
import (
2020
"context"
2121
"encoding/json"
22+
"fmt"
2223
"io"
2324
"io/ioutil"
2425
"net/http"
@@ -212,8 +213,8 @@ func (d *RuntimeManagerDockerServer) HandleStopContainer(ctx context.Context, wr
212213
runtimeHookPath = config.StopPodSandbox
213214
podInfo := store.GetPodSandboxInfo(containerID)
214215
if podInfo == nil {
215-
// refuse the req
216-
http.Error(wr, "Failed to get pod info", http.StatusInternalServerError)
216+
// 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
217+
http.Error(wr, fmt.Sprintf("No such container: %s", containerID), http.StatusInternalServerError)
217218
return
218219
}
219220
hookReq = podInfo.GetPodSandboxHookRequest()

pkg/runtimeproxy/server/docker/server.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package docker
1919
import (
2020
"bytes"
2121
"context"
22+
"fmt"
2223
"net"
2324
"net/http"
2425
"net/http/httputil"
@@ -140,24 +141,24 @@ func (d *RuntimeManagerDockerServer) failOver(dockerClient proxyDockerClient) er
140141
}
141142

142143
for _, c := range containers {
143-
podID := c.Labels[types.SandboxIDLabelKey]
144-
podCheckPoint := store.GetPodSandboxInfo(podID)
145-
if podCheckPoint == nil {
146-
klog.Errorf("no pod info related to containerID %v", c.ID)
147-
continue
148-
}
149-
store.WriteContainerInfo(c.ID, &store.ContainerInfo{
144+
cInfo := &store.ContainerInfo{
150145
ContainerResourceHookRequest: &v1alpha1.ContainerResourceHookRequest{
151-
PodMeta: podCheckPoint.PodMeta,
152146
ContainerResources: HostConfigToResource(c.ContainerJSON.HostConfig),
153147
ContainerAnnotations: c.Labels,
154148
ContainerMata: &v1alpha1.ContainerMetadata{
155149
Name: c.Name,
156150
Id: c.ID,
157151
},
158-
PodResources: podCheckPoint.Resources,
159152
},
160-
})
153+
}
154+
podID := c.Labels[types.SandboxIDLabelKey]
155+
podCheckPoint := store.GetPodSandboxInfo(podID)
156+
if podCheckPoint != nil {
157+
cInfo.ContainerResourceHookRequest.PodMeta = podCheckPoint.PodMeta
158+
cInfo.ContainerResourceHookRequest.PodResources = podCheckPoint.Resources
159+
continue
160+
}
161+
store.WriteContainerInfo(c.ID, cInfo)
161162
}
162163
info, err := dockerClient.Info(context.TODO())
163164
if err != nil {
@@ -191,8 +192,7 @@ func (d *RuntimeManagerDockerServer) Run() error {
191192

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

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

0 commit comments

Comments
 (0)