mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #108007 from endocrimes/dani/cm-remove-docker
cm: Remove legacy docker references
This commit is contained in:
commit
3b4a9cdfff
@ -25,7 +25,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -36,7 +35,6 @@ import (
|
|||||||
"github.com/opencontainers/runc/libcontainer/configs"
|
"github.com/opencontainers/runc/libcontainer/configs"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/mount-utils"
|
"k8s.io/mount-utils"
|
||||||
utilio "k8s.io/utils/io"
|
|
||||||
utilpath "k8s.io/utils/path"
|
utilpath "k8s.io/utils/path"
|
||||||
|
|
||||||
libcontaineruserns "github.com/opencontainers/runc/libcontainer/userns"
|
libcontaineruserns "github.com/opencontainers/runc/libcontainer/userns"
|
||||||
@ -44,7 +42,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
utilversion "k8s.io/apimachinery/pkg/util/version"
|
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
@ -70,20 +67,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubelet/status"
|
"k8s.io/kubernetes/pkg/kubelet/status"
|
||||||
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework"
|
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework"
|
||||||
"k8s.io/kubernetes/pkg/util/oom"
|
"k8s.io/kubernetes/pkg/util/oom"
|
||||||
"k8s.io/kubernetes/pkg/util/procfs"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
dockerProcessName = "dockerd"
|
|
||||||
// dockerd option --pidfile can specify path to use for daemon PID file, pid file path is default "/var/run/docker.pid"
|
|
||||||
dockerPidFile = "/var/run/docker.pid"
|
|
||||||
containerdProcessName = "containerd"
|
|
||||||
maxPidFileLength = 1 << 10 // 1KB
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// The docker version in which containerd was introduced.
|
|
||||||
containerdAPIVersion = utilversion.MustParseGeneric("1.23")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A non-user container tracked by the Kubelet.
|
// A non-user container tracked by the Kubelet.
|
||||||
@ -496,24 +479,6 @@ func (cm *containerManagerImpl) setupNode(activePods ActivePodsFunc) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
systemContainers := []*systemContainer{}
|
systemContainers := []*systemContainer{}
|
||||||
if cm.ContainerRuntime == "docker" {
|
|
||||||
// With the docker-CRI integration, dockershim manages the cgroups
|
|
||||||
// and oom score for the docker processes.
|
|
||||||
// Check the cgroup for docker periodically, so kubelet can serve stats for the docker runtime.
|
|
||||||
// TODO(KEP#866): remove special processing for CRI "docker" enablement
|
|
||||||
cm.periodicTasks = append(cm.periodicTasks, func() {
|
|
||||||
klog.V(4).InfoS("Adding periodic tasks for docker CRI integration")
|
|
||||||
cont, err := getContainerNameForProcess(dockerProcessName, dockerPidFile)
|
|
||||||
if err != nil {
|
|
||||||
klog.ErrorS(err, "Failed to get container name for process")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
klog.V(2).InfoS("Discovered runtime cgroup name", "cgroupName", cont)
|
|
||||||
cm.Lock()
|
|
||||||
defer cm.Unlock()
|
|
||||||
cm.RuntimeCgroupsName = cont
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if cm.SystemCgroupsName != "" {
|
if cm.SystemCgroupsName != "" {
|
||||||
if cm.SystemCgroupsName == "/" {
|
if cm.SystemCgroupsName == "/" {
|
||||||
@ -561,21 +526,6 @@ func (cm *containerManagerImpl) setupNode(activePods ActivePodsFunc) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getContainerNameForProcess(name, pidFile string) (string, error) {
|
|
||||||
pids, err := getPidsForProcess(name, pidFile)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to detect process id for %q - %v", name, err)
|
|
||||||
}
|
|
||||||
if len(pids) == 0 {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
cont, err := getContainer(pids[0])
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return cont, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cm *containerManagerImpl) GetNodeConfig() NodeConfig {
|
func (cm *containerManagerImpl) GetNodeConfig() NodeConfig {
|
||||||
cm.RLock()
|
cm.RLock()
|
||||||
defer cm.RUnlock()
|
defer cm.RUnlock()
|
||||||
@ -820,78 +770,6 @@ func isProcessRunningInHost(pid int) (bool, error) {
|
|||||||
return initPidNs == processPidNs, nil
|
return initPidNs == processPidNs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPidFromPidFile(pidFile string) (int, error) {
|
|
||||||
file, err := os.Open(pidFile)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error opening pid file %s: %v", pidFile, err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
data, err := utilio.ReadAtMost(file, maxPidFileLength)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error reading pid file %s: %v", pidFile, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pid, err := strconv.Atoi(string(data))
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error parsing %s as a number: %v", string(data), err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return pid, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPidsForProcess(name, pidFile string) ([]int, error) {
|
|
||||||
if len(pidFile) == 0 {
|
|
||||||
return procfs.PidOf(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
pid, err := getPidFromPidFile(pidFile)
|
|
||||||
if err == nil {
|
|
||||||
return []int{pid}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to lookup pid by process name
|
|
||||||
pids, err2 := procfs.PidOf(name)
|
|
||||||
if err2 == nil {
|
|
||||||
return pids, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return error from getPidFromPidFile since that should have worked
|
|
||||||
// and is the real source of the problem.
|
|
||||||
klog.V(4).InfoS("Unable to get pid from file", "path", pidFile, "err", err)
|
|
||||||
return []int{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensures that the Docker daemon is in the desired container.
|
|
||||||
// Temporarily export the function to be used by dockershim.
|
|
||||||
// TODO(yujuhong): Move this function to dockershim once kubelet migrates to
|
|
||||||
// dockershim as the default.
|
|
||||||
func EnsureDockerInContainer(dockerAPIVersion *utilversion.Version, oomScoreAdj int, manager cgroups.Manager) error {
|
|
||||||
type process struct{ name, file string }
|
|
||||||
dockerProcs := []process{{dockerProcessName, dockerPidFile}}
|
|
||||||
if dockerAPIVersion.AtLeast(containerdAPIVersion) {
|
|
||||||
// By default containerd is started separately, so there is no pid file.
|
|
||||||
containerdPidFile := ""
|
|
||||||
dockerProcs = append(dockerProcs, process{containerdProcessName, containerdPidFile})
|
|
||||||
}
|
|
||||||
var errs []error
|
|
||||||
for _, proc := range dockerProcs {
|
|
||||||
pids, err := getPidsForProcess(proc.name, proc.file)
|
|
||||||
if err != nil {
|
|
||||||
errs = append(errs, fmt.Errorf("failed to get pids for %q: %v", proc.name, err))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move if the pid is not already in the desired container.
|
|
||||||
for _, pid := range pids {
|
|
||||||
if err := ensureProcessInContainerWithOOMScore(pid, oomScoreAdj, manager); err != nil {
|
|
||||||
errs = append(errs, fmt.Errorf("errors moving %q pid: %v", proc.name, err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return utilerrors.NewAggregate(errs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureProcessInContainerWithOOMScore(pid int, oomScoreAdj int, manager cgroups.Manager) error {
|
func ensureProcessInContainerWithOOMScore(pid int, oomScoreAdj int, manager cgroups.Manager) error {
|
||||||
if runningInHost, err := isProcessRunningInHost(pid); err != nil {
|
if runningInHost, err := isProcessRunningInHost(pid); err != nil {
|
||||||
// Err on the side of caution. Avoid moving the docker daemon unless we are able to identify its context.
|
// Err on the side of caution. Avoid moving the docker daemon unless we are able to identify its context.
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"
|
libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
"k8s.io/kubernetes/pkg/api/v1/resource"
|
"k8s.io/kubernetes/pkg/api/v1/resource"
|
||||||
@ -340,12 +340,5 @@ func GetKubeletContainer(kubeletCgroups string) (string, error) {
|
|||||||
|
|
||||||
// GetRuntimeContainer returns the cgroup used by the container runtime
|
// GetRuntimeContainer returns the cgroup used by the container runtime
|
||||||
func GetRuntimeContainer(containerRuntime, runtimeCgroups string) (string, error) {
|
func GetRuntimeContainer(containerRuntime, runtimeCgroups string) (string, error) {
|
||||||
if containerRuntime == "docker" {
|
|
||||||
cont, err := getContainerNameForProcess(dockerProcessName, dockerPidFile)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to get container name for docker process: %v", err)
|
|
||||||
}
|
|
||||||
return cont, nil
|
|
||||||
}
|
|
||||||
return runtimeCgroups, nil
|
return runtimeCgroups, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user