docker_service.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package dockershim
  14. import (
  15. "context"
  16. "fmt"
  17. "net/http"
  18. "path"
  19. "path/filepath"
  20. "sync"
  21. "time"
  22. "github.com/blang/semver"
  23. dockertypes "github.com/docker/docker/api/types"
  24. "k8s.io/klog"
  25. "k8s.io/api/core/v1"
  26. runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
  27. kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
  28. "k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
  29. "k8s.io/kubernetes/pkg/kubelet/checkpointmanager/errors"
  30. kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
  31. "k8s.io/kubernetes/pkg/kubelet/dockershim/cm"
  32. "k8s.io/kubernetes/pkg/kubelet/dockershim/network"
  33. "k8s.io/kubernetes/pkg/kubelet/dockershim/network/cni"
  34. "k8s.io/kubernetes/pkg/kubelet/dockershim/network/hostport"
  35. "k8s.io/kubernetes/pkg/kubelet/dockershim/network/kubenet"
  36. "k8s.io/kubernetes/pkg/kubelet/server/streaming"
  37. "k8s.io/kubernetes/pkg/kubelet/util/cache"
  38. "k8s.io/kubernetes/pkg/kubelet/dockershim/libdocker"
  39. "k8s.io/kubernetes/pkg/kubelet/dockershim/metrics"
  40. )
  41. const (
  42. dockerRuntimeName = "docker"
  43. kubeAPIVersion = "0.1.0"
  44. // String used to detect docker host mode for various namespaces (e.g.
  45. // networking). Must match the value returned by docker inspect -f
  46. // '{{.HostConfig.NetworkMode}}'.
  47. namespaceModeHost = "host"
  48. dockerNetNSFmt = "/proc/%v/ns/net"
  49. // Internal docker labels used to identify whether a container is a sandbox
  50. // or a regular container.
  51. // TODO: This is not backward compatible with older containers. We will
  52. // need to add filtering based on names.
  53. containerTypeLabelKey = "io.kubernetes.docker.type"
  54. containerTypeLabelSandbox = "podsandbox"
  55. containerTypeLabelContainer = "container"
  56. containerLogPathLabelKey = "io.kubernetes.container.logpath"
  57. sandboxIDLabelKey = "io.kubernetes.sandbox.id"
  58. // The expiration time of version cache.
  59. versionCacheTTL = 60 * time.Second
  60. defaultCgroupDriver = "cgroupfs"
  61. // TODO: https://github.com/kubernetes/kubernetes/pull/31169 provides experimental
  62. // defaulting of host user namespace that may be enabled when the docker daemon
  63. // is using remapped UIDs.
  64. // Dockershim should provide detection support for a remapping environment .
  65. // This should be included in the feature proposal. Defaulting may still occur according
  66. // to kubelet behavior and system settings in addition to any API flags that may be introduced.
  67. )
  68. // CRIService includes all methods necessary for a CRI server.
  69. type CRIService interface {
  70. runtimeapi.RuntimeServiceServer
  71. runtimeapi.ImageServiceServer
  72. Start() error
  73. }
  74. // DockerService is an interface that embeds the new RuntimeService and
  75. // ImageService interfaces.
  76. type DockerService interface {
  77. CRIService
  78. // For serving streaming calls.
  79. http.Handler
  80. // For supporting legacy features.
  81. DockerLegacyService
  82. }
  83. // NetworkPluginSettings is the subset of kubelet runtime args we pass
  84. // to the container runtime shim so it can probe for network plugins.
  85. // In the future we will feed these directly to a standalone container
  86. // runtime process.
  87. type NetworkPluginSettings struct {
  88. // HairpinMode is best described by comments surrounding the kubelet arg
  89. HairpinMode kubeletconfig.HairpinMode
  90. // NonMasqueradeCIDR is the range of ips which should *not* be included
  91. // in any MASQUERADE rules applied by the plugin
  92. NonMasqueradeCIDR string
  93. // PluginName is the name of the plugin, runtime shim probes for
  94. PluginName string
  95. // PluginBinDirString is a list of directiores delimited by commas, in
  96. // which the binaries for the plugin with PluginName may be found.
  97. PluginBinDirString string
  98. // PluginBinDirs is an array of directories in which the binaries for
  99. // the plugin with PluginName may be found. The admin is responsible for
  100. // provisioning these binaries before-hand.
  101. PluginBinDirs []string
  102. // PluginConfDir is the directory in which the admin places a CNI conf.
  103. // Depending on the plugin, this may be an optional field, eg: kubenet
  104. // generates its own plugin conf.
  105. PluginConfDir string
  106. // PluginCacheDir is the directory in which CNI should store cache files.
  107. PluginCacheDir string
  108. // MTU is the desired MTU for network devices created by the plugin.
  109. MTU int
  110. }
  111. // namespaceGetter is a wrapper around the dockerService that implements
  112. // the network.NamespaceGetter interface.
  113. type namespaceGetter struct {
  114. ds *dockerService
  115. }
  116. func (n *namespaceGetter) GetNetNS(containerID string) (string, error) {
  117. return n.ds.GetNetNS(containerID)
  118. }
  119. // portMappingGetter is a wrapper around the dockerService that implements
  120. // the network.PortMappingGetter interface.
  121. type portMappingGetter struct {
  122. ds *dockerService
  123. }
  124. func (p *portMappingGetter) GetPodPortMappings(containerID string) ([]*hostport.PortMapping, error) {
  125. return p.ds.GetPodPortMappings(containerID)
  126. }
  127. // dockerNetworkHost implements network.Host by wrapping the legacy host passed in by the kubelet
  128. // and dockerServices which implements the rest of the network host interfaces.
  129. // The legacy host methods are slated for deletion.
  130. type dockerNetworkHost struct {
  131. *namespaceGetter
  132. *portMappingGetter
  133. }
  134. var internalLabelKeys = []string{containerTypeLabelKey, containerLogPathLabelKey, sandboxIDLabelKey}
  135. // ClientConfig is parameters used to initialize docker client
  136. type ClientConfig struct {
  137. DockerEndpoint string
  138. RuntimeRequestTimeout time.Duration
  139. ImagePullProgressDeadline time.Duration
  140. // Configuration for fake docker client
  141. EnableSleep bool
  142. WithTraceDisabled bool
  143. }
  144. // NewDockerClientFromConfig create a docker client from given configure
  145. // return nil if nil configure is given.
  146. func NewDockerClientFromConfig(config *ClientConfig) libdocker.Interface {
  147. if config != nil {
  148. // Create docker client.
  149. client := libdocker.ConnectToDockerOrDie(
  150. config.DockerEndpoint,
  151. config.RuntimeRequestTimeout,
  152. config.ImagePullProgressDeadline,
  153. )
  154. return client
  155. }
  156. return nil
  157. }
  158. // NewDockerService creates a new `DockerService` struct.
  159. // NOTE: Anything passed to DockerService should be eventually handled in another way when we switch to running the shim as a different process.
  160. func NewDockerService(config *ClientConfig, podSandboxImage string, streamingConfig *streaming.Config, pluginSettings *NetworkPluginSettings,
  161. cgroupsName string, kubeCgroupDriver string, dockershimRootDir string, startLocalStreamingServer bool) (DockerService, error) {
  162. client := NewDockerClientFromConfig(config)
  163. c := libdocker.NewInstrumentedInterface(client)
  164. checkpointManager, err := checkpointmanager.NewCheckpointManager(filepath.Join(dockershimRootDir, sandboxCheckpointDir))
  165. if err != nil {
  166. return nil, err
  167. }
  168. ds := &dockerService{
  169. client: c,
  170. os: kubecontainer.RealOS{},
  171. podSandboxImage: podSandboxImage,
  172. streamingRuntime: &streamingRuntime{
  173. client: client,
  174. execHandler: &NativeExecHandler{},
  175. },
  176. containerManager: cm.NewContainerManager(cgroupsName, client),
  177. checkpointManager: checkpointManager,
  178. startLocalStreamingServer: startLocalStreamingServer,
  179. networkReady: make(map[string]bool),
  180. containerCleanupInfos: make(map[string]*containerCleanupInfo),
  181. }
  182. // check docker version compatibility.
  183. if err = ds.checkVersionCompatibility(); err != nil {
  184. return nil, err
  185. }
  186. // create streaming server if configured.
  187. if streamingConfig != nil {
  188. var err error
  189. ds.streamingServer, err = streaming.NewServer(*streamingConfig, ds.streamingRuntime)
  190. if err != nil {
  191. return nil, err
  192. }
  193. }
  194. // Determine the hairpin mode.
  195. if err := effectiveHairpinMode(pluginSettings); err != nil {
  196. // This is a non-recoverable error. Returning it up the callstack will just
  197. // lead to retries of the same failure, so just fail hard.
  198. return nil, err
  199. }
  200. klog.Infof("Hairpin mode set to %q", pluginSettings.HairpinMode)
  201. // dockershim currently only supports CNI plugins.
  202. pluginSettings.PluginBinDirs = cni.SplitDirs(pluginSettings.PluginBinDirString)
  203. cniPlugins := cni.ProbeNetworkPlugins(pluginSettings.PluginConfDir, pluginSettings.PluginCacheDir, pluginSettings.PluginBinDirs)
  204. cniPlugins = append(cniPlugins, kubenet.NewPlugin(pluginSettings.PluginBinDirs, pluginSettings.PluginCacheDir))
  205. netHost := &dockerNetworkHost{
  206. &namespaceGetter{ds},
  207. &portMappingGetter{ds},
  208. }
  209. plug, err := network.InitNetworkPlugin(cniPlugins, pluginSettings.PluginName, netHost, pluginSettings.HairpinMode, pluginSettings.NonMasqueradeCIDR, pluginSettings.MTU)
  210. if err != nil {
  211. return nil, fmt.Errorf("didn't find compatible CNI plugin with given settings %+v: %v", pluginSettings, err)
  212. }
  213. ds.network = network.NewPluginManager(plug)
  214. klog.Infof("Docker cri networking managed by %v", plug.Name())
  215. // NOTE: cgroup driver is only detectable in docker 1.11+
  216. cgroupDriver := defaultCgroupDriver
  217. dockerInfo, err := ds.client.Info()
  218. klog.Infof("Docker Info: %+v", dockerInfo)
  219. if err != nil {
  220. klog.Errorf("Failed to execute Info() call to the Docker client: %v", err)
  221. klog.Warningf("Falling back to use the default driver: %q", cgroupDriver)
  222. } else if len(dockerInfo.CgroupDriver) == 0 {
  223. klog.Warningf("No cgroup driver is set in Docker")
  224. klog.Warningf("Falling back to use the default driver: %q", cgroupDriver)
  225. } else {
  226. cgroupDriver = dockerInfo.CgroupDriver
  227. }
  228. if len(kubeCgroupDriver) != 0 && kubeCgroupDriver != cgroupDriver {
  229. return nil, fmt.Errorf("misconfiguration: kubelet cgroup driver: %q is different from docker cgroup driver: %q", kubeCgroupDriver, cgroupDriver)
  230. }
  231. klog.Infof("Setting cgroupDriver to %s", cgroupDriver)
  232. ds.cgroupDriver = cgroupDriver
  233. ds.versionCache = cache.NewObjectCache(
  234. func() (interface{}, error) {
  235. return ds.getDockerVersion()
  236. },
  237. versionCacheTTL,
  238. )
  239. // Register prometheus metrics.
  240. metrics.Register()
  241. return ds, nil
  242. }
  243. type dockerService struct {
  244. client libdocker.Interface
  245. os kubecontainer.OSInterface
  246. podSandboxImage string
  247. streamingRuntime *streamingRuntime
  248. streamingServer streaming.Server
  249. network *network.PluginManager
  250. // Map of podSandboxID :: network-is-ready
  251. networkReady map[string]bool
  252. networkReadyLock sync.Mutex
  253. containerManager cm.ContainerManager
  254. // cgroup driver used by Docker runtime.
  255. cgroupDriver string
  256. checkpointManager checkpointmanager.CheckpointManager
  257. // caches the version of the runtime.
  258. // To be compatible with multiple docker versions, we need to perform
  259. // version checking for some operations. Use this cache to avoid querying
  260. // the docker daemon every time we need to do such checks.
  261. versionCache *cache.ObjectCache
  262. // startLocalStreamingServer indicates whether dockershim should start a
  263. // streaming server on localhost.
  264. startLocalStreamingServer bool
  265. // containerCleanupInfos maps container IDs to the `containerCleanupInfo` structs
  266. // needed to clean up after containers have been removed.
  267. // (see `applyPlatformSpecificDockerConfig` and `performPlatformSpecificContainerCleanup`
  268. // methods for more info).
  269. containerCleanupInfos map[string]*containerCleanupInfo
  270. }
  271. // TODO: handle context.
  272. // Version returns the runtime name, runtime version and runtime API version
  273. func (ds *dockerService) Version(_ context.Context, r *runtimeapi.VersionRequest) (*runtimeapi.VersionResponse, error) {
  274. v, err := ds.getDockerVersion()
  275. if err != nil {
  276. return nil, err
  277. }
  278. return &runtimeapi.VersionResponse{
  279. Version: kubeAPIVersion,
  280. RuntimeName: dockerRuntimeName,
  281. RuntimeVersion: v.Version,
  282. RuntimeApiVersion: v.APIVersion,
  283. }, nil
  284. }
  285. // getDockerVersion gets the version information from docker.
  286. func (ds *dockerService) getDockerVersion() (*dockertypes.Version, error) {
  287. v, err := ds.client.Version()
  288. if err != nil {
  289. return nil, fmt.Errorf("failed to get docker version: %v", err)
  290. }
  291. // Docker API version (e.g., 1.23) is not semver compatible. Add a ".0"
  292. // suffix to remedy this.
  293. v.APIVersion = fmt.Sprintf("%s.0", v.APIVersion)
  294. return v, nil
  295. }
  296. // UpdateRuntimeConfig updates the runtime config. Currently only handles podCIDR updates.
  297. func (ds *dockerService) UpdateRuntimeConfig(_ context.Context, r *runtimeapi.UpdateRuntimeConfigRequest) (*runtimeapi.UpdateRuntimeConfigResponse, error) {
  298. runtimeConfig := r.GetRuntimeConfig()
  299. if runtimeConfig == nil {
  300. return &runtimeapi.UpdateRuntimeConfigResponse{}, nil
  301. }
  302. klog.Infof("docker cri received runtime config %+v", runtimeConfig)
  303. if ds.network != nil && runtimeConfig.NetworkConfig.PodCidr != "" {
  304. event := make(map[string]interface{})
  305. event[network.NET_PLUGIN_EVENT_POD_CIDR_CHANGE_DETAIL_CIDR] = runtimeConfig.NetworkConfig.PodCidr
  306. ds.network.Event(network.NET_PLUGIN_EVENT_POD_CIDR_CHANGE, event)
  307. }
  308. return &runtimeapi.UpdateRuntimeConfigResponse{}, nil
  309. }
  310. // GetNetNS returns the network namespace of the given containerID. The ID
  311. // supplied is typically the ID of a pod sandbox. This getter doesn't try
  312. // to map non-sandbox IDs to their respective sandboxes.
  313. func (ds *dockerService) GetNetNS(podSandboxID string) (string, error) {
  314. r, err := ds.client.InspectContainer(podSandboxID)
  315. if err != nil {
  316. return "", err
  317. }
  318. return getNetworkNamespace(r)
  319. }
  320. // GetPodPortMappings returns the port mappings of the given podSandbox ID.
  321. func (ds *dockerService) GetPodPortMappings(podSandboxID string) ([]*hostport.PortMapping, error) {
  322. // TODO: get portmappings from docker labels for backward compatibility
  323. checkpoint := NewPodSandboxCheckpoint("", "", &CheckpointData{})
  324. err := ds.checkpointManager.GetCheckpoint(podSandboxID, checkpoint)
  325. // Return empty portMappings if checkpoint is not found
  326. if err != nil {
  327. if err == errors.ErrCheckpointNotFound {
  328. return nil, nil
  329. }
  330. errRem := ds.checkpointManager.RemoveCheckpoint(podSandboxID)
  331. if errRem != nil {
  332. klog.Errorf("Failed to delete corrupt checkpoint for sandbox %q: %v", podSandboxID, errRem)
  333. }
  334. return nil, err
  335. }
  336. _, _, _, checkpointedPortMappings, _ := checkpoint.GetData()
  337. portMappings := make([]*hostport.PortMapping, 0, len(checkpointedPortMappings))
  338. for _, pm := range checkpointedPortMappings {
  339. proto := toAPIProtocol(*pm.Protocol)
  340. portMappings = append(portMappings, &hostport.PortMapping{
  341. HostPort: *pm.HostPort,
  342. ContainerPort: *pm.ContainerPort,
  343. Protocol: proto,
  344. HostIP: pm.HostIP,
  345. })
  346. }
  347. return portMappings, nil
  348. }
  349. // Start initializes and starts components in dockerService.
  350. func (ds *dockerService) Start() error {
  351. ds.initCleanup()
  352. // Initialize the legacy cleanup flag.
  353. if ds.startLocalStreamingServer {
  354. go func() {
  355. if err := ds.streamingServer.Start(true); err != nil {
  356. klog.Fatalf("Streaming server stopped unexpectedly: %v", err)
  357. }
  358. }()
  359. }
  360. return ds.containerManager.Start()
  361. }
  362. // initCleanup is responsible for cleaning up any crufts left by previous
  363. // runs. If there are any errors, it simply logs them.
  364. func (ds *dockerService) initCleanup() {
  365. errors := ds.platformSpecificContainerInitCleanup()
  366. for _, err := range errors {
  367. klog.Warningf("initialization error: %v", err)
  368. }
  369. }
  370. // Status returns the status of the runtime.
  371. func (ds *dockerService) Status(_ context.Context, r *runtimeapi.StatusRequest) (*runtimeapi.StatusResponse, error) {
  372. runtimeReady := &runtimeapi.RuntimeCondition{
  373. Type: runtimeapi.RuntimeReady,
  374. Status: true,
  375. }
  376. networkReady := &runtimeapi.RuntimeCondition{
  377. Type: runtimeapi.NetworkReady,
  378. Status: true,
  379. }
  380. conditions := []*runtimeapi.RuntimeCondition{runtimeReady, networkReady}
  381. if _, err := ds.client.Version(); err != nil {
  382. runtimeReady.Status = false
  383. runtimeReady.Reason = "DockerDaemonNotReady"
  384. runtimeReady.Message = fmt.Sprintf("docker: failed to get docker version: %v", err)
  385. }
  386. if err := ds.network.Status(); err != nil {
  387. networkReady.Status = false
  388. networkReady.Reason = "NetworkPluginNotReady"
  389. networkReady.Message = fmt.Sprintf("docker: network plugin is not ready: %v", err)
  390. }
  391. status := &runtimeapi.RuntimeStatus{Conditions: conditions}
  392. return &runtimeapi.StatusResponse{Status: status}, nil
  393. }
  394. func (ds *dockerService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  395. if ds.streamingServer != nil {
  396. ds.streamingServer.ServeHTTP(w, r)
  397. } else {
  398. http.NotFound(w, r)
  399. }
  400. }
  401. // GenerateExpectedCgroupParent returns cgroup parent in syntax expected by cgroup driver
  402. func (ds *dockerService) GenerateExpectedCgroupParent(cgroupParent string) (string, error) {
  403. if cgroupParent != "" {
  404. // if docker uses the systemd cgroup driver, it expects *.slice style names for cgroup parent.
  405. // if we configured kubelet to use --cgroup-driver=cgroupfs, and docker is configured to use systemd driver
  406. // docker will fail to launch the container because the name we provide will not be a valid slice.
  407. // this is a very good thing.
  408. if ds.cgroupDriver == "systemd" {
  409. // Pass only the last component of the cgroup path to systemd.
  410. cgroupParent = path.Base(cgroupParent)
  411. }
  412. }
  413. klog.V(3).Infof("Setting cgroup parent to: %q", cgroupParent)
  414. return cgroupParent, nil
  415. }
  416. // checkVersionCompatibility verifies whether docker is in a compatible version.
  417. func (ds *dockerService) checkVersionCompatibility() error {
  418. apiVersion, err := ds.getDockerAPIVersion()
  419. if err != nil {
  420. return err
  421. }
  422. minAPIVersion, err := semver.Parse(libdocker.MinimumDockerAPIVersion)
  423. if err != nil {
  424. return err
  425. }
  426. // Verify the docker version.
  427. result := apiVersion.Compare(minAPIVersion)
  428. if result < 0 {
  429. return fmt.Errorf("docker API version is older than %s", libdocker.MinimumDockerAPIVersion)
  430. }
  431. return nil
  432. }
  433. // getDockerAPIVersion gets the semver-compatible docker api version.
  434. func (ds *dockerService) getDockerAPIVersion() (*semver.Version, error) {
  435. var dv *dockertypes.Version
  436. var err error
  437. if ds.versionCache != nil {
  438. dv, err = ds.getDockerVersionFromCache()
  439. } else {
  440. dv, err = ds.getDockerVersion()
  441. }
  442. if err != nil {
  443. return nil, err
  444. }
  445. apiVersion, err := semver.Parse(dv.APIVersion)
  446. if err != nil {
  447. return nil, err
  448. }
  449. return &apiVersion, nil
  450. }
  451. func (ds *dockerService) getDockerVersionFromCache() (*dockertypes.Version, error) {
  452. // We only store on key in the cache.
  453. const dummyKey = "version"
  454. value, err := ds.versionCache.Get(dummyKey)
  455. if err != nil {
  456. return nil, err
  457. }
  458. dv, ok := value.(*dockertypes.Version)
  459. if !ok {
  460. return nil, fmt.Errorf("converted to *dockertype.Version error")
  461. }
  462. return dv, nil
  463. }
  464. func toAPIProtocol(protocol Protocol) v1.Protocol {
  465. switch protocol {
  466. case protocolTCP:
  467. return v1.ProtocolTCP
  468. case protocolUDP:
  469. return v1.ProtocolUDP
  470. case protocolSCTP:
  471. return v1.ProtocolSCTP
  472. }
  473. klog.Warningf("Unknown protocol %q: defaulting to TCP", protocol)
  474. return v1.ProtocolTCP
  475. }
  476. // effectiveHairpinMode determines the effective hairpin mode given the
  477. // configured mode, and whether cbr0 should be configured.
  478. func effectiveHairpinMode(s *NetworkPluginSettings) error {
  479. // The hairpin mode setting doesn't matter if:
  480. // - We're not using a bridge network. This is hard to check because we might
  481. // be using a plugin.
  482. // - It's set to hairpin-veth for a container runtime that doesn't know how
  483. // to set the hairpin flag on the veth's of containers. Currently the
  484. // docker runtime is the only one that understands this.
  485. // - It's set to "none".
  486. if s.HairpinMode == kubeletconfig.PromiscuousBridge || s.HairpinMode == kubeletconfig.HairpinVeth {
  487. if s.HairpinMode == kubeletconfig.PromiscuousBridge && s.PluginName != "kubenet" {
  488. // This is not a valid combination, since promiscuous-bridge only works on kubenet. Users might be using the
  489. // default values (from before the hairpin-mode flag existed) and we
  490. // should keep the old behavior.
  491. klog.Warningf("Hairpin mode set to %q but kubenet is not enabled, falling back to %q", s.HairpinMode, kubeletconfig.HairpinVeth)
  492. s.HairpinMode = kubeletconfig.HairpinVeth
  493. return nil
  494. }
  495. } else if s.HairpinMode != kubeletconfig.HairpinNone {
  496. return fmt.Errorf("unknown value: %q", s.HairpinMode)
  497. }
  498. return nil
  499. }