Skip to content

Commit

Permalink
Merge pull request kubernetes#108007 from endocrimes/dani/cm-remove-d…
Browse files Browse the repository at this point in the history
…ocker

cm: Remove legacy docker references
  • Loading branch information
k8s-ci-robot authored Feb 10, 2022
2 parents 518a3c2 + c198062 commit 3b4a9cd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 130 deletions.
122 changes: 0 additions & 122 deletions pkg/kubelet/cm/container_manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"io/ioutil"
"os"
"path"
"strconv"
"strings"
"sync"
"time"
Expand All @@ -36,15 +35,13 @@ import (
"github.com/opencontainers/runc/libcontainer/configs"
"k8s.io/klog/v2"
"k8s.io/mount-utils"
utilio "k8s.io/utils/io"
utilpath "k8s.io/utils/path"

libcontaineruserns "github.com/opencontainers/runc/libcontainer/userns"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
utilversion "k8s.io/apimachinery/pkg/util/version"
"k8s.io/apimachinery/pkg/util/wait"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/tools/record"
Expand All @@ -70,20 +67,6 @@ import (
"k8s.io/kubernetes/pkg/kubelet/status"
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework"
"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.
Expand Down Expand Up @@ -496,24 +479,6 @@ func (cm *containerManagerImpl) setupNode(activePods ActivePodsFunc) error {
}

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 == "/" {
Expand Down Expand Up @@ -561,21 +526,6 @@ func (cm *containerManagerImpl) setupNode(activePods ActivePodsFunc) error {
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 {
cm.RLock()
defer cm.RUnlock()
Expand Down Expand Up @@ -820,78 +770,6 @@ func isProcessRunningInHost(pid int) (bool, error) {
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 {
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.
Expand Down
9 changes: 1 addition & 8 deletions pkg/kubelet/cm/helpers_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/api/v1/resource"
Expand Down Expand Up @@ -340,12 +340,5 @@ func GetKubeletContainer(kubeletCgroups string) (string, error) {

// GetRuntimeContainer returns the cgroup used by the container runtime
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
}

0 comments on commit 3b4a9cd

Please sign in to comment.