Merge pull request #87746 from mattjmcnaughton/mattjmcnaughton/poc-compiling-kubelet-wo-docker

Support compiling Kubelet w/o docker/docker
This commit is contained in:
Kubernetes Prow Robot 2020-05-09 12:01:51 -07:00 committed by GitHub
commit b5f67110ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
98 changed files with 447 additions and 155 deletions

View File

@ -60,14 +60,11 @@ go_library(
"//pkg/kubelet/cm/cpuset:go_default_library",
"//pkg/kubelet/config:go_default_library",
"//pkg/kubelet/container:go_default_library",
"//pkg/kubelet/dockershim:go_default_library",
"//pkg/kubelet/dockershim/remote:go_default_library",
"//pkg/kubelet/eviction:go_default_library",
"//pkg/kubelet/eviction/api:go_default_library",
"//pkg/kubelet/kubeletconfig:go_default_library",
"//pkg/kubelet/kubeletconfig/configfiles:go_default_library",
"//pkg/kubelet/server:go_default_library",
"//pkg/kubelet/server/streaming:go_default_library",
"//pkg/kubelet/stats/pidlimit:go_default_library",
"//pkg/kubelet/types:go_default_library",
"//pkg/util/filesystem:go_default_library",

View File

@ -51,7 +51,6 @@ func NewContainerRuntimeOptions() *config.ContainerRuntimeOptions {
DockershimRootDirectory: "/var/lib/dockershim",
PodSandboxImage: defaultPodSandboxImage,
ImagePullProgressDeadline: metav1.Duration{Duration: 1 * time.Minute},
ExperimentalDockershim: false,
//Alpha feature
CNIBinDir: "/opt/cni/bin",

View File

@ -24,7 +24,6 @@ import (
"fmt"
"net"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
@ -84,14 +83,11 @@ import (
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/config"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/dockershim"
dockerremote "k8s.io/kubernetes/pkg/kubelet/dockershim/remote"
"k8s.io/kubernetes/pkg/kubelet/eviction"
evictionapi "k8s.io/kubernetes/pkg/kubelet/eviction/api"
dynamickubeletconfig "k8s.io/kubernetes/pkg/kubelet/kubeletconfig"
"k8s.io/kubernetes/pkg/kubelet/kubeletconfig/configfiles"
"k8s.io/kubernetes/pkg/kubelet/server"
"k8s.io/kubernetes/pkg/kubelet/server/streaming"
"k8s.io/kubernetes/pkg/kubelet/stats/pidlimit"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
utilfs "k8s.io/kubernetes/pkg/util/filesystem"
@ -259,14 +255,6 @@ HTTP server: The kubelet can also listen for HTTP and respond to a simple API
// set up stopCh here in order to be reused by kubelet and docker shim
stopCh := genericapiserver.SetupSignalHandler()
// start the experimental docker shim, if enabled
if kubeletServer.KubeletFlags.ExperimentalDockershim {
if err := RunDockershim(&kubeletServer.KubeletFlags, kubeletConfig, stopCh); err != nil {
klog.Fatal(err)
}
return
}
// run the kubelet
klog.V(5).Infof("KubeletConfiguration: %#v", kubeletServer.KubeletConfiguration)
if err := Run(kubeletServer, kubeletDeps, utilfeature.DefaultFeatureGate, stopCh); err != nil {
@ -375,9 +363,9 @@ func UnsecuredDependencies(s *options.KubeletServer, featureGate featuregate.Fea
hu := hostutil.NewHostUtil()
var pluginRunner = exec.New()
var dockerClientConfig *dockershim.ClientConfig
var dockerOptions *kubelet.DockerOptions
if s.ContainerRuntime == kubetypes.DockerContainerRuntime {
dockerClientConfig = &dockershim.ClientConfig{
dockerOptions = &kubelet.DockerOptions{
DockerEndpoint: s.DockerEndpoint,
RuntimeRequestTimeout: s.RuntimeRequestTimeout.Duration,
ImagePullProgressDeadline: s.ImagePullProgressDeadline.Duration,
@ -393,7 +381,7 @@ func UnsecuredDependencies(s *options.KubeletServer, featureGate featuregate.Fea
CAdvisorInterface: nil, // cadvisor.New launches background processes (bg http.ListenAndServe, and some bg cleaners), not set here
Cloud: nil, // cloud provider might start background processes
ContainerManager: nil,
DockerClientConfig: dockerClientConfig,
DockerOptions: dockerOptions,
KubeClient: nil,
HeartbeatClient: nil,
EventClient: nil,
@ -1271,51 +1259,3 @@ func BootstrapKubeletConfigController(dynamicConfigDir string, transform dynamic
}
return kc, c, nil
}
// RunDockershim only starts the dockershim in current process. This is only used for cri validate testing purpose
// TODO(random-liu): Move this to a separate binary.
func RunDockershim(f *options.KubeletFlags, c *kubeletconfiginternal.KubeletConfiguration, stopCh <-chan struct{}) error {
r := &f.ContainerRuntimeOptions
// Initialize docker client configuration.
dockerClientConfig := &dockershim.ClientConfig{
DockerEndpoint: r.DockerEndpoint,
RuntimeRequestTimeout: c.RuntimeRequestTimeout.Duration,
ImagePullProgressDeadline: r.ImagePullProgressDeadline.Duration,
}
// Initialize network plugin settings.
pluginSettings := dockershim.NetworkPluginSettings{
HairpinMode: kubeletconfiginternal.HairpinMode(c.HairpinMode),
NonMasqueradeCIDR: f.NonMasqueradeCIDR,
PluginName: r.NetworkPluginName,
PluginConfDir: r.CNIConfDir,
PluginBinDirString: r.CNIBinDir,
PluginCacheDir: r.CNICacheDir,
MTU: int(r.NetworkPluginMTU),
}
// Initialize streaming configuration. (Not using TLS now)
streamingConfig := &streaming.Config{
// Use a relative redirect (no scheme or host).
BaseURL: &url.URL{Path: "/cri/"},
StreamIdleTimeout: c.StreamingConnectionIdleTimeout.Duration,
StreamCreationTimeout: streaming.DefaultConfig.StreamCreationTimeout,
SupportedRemoteCommandProtocols: streaming.DefaultConfig.SupportedRemoteCommandProtocols,
SupportedPortForwardProtocols: streaming.DefaultConfig.SupportedPortForwardProtocols,
}
// Standalone dockershim will always start the local streaming server.
ds, err := dockershim.NewDockerService(dockerClientConfig, r.PodSandboxImage, streamingConfig, &pluginSettings,
f.RuntimeCgroups, c.CgroupDriver, r.DockershimRootDirectory, true /*startLocalStreamingServer*/)
if err != nil {
return err
}
klog.V(2).Infof("Starting the GRPC server for the docker CRI shim.")
server := dockerremote.NewDockerServer(f.RemoteRuntimeEndpoint, ds)
if err := server.Start(); err != nil {
return err
}
<-stopCh
return nil
}

View File

@ -48,6 +48,7 @@ if [[ ${EXCLUDE_TYPECHECK:-} =~ ^[yY]$ ]]; then
EXCLUDED_PATTERNS+=(
"verify-typecheck.sh" # runs in separate typecheck job
"verify-typecheck-providerless.sh" # runs in separate typecheck job
"verify-typecheck-dockerless.sh" # runs in separate typecheck job
)
fi

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
cd "${KUBE_ROOT}"
# verify the dockerless build
hack/verify-typecheck.sh --skip-test --tags=dockerless --ignore-dirs=test

View File

@ -13,6 +13,7 @@ go_library(
"doc.go",
"errors.go",
"kubelet.go",
"kubelet_dockershim.go",
"kubelet_getters.go",
"kubelet_network.go",
"kubelet_network_linux.go",
@ -61,6 +62,7 @@ go_library(
"//pkg/kubelet/images:go_default_library",
"//pkg/kubelet/kubeletconfig:go_default_library",
"//pkg/kubelet/kuberuntime:go_default_library",
"//pkg/kubelet/legacy:go_default_library",
"//pkg/kubelet/lifecycle:go_default_library",
"//pkg/kubelet/logs:go_default_library",
"//pkg/kubelet/metrics:go_default_library",
@ -297,6 +299,7 @@ filegroup(
"//pkg/kubelet/kubeletconfig:all-srcs",
"//pkg/kubelet/kuberuntime:all-srcs",
"//pkg/kubelet/leaky:all-srcs",
"//pkg/kubelet/legacy:all-srcs",
"//pkg/kubelet/lifecycle:all-srcs",
"//pkg/kubelet/logs:all-srcs",
"//pkg/kubelet/metrics:all-srcs",

View File

@ -10,6 +10,7 @@ go_library(
name = "go_default_library",
srcs = [
"cadvisor_linux.go",
"cadvisor_linux_docker.go",
"cadvisor_unsupported.go",
"cadvisor_windows.go",
"doc.go",

View File

@ -29,7 +29,6 @@ import (
// Register supported container handlers.
_ "github.com/google/cadvisor/container/containerd/install"
_ "github.com/google/cadvisor/container/crio/install"
_ "github.com/google/cadvisor/container/docker/install"
_ "github.com/google/cadvisor/container/systemd/install"
// Register cloud info providers.

View File

@ -0,0 +1,25 @@
// +build linux,!dockerless
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cadvisor
import (
// We only want to perform this docker specific cadvisor init when we are not
// using the `dockerless` build tag.
_ "github.com/google/cadvisor/container/docker/install"
)

View File

@ -46,8 +46,6 @@ type ContainerRuntimeOptions struct {
// DockershimRootDirectory is the path to the dockershim root directory. Defaults to
// /var/lib/dockershim if unset. Exposed for integration testing (e.g. in OpenShift).
DockershimRootDirectory string
// Enable dockershim only mode.
ExperimentalDockershim bool
// PodSandboxImage is the image whose network/ipc namespaces
// containers in each pod will use.
PodSandboxImage string
@ -89,8 +87,6 @@ func (s *ContainerRuntimeOptions) AddFlags(fs *pflag.FlagSet) {
fs.MarkDeprecated("redirect-container-streaming", "Container streaming redirection will be removed from the kubelet in v1.20, and this flag will be removed in v1.22. For more details, see http://git.k8s.io/enhancements/keps/sig-node/20191205-container-streaming-requests.md")
// Docker-specific settings.
fs.BoolVar(&s.ExperimentalDockershim, "experimental-dockershim", s.ExperimentalDockershim, "Enable dockershim only mode. In this mode, kubelet will only start dockershim without any other functionalities. This flag only serves test purpose, please do not use it unless you are conscious of what you are doing. [default=false]")
fs.MarkHidden("experimental-dockershim")
fs.StringVar(&s.DockershimRootDirectory, "experimental-dockershim-root-directory", s.DockershimRootDirectory, "Path to the dockershim root directory.")
fs.MarkHidden("experimental-dockershim-root-directory")
fs.StringVar(&s.PodSandboxImage, "pod-infra-container-image", s.PodSandboxImage, fmt.Sprintf("The image whose network/ipc namespaces containers in each pod will use. %s", dockerOnlyWarning))

View File

@ -49,8 +49,8 @@ go_library(
"//pkg/kubelet/dockershim/network/cni:go_default_library",
"//pkg/kubelet/dockershim/network/hostport:go_default_library",
"//pkg/kubelet/dockershim/network/kubenet:go_default_library",
"//pkg/kubelet/kuberuntime:go_default_library",
"//pkg/kubelet/leaky:go_default_library",
"//pkg/kubelet/legacy:go_default_library",
"//pkg/kubelet/server/streaming:go_default_library",
"//pkg/kubelet/types:go_default_library",
"//pkg/kubelet/util/cache:go_default_library",

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build linux
// +build linux,!dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build !linux,!windows
// +build !linux,!windows,!dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build windows
// +build windows,!dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build !windows
// +build !windows,!dockerless
/*
Copyright 2019 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build windows
// +build windows,!dockerless
/*
Copyright 2019 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2019 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build linux
// +build linux,!dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build !linux,!windows
// +build !linux,!windows,!dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build windows
// +build windows,!dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.
@ -32,25 +34,17 @@ import (
kubetypes "k8s.io/apimachinery/pkg/types"
"k8s.io/klog"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/kuberuntime"
"k8s.io/kubernetes/pkg/kubelet/dockershim/libdocker"
)
// DockerLegacyService interface embeds some legacy methods for backward compatibility.
// This file/interface will be removed in the near future. Do not modify or add
// more functions.
type DockerLegacyService interface {
// GetContainerLogs gets logs for a specific container.
GetContainerLogs(context.Context, *v1.Pod, kubecontainer.ContainerID, *v1.PodLogOptions, io.Writer, io.Writer) error
// IsCRISupportedLogDriver checks whether the logging driver used by docker is
// supported by native CRI integration.
// TODO(resouer): remove this when deprecating unsupported log driver
IsCRISupportedLogDriver() (bool, error)
kuberuntime.LegacyLogProvider
}
// We define `DockerLegacyService` in `pkg/kubelet/legacy`, instead of in this
// file. We make this decision because `pkg/kubelet` depends on
// `DockerLegacyService`, and we want to be able to build the `kubelet` without
// relying on `github.com/docker/docker` or `pkg/kubelet/dockershim`.
//
// See https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/20200205-build-kubelet-without-docker.md
// for details.
// GetContainerLogs get container logs directly from docker daemon.
func (d *dockerService) GetContainerLogs(_ context.Context, pod *v1.Pod, containerID kubecontainer.ContainerID, logOptions *v1.PodLogOptions, stdout, stderr io.Writer) error {

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2018 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.
@ -40,6 +42,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet/dockershim/network/cni"
"k8s.io/kubernetes/pkg/kubelet/dockershim/network/hostport"
"k8s.io/kubernetes/pkg/kubelet/dockershim/network/kubenet"
"k8s.io/kubernetes/pkg/kubelet/legacy"
"k8s.io/kubernetes/pkg/kubelet/server/streaming"
"k8s.io/kubernetes/pkg/kubelet/util/cache"
@ -97,7 +100,7 @@ type DockerService interface {
http.Handler
// For supporting legacy features.
DockerLegacyService
legacy.DockerLegacyService
}
// NetworkPluginSettings is the subset of kubelet runtime args we pass

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2019 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build linux
// +build linux,!dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2019 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build !linux,!windows
// +build !linux,!windows,!dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build windows
// +build windows,!dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build !windows
// +build !windows,!dockerless
/*
Copyright 2019 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build windows
// +build windows,!dockerless
/*
Copyright 2019 The Kubernetes Authors.

View File

@ -0,0 +1,19 @@
// +build dockerless
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package dockershim

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2015 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build linux
// +build linux,!dockerless
/*
Copyright 2015 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build linux
// +build linux,!dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build !linux,!windows
// +build !linux,!windows,!dockerless
/*
Copyright 2015 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build windows
// +build windows,!dockerless
/*
Copyright 2015 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2015 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2015 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build !windows
// +build !windows,!dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build linux
// +build linux,!dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build windows
// +build windows,!dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2015 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2015 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build linux
// +build linux,!dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2015 The Kubernetes Authors.

View File

@ -1,4 +1,4 @@
// +build !linux
// +build !linux,!dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2014 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2016 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -1,3 +1,5 @@
// +build !dockerless
/*
Copyright 2017 The Kubernetes Authors.

View File

@ -70,13 +70,12 @@ import (
"k8s.io/kubernetes/pkg/kubelet/config"
"k8s.io/kubernetes/pkg/kubelet/configmap"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/dockershim"
dockerremote "k8s.io/kubernetes/pkg/kubelet/dockershim/remote"
"k8s.io/kubernetes/pkg/kubelet/events"
"k8s.io/kubernetes/pkg/kubelet/eviction"
"k8s.io/kubernetes/pkg/kubelet/images"
"k8s.io/kubernetes/pkg/kubelet/kubeletconfig"
"k8s.io/kubernetes/pkg/kubelet/kuberuntime"
"k8s.io/kubernetes/pkg/kubelet/legacy"
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
"k8s.io/kubernetes/pkg/kubelet/logs"
"k8s.io/kubernetes/pkg/kubelet/metrics"
@ -213,7 +212,7 @@ type Dependencies struct {
CAdvisorInterface cadvisor.Interface
Cloud cloudprovider.Interface
ContainerManager cm.ContainerManager
DockerClientConfig *dockershim.ClientConfig
DockerOptions *DockerOptions
EventClient v1core.EventsGetter
HeartbeatClient clientset.Interface
OnHeartbeatFailure func()
@ -232,11 +231,20 @@ type Dependencies struct {
RemoteRuntimeService internalapi.RuntimeService
RemoteImageService internalapi.ImageManagerService
criHandler http.Handler
dockerLegacyService dockershim.DockerLegacyService
dockerLegacyService legacy.DockerLegacyService
// remove it after cadvisor.UsingLegacyCadvisorStats dropped.
useLegacyCadvisorStats bool
}
// DockerOptions contains docker specific configuration. Importantly, since it
// lives outside of `dockershim`, it should not depend on the `docker/docker`
// client library.
type DockerOptions struct {
DockerEndpoint string
RuntimeRequestTimeout time.Duration
ImagePullProgressDeadline time.Duration
}
// makePodSourceConfig creates a config.PodConfig from the given
// KubeletConfiguration or returns an error.
func makePodSourceConfig(kubeCfg *kubeletconfiginternal.KubeletConfiguration, kubeDeps *Dependencies, nodeName types.NodeName, bootstrapCheckpointPath string) (*config.PodConfig, error) {
@ -306,46 +314,15 @@ func PreInitRuntimeService(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
switch containerRuntime {
case kubetypes.DockerContainerRuntime:
// TODO: These need to become arguments to a standalone docker shim.
pluginSettings := dockershim.NetworkPluginSettings{
HairpinMode: kubeletconfiginternal.HairpinMode(kubeCfg.HairpinMode),
NonMasqueradeCIDR: nonMasqueradeCIDR,
PluginName: crOptions.NetworkPluginName,
PluginConfDir: crOptions.CNIConfDir,
PluginBinDirString: crOptions.CNIBinDir,
PluginCacheDir: crOptions.CNICacheDir,
MTU: int(crOptions.NetworkPluginMTU),
}
// Create and start the CRI shim running as a grpc server.
streamingConfig := getStreamingConfig(kubeCfg, kubeDeps, crOptions)
ds, err := dockershim.NewDockerService(kubeDeps.DockerClientConfig, crOptions.PodSandboxImage, streamingConfig,
&pluginSettings, runtimeCgroups, kubeCfg.CgroupDriver, crOptions.DockershimRootDirectory, !crOptions.RedirectContainerStreaming)
if err != nil {
return err
}
if crOptions.RedirectContainerStreaming {
kubeDeps.criHandler = ds
}
// The unix socket for kubelet <-> dockershim communication, dockershim start before runtime service init.
klog.V(5).Infof("RemoteRuntimeEndpoint: %q, RemoteImageEndpoint: %q",
runDockershim(
kubeCfg,
kubeDeps,
crOptions,
runtimeCgroups,
remoteRuntimeEndpoint,
remoteImageEndpoint)
klog.V(2).Infof("Starting the GRPC server for the docker CRI shim.")
dockerServer := dockerremote.NewDockerServer(remoteRuntimeEndpoint, ds)
if err := dockerServer.Start(); err != nil {
return err
}
// Create dockerLegacyService when the logging driver is not supported.
supported, err := ds.IsCRISupportedLogDriver()
if err != nil {
return err
}
if !supported {
kubeDeps.dockerLegacyService = ds
}
remoteImageEndpoint,
nonMasqueradeCIDR,
)
case kubetypes.RemoteContainerRuntime:
// No-op.
break
@ -1155,7 +1132,7 @@ type Kubelet struct {
// dockerLegacyService contains some legacy methods for backward compatibility.
// It should be set only when docker is using non json-file logging driver.
dockerLegacyService dockershim.DockerLegacyService
dockerLegacyService legacy.DockerLegacyService
// StatsProvider provides the node and the container stats.
*stats.StatsProvider

View File

@ -0,0 +1,83 @@
// +build !dockerless
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kubelet
import (
"k8s.io/klog"
kubeletconfiginternal "k8s.io/kubernetes/pkg/kubelet/apis/config"
"k8s.io/kubernetes/pkg/kubelet/config"
"k8s.io/kubernetes/pkg/kubelet/dockershim"
dockerremote "k8s.io/kubernetes/pkg/kubelet/dockershim/remote"
)
func runDockershim(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
kubeDeps *Dependencies,
crOptions *config.ContainerRuntimeOptions,
runtimeCgroups string,
remoteRuntimeEndpoint string,
remoteImageEndpoint string,
nonMasqueradeCIDR string) error {
pluginSettings := dockershim.NetworkPluginSettings{
HairpinMode: kubeletconfiginternal.HairpinMode(kubeCfg.HairpinMode),
NonMasqueradeCIDR: nonMasqueradeCIDR,
PluginName: crOptions.NetworkPluginName,
PluginConfDir: crOptions.CNIConfDir,
PluginBinDirString: crOptions.CNIBinDir,
PluginCacheDir: crOptions.CNICacheDir,
MTU: int(crOptions.NetworkPluginMTU),
}
// Create and start the CRI shim running as a grpc server.
streamingConfig := getStreamingConfig(kubeCfg, kubeDeps, crOptions)
dockerClientConfig := &dockershim.ClientConfig{
DockerEndpoint: kubeDeps.DockerOptions.DockerEndpoint,
RuntimeRequestTimeout: kubeDeps.DockerOptions.RuntimeRequestTimeout,
ImagePullProgressDeadline: kubeDeps.DockerOptions.ImagePullProgressDeadline,
}
ds, err := dockershim.NewDockerService(dockerClientConfig, crOptions.PodSandboxImage, streamingConfig,
&pluginSettings, runtimeCgroups, kubeCfg.CgroupDriver, crOptions.DockershimRootDirectory, !crOptions.RedirectContainerStreaming)
if err != nil {
return err
}
if crOptions.RedirectContainerStreaming {
kubeDeps.criHandler = ds
}
// The unix socket for kubelet <-> dockershim communication, dockershim start before runtime service init.
klog.V(5).Infof("RemoteRuntimeEndpoint: %q, RemoteImageEndpoint: %q",
remoteRuntimeEndpoint,
remoteImageEndpoint)
klog.V(2).Infof("Starting the GRPC server for the docker CRI shim.")
dockerServer := dockerremote.NewDockerServer(remoteRuntimeEndpoint, ds)
if err := dockerServer.Start(); err != nil {
return err
}
// Create dockerLegacyService when the logging driver is not supported.
supported, err := ds.IsCRISupportedLogDriver()
if err != nil {
return err
}
if !supported {
kubeDeps.dockerLegacyService = ds
}
return nil
}

View File

@ -0,0 +1,36 @@
// +build dockerless
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kubelet
import (
"fmt"
kubeletconfiginternal "k8s.io/kubernetes/pkg/kubelet/apis/config"
"k8s.io/kubernetes/pkg/kubelet/config"
)
func runDockershim(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
kubeDeps *Dependencies,
crOptions *config.ContainerRuntimeOptions,
runtimeCgroups string,
remoteRuntimeEndpoint string,
remoteImageEndpoint string,
nonMasqueradeCIDR string) error {
return fmt.Errorf("trying to use docker runtime, w/ Kubelet compiled w/o docker support")
}

27
pkg/kubelet/legacy/BUILD Normal file
View File

@ -0,0 +1,27 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["logs.go"],
importpath = "k8s.io/kubernetes/pkg/kubelet/legacy",
visibility = ["//visibility:public"],
deps = [
"//pkg/kubelet/container:go_default_library",
"//pkg/kubelet/kuberuntime:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,53 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package legacy
import (
"context"
"io"
"k8s.io/api/core/v1"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/kuberuntime"
)
// DockerLegacyService interface is used throughout `pkg/kubelet`.
// It used to live in the `pkg/kubelet/dockershim` package. While we
// would eventually like to remove it entirely, we need to give users some form
// of warning.
//
// By including the interface in
// `pkg/kubelet/legacy/logs.go`, we ensure the interface is
// available to `pkg/kubelet`, even when we are building with the `dockerless`
// tag (i.e. not compiling the dockershim).
// While the interface always exists, there will be no implementations of the
// interface when building with the `dockerless` tag. The lack of
// implementations should not be an issue, as we only expect `pkg/kubelet` code
// to need an implementation of the `DockerLegacyService` when we are using
// docker. If we are using docker, but building with the `dockerless` tag, than
// this will be just one of many things that breaks.
type DockerLegacyService interface {
// GetContainerLogs gets logs for a specific container.
GetContainerLogs(context.Context, *v1.Pod, kubecontainer.ContainerID, *v1.PodLogOptions, io.Writer, io.Writer) error
// IsCRISupportedLogDriver checks whether the logging driver used by docker is
// supported by native CRI integration.
// TODO(resouer): remove this when deprecating unsupported log driver
IsCRISupportedLogDriver() (bool, error)
kuberuntime.LegacyLogProvider
}