mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Split the Kubelet flag options and struct
Reduces the size of the app/server.go file and ensures that the flags and their defaults are clearly separated.
This commit is contained in:
parent
b1e4831265
commit
791d160b42
@ -17,13 +17,14 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app"
|
||||
"k8s.io/kubernetes/cmd/kubelet/app"
|
||||
"k8s.io/kubernetes/cmd/kubelet/app/options"
|
||||
)
|
||||
|
||||
// NewKubelet creates a new hyperkube Server object that includes the
|
||||
// description and flags.
|
||||
func NewKubelet() *Server {
|
||||
s := kubeletapp.NewKubeletServer()
|
||||
s := options.NewKubeletServer()
|
||||
hks := Server{
|
||||
SimpleUsage: "kubelet",
|
||||
Long: `The kubelet binary is responsible for maintaining a set of containers on a
|
||||
@ -33,7 +34,7 @@ func NewKubelet() *Server {
|
||||
configuration data, with the running set of containers by starting or stopping
|
||||
Docker containers.`,
|
||||
Run: func(_ *Server, _ []string) error {
|
||||
return s.Run(nil)
|
||||
return app.Run(s, nil)
|
||||
},
|
||||
}
|
||||
s.AddFlags(hks.Flags())
|
||||
|
280
cmd/kubelet/app/options/options.go
Normal file
280
cmd/kubelet/app/options/options.go
Normal file
@ -0,0 +1,280 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 options contains all of the primary arguments for a kubelet.
|
||||
package options
|
||||
|
||||
import (
|
||||
"net"
|
||||
_ "net/http/pprof"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/kubelet/qos"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/master/ports"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultRootDir = "/var/lib/kubelet"
|
||||
experimentalFlannelOverlay = false
|
||||
)
|
||||
|
||||
// KubeletServer encapsulates all of the parameters necessary for starting up
|
||||
// a kubelet. These can either be set via command line or directly.
|
||||
type KubeletServer struct {
|
||||
Address net.IP
|
||||
AllowPrivileged bool
|
||||
APIServerList []string
|
||||
AuthPath util.StringFlag // Deprecated -- use KubeConfig instead
|
||||
CAdvisorPort uint
|
||||
CertDirectory string
|
||||
CgroupRoot string
|
||||
CloudConfigFile string
|
||||
CloudProvider string
|
||||
ClusterDNS net.IP
|
||||
ClusterDomain string
|
||||
Config string
|
||||
ConfigureCBR0 bool
|
||||
ContainerRuntime string
|
||||
CPUCFSQuota bool
|
||||
DockerDaemonContainer string
|
||||
DockerEndpoint string
|
||||
DockerExecHandlerName string
|
||||
EnableDebuggingHandlers bool
|
||||
EnableServer bool
|
||||
EventBurst int
|
||||
EventRecordQPS float32
|
||||
FileCheckFrequency time.Duration
|
||||
HealthzBindAddress net.IP
|
||||
HealthzPort int
|
||||
HostnameOverride string
|
||||
HostNetworkSources string
|
||||
HostPIDSources string
|
||||
HostIPCSources string
|
||||
HTTPCheckFrequency time.Duration
|
||||
ImageGCHighThresholdPercent int
|
||||
ImageGCLowThresholdPercent int
|
||||
KubeConfig util.StringFlag
|
||||
LowDiskSpaceThresholdMB int
|
||||
ManifestURL string
|
||||
ManifestURLHeader string
|
||||
MasterServiceNamespace string
|
||||
MaxContainerCount int
|
||||
MaxOpenFiles uint64
|
||||
MaxPerPodContainerCount int
|
||||
MaxPods int
|
||||
MinimumGCAge time.Duration
|
||||
NetworkPluginDir string
|
||||
NetworkPluginName string
|
||||
VolumePluginDir string
|
||||
NodeLabels []string
|
||||
NodeLabelsFile string
|
||||
NodeStatusUpdateFrequency time.Duration
|
||||
OOMScoreAdj int
|
||||
PodCIDR string
|
||||
PodInfraContainerImage string
|
||||
Port uint
|
||||
ReadOnlyPort uint
|
||||
RegisterNode bool
|
||||
RegisterSchedulable bool
|
||||
RegistryBurst int
|
||||
RegistryPullQPS float64
|
||||
ResolverConfig string
|
||||
ResourceContainer string
|
||||
RktPath string
|
||||
RktStage1Image string
|
||||
RootDirectory string
|
||||
RunOnce bool
|
||||
StandaloneMode bool
|
||||
StreamingConnectionIdleTimeout time.Duration
|
||||
SyncFrequency time.Duration
|
||||
SystemContainer string
|
||||
TLSCertFile string
|
||||
TLSPrivateKeyFile string
|
||||
ReconcileCIDR bool
|
||||
|
||||
// Flags intended for testing
|
||||
// Is the kubelet containerized?
|
||||
Containerized bool
|
||||
// Insert a probability of random errors during calls to the master.
|
||||
ChaosChance float64
|
||||
// Crash immediately, rather than eating panics.
|
||||
ReallyCrashForTesting bool
|
||||
|
||||
KubeAPIQPS float32
|
||||
KubeAPIBurst int
|
||||
|
||||
// Pull images one at a time.
|
||||
SerializeImagePulls bool
|
||||
ExperimentalFlannelOverlay bool
|
||||
OutOfDiskTransitionFrequency time.Duration
|
||||
NodeIP net.IP
|
||||
}
|
||||
|
||||
// NewKubeletServer will create a new KubeletServer with default values.
|
||||
func NewKubeletServer() *KubeletServer {
|
||||
return &KubeletServer{
|
||||
Address: net.ParseIP("0.0.0.0"),
|
||||
AuthPath: util.NewStringFlag("/var/lib/kubelet/kubernetes_auth"), // deprecated
|
||||
CAdvisorPort: 4194,
|
||||
CertDirectory: "/var/run/kubernetes",
|
||||
CgroupRoot: "",
|
||||
ConfigureCBR0: false,
|
||||
ContainerRuntime: "docker",
|
||||
CPUCFSQuota: false,
|
||||
DockerDaemonContainer: "/docker-daemon",
|
||||
DockerExecHandlerName: "native",
|
||||
EventBurst: 10,
|
||||
EventRecordQPS: 5.0,
|
||||
EnableDebuggingHandlers: true,
|
||||
EnableServer: true,
|
||||
FileCheckFrequency: 20 * time.Second,
|
||||
HealthzBindAddress: net.ParseIP("127.0.0.1"),
|
||||
HealthzPort: 10248,
|
||||
HostNetworkSources: kubetypes.AllSource,
|
||||
HostPIDSources: kubetypes.AllSource,
|
||||
HostIPCSources: kubetypes.AllSource,
|
||||
HTTPCheckFrequency: 20 * time.Second,
|
||||
ImageGCHighThresholdPercent: 90,
|
||||
ImageGCLowThresholdPercent: 80,
|
||||
KubeConfig: util.NewStringFlag("/var/lib/kubelet/kubeconfig"),
|
||||
LowDiskSpaceThresholdMB: 256,
|
||||
MasterServiceNamespace: api.NamespaceDefault,
|
||||
MaxContainerCount: 100,
|
||||
MaxPerPodContainerCount: 2,
|
||||
MaxOpenFiles: 1000000,
|
||||
MaxPods: 40,
|
||||
MinimumGCAge: 1 * time.Minute,
|
||||
NetworkPluginDir: "/usr/libexec/kubernetes/kubelet-plugins/net/exec/",
|
||||
NetworkPluginName: "",
|
||||
VolumePluginDir: "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/",
|
||||
NodeLabels: []string{},
|
||||
NodeLabelsFile: "",
|
||||
NodeStatusUpdateFrequency: 10 * time.Second,
|
||||
OOMScoreAdj: qos.KubeletOOMScoreAdj,
|
||||
PodInfraContainerImage: kubetypes.PodInfraContainerImage,
|
||||
Port: ports.KubeletPort,
|
||||
ReadOnlyPort: ports.KubeletReadOnlyPort,
|
||||
RegisterNode: true, // will be ignored if no apiserver is configured
|
||||
RegisterSchedulable: true,
|
||||
RegistryBurst: 10,
|
||||
RegistryPullQPS: 5.0,
|
||||
ResourceContainer: "/kubelet",
|
||||
RktPath: "",
|
||||
RktStage1Image: "",
|
||||
RootDirectory: defaultRootDir,
|
||||
SerializeImagePulls: true,
|
||||
StreamingConnectionIdleTimeout: 5 * time.Minute,
|
||||
SyncFrequency: 1 * time.Minute,
|
||||
SystemContainer: "",
|
||||
ReconcileCIDR: true,
|
||||
KubeAPIQPS: 5.0,
|
||||
KubeAPIBurst: 10,
|
||||
ExperimentalFlannelOverlay: experimentalFlannelOverlay,
|
||||
OutOfDiskTransitionFrequency: 5 * time.Minute,
|
||||
}
|
||||
}
|
||||
|
||||
// AddFlags adds flags for a specific KubeletServer to the specified FlagSet
|
||||
func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&s.Config, "config", s.Config, "Path to the config file or directory of files")
|
||||
fs.DurationVar(&s.SyncFrequency, "sync-frequency", s.SyncFrequency, "Max period between synchronizing running containers and config")
|
||||
fs.DurationVar(&s.FileCheckFrequency, "file-check-frequency", s.FileCheckFrequency, "Duration between checking config files for new data")
|
||||
fs.DurationVar(&s.HTTPCheckFrequency, "http-check-frequency", s.HTTPCheckFrequency, "Duration between checking http for new data")
|
||||
fs.StringVar(&s.ManifestURL, "manifest-url", s.ManifestURL, "URL for accessing the container manifest")
|
||||
fs.StringVar(&s.ManifestURLHeader, "manifest-url-header", s.ManifestURLHeader, "HTTP header to use when accessing the manifest URL, with the key separated from the value with a ':', as in 'key:value'")
|
||||
fs.BoolVar(&s.EnableServer, "enable-server", s.EnableServer, "Enable the Kubelet's server")
|
||||
fs.IPVar(&s.Address, "address", s.Address, "The IP address for the Kubelet to serve on (set to 0.0.0.0 for all interfaces)")
|
||||
fs.UintVar(&s.Port, "port", s.Port, "The port for the Kubelet to serve on.")
|
||||
fs.UintVar(&s.ReadOnlyPort, "read-only-port", s.ReadOnlyPort, "The read-only port for the Kubelet to serve on with no authentication/authorization (set to 0 to disable)")
|
||||
fs.StringVar(&s.TLSCertFile, "tls-cert-file", s.TLSCertFile, ""+
|
||||
"File containing x509 Certificate for HTTPS. (CA cert, if any, concatenated after server cert). "+
|
||||
"If --tls-cert-file and --tls-private-key-file are not provided, a self-signed certificate and key "+
|
||||
"are generated for the public address and saved to the directory passed to --cert-dir.")
|
||||
fs.StringVar(&s.TLSPrivateKeyFile, "tls-private-key-file", s.TLSPrivateKeyFile, "File containing x509 private key matching --tls-cert-file.")
|
||||
fs.StringVar(&s.CertDirectory, "cert-dir", s.CertDirectory, "The directory where the TLS certs are located (by default /var/run/kubernetes). "+
|
||||
"If --tls-cert-file and --tls-private-key-file are provided, this flag will be ignored.")
|
||||
fs.StringVar(&s.HostnameOverride, "hostname-override", s.HostnameOverride, "If non-empty, will use this string as identification instead of the actual hostname.")
|
||||
fs.StringVar(&s.PodInfraContainerImage, "pod-infra-container-image", s.PodInfraContainerImage, "The image whose network/ipc namespaces containers in each pod will use.")
|
||||
fs.StringVar(&s.DockerEndpoint, "docker-endpoint", s.DockerEndpoint, "If non-empty, use this for the docker endpoint to communicate with")
|
||||
fs.StringVar(&s.RootDirectory, "root-dir", s.RootDirectory, "Directory path for managing kubelet files (volume mounts,etc).")
|
||||
fs.BoolVar(&s.AllowPrivileged, "allow-privileged", s.AllowPrivileged, "If true, allow containers to request privileged mode. [default=false]")
|
||||
fs.StringVar(&s.HostNetworkSources, "host-network-sources", s.HostNetworkSources, "Comma-separated list of sources from which the Kubelet allows pods to use of host network. [default=\"*\"]")
|
||||
fs.StringVar(&s.HostPIDSources, "host-pid-sources", s.HostPIDSources, "Comma-separated list of sources from which the Kubelet allows pods to use the host pid namespace. [default=\"*\"]")
|
||||
fs.StringVar(&s.HostIPCSources, "host-ipc-sources", s.HostIPCSources, "Comma-separated list of sources from which the Kubelet allows pods to use the host ipc namespace. [default=\"*\"]")
|
||||
fs.Float64Var(&s.RegistryPullQPS, "registry-qps", s.RegistryPullQPS, "If > 0, limit registry pull QPS to this value. If 0, unlimited. [default=5.0]")
|
||||
fs.IntVar(&s.RegistryBurst, "registry-burst", s.RegistryBurst, "Maximum size of a bursty pulls, temporarily allows pulls to burst to this number, while still not exceeding registry-qps. Only used if --registry-qps > 0")
|
||||
fs.Float32Var(&s.EventRecordQPS, "event-qps", s.EventRecordQPS, "If > 0, limit event creations per second to this value. If 0, unlimited.")
|
||||
fs.IntVar(&s.EventBurst, "event-burst", s.EventBurst, "Maximum size of a bursty event records, temporarily allows event records to burst to this number, while still not exceeding event-qps. Only used if --event-qps > 0")
|
||||
fs.BoolVar(&s.RunOnce, "runonce", s.RunOnce, "If true, exit after spawning pods from local manifests or remote urls. Exclusive with --api-servers, and --enable-server")
|
||||
fs.BoolVar(&s.EnableDebuggingHandlers, "enable-debugging-handlers", s.EnableDebuggingHandlers, "Enables server endpoints for log collection and local running of containers and commands")
|
||||
fs.DurationVar(&s.MinimumGCAge, "minimum-container-ttl-duration", s.MinimumGCAge, "Minimum age for a finished container before it is garbage collected. Examples: '300ms', '10s' or '2h45m'")
|
||||
fs.IntVar(&s.MaxPerPodContainerCount, "maximum-dead-containers-per-container", s.MaxPerPodContainerCount, "Maximum number of old instances to retain per container. Each container takes up some disk space. Default: 2.")
|
||||
fs.IntVar(&s.MaxContainerCount, "maximum-dead-containers", s.MaxContainerCount, "Maximum number of old instances of containers to retain globally. Each container takes up some disk space. Default: 100.")
|
||||
fs.Var(&s.AuthPath, "auth-path", "Path to .kubernetes_auth file, specifying how to authenticate to API server.")
|
||||
fs.MarkDeprecated("auth-path", "will be removed in a future version")
|
||||
fs.Var(&s.KubeConfig, "kubeconfig", "Path to a kubeconfig file, specifying how to authenticate to API server (the master location is set by the api-servers flag).")
|
||||
fs.UintVar(&s.CAdvisorPort, "cadvisor-port", s.CAdvisorPort, "The port of the localhost cAdvisor endpoint")
|
||||
fs.IntVar(&s.HealthzPort, "healthz-port", s.HealthzPort, "The port of the localhost healthz endpoint")
|
||||
fs.IPVar(&s.HealthzBindAddress, "healthz-bind-address", s.HealthzBindAddress, "The IP address for the healthz server to serve on, defaulting to 127.0.0.1 (set to 0.0.0.0 for all interfaces)")
|
||||
fs.IntVar(&s.OOMScoreAdj, "oom-score-adj", s.OOMScoreAdj, "The oom-score-adj value for kubelet process. Values must be within the range [-1000, 1000]")
|
||||
fs.StringSliceVar(&s.APIServerList, "api-servers", []string{}, "List of Kubernetes API servers for publishing events, and reading pods and services. (ip:port), comma separated.")
|
||||
fs.BoolVar(&s.RegisterNode, "register-node", s.RegisterNode, "Register the node with the apiserver (defaults to true if --api-servers is set)")
|
||||
fs.StringVar(&s.ClusterDomain, "cluster-domain", s.ClusterDomain, "Domain for this cluster. If set, kubelet will configure all containers to search this domain in addition to the host's search domains")
|
||||
fs.StringVar(&s.MasterServiceNamespace, "master-service-namespace", s.MasterServiceNamespace, "The namespace from which the kubernetes master services should be injected into pods")
|
||||
fs.IPVar(&s.ClusterDNS, "cluster-dns", s.ClusterDNS, "IP address for a cluster DNS server. If set, kubelet will configure all containers to use this for DNS resolution in addition to the host's DNS servers")
|
||||
fs.DurationVar(&s.StreamingConnectionIdleTimeout, "streaming-connection-idle-timeout", s.StreamingConnectionIdleTimeout, "Maximum time a streaming connection can be idle before the connection is automatically closed. Example: '5m'")
|
||||
fs.StringSliceVar(&s.NodeLabels, "node-label", []string{}, "add labels when registering the node in the cluster, the flag can be used multiple times (key=value)")
|
||||
fs.StringVar(&s.NodeLabelsFile, "node-labels-file", "", "the path to a yaml or json file containing a series of key pair labels to apply on node registration")
|
||||
fs.DurationVar(&s.NodeStatusUpdateFrequency, "node-status-update-frequency", s.NodeStatusUpdateFrequency, "Specifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller. Default: 10s")
|
||||
fs.IntVar(&s.ImageGCHighThresholdPercent, "image-gc-high-threshold", s.ImageGCHighThresholdPercent, "The percent of disk usage after which image garbage collection is always run. Default: 90%")
|
||||
fs.IntVar(&s.ImageGCLowThresholdPercent, "image-gc-low-threshold", s.ImageGCLowThresholdPercent, "The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. Default: 80%")
|
||||
fs.IntVar(&s.LowDiskSpaceThresholdMB, "low-diskspace-threshold-mb", s.LowDiskSpaceThresholdMB, "The absolute free disk space, in MB, to maintain. When disk space falls below this threshold, new pods would be rejected. Default: 256")
|
||||
fs.StringVar(&s.NetworkPluginName, "network-plugin", s.NetworkPluginName, "<Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle")
|
||||
fs.StringVar(&s.NetworkPluginDir, "network-plugin-dir", s.NetworkPluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for network plugins")
|
||||
fs.StringVar(&s.VolumePluginDir, "volume-plugin-dir", s.VolumePluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for additional third party volume plugins")
|
||||
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services. Empty string for no provider.")
|
||||
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
|
||||
fs.StringVar(&s.ResourceContainer, "resource-container", s.ResourceContainer, "Absolute name of the resource-only container to create and run the Kubelet in (Default: /kubelet).")
|
||||
fs.StringVar(&s.CgroupRoot, "cgroup-root", s.CgroupRoot, "Optional root cgroup to use for pods. This is handled by the container runtime on a best effort basis. Default: '', which means use the container runtime default.")
|
||||
fs.StringVar(&s.ContainerRuntime, "container-runtime", s.ContainerRuntime, "The container runtime to use. Possible values: 'docker', 'rkt'. Default: 'docker'.")
|
||||
fs.StringVar(&s.RktPath, "rkt-path", s.RktPath, "Path of rkt binary. Leave empty to use the first rkt in $PATH. Only used if --container-runtime='rkt'")
|
||||
fs.StringVar(&s.RktStage1Image, "rkt-stage1-image", s.RktStage1Image, "image to use as stage1. Local paths and http/https URLs are supported. If empty, the 'stage1.aci' in the same directory as '--rkt-path' will be used")
|
||||
fs.StringVar(&s.SystemContainer, "system-container", s.SystemContainer, "Optional resource-only container in which to place all non-kernel processes that are not already in a container. Empty for no container. Rolling back the flag requires a reboot. (Default: \"\").")
|
||||
fs.BoolVar(&s.ConfigureCBR0, "configure-cbr0", s.ConfigureCBR0, "If true, kubelet will configure cbr0 based on Node.Spec.PodCIDR.")
|
||||
fs.IntVar(&s.MaxPods, "max-pods", s.MaxPods, "Number of Pods that can run on this Kubelet.")
|
||||
fs.StringVar(&s.DockerExecHandlerName, "docker-exec-handler", s.DockerExecHandlerName, "Handler to use when executing a command in a container. Valid values are 'native' and 'nsenter'. Defaults to 'native'.")
|
||||
fs.StringVar(&s.PodCIDR, "pod-cidr", "", "The CIDR to use for pod IP addresses, only used in standalone mode. In cluster mode, this is obtained from the master.")
|
||||
fs.StringVar(&s.ResolverConfig, "resolv-conf", kubetypes.ResolvConfDefault, "Resolver configuration file used as the basis for the container DNS resolution configuration.")
|
||||
fs.BoolVar(&s.CPUCFSQuota, "cpu-cfs-quota", s.CPUCFSQuota, "Enable CPU CFS quota enforcement for containers that specify CPU limits")
|
||||
// Flags intended for testing, not recommended used in production environments.
|
||||
fs.BoolVar(&s.ReallyCrashForTesting, "really-crash-for-testing", s.ReallyCrashForTesting, "If true, when panics occur crash. Intended for testing.")
|
||||
fs.Float64Var(&s.ChaosChance, "chaos-chance", s.ChaosChance, "If > 0.0, introduce random client errors and latency. Intended for testing. [default=0.0]")
|
||||
fs.BoolVar(&s.Containerized, "containerized", s.Containerized, "Experimental support for running kubelet in a container. Intended for testing. [default=false]")
|
||||
fs.Uint64Var(&s.MaxOpenFiles, "max-open-files", s.MaxOpenFiles, "Number of files that can be opened by Kubelet process. [default=1000000]")
|
||||
fs.BoolVar(&s.ReconcileCIDR, "reconcile-cidr", s.ReconcileCIDR, "Reconcile node CIDR with the CIDR specified by the API server. No-op if register-node or configure-cbr0 is false. [default=true]")
|
||||
fs.BoolVar(&s.RegisterSchedulable, "register-schedulable", s.RegisterSchedulable, "Register the node as schedulable. No-op if register-node is false. [default=true]")
|
||||
fs.Float32Var(&s.KubeAPIQPS, "kube-api-qps", s.KubeAPIQPS, "QPS to use while talking with kubernetes apiserver")
|
||||
fs.IntVar(&s.KubeAPIBurst, "kube-api-burst", s.KubeAPIBurst, "Burst to use while talking with kubernetes apiserver")
|
||||
fs.BoolVar(&s.SerializeImagePulls, "serialize-image-pulls", s.SerializeImagePulls, "Pull images one at a time. We recommend *not* changing the default value on nodes that run docker daemon with version < 1.9 or an Aufs storage backend. Issue #10959 has more details. [default=true]")
|
||||
fs.BoolVar(&s.ExperimentalFlannelOverlay, "experimental-flannel-overlay", s.ExperimentalFlannelOverlay, "Experimental support for starting the kubelet with the default overlay network (flannel). Assumes flanneld is already running in client mode. [default=false]")
|
||||
fs.DurationVar(&s.OutOfDiskTransitionFrequency, "outofdisk-transition-frequency", s.OutOfDiskTransitionFrequency, "Duration for which the kubelet has to wait before transitioning out of out-of-disk node condition status. Default: 5m0s")
|
||||
fs.IPVar(&s.NodeIP, "node-ip", s.NodeIP, "IP address of the node. If set, kubelet will use this IP address for the node")
|
||||
}
|
@ -29,6 +29,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"k8s.io/kubernetes/cmd/kubelet/app/options"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/capabilities"
|
||||
"k8s.io/kubernetes/pkg/client/chaosclient"
|
||||
@ -37,6 +42,7 @@ import (
|
||||
clientauth "k8s.io/kubernetes/pkg/client/unversioned/auth"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
|
||||
clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
|
||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||
"k8s.io/kubernetes/pkg/credentialprovider"
|
||||
"k8s.io/kubernetes/pkg/healthz"
|
||||
"k8s.io/kubernetes/pkg/kubelet"
|
||||
@ -46,10 +52,8 @@ import (
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/kubelet/dockertools"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
"k8s.io/kubernetes/pkg/kubelet/qos"
|
||||
"k8s.io/kubernetes/pkg/kubelet/server"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/master/ports"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/chmod"
|
||||
"k8s.io/kubernetes/pkg/util/chown"
|
||||
@ -58,110 +62,8 @@ import (
|
||||
nodeutil "k8s.io/kubernetes/pkg/util/node"
|
||||
"k8s.io/kubernetes/pkg/util/oom"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultRootDir = "/var/lib/kubelet"
|
||||
experimentalFlannelOverlay = false
|
||||
)
|
||||
|
||||
// KubeletServer encapsulates all of the parameters necessary for starting up
|
||||
// a kubelet. These can either be set via command line or directly.
|
||||
type KubeletServer struct {
|
||||
Address net.IP
|
||||
AllowPrivileged bool
|
||||
APIServerList []string
|
||||
AuthPath util.StringFlag // Deprecated -- use KubeConfig instead
|
||||
CAdvisorPort uint
|
||||
CertDirectory string
|
||||
CgroupRoot string
|
||||
CloudConfigFile string
|
||||
CloudProvider string
|
||||
ClusterDNS net.IP
|
||||
ClusterDomain string
|
||||
Config string
|
||||
ConfigureCBR0 bool
|
||||
ContainerRuntime string
|
||||
CPUCFSQuota bool
|
||||
DockerDaemonContainer string
|
||||
DockerEndpoint string
|
||||
DockerExecHandlerName string
|
||||
EnableDebuggingHandlers bool
|
||||
EnableServer bool
|
||||
EventBurst int
|
||||
EventRecordQPS float32
|
||||
FileCheckFrequency time.Duration
|
||||
HealthzBindAddress net.IP
|
||||
HealthzPort int
|
||||
HostnameOverride string
|
||||
HostNetworkSources string
|
||||
HostPIDSources string
|
||||
HostIPCSources string
|
||||
HTTPCheckFrequency time.Duration
|
||||
ImageGCHighThresholdPercent int
|
||||
ImageGCLowThresholdPercent int
|
||||
KubeConfig util.StringFlag
|
||||
LowDiskSpaceThresholdMB int
|
||||
ManifestURL string
|
||||
ManifestURLHeader string
|
||||
MasterServiceNamespace string
|
||||
MaxContainerCount int
|
||||
MaxOpenFiles uint64
|
||||
MaxPerPodContainerCount int
|
||||
MaxPods int
|
||||
MinimumGCAge time.Duration
|
||||
NetworkPluginDir string
|
||||
VolumePluginDir string
|
||||
NetworkPluginName string
|
||||
NodeLabels []string
|
||||
NodeLabelsFile string
|
||||
NodeStatusUpdateFrequency time.Duration
|
||||
OOMScoreAdj int
|
||||
PodCIDR string
|
||||
PodInfraContainerImage string
|
||||
Port uint
|
||||
ReadOnlyPort uint
|
||||
RegisterNode bool
|
||||
RegisterSchedulable bool
|
||||
RegistryBurst int
|
||||
RegistryPullQPS float64
|
||||
ResolverConfig string
|
||||
ResourceContainer string
|
||||
RktPath string
|
||||
RktStage1Image string
|
||||
RootDirectory string
|
||||
RunOnce bool
|
||||
StandaloneMode bool
|
||||
StreamingConnectionIdleTimeout time.Duration
|
||||
SyncFrequency time.Duration
|
||||
SystemContainer string
|
||||
TLSCertFile string
|
||||
TLSPrivateKeyFile string
|
||||
ReconcileCIDR bool
|
||||
OutOfDiskTransitionFrequency time.Duration
|
||||
|
||||
// Flags intended for testing
|
||||
// Is the kubelet containerized?
|
||||
Containerized bool
|
||||
// Insert a probability of random errors during calls to the master.
|
||||
ChaosChance float64
|
||||
// Crash immediately, rather than eating panics.
|
||||
ReallyCrashForTesting bool
|
||||
|
||||
KubeAPIQPS float32
|
||||
KubeAPIBurst int
|
||||
|
||||
// Pull images one at a time.
|
||||
SerializeImagePulls bool
|
||||
ExperimentalFlannelOverlay bool
|
||||
NodeIP net.IP
|
||||
}
|
||||
|
||||
// bootstrapping interface for kubelet, targets the initialization protocol
|
||||
type KubeletBootstrap interface {
|
||||
BirthCry()
|
||||
@ -175,73 +77,9 @@ type KubeletBootstrap interface {
|
||||
// create and initialize a Kubelet instance
|
||||
type KubeletBuilder func(kc *KubeletConfig) (KubeletBootstrap, *config.PodConfig, error)
|
||||
|
||||
// NewKubeletServer will create a new KubeletServer with default values.
|
||||
func NewKubeletServer() *KubeletServer {
|
||||
return &KubeletServer{
|
||||
Address: net.ParseIP("0.0.0.0"),
|
||||
AuthPath: util.NewStringFlag("/var/lib/kubelet/kubernetes_auth"), // deprecated
|
||||
CAdvisorPort: 4194,
|
||||
CertDirectory: "/var/run/kubernetes",
|
||||
CgroupRoot: "",
|
||||
ConfigureCBR0: false,
|
||||
ContainerRuntime: "docker",
|
||||
CPUCFSQuota: false,
|
||||
DockerDaemonContainer: "/docker-daemon",
|
||||
DockerExecHandlerName: "native",
|
||||
EventBurst: 10,
|
||||
EventRecordQPS: 5.0,
|
||||
EnableDebuggingHandlers: true,
|
||||
EnableServer: true,
|
||||
FileCheckFrequency: 20 * time.Second,
|
||||
HealthzBindAddress: net.ParseIP("127.0.0.1"),
|
||||
HealthzPort: 10248,
|
||||
HostNetworkSources: kubetypes.AllSource,
|
||||
HostPIDSources: kubetypes.AllSource,
|
||||
HostIPCSources: kubetypes.AllSource,
|
||||
HTTPCheckFrequency: 20 * time.Second,
|
||||
ImageGCHighThresholdPercent: 90,
|
||||
ImageGCLowThresholdPercent: 80,
|
||||
KubeConfig: util.NewStringFlag("/var/lib/kubelet/kubeconfig"),
|
||||
LowDiskSpaceThresholdMB: 256,
|
||||
MasterServiceNamespace: api.NamespaceDefault,
|
||||
MaxContainerCount: 100,
|
||||
MaxPerPodContainerCount: 2,
|
||||
MaxOpenFiles: 1000000,
|
||||
MaxPods: 40,
|
||||
MinimumGCAge: 1 * time.Minute,
|
||||
NetworkPluginDir: "/usr/libexec/kubernetes/kubelet-plugins/net/exec/",
|
||||
VolumePluginDir: "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/",
|
||||
NetworkPluginName: "",
|
||||
NodeLabels: []string{},
|
||||
NodeLabelsFile: "",
|
||||
NodeStatusUpdateFrequency: 10 * time.Second,
|
||||
OOMScoreAdj: qos.KubeletOOMScoreAdj,
|
||||
PodInfraContainerImage: dockertools.PodInfraContainerImage,
|
||||
Port: ports.KubeletPort,
|
||||
ReadOnlyPort: ports.KubeletReadOnlyPort,
|
||||
RegisterNode: true, // will be ignored if no apiserver is configured
|
||||
RegisterSchedulable: true,
|
||||
RegistryBurst: 10,
|
||||
RegistryPullQPS: 5.0,
|
||||
ResourceContainer: "/kubelet",
|
||||
RktPath: "",
|
||||
RktStage1Image: "",
|
||||
RootDirectory: defaultRootDir,
|
||||
SerializeImagePulls: true,
|
||||
StreamingConnectionIdleTimeout: 5 * time.Minute,
|
||||
SyncFrequency: 1 * time.Minute,
|
||||
SystemContainer: "",
|
||||
ReconcileCIDR: true,
|
||||
KubeAPIQPS: 5.0,
|
||||
KubeAPIBurst: 10,
|
||||
OutOfDiskTransitionFrequency: 5 * time.Minute,
|
||||
ExperimentalFlannelOverlay: experimentalFlannelOverlay,
|
||||
}
|
||||
}
|
||||
|
||||
// NewKubeletCommand creates a *cobra.Command object with default parameters
|
||||
func NewKubeletCommand() *cobra.Command {
|
||||
s := NewKubeletServer()
|
||||
s := options.NewKubeletServer()
|
||||
s.AddFlags(pflag.CommandLine)
|
||||
cmd := &cobra.Command{
|
||||
Use: "kubelet",
|
||||
@ -269,96 +107,9 @@ HTTP server: The kubelet can also listen for HTTP and respond to a simple API
|
||||
return cmd
|
||||
}
|
||||
|
||||
// AddFlags adds flags for a specific KubeletServer to the specified FlagSet
|
||||
func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&s.Config, "config", s.Config, "Path to the config file or directory of files")
|
||||
fs.DurationVar(&s.SyncFrequency, "sync-frequency", s.SyncFrequency, "Max period between synchronizing running containers and config")
|
||||
fs.DurationVar(&s.FileCheckFrequency, "file-check-frequency", s.FileCheckFrequency, "Duration between checking config files for new data")
|
||||
fs.DurationVar(&s.HTTPCheckFrequency, "http-check-frequency", s.HTTPCheckFrequency, "Duration between checking http for new data")
|
||||
fs.StringVar(&s.ManifestURL, "manifest-url", s.ManifestURL, "URL for accessing the container manifest")
|
||||
fs.StringVar(&s.ManifestURLHeader, "manifest-url-header", s.ManifestURLHeader, "HTTP header to use when accessing the manifest URL, with the key separated from the value with a ':', as in 'key:value'")
|
||||
fs.BoolVar(&s.EnableServer, "enable-server", s.EnableServer, "Enable the Kubelet's server")
|
||||
fs.IPVar(&s.Address, "address", s.Address, "The IP address for the Kubelet to serve on (set to 0.0.0.0 for all interfaces)")
|
||||
fs.UintVar(&s.Port, "port", s.Port, "The port for the Kubelet to serve on.")
|
||||
fs.UintVar(&s.ReadOnlyPort, "read-only-port", s.ReadOnlyPort, "The read-only port for the Kubelet to serve on with no authentication/authorization (set to 0 to disable)")
|
||||
fs.StringVar(&s.TLSCertFile, "tls-cert-file", s.TLSCertFile, ""+
|
||||
"File containing x509 Certificate for HTTPS. (CA cert, if any, concatenated after server cert). "+
|
||||
"If --tls-cert-file and --tls-private-key-file are not provided, a self-signed certificate and key "+
|
||||
"are generated for the public address and saved to the directory passed to --cert-dir.")
|
||||
fs.StringVar(&s.TLSPrivateKeyFile, "tls-private-key-file", s.TLSPrivateKeyFile, "File containing x509 private key matching --tls-cert-file.")
|
||||
fs.StringVar(&s.CertDirectory, "cert-dir", s.CertDirectory, "The directory where the TLS certs are located (by default /var/run/kubernetes). "+
|
||||
"If --tls-cert-file and --tls-private-key-file are provided, this flag will be ignored.")
|
||||
fs.StringVar(&s.HostnameOverride, "hostname-override", s.HostnameOverride, "If non-empty, will use this string as identification instead of the actual hostname.")
|
||||
fs.StringVar(&s.PodInfraContainerImage, "pod-infra-container-image", s.PodInfraContainerImage, "The image whose network/ipc namespaces containers in each pod will use.")
|
||||
fs.StringVar(&s.DockerEndpoint, "docker-endpoint", s.DockerEndpoint, "If non-empty, use this for the docker endpoint to communicate with")
|
||||
fs.StringVar(&s.RootDirectory, "root-dir", s.RootDirectory, "Directory path for managing kubelet files (volume mounts,etc).")
|
||||
fs.BoolVar(&s.AllowPrivileged, "allow-privileged", s.AllowPrivileged, "If true, allow containers to request privileged mode. [default=false]")
|
||||
fs.StringVar(&s.HostNetworkSources, "host-network-sources", s.HostNetworkSources, "Comma-separated list of sources from which the Kubelet allows pods to use of host network. [default=\"*\"]")
|
||||
fs.StringVar(&s.HostPIDSources, "host-pid-sources", s.HostPIDSources, "Comma-separated list of sources from which the Kubelet allows pods to use the host pid namespace. [default=\"*\"]")
|
||||
fs.StringVar(&s.HostIPCSources, "host-ipc-sources", s.HostIPCSources, "Comma-separated list of sources from which the Kubelet allows pods to use the host ipc namespace. [default=\"*\"]")
|
||||
fs.Float64Var(&s.RegistryPullQPS, "registry-qps", s.RegistryPullQPS, "If > 0, limit registry pull QPS to this value. If 0, unlimited. [default=5.0]")
|
||||
fs.IntVar(&s.RegistryBurst, "registry-burst", s.RegistryBurst, "Maximum size of a bursty pulls, temporarily allows pulls to burst to this number, while still not exceeding registry-qps. Only used if --registry-qps > 0")
|
||||
fs.Float32Var(&s.EventRecordQPS, "event-qps", s.EventRecordQPS, "If > 0, limit event creations per second to this value. If 0, unlimited.")
|
||||
fs.IntVar(&s.EventBurst, "event-burst", s.EventBurst, "Maximum size of a bursty event records, temporarily allows event records to burst to this number, while still not exceeding event-qps. Only used if --event-qps > 0")
|
||||
fs.BoolVar(&s.RunOnce, "runonce", s.RunOnce, "If true, exit after spawning pods from local manifests or remote urls. Exclusive with --api-servers, and --enable-server")
|
||||
fs.BoolVar(&s.EnableDebuggingHandlers, "enable-debugging-handlers", s.EnableDebuggingHandlers, "Enables server endpoints for log collection and local running of containers and commands")
|
||||
fs.DurationVar(&s.MinimumGCAge, "minimum-container-ttl-duration", s.MinimumGCAge, "Minimum age for a finished container before it is garbage collected. Examples: '300ms', '10s' or '2h45m'")
|
||||
fs.IntVar(&s.MaxPerPodContainerCount, "maximum-dead-containers-per-container", s.MaxPerPodContainerCount, "Maximum number of old instances to retain per container. Each container takes up some disk space. Default: 2.")
|
||||
fs.IntVar(&s.MaxContainerCount, "maximum-dead-containers", s.MaxContainerCount, "Maximum number of old instances of containers to retain globally. Each container takes up some disk space. Default: 100.")
|
||||
fs.Var(&s.AuthPath, "auth-path", "Path to .kubernetes_auth file, specifying how to authenticate to API server.")
|
||||
fs.MarkDeprecated("auth-path", "will be removed in a future version")
|
||||
fs.Var(&s.KubeConfig, "kubeconfig", "Path to a kubeconfig file, specifying how to authenticate to API server (the master location is set by the api-servers flag).")
|
||||
fs.UintVar(&s.CAdvisorPort, "cadvisor-port", s.CAdvisorPort, "The port of the localhost cAdvisor endpoint")
|
||||
fs.IntVar(&s.HealthzPort, "healthz-port", s.HealthzPort, "The port of the localhost healthz endpoint")
|
||||
fs.IPVar(&s.HealthzBindAddress, "healthz-bind-address", s.HealthzBindAddress, "The IP address for the healthz server to serve on, defaulting to 127.0.0.1 (set to 0.0.0.0 for all interfaces)")
|
||||
fs.IntVar(&s.OOMScoreAdj, "oom-score-adj", s.OOMScoreAdj, "The oom-score-adj value for kubelet process. Values must be within the range [-1000, 1000]")
|
||||
fs.StringSliceVar(&s.APIServerList, "api-servers", []string{}, "List of Kubernetes API servers for publishing events, and reading pods and services. (ip:port), comma separated.")
|
||||
fs.BoolVar(&s.RegisterNode, "register-node", s.RegisterNode, "Register the node with the apiserver (defaults to true if --api-servers is set)")
|
||||
fs.StringVar(&s.ClusterDomain, "cluster-domain", s.ClusterDomain, "Domain for this cluster. If set, kubelet will configure all containers to search this domain in addition to the host's search domains")
|
||||
fs.StringVar(&s.MasterServiceNamespace, "master-service-namespace", s.MasterServiceNamespace, "The namespace from which the kubernetes master services should be injected into pods")
|
||||
fs.IPVar(&s.ClusterDNS, "cluster-dns", s.ClusterDNS, "IP address for a cluster DNS server. If set, kubelet will configure all containers to use this for DNS resolution in addition to the host's DNS servers")
|
||||
fs.DurationVar(&s.StreamingConnectionIdleTimeout, "streaming-connection-idle-timeout", s.StreamingConnectionIdleTimeout, "Maximum time a streaming connection can be idle before the connection is automatically closed. Example: '5m'")
|
||||
fs.StringSliceVar(&s.NodeLabels, "node-label", []string{}, "add labels when registering the node in the cluster, the flag can be used multiple times (key=value)")
|
||||
fs.StringVar(&s.NodeLabelsFile, "node-labels-file", "", "the path to a yaml or json file containing a series of key pair labels to apply on node registration")
|
||||
fs.DurationVar(&s.NodeStatusUpdateFrequency, "node-status-update-frequency", s.NodeStatusUpdateFrequency, "Specifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller. Default: 10s")
|
||||
fs.IntVar(&s.ImageGCHighThresholdPercent, "image-gc-high-threshold", s.ImageGCHighThresholdPercent, "The percent of disk usage after which image garbage collection is always run. Default: 90%")
|
||||
fs.IntVar(&s.ImageGCLowThresholdPercent, "image-gc-low-threshold", s.ImageGCLowThresholdPercent, "The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. Default: 80%")
|
||||
fs.IntVar(&s.LowDiskSpaceThresholdMB, "low-diskspace-threshold-mb", s.LowDiskSpaceThresholdMB, "The absolute free disk space, in MB, to maintain. When disk space falls below this threshold, new pods would be rejected. Default: 256")
|
||||
fs.StringVar(&s.NetworkPluginName, "network-plugin", s.NetworkPluginName, "<Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle")
|
||||
fs.StringVar(&s.NetworkPluginDir, "network-plugin-dir", s.NetworkPluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for network plugins")
|
||||
fs.StringVar(&s.VolumePluginDir, "volume-plugin-dir", s.VolumePluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for additional third party volume plugins")
|
||||
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services. Empty string for no provider.")
|
||||
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
|
||||
fs.StringVar(&s.ResourceContainer, "resource-container", s.ResourceContainer, "Absolute name of the resource-only container to create and run the Kubelet in (Default: /kubelet).")
|
||||
fs.StringVar(&s.CgroupRoot, "cgroup-root", s.CgroupRoot, "Optional root cgroup to use for pods. This is handled by the container runtime on a best effort basis. Default: '', which means use the container runtime default.")
|
||||
fs.StringVar(&s.ContainerRuntime, "container-runtime", s.ContainerRuntime, "The container runtime to use. Possible values: 'docker', 'rkt'. Default: 'docker'.")
|
||||
fs.StringVar(&s.RktPath, "rkt-path", s.RktPath, "Path of rkt binary. Leave empty to use the first rkt in $PATH. Only used if --container-runtime='rkt'")
|
||||
fs.StringVar(&s.RktStage1Image, "rkt-stage1-image", s.RktStage1Image, "image to use as stage1. Local paths and http/https URLs are supported. If empty, the 'stage1.aci' in the same directory as '--rkt-path' will be used")
|
||||
fs.StringVar(&s.SystemContainer, "system-container", s.SystemContainer, "Optional resource-only container in which to place all non-kernel processes that are not already in a container. Empty for no container. Rolling back the flag requires a reboot. (Default: \"\").")
|
||||
fs.BoolVar(&s.ConfigureCBR0, "configure-cbr0", s.ConfigureCBR0, "If true, kubelet will configure cbr0 based on Node.Spec.PodCIDR.")
|
||||
fs.IntVar(&s.MaxPods, "max-pods", s.MaxPods, "Number of Pods that can run on this Kubelet.")
|
||||
fs.StringVar(&s.DockerExecHandlerName, "docker-exec-handler", s.DockerExecHandlerName, "Handler to use when executing a command in a container. Valid values are 'native' and 'nsenter'. Defaults to 'native'.")
|
||||
fs.StringVar(&s.PodCIDR, "pod-cidr", "", "The CIDR to use for pod IP addresses, only used in standalone mode. In cluster mode, this is obtained from the master.")
|
||||
fs.StringVar(&s.ResolverConfig, "resolv-conf", kubelet.ResolvConfDefault, "Resolver configuration file used as the basis for the container DNS resolution configuration.")
|
||||
fs.BoolVar(&s.CPUCFSQuota, "cpu-cfs-quota", s.CPUCFSQuota, "Enable CPU CFS quota enforcement for containers that specify CPU limits")
|
||||
// Flags intended for testing, not recommended used in production environments.
|
||||
fs.BoolVar(&s.ReallyCrashForTesting, "really-crash-for-testing", s.ReallyCrashForTesting, "If true, when panics occur crash. Intended for testing.")
|
||||
fs.Float64Var(&s.ChaosChance, "chaos-chance", s.ChaosChance, "If > 0.0, introduce random client errors and latency. Intended for testing. [default=0.0]")
|
||||
fs.BoolVar(&s.Containerized, "containerized", s.Containerized, "Experimental support for running kubelet in a container. Intended for testing. [default=false]")
|
||||
fs.Uint64Var(&s.MaxOpenFiles, "max-open-files", s.MaxOpenFiles, "Number of files that can be opened by Kubelet process. [default=1000000]")
|
||||
fs.BoolVar(&s.ReconcileCIDR, "reconcile-cidr", s.ReconcileCIDR, "Reconcile node CIDR with the CIDR specified by the API server. No-op if register-node or configure-cbr0 is false. [default=true]")
|
||||
fs.BoolVar(&s.RegisterSchedulable, "register-schedulable", s.RegisterSchedulable, "Register the node as schedulable. No-op if register-node is false. [default=true]")
|
||||
fs.Float32Var(&s.KubeAPIQPS, "kube-api-qps", s.KubeAPIQPS, "QPS to use while talking with kubernetes apiserver")
|
||||
fs.IntVar(&s.KubeAPIBurst, "kube-api-burst", s.KubeAPIBurst, "Burst to use while talking with kubernetes apiserver")
|
||||
fs.BoolVar(&s.SerializeImagePulls, "serialize-image-pulls", s.SerializeImagePulls, "Pull images one at a time. We recommend *not* changing the default value on nodes that run docker daemon with version < 1.9 or an Aufs storage backend. Issue #10959 has more details. [default=true]")
|
||||
fs.DurationVar(&s.OutOfDiskTransitionFrequency, "outofdisk-transition-frequency", s.OutOfDiskTransitionFrequency, "Duration for which the kubelet has to wait before transitioning out of out-of-disk node condition status. Default: 5m0s")
|
||||
fs.BoolVar(&s.ExperimentalFlannelOverlay, "experimental-flannel-overlay", s.ExperimentalFlannelOverlay, "Experimental support for starting the kubelet with the default overlay network (flannel). Assumes flanneld is already running in client mode. [default=false]")
|
||||
fs.IPVar(&s.NodeIP, "node-ip", s.NodeIP, "IP address of the node. If set, kubelet will use this IP address for the node")
|
||||
}
|
||||
|
||||
// UnsecuredKubeletConfig returns a KubeletConfig suitable for being run, or an error if the server setup
|
||||
// is not valid. It will not start any background processes, and does not include authentication/authorization
|
||||
func (s *KubeletServer) UnsecuredKubeletConfig() (*KubeletConfig, error) {
|
||||
func UnsecuredKubeletConfig(s *options.KubeletServer) (*KubeletConfig, error) {
|
||||
hostNetworkSources, err := kubetypes.GetValidatedSources(strings.Split(s.HostNetworkSources, ","))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -385,7 +136,7 @@ func (s *KubeletServer) UnsecuredKubeletConfig() (*KubeletConfig, error) {
|
||||
chmodRunner := chmod.New()
|
||||
chownRunner := chown.New()
|
||||
|
||||
tlsOptions, err := s.InitializeTLS()
|
||||
tlsOptions, err := InitializeTLS(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -502,16 +253,16 @@ func (s *KubeletServer) UnsecuredKubeletConfig() (*KubeletConfig, error) {
|
||||
// The kcfg argument may be nil - if so, it is initialized from the settings on KubeletServer.
|
||||
// Otherwise, the caller is assumed to have set up the KubeletConfig object and all defaults
|
||||
// will be ignored.
|
||||
func (s *KubeletServer) Run(kcfg *KubeletConfig) error {
|
||||
func Run(s *options.KubeletServer, kcfg *KubeletConfig) error {
|
||||
var err error
|
||||
if kcfg == nil {
|
||||
cfg, err := s.UnsecuredKubeletConfig()
|
||||
cfg, err := UnsecuredKubeletConfig(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
kcfg = cfg
|
||||
|
||||
clientConfig, err := s.CreateAPIServerClientConfig()
|
||||
clientConfig, err := CreateAPIServerClientConfig(s)
|
||||
if err == nil {
|
||||
kcfg.KubeClient, err = client.New(clientConfig)
|
||||
|
||||
@ -584,7 +335,7 @@ func (s *KubeletServer) Run(kcfg *KubeletConfig) error {
|
||||
|
||||
// InitializeTLS checks for a configured TLSCertFile and TLSPrivateKeyFile: if unspecified a new self-signed
|
||||
// certificate and key file are generated. Returns a configured server.TLSOptions object.
|
||||
func (s *KubeletServer) InitializeTLS() (*server.TLSOptions, error) {
|
||||
func InitializeTLS(s *options.KubeletServer) (*server.TLSOptions, error) {
|
||||
if s.TLSCertFile == "" && s.TLSPrivateKeyFile == "" {
|
||||
s.TLSCertFile = path.Join(s.CertDirectory, "kubelet.crt")
|
||||
s.TLSPrivateKeyFile = path.Join(s.CertDirectory, "kubelet.key")
|
||||
@ -606,7 +357,7 @@ func (s *KubeletServer) InitializeTLS() (*server.TLSOptions, error) {
|
||||
return tlsOptions, nil
|
||||
}
|
||||
|
||||
func (s *KubeletServer) authPathClientConfig(useDefaults bool) (*client.Config, error) {
|
||||
func authPathClientConfig(s *options.KubeletServer, useDefaults bool) (*client.Config, error) {
|
||||
authInfo, err := clientauth.LoadFromFile(s.AuthPath.Value())
|
||||
if err != nil && !useDefaults {
|
||||
return nil, err
|
||||
@ -628,7 +379,7 @@ func (s *KubeletServer) authPathClientConfig(useDefaults bool) (*client.Config,
|
||||
return &authConfig, nil
|
||||
}
|
||||
|
||||
func (s *KubeletServer) kubeconfigClientConfig() (*client.Config, error) {
|
||||
func kubeconfigClientConfig(s *options.KubeletServer) (*client.Config, error) {
|
||||
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
||||
&clientcmd.ClientConfigLoadingRules{ExplicitPath: s.KubeConfig.Value()},
|
||||
&clientcmd.ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: s.APIServerList[0]}}).ClientConfig()
|
||||
@ -640,20 +391,21 @@ func (s *KubeletServer) kubeconfigClientConfig() (*client.Config, error) {
|
||||
// to load the default kubeconfig file, then the default auth path file, and
|
||||
// fall back to the default auth (none) without an error.
|
||||
// TODO(roberthbailey): Remove support for --auth-path
|
||||
func (s *KubeletServer) createClientConfig() (*client.Config, error) {
|
||||
func createClientConfig(s *options.KubeletServer) (*client.Config, error) {
|
||||
if s.KubeConfig.Provided() && s.AuthPath.Provided() {
|
||||
return nil, fmt.Errorf("cannot specify both --kubeconfig and --auth-path")
|
||||
}
|
||||
if s.KubeConfig.Provided() {
|
||||
return s.kubeconfigClientConfig()
|
||||
} else if s.AuthPath.Provided() {
|
||||
return s.authPathClientConfig(false)
|
||||
return kubeconfigClientConfig(s)
|
||||
}
|
||||
if s.AuthPath.Provided() {
|
||||
return authPathClientConfig(s, false)
|
||||
}
|
||||
// Try the kubeconfig default first, falling back to the auth path default.
|
||||
clientConfig, err := s.kubeconfigClientConfig()
|
||||
clientConfig, err := kubeconfigClientConfig(s)
|
||||
if err != nil {
|
||||
glog.Warningf("Could not load kubeconfig file %s: %v. Trying auth path instead.", s.KubeConfig, err)
|
||||
return s.authPathClientConfig(true)
|
||||
return authPathClientConfig(s, true)
|
||||
}
|
||||
return clientConfig, nil
|
||||
}
|
||||
@ -662,7 +414,7 @@ func (s *KubeletServer) createClientConfig() (*client.Config, error) {
|
||||
// including api-server-list, via createClientConfig and then injects chaos into
|
||||
// the configuration via addChaosToClientConfig. This func is exported to support
|
||||
// integration with third party kubelet extensions (e.g. kubernetes-mesos).
|
||||
func (s *KubeletServer) CreateAPIServerClientConfig() (*client.Config, error) {
|
||||
func CreateAPIServerClientConfig(s *options.KubeletServer) (*client.Config, error) {
|
||||
if len(s.APIServerList) < 1 {
|
||||
return nil, fmt.Errorf("no api servers specified")
|
||||
}
|
||||
@ -671,7 +423,7 @@ func (s *KubeletServer) CreateAPIServerClientConfig() (*client.Config, error) {
|
||||
glog.Infof("Multiple api servers specified. Picking first one")
|
||||
}
|
||||
|
||||
clientConfig, err := s.createClientConfig()
|
||||
clientConfig, err := createClientConfig(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -680,12 +432,12 @@ func (s *KubeletServer) CreateAPIServerClientConfig() (*client.Config, error) {
|
||||
clientConfig.QPS = s.KubeAPIQPS
|
||||
clientConfig.Burst = s.KubeAPIBurst
|
||||
|
||||
s.addChaosToClientConfig(clientConfig)
|
||||
addChaosToClientConfig(s, clientConfig)
|
||||
return clientConfig, nil
|
||||
}
|
||||
|
||||
// addChaosToClientConfig injects random errors into client connections if configured.
|
||||
func (s *KubeletServer) addChaosToClientConfig(config *client.Config) {
|
||||
func addChaosToClientConfig(s *options.KubeletServer, config *client.Config) {
|
||||
if s.ChaosChance != 0.0 {
|
||||
config.WrapTransport = func(rt http.RoundTripper) http.RoundTripper {
|
||||
seed := chaosclient.NewSeed(1)
|
||||
@ -756,14 +508,14 @@ func SimpleKubelet(client *client.Client,
|
||||
NodeStatusUpdateFrequency: nodeStatusUpdateFrequency,
|
||||
OOMAdjuster: oom.NewFakeOOMAdjuster(),
|
||||
OSInterface: osInterface,
|
||||
PodInfraContainerImage: dockertools.PodInfraContainerImage,
|
||||
PodInfraContainerImage: kubetypes.PodInfraContainerImage,
|
||||
Port: port,
|
||||
ReadOnlyPort: readOnlyPort,
|
||||
RegisterNode: true,
|
||||
RegisterSchedulable: true,
|
||||
RegistryBurst: 10,
|
||||
RegistryPullQPS: 5.0,
|
||||
ResolverConfig: kubelet.ResolvConfDefault,
|
||||
ResolverConfig: kubetypes.ResolvConfDefault,
|
||||
ResourceContainer: "/kubelet",
|
||||
RootDirectory: rootDir,
|
||||
SerializeImagePulls: true,
|
||||
|
@ -25,7 +25,8 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app"
|
||||
"k8s.io/kubernetes/cmd/kubelet/app"
|
||||
"k8s.io/kubernetes/cmd/kubelet/app/options"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/version/verflag"
|
||||
|
||||
@ -34,7 +35,7 @@ import (
|
||||
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
s := kubeletapp.NewKubeletServer()
|
||||
s := options.NewKubeletServer()
|
||||
s.AddFlags(pflag.CommandLine)
|
||||
|
||||
util.InitFlags()
|
||||
@ -43,7 +44,7 @@ func main() {
|
||||
|
||||
verflag.PrintAndExitIfRequested()
|
||||
|
||||
if err := s.Run(nil); err != nil {
|
||||
if err := app.Run(s, nil); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
bindings "github.com/mesos/mesos-go/executor"
|
||||
"github.com/spf13/pflag"
|
||||
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app"
|
||||
"k8s.io/kubernetes/cmd/kubelet/app/options"
|
||||
"k8s.io/kubernetes/contrib/mesos/pkg/executor"
|
||||
"k8s.io/kubernetes/contrib/mesos/pkg/executor/config"
|
||||
"k8s.io/kubernetes/contrib/mesos/pkg/hyperkube"
|
||||
@ -42,7 +43,7 @@ import (
|
||||
)
|
||||
|
||||
type KubeletExecutorServer struct {
|
||||
*kubeletapp.KubeletServer
|
||||
*options.KubeletServer
|
||||
SuicideTimeout time.Duration
|
||||
LaunchGracePeriod time.Duration
|
||||
|
||||
@ -54,7 +55,7 @@ type KubeletExecutorServer struct {
|
||||
|
||||
func NewKubeletExecutorServer() *KubeletExecutorServer {
|
||||
k := &KubeletExecutorServer{
|
||||
KubeletServer: kubeletapp.NewKubeletServer(),
|
||||
KubeletServer: options.NewKubeletServer(),
|
||||
SuicideTimeout: config.DefaultSuicideTimeout,
|
||||
LaunchGracePeriod: config.DefaultLaunchGracePeriod,
|
||||
kletReady: make(chan struct{}),
|
||||
@ -156,7 +157,7 @@ func (s *KubeletExecutorServer) runKubelet(
|
||||
}
|
||||
}()
|
||||
|
||||
kcfg, err := s.UnsecuredKubeletConfig()
|
||||
kcfg, err := kubeletapp.UnsecuredKubeletConfig(s.KubeletServer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -186,7 +187,7 @@ func (s *KubeletExecutorServer) runKubelet(
|
||||
kcfg.KubeClient = apiclient
|
||||
|
||||
// taken from KubeletServer#Run(*KubeletConfig)
|
||||
eventClientConfig, err := s.CreateAPIServerClientConfig()
|
||||
eventClientConfig, err := kubeletapp.CreateAPIServerClientConfig(s.KubeletServer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -242,7 +243,7 @@ func (s *KubeletExecutorServer) runKubelet(
|
||||
// initialize the cloud provider. We explicitly wouldn't want
|
||||
// that because then every kubelet instance would query the master
|
||||
// state.json which does not scale.
|
||||
err = s.KubeletServer.Run(kcfg)
|
||||
err = kubeletapp.Run(s.KubeletServer, kcfg)
|
||||
|
||||
return
|
||||
}
|
||||
@ -263,7 +264,7 @@ func (s *KubeletExecutorServer) Run(hks hyperkube.Interface, _ []string) error {
|
||||
|
||||
// create apiserver client
|
||||
var apiclient *client.Client
|
||||
clientConfig, err := s.CreateAPIServerClientConfig()
|
||||
clientConfig, err := kubeletapp.CreateAPIServerClientConfig(s.KubeletServer)
|
||||
if err == nil {
|
||||
apiclient, err = client.New(clientConfig)
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app"
|
||||
exservice "k8s.io/kubernetes/contrib/mesos/pkg/executor/service"
|
||||
"k8s.io/kubernetes/contrib/mesos/pkg/hyperkube"
|
||||
"k8s.io/kubernetes/contrib/mesos/pkg/minion/config"
|
||||
@ -250,7 +251,7 @@ func (ms *MinionServer) Run(hks hyperkube.Interface, _ []string) error {
|
||||
}
|
||||
|
||||
// create apiserver client
|
||||
clientConfig, err := ms.KubeletExecutorServer.CreateAPIServerClientConfig()
|
||||
clientConfig, err := kubeletapp.CreateAPIServerClientConfig(ms.KubeletExecutorServer.KubeletServer)
|
||||
if err != nil {
|
||||
// required for k8sm since we need to send api.Binding information
|
||||
// back to the apiserver
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"time"
|
||||
|
||||
log "github.com/golang/glog"
|
||||
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app"
|
||||
"k8s.io/kubernetes/cmd/kubelet/app/options"
|
||||
"k8s.io/kubernetes/contrib/mesos/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
@ -47,7 +47,7 @@ type StatusUpdater struct {
|
||||
}
|
||||
|
||||
func NewStatusUpdater(client *client.Client, relistPeriod time.Duration, nowFunc func() time.Time) *StatusUpdater {
|
||||
kubecfg := kubeletapp.NewKubeletServer() // only create to get the config, this is without side-effects
|
||||
kubecfg := options.NewKubeletServer() // only create to get the config, this is without side-effects
|
||||
return &StatusUpdater{
|
||||
client: client,
|
||||
relistPeriod: relistPeriod,
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/kubernetes/cmd/kube-controller-manager/app"
|
||||
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app"
|
||||
cmapp "k8s.io/kubernetes/cmd/kube-controller-manager/app"
|
||||
"k8s.io/kubernetes/cmd/kubelet/app/options"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
)
|
||||
@ -46,8 +46,8 @@ func Test_nodeWithUpdatedStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
cm := app.NewCMServer()
|
||||
kubecfg := kubeletapp.NewKubeletServer()
|
||||
cm := cmapp.NewCMServer()
|
||||
kubecfg := options.NewKubeletServer()
|
||||
assert.True(t, kubecfg.NodeStatusUpdateFrequency*3 < cm.NodeMonitorGracePeriod) // sanity check for defaults
|
||||
|
||||
n := testNode(0, api.ConditionTrue, "KubeletReady")
|
||||
|
@ -216,6 +216,16 @@ func (c *ContainerID) UnmarshalJSON(data []byte) error {
|
||||
return c.ParseString(string(data))
|
||||
}
|
||||
|
||||
// DockerID is an ID of docker container. It is a type to make it clear when we're working with docker container Ids
|
||||
type DockerID string
|
||||
|
||||
func (id DockerID) ContainerID() ContainerID {
|
||||
return ContainerID{
|
||||
Type: "docker",
|
||||
ID: string(id),
|
||||
}
|
||||
}
|
||||
|
||||
type ContainerState string
|
||||
|
||||
const (
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
)
|
||||
|
||||
// This file contains helper functions to convert docker API types to runtime
|
||||
@ -55,7 +54,7 @@ func toRuntimeContainer(c *docker.APIContainers) (*kubecontainer.Container, erro
|
||||
}
|
||||
|
||||
return &kubecontainer.Container{
|
||||
ID: kubetypes.DockerID(c.ID).ContainerID(),
|
||||
ID: kubecontainer.DockerID(c.ID).ContainerID(),
|
||||
Name: dockerName.ContainerName,
|
||||
Image: c.Image,
|
||||
Hash: hash,
|
||||
|
@ -38,10 +38,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
PodInfraContainerName = leaky.PodInfraContainerName
|
||||
DockerPrefix = "docker://"
|
||||
PodInfraContainerImage = "gcr.io/google_containers/pause:2.0"
|
||||
LogSuffix = "log"
|
||||
PodInfraContainerName = leaky.PodInfraContainerName
|
||||
DockerPrefix = "docker://"
|
||||
LogSuffix = "log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -189,7 +189,7 @@ func TestExecSupportNotExists(t *testing.T) {
|
||||
|
||||
func TestDockerContainerCommand(t *testing.T) {
|
||||
runner := &DockerManager{}
|
||||
containerID := kubetypes.DockerID("1234").ContainerID()
|
||||
containerID := kubecontainer.DockerID("1234").ContainerID()
|
||||
command := []string{"ls"}
|
||||
cmd, _ := runner.getRunInContainerCommand(containerID, command)
|
||||
if cmd.Dir != "/var/lib/docker/execdriver/native/"+containerID.ID {
|
||||
@ -578,13 +578,13 @@ func TestFindContainersByPod(t *testing.T) {
|
||||
Namespace: "ns",
|
||||
Containers: []*kubecontainer.Container{
|
||||
{
|
||||
ID: kubetypes.DockerID("foobar").ContainerID(),
|
||||
ID: kubecontainer.DockerID("foobar").ContainerID(),
|
||||
Name: "foobar",
|
||||
Hash: 0x1234,
|
||||
State: kubecontainer.ContainerStateUnknown,
|
||||
},
|
||||
{
|
||||
ID: kubetypes.DockerID("baz").ContainerID(),
|
||||
ID: kubecontainer.DockerID("baz").ContainerID(),
|
||||
Name: "baz",
|
||||
Hash: 0x1234,
|
||||
State: kubecontainer.ContainerStateUnknown,
|
||||
@ -597,7 +597,7 @@ func TestFindContainersByPod(t *testing.T) {
|
||||
Namespace: "ns",
|
||||
Containers: []*kubecontainer.Container{
|
||||
{
|
||||
ID: kubetypes.DockerID("barbar").ContainerID(),
|
||||
ID: kubecontainer.DockerID("barbar").ContainerID(),
|
||||
Name: "barbar",
|
||||
Hash: 0x1234,
|
||||
State: kubecontainer.ContainerStateUnknown,
|
||||
@ -639,19 +639,19 @@ func TestFindContainersByPod(t *testing.T) {
|
||||
Namespace: "ns",
|
||||
Containers: []*kubecontainer.Container{
|
||||
{
|
||||
ID: kubetypes.DockerID("foobar").ContainerID(),
|
||||
ID: kubecontainer.DockerID("foobar").ContainerID(),
|
||||
Name: "foobar",
|
||||
Hash: 0x1234,
|
||||
State: kubecontainer.ContainerStateUnknown,
|
||||
},
|
||||
{
|
||||
ID: kubetypes.DockerID("barfoo").ContainerID(),
|
||||
ID: kubecontainer.DockerID("barfoo").ContainerID(),
|
||||
Name: "barfoo",
|
||||
Hash: 0x1234,
|
||||
State: kubecontainer.ContainerStateUnknown,
|
||||
},
|
||||
{
|
||||
ID: kubetypes.DockerID("baz").ContainerID(),
|
||||
ID: kubecontainer.DockerID("baz").ContainerID(),
|
||||
Name: "baz",
|
||||
Hash: 0x1234,
|
||||
State: kubecontainer.ContainerStateUnknown,
|
||||
@ -664,7 +664,7 @@ func TestFindContainersByPod(t *testing.T) {
|
||||
Namespace: "ns",
|
||||
Containers: []*kubecontainer.Container{
|
||||
{
|
||||
ID: kubetypes.DockerID("barbar").ContainerID(),
|
||||
ID: kubecontainer.DockerID("barbar").ContainerID(),
|
||||
Name: "barbar",
|
||||
Hash: 0x1234,
|
||||
State: kubecontainer.ContainerStateUnknown,
|
||||
@ -677,7 +677,7 @@ func TestFindContainersByPod(t *testing.T) {
|
||||
Namespace: "ns",
|
||||
Containers: []*kubecontainer.Container{
|
||||
{
|
||||
ID: kubetypes.DockerID("bazbaz").ContainerID(),
|
||||
ID: kubecontainer.DockerID("bazbaz").ContainerID(),
|
||||
Name: "bazbaz",
|
||||
Hash: 0x1234,
|
||||
State: kubecontainer.ContainerStateUnknown,
|
||||
@ -696,7 +696,7 @@ func TestFindContainersByPod(t *testing.T) {
|
||||
fakeClient := &FakeDockerClient{}
|
||||
np, _ := network.InitNetworkPlugin([]network.NetworkPlugin{}, "", network.NewFakeHost(nil))
|
||||
// image back-off is set to nil, this test shouldnt pull images
|
||||
containerManager := NewFakeDockerManager(fakeClient, &record.FakeRecorder{}, nil, nil, &cadvisorapi.MachineInfo{}, PodInfraContainerImage, 0, 0, "", kubecontainer.FakeOS{}, np, nil, nil, nil)
|
||||
containerManager := NewFakeDockerManager(fakeClient, &record.FakeRecorder{}, nil, nil, &cadvisorapi.MachineInfo{}, kubetypes.PodInfraContainerImage, 0, 0, "", kubecontainer.FakeOS{}, np, nil, nil, nil)
|
||||
for i, test := range tests {
|
||||
fakeClient.ContainerList = test.containerList
|
||||
fakeClient.ExitedContainerList = test.exitedContainerList
|
||||
|
@ -319,7 +319,7 @@ func (dm *DockerManager) determineContainerIP(podNamespace, podName string, cont
|
||||
}
|
||||
|
||||
if dm.networkPlugin.Name() != network.DefaultPluginName {
|
||||
netStatus, err := dm.networkPlugin.Status(podNamespace, podName, kubetypes.DockerID(container.ID))
|
||||
netStatus, err := dm.networkPlugin.Status(podNamespace, podName, kubecontainer.DockerID(container.ID))
|
||||
if err != nil {
|
||||
glog.Errorf("NetworkPlugin %s failed on the status hook for pod '%s' - %v", dm.networkPlugin.Name(), podName, err)
|
||||
} else if netStatus != nil {
|
||||
@ -354,7 +354,7 @@ func (dm *DockerManager) inspectContainer(id string, podName, podNamespace strin
|
||||
RestartCount: containerInfo.RestartCount,
|
||||
Image: iResult.Config.Image,
|
||||
ImageID: DockerPrefix + iResult.Image,
|
||||
ID: kubetypes.DockerID(id).ContainerID(),
|
||||
ID: kubecontainer.DockerID(id).ContainerID(),
|
||||
ExitCode: iResult.State.ExitCode,
|
||||
CreatedAt: iResult.Created,
|
||||
Hash: hash,
|
||||
@ -771,7 +771,7 @@ func (dm *DockerManager) runContainer(
|
||||
}
|
||||
dm.recorder.Eventf(ref, api.EventTypeNormal, kubecontainer.StartedContainer, "Started container with docker id %v", util.ShortenString(dockerContainer.ID, 12))
|
||||
|
||||
return kubetypes.DockerID(dockerContainer.ID).ContainerID(), nil
|
||||
return kubecontainer.DockerID(dockerContainer.ID).ContainerID(), nil
|
||||
}
|
||||
|
||||
func setEntrypointAndCommand(container *api.Container, opts *kubecontainer.RunContainerOptions, dockerOpts *docker.CreateContainerOptions) {
|
||||
@ -1266,7 +1266,7 @@ func (dm *DockerManager) KillPod(pod *api.Pod, runningPod kubecontainer.Pod) err
|
||||
}
|
||||
wg.Wait()
|
||||
if networkContainer != nil {
|
||||
if err := dm.networkPlugin.TearDownPod(runningPod.Namespace, runningPod.Name, kubetypes.DockerID(networkContainer.ID.ID)); err != nil {
|
||||
if err := dm.networkPlugin.TearDownPod(runningPod.Namespace, runningPod.Name, kubecontainer.DockerID(networkContainer.ID.ID)); err != nil {
|
||||
glog.Errorf("Failed tearing down the infra container: %v", err)
|
||||
errs <- err
|
||||
}
|
||||
@ -1559,7 +1559,7 @@ func appendToFile(filePath, stringToAppend string) error {
|
||||
}
|
||||
|
||||
// createPodInfraContainer starts the pod infra container for a pod. Returns the docker container ID of the newly created container.
|
||||
func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubetypes.DockerID, error) {
|
||||
func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubecontainer.DockerID, error) {
|
||||
start := time.Now()
|
||||
defer func() {
|
||||
metrics.ContainerManagerLatency.WithLabelValues("createPodInfraContainer").Observe(metrics.SinceInMicroseconds(start))
|
||||
@ -1601,7 +1601,7 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubetypes.Docker
|
||||
return "", err
|
||||
}
|
||||
|
||||
return kubetypes.DockerID(id.ID), nil
|
||||
return kubecontainer.DockerID(id.ID), nil
|
||||
}
|
||||
|
||||
// Structure keeping information on changes that need to happen for a pod. The semantics is as follows:
|
||||
@ -1617,9 +1617,9 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubetypes.Docker
|
||||
type podContainerChangesSpec struct {
|
||||
StartInfraContainer bool
|
||||
InfraChanged bool
|
||||
InfraContainerId kubetypes.DockerID
|
||||
InfraContainerId kubecontainer.DockerID
|
||||
ContainersToStart map[int]string
|
||||
ContainersToKeep map[kubetypes.DockerID]int
|
||||
ContainersToKeep map[kubecontainer.DockerID]int
|
||||
}
|
||||
|
||||
func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kubecontainer.PodStatus) (podContainerChangesSpec, error) {
|
||||
@ -1630,10 +1630,10 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub
|
||||
glog.V(4).Infof("Syncing Pod %q: %+v", format.Pod(pod), pod)
|
||||
|
||||
containersToStart := make(map[int]string)
|
||||
containersToKeep := make(map[kubetypes.DockerID]int)
|
||||
containersToKeep := make(map[kubecontainer.DockerID]int)
|
||||
|
||||
var err error
|
||||
var podInfraContainerID kubetypes.DockerID
|
||||
var podInfraContainerID kubecontainer.DockerID
|
||||
var changed bool
|
||||
podInfraContainerStatus := podStatus.FindContainerStatusByName(PodInfraContainerName)
|
||||
if podInfraContainerStatus != nil && podInfraContainerStatus.State == kubecontainer.ContainerStateRunning {
|
||||
@ -1652,7 +1652,7 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub
|
||||
} else {
|
||||
glog.V(4).Infof("Pod infra container looks good, keep it %q", format.Pod(pod))
|
||||
createPodInfraContainer = false
|
||||
podInfraContainerID = kubetypes.DockerID(podInfraContainerStatus.ID.ID)
|
||||
podInfraContainerID = kubecontainer.DockerID(podInfraContainerStatus.ID.ID)
|
||||
containersToKeep[podInfraContainerID] = -1
|
||||
}
|
||||
|
||||
@ -1672,7 +1672,7 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub
|
||||
continue
|
||||
}
|
||||
|
||||
containerID := kubetypes.DockerID(containerStatus.ID.ID)
|
||||
containerID := kubecontainer.DockerID(containerStatus.ID.ID)
|
||||
hash := containerStatus.Hash
|
||||
glog.V(3).Infof("pod %q container %q exists as %v", format.Pod(pod), container.Name, containerID)
|
||||
|
||||
@ -1718,7 +1718,7 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub
|
||||
|
||||
// If Infra container is the last running one, we don't want to keep it.
|
||||
if !createPodInfraContainer && len(containersToStart) == 0 && len(containersToKeep) == 1 {
|
||||
containersToKeep = make(map[kubetypes.DockerID]int)
|
||||
containersToKeep = make(map[kubecontainer.DockerID]int)
|
||||
}
|
||||
|
||||
return podContainerChangesSpec{
|
||||
@ -1780,7 +1780,7 @@ func (dm *DockerManager) SyncPod(pod *api.Pod, _ api.PodStatus, podStatus *kubec
|
||||
// Otherwise kill any running containers in this pod which are not specified as ones to keep.
|
||||
runningContainerStatues := podStatus.GetRunningContainerStatuses()
|
||||
for _, containerStatus := range runningContainerStatues {
|
||||
_, keep := containerChanges.ContainersToKeep[kubetypes.DockerID(containerStatus.ID.ID)]
|
||||
_, keep := containerChanges.ContainersToKeep[kubecontainer.DockerID(containerStatus.ID.ID)]
|
||||
if !keep {
|
||||
// NOTE(random-liu): Just log ID or log container status here?
|
||||
glog.V(3).Infof("Killing unwanted container %+v", containerStatus)
|
||||
|
@ -88,7 +88,7 @@ func newTestDockerManagerWithHTTPClient(fakeHTTPClient *fakeHTTP) (*DockerManage
|
||||
proberesults.NewManager(),
|
||||
containerRefManager,
|
||||
&cadvisorapi.MachineInfo{},
|
||||
PodInfraContainerImage,
|
||||
kubetypes.PodInfraContainerImage,
|
||||
0, 0, "",
|
||||
kubecontainer.FakeOS{},
|
||||
networkPlugin,
|
||||
@ -532,7 +532,7 @@ func generatePodInfraContainerHash(pod *api.Pod) uint64 {
|
||||
|
||||
container := &api.Container{
|
||||
Name: PodInfraContainerName,
|
||||
Image: PodInfraContainerImage,
|
||||
Image: kubetypes.PodInfraContainerImage,
|
||||
Ports: ports,
|
||||
ImagePullPolicy: podInfraContainerImagePullPolicy,
|
||||
}
|
||||
@ -830,7 +830,7 @@ func TestSyncPodsUnhealthy(t *testing.T) {
|
||||
ID: infraContainerID,
|
||||
Name: "/k8s_POD." + strconv.FormatUint(generatePodInfraContainerHash(pod), 16) + "_foo_new_12345678_42",
|
||||
}})
|
||||
dm.livenessManager.Set(kubetypes.DockerID(unhealthyContainerID).ContainerID(), proberesults.Failure, nil)
|
||||
dm.livenessManager.Set(kubecontainer.DockerID(unhealthyContainerID).ContainerID(), proberesults.Failure, nil)
|
||||
|
||||
runSyncPod(t, dm, fakeDocker, pod, nil, false)
|
||||
|
||||
|
@ -106,9 +106,6 @@ const (
|
||||
// not block on anything else.
|
||||
podKillingChannelCapacity = 50
|
||||
|
||||
// system default DNS resolver configuration
|
||||
ResolvConfDefault = "/etc/resolv.conf"
|
||||
|
||||
// Period for performing global cleanup tasks.
|
||||
housekeepingPeriod = time.Second * 2
|
||||
|
||||
|
@ -28,7 +28,6 @@ import (
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/kubelet/dockertools"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -102,7 +101,7 @@ func (plugin *cniNetworkPlugin) Name() string {
|
||||
return CNIPluginName
|
||||
}
|
||||
|
||||
func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubetypes.DockerID) error {
|
||||
func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
|
||||
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
|
||||
if !ok {
|
||||
return fmt.Errorf("CNI execution called on non-docker runtime")
|
||||
@ -121,7 +120,7 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubet
|
||||
return err
|
||||
}
|
||||
|
||||
func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id kubetypes.DockerID) error {
|
||||
func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
|
||||
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
|
||||
if !ok {
|
||||
return fmt.Errorf("CNI execution called on non-docker runtime")
|
||||
@ -136,7 +135,7 @@ func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id ku
|
||||
|
||||
// TODO: Use the addToNetwork function to obtain the IP of the Pod. That will assume idempotent ADD call to the plugin.
|
||||
// Also fix the runtime's call to Status function to be done only in the case that the IP is lost, no need to do periodic calls
|
||||
func (plugin *cniNetworkPlugin) Status(namespace string, name string, id kubetypes.DockerID) (*network.PodNetworkStatus, error) {
|
||||
func (plugin *cniNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*network.PodNetworkStatus, error) {
|
||||
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("CNI execution called on non-docker runtime")
|
||||
|
@ -38,6 +38,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/dockertools"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
proberesults "k8s.io/kubernetes/pkg/kubelet/prober/results"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
)
|
||||
|
||||
// The temp dir where test plugins will be stored.
|
||||
@ -156,7 +157,7 @@ func newTestDockerManager() (*dockertools.DockerManager, *dockertools.FakeDocker
|
||||
proberesults.NewManager(),
|
||||
containerRefManager,
|
||||
&cadvisorapi.MachineInfo{},
|
||||
dockertools.PodInfraContainerImage,
|
||||
kubetypes.PodInfraContainerImage,
|
||||
0, 0, "",
|
||||
kubecontainer.FakeOS{},
|
||||
networkPlugin,
|
||||
|
@ -66,8 +66,8 @@ import (
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
utilexec "k8s.io/kubernetes/pkg/util/exec"
|
||||
)
|
||||
|
||||
@ -132,19 +132,19 @@ func (plugin *execNetworkPlugin) validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (plugin *execNetworkPlugin) SetUpPod(namespace string, name string, id kubetypes.DockerID) error {
|
||||
func (plugin *execNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
|
||||
out, err := utilexec.New().Command(plugin.getExecutable(), setUpCmd, namespace, name, string(id)).CombinedOutput()
|
||||
glog.V(5).Infof("SetUpPod 'exec' network plugin output: %s, %v", string(out), err)
|
||||
return err
|
||||
}
|
||||
|
||||
func (plugin *execNetworkPlugin) TearDownPod(namespace string, name string, id kubetypes.DockerID) error {
|
||||
func (plugin *execNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
|
||||
out, err := utilexec.New().Command(plugin.getExecutable(), tearDownCmd, namespace, name, string(id)).CombinedOutput()
|
||||
glog.V(5).Infof("TearDownPod 'exec' network plugin output: %s, %v", string(out), err)
|
||||
return err
|
||||
}
|
||||
|
||||
func (plugin *execNetworkPlugin) Status(namespace string, name string, id kubetypes.DockerID) (*network.PodNetworkStatus, error) {
|
||||
func (plugin *execNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*network.PodNetworkStatus, error) {
|
||||
out, err := utilexec.New().Command(plugin.getExecutable(), statusCmd, namespace, name, string(id)).CombinedOutput()
|
||||
glog.V(5).Infof("Status 'exec' network plugin output: %s, %v", string(out), err)
|
||||
if err != nil {
|
||||
|
@ -26,7 +26,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
utilerrors "k8s.io/kubernetes/pkg/util/errors"
|
||||
"k8s.io/kubernetes/pkg/util/validation"
|
||||
)
|
||||
@ -46,13 +45,13 @@ type NetworkPlugin interface {
|
||||
// SetUpPod is the method called after the infra container of
|
||||
// the pod has been created but before the other containers of the
|
||||
// pod are launched.
|
||||
SetUpPod(namespace string, name string, podInfraContainerID kubetypes.DockerID) error
|
||||
SetUpPod(namespace string, name string, podInfraContainerID kubecontainer.DockerID) error
|
||||
|
||||
// TearDownPod is the method called before a pod's infra container will be deleted
|
||||
TearDownPod(namespace string, name string, podInfraContainerID kubetypes.DockerID) error
|
||||
TearDownPod(namespace string, name string, podInfraContainerID kubecontainer.DockerID) error
|
||||
|
||||
// Status is the method called to obtain the ipv4 or ipv6 addresses of the container
|
||||
Status(namespace string, name string, podInfraContainerID kubetypes.DockerID) (*PodNetworkStatus, error)
|
||||
Status(namespace string, name string, podInfraContainerID kubecontainer.DockerID) (*PodNetworkStatus, error)
|
||||
}
|
||||
|
||||
// PodNetworkStatus stores the network status of a pod (currently just the primary IP address)
|
||||
@ -134,14 +133,14 @@ func (plugin *noopNetworkPlugin) Name() string {
|
||||
return DefaultPluginName
|
||||
}
|
||||
|
||||
func (plugin *noopNetworkPlugin) SetUpPod(namespace string, name string, id kubetypes.DockerID) error {
|
||||
func (plugin *noopNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (plugin *noopNetworkPlugin) TearDownPod(namespace string, name string, id kubetypes.DockerID) error {
|
||||
func (plugin *noopNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (plugin *noopNetworkPlugin) Status(namespace string, name string, id kubetypes.DockerID) (*PodNetworkStatus, error) {
|
||||
func (plugin *noopNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*PodNetworkStatus, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
23
pkg/kubelet/types/constants.go
Normal file
23
pkg/kubelet/types/constants.go
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 types
|
||||
|
||||
const (
|
||||
PodInfraContainerImage = "gcr.io/google_containers/pause:2.0"
|
||||
// system default DNS resolver configuration
|
||||
ResolvConfDefault = "/etc/resolv.conf"
|
||||
)
|
@ -21,21 +21,10 @@ import (
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
)
|
||||
|
||||
// TODO: Reconcile custom types in kubelet/types and this subpackage
|
||||
|
||||
// DockerID is an ID of docker container. It is a type to make it clear when we're working with docker container Ids
|
||||
type DockerID string
|
||||
|
||||
func (id DockerID) ContainerID() kubecontainer.ContainerID {
|
||||
return kubecontainer.ContainerID{
|
||||
Type: "docker",
|
||||
ID: string(id),
|
||||
}
|
||||
}
|
||||
|
||||
type HttpGetter interface {
|
||||
Get(url string) (*http.Response, error)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user