Created
August 2, 2021 08:00
-
-
Save zeusro/42a0193a6eed62b329f3f17ad5cd5cb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 根据宿主机目录中的文件找到具体容器运行时 | |
detectRuntime("/var/run") | |
func detectRuntime(varRunPath string) []runtimeConfig { | |
var err error | |
var cfgs []runtimeConfig | |
// pouch | |
{ | |
_, err1 := os.Stat(fmt.Sprintf("%s/pouchd.sock", varRunPath)) | |
_, err2 := os.Stat(fmt.Sprintf("%s/pouchcri.sock", varRunPath)) | |
if err1 == nil && err2 == nil { | |
cfgs = append(cfgs, runtimeConfig{ | |
runtimeType: ContainerRuntimePouch, | |
runtimeURI: fmt.Sprintf("unix://%s/pouchd.sock", varRunPath), | |
runtimeRemoteURI: fmt.Sprintf("unix://%s/pouchcri.sock", varRunPath), | |
}) | |
} else if err1 == nil && err2 != nil { | |
klog.Errorf("%s/pouchd.sock exists, but not found %s/pouchcri.sock", varRunPath, varRunPath) | |
} else if err1 != nil && err2 == nil { | |
klog.Errorf("%s/pouchdcri.sock exists, but not found %s/pouchd.sock", varRunPath, varRunPath) | |
} | |
} | |
// docker | |
{ | |
_, err1 := os.Stat(fmt.Sprintf("%s/docker.sock", varRunPath)) | |
_, err2 := os.Stat(fmt.Sprintf("%s/dockershim.sock", varRunPath)) | |
if err1 == nil && err2 == nil { | |
cfgs = append(cfgs, runtimeConfig{ | |
runtimeType: ContainerRuntimeDocker, | |
runtimeURI: fmt.Sprintf("unix://%s/docker.sock", varRunPath), | |
runtimeRemoteURI: fmt.Sprintf("unix://%s/dockershim.sock", varRunPath), | |
}) | |
} else if err1 == nil && err2 != nil { | |
klog.Errorf("%s/docker.sock exists, but not found %s/dockershim.sock", varRunPath, varRunPath) | |
} else if err1 != nil && err2 == nil { | |
klog.Errorf("%s/dockershim.sock exists, but not found %s/docker.sock", varRunPath, varRunPath) | |
} | |
} | |
// containerd | |
{ | |
if _, err = os.Stat(fmt.Sprintf("%s/containerd.sock", varRunPath)); err == nil { | |
cfgs = append(cfgs, runtimeConfig{ | |
runtimeType: ContainerRuntimeContainerd, | |
runtimeRemoteURI: fmt.Sprintf("unix://%s/containerd.sock", varRunPath), | |
}) | |
} | |
if _, err = os.Stat(fmt.Sprintf("%s/containerd/containerd.sock", varRunPath)); err == nil { | |
cfgs = append(cfgs, runtimeConfig{ | |
runtimeType: ContainerRuntimeContainerd, | |
runtimeRemoteURI: fmt.Sprintf("unix://%s/containerd/containerd.sock", varRunPath), | |
}) | |
} | |
} | |
return cfgs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
复制自
https://github.com/openkruise/kruise/blob/master/pkg/daemon/criruntime/factory.go
,值得注意的是,openshift平台(版本 4.7.11),
/var/run
目录下面只有运行这个方法,会得到一个空数组。