Merge pull request #8518 from afbjorklund/docker-containerd
Make sure to use internal containerd for dockerpull/8544/head
commit
4f6a9f6518
|
@ -478,6 +478,16 @@ func (f *FakeRunner) systemctl(args []string, root bool) (string, error) { // no
|
|||
return out, nil
|
||||
}
|
||||
return out, fmt.Errorf("%s in state: %v", svc, state)
|
||||
case "cat":
|
||||
f.t.Logf("fake systemctl: %s cat: %v", svc, state)
|
||||
if svc == "docker.service" {
|
||||
out += "[Unit]\n"
|
||||
out += "Description=Docker Application Container Engine\n"
|
||||
out += "Documentation=https://docs.docker.com\n"
|
||||
//out += "BindsTo=containerd.service\n"
|
||||
return out, nil
|
||||
}
|
||||
return out, fmt.Errorf("%s cat unimplemented", svc)
|
||||
default:
|
||||
return out, fmt.Errorf("unimplemented fake action: %q", action)
|
||||
}
|
||||
|
@ -526,6 +536,14 @@ var defaultServices = map[string]serviceState{
|
|||
"containerd": SvcExited,
|
||||
}
|
||||
|
||||
// allServices reflects the state of all actual services running at once
|
||||
var allServices = map[string]serviceState{
|
||||
"docker": SvcRunning,
|
||||
"crio": SvcRunning,
|
||||
"crio-shutdown": SvcExited,
|
||||
"containerd": SvcRunning,
|
||||
}
|
||||
|
||||
func TestDisable(t *testing.T) {
|
||||
var tests = []struct {
|
||||
runtime string
|
||||
|
@ -558,32 +576,43 @@ func TestDisable(t *testing.T) {
|
|||
|
||||
func TestEnable(t *testing.T) {
|
||||
var tests = []struct {
|
||||
runtime string
|
||||
want map[string]serviceState
|
||||
runtime string
|
||||
services map[string]serviceState
|
||||
want map[string]serviceState
|
||||
}{
|
||||
{"docker", map[string]serviceState{
|
||||
"docker": SvcRunning,
|
||||
"containerd": SvcExited,
|
||||
"crio": SvcExited,
|
||||
"crio-shutdown": SvcExited,
|
||||
}},
|
||||
{"containerd", map[string]serviceState{
|
||||
"docker": SvcExited,
|
||||
"containerd": SvcRestarted,
|
||||
"crio": SvcExited,
|
||||
"crio-shutdown": SvcExited,
|
||||
}},
|
||||
{"crio", map[string]serviceState{
|
||||
"docker": SvcExited,
|
||||
"containerd": SvcExited,
|
||||
"crio": SvcRunning,
|
||||
"crio-shutdown": SvcExited,
|
||||
}},
|
||||
{"docker", defaultServices,
|
||||
map[string]serviceState{
|
||||
"docker": SvcRunning,
|
||||
"containerd": SvcExited,
|
||||
"crio": SvcExited,
|
||||
"crio-shutdown": SvcExited,
|
||||
}},
|
||||
{"docker", allServices,
|
||||
map[string]serviceState{
|
||||
"docker": SvcRestarted,
|
||||
"containerd": SvcExited,
|
||||
"crio": SvcExited,
|
||||
"crio-shutdown": SvcExited,
|
||||
}},
|
||||
{"containerd", defaultServices,
|
||||
map[string]serviceState{
|
||||
"docker": SvcExited,
|
||||
"containerd": SvcRestarted,
|
||||
"crio": SvcExited,
|
||||
"crio-shutdown": SvcExited,
|
||||
}},
|
||||
{"crio", defaultServices,
|
||||
map[string]serviceState{
|
||||
"docker": SvcExited,
|
||||
"containerd": SvcExited,
|
||||
"crio": SvcRunning,
|
||||
"crio-shutdown": SvcExited,
|
||||
}},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.runtime, func(t *testing.T) {
|
||||
runner := NewFakeRunner(t)
|
||||
for k, v := range defaultServices {
|
||||
for k, v := range tc.services {
|
||||
runner.services[k] = v
|
||||
}
|
||||
cr, err := New(Config{Type: tc.runtime, Runner: runner})
|
||||
|
|
|
@ -104,6 +104,8 @@ func (r *Docker) Active() bool {
|
|||
|
||||
// Enable idempotently enables Docker on a host
|
||||
func (r *Docker) Enable(disOthers, forceSystemd bool) error {
|
||||
containerdWasActive := r.Init.Active("containerd")
|
||||
|
||||
if disOthers {
|
||||
if err := disableOthers(r, r.Runner); err != nil {
|
||||
glog.Warningf("disableOthers: %v", err)
|
||||
|
@ -117,6 +119,11 @@ func (r *Docker) Enable(disOthers, forceSystemd bool) error {
|
|||
return r.Init.Restart("docker")
|
||||
}
|
||||
|
||||
if containerdWasActive && !dockerBoundToContainerd(r.Runner) {
|
||||
// Make sure to use the internal containerd
|
||||
return r.Init.Restart("docker")
|
||||
}
|
||||
|
||||
return r.Init.Start("docker")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue