Commit 14940eda authored by Random-Liu's avatar Random-Liu

Add legacy container cleanup

parent c84f3abc
......@@ -75,6 +75,15 @@ func (ds *dockerService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*
result = append(result, converted)
}
// Include legacy containers if there are still legacy containers not cleaned up yet.
if !ds.legacyCleanup.Done() {
legacyContainers, err := ds.ListLegacyContainers(filter)
if err != nil {
return nil, err
}
// Legacy containers are always older, so we can safely append them to the end.
result = append(result, legacyContainers...)
}
return result, nil
}
......@@ -360,6 +369,15 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeapi.Contai
ct, st, ft := createdAt.UnixNano(), startedAt.UnixNano(), finishedAt.UnixNano()
exitCode := int32(r.State.ExitCode)
// If the container has no containerTypeLabelKey label, treat it as a legacy container.
if _, ok := r.Config.Labels[containerTypeLabelKey]; !ok {
names, labels, err := convertLegacyNameAndLabels([]string{r.Name}, r.Config.Labels)
if err != nil {
return nil, err
}
r.Name, r.Config.Labels = names[0], labels
}
metadata, err := parseContainerName(r.Name)
if err != nil {
return nil, err
......
......@@ -244,12 +244,23 @@ func (ds *dockerService) PodSandboxStatus(podSandboxID string) (*runtimeapi.PodS
}
network := &runtimeapi.PodSandboxNetworkStatus{Ip: IP}
netNS := getNetworkNamespace(r)
hostNetwork := sharesHostNetwork(r)
// If the sandbox has no containerTypeLabelKey label, treat it as a legacy sandbox.
if _, ok := r.Config.Labels[containerTypeLabelKey]; !ok {
names, labels, err := convertLegacyNameAndLabels([]string{r.Name}, r.Config.Labels)
if err != nil {
return nil, err
}
r.Name, r.Config.Labels = names[0], labels
// Forcibly trigger infra container restart.
hostNetwork = !hostNetwork
}
metadata, err := parseSandboxName(r.Name)
if err != nil {
return nil, err
}
hostNetwork := sharesHostNetwork(r)
labels, annotations := extractLabels(r.Config.Labels)
return &runtimeapi.PodSandboxStatus{
Id: r.ID,
......@@ -318,7 +329,7 @@ func (ds *dockerService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]
c := containers[i]
converted, err := containerToRuntimeAPISandbox(&c)
if err != nil {
glog.V(4).Infof("Unable to convert docker to runtime API sandbox: %v", err)
glog.V(4).Infof("Unable to convert docker to runtime API sandbox %+v: %v", c, err)
continue
}
if filterOutReadySandboxes && converted.State == runtimeapi.PodSandboxState_SANDBOX_READY {
......@@ -353,6 +364,16 @@ func (ds *dockerService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]
result = append(result, checkpointToRuntimeAPISandbox(id, checkpoint))
}
}
// Include legacy sandboxes if there are still legacy sandboxes not cleaned up yet.
if !ds.legacyCleanup.Done() {
legacySandboxes, err := ds.ListLegacyPodSandbox(filter)
if err != nil {
return nil, err
}
// Legacy sandboxes are always older, so we can safely append them to the end.
result = append(result, legacySandboxes...)
}
return result, nil
}
......
......@@ -153,7 +153,6 @@ func NewDockerService(client dockertools.DockerInterface, seccompProfileRoot str
glog.Infof("Setting cgroupDriver to %s", cgroupDriver)
}
ds.cgroupDriver = cgroupDriver
return ds, nil
}
......@@ -179,6 +178,8 @@ type dockerService struct {
// cgroup driver used by Docker runtime.
cgroupDriver string
checkpointHandler CheckpointHandler
// legacyCleanup indicates whether legacy cleanup has finished or not.
legacyCleanup legacyCleanupFlag
}
// Version returns the runtime name, runtime version and runtime API version
......@@ -241,6 +242,8 @@ type dockerNetworkHost struct {
// Start initializes and starts components in dockerService.
func (ds *dockerService) Start() error {
// Initialize the legacy cleanup flag.
ds.LegacyCleanupInit()
return ds.containerManager.Start()
}
......
......@@ -76,7 +76,6 @@ func makeContainerName(s *runtimeapi.PodSandboxConfig, c *runtimeapi.ContainerCo
s.Metadata.Uid, // 4 sandbox uid
fmt.Sprintf("%d", c.Metadata.Attempt), // 5
}, nameDelimiter)
}
// randomizeName randomizes the container name. This should only be used when we hit the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment