Commit Graph

337 Commits

Author SHA1 Message Date
Antonio Ojea
a7469cf680 sort and filter exposed Pod IPs
runtimes may return an arbitrary number of Pod IPs, however, kubernetes
only takes into consideration the first one of each IP family.

The order of the IPs are the one defined by the Kubelet:
- default prefer IPv4
- if NodeIPs are defined, matching the first nodeIP family

PodIP is always the first IP of PodIPs.

The downward API must expose the same IPs and in the same order than
the pod.Status API object.
2021-07-07 00:15:31 +02:00
Clayton Coleman
3eadd1a9ea
Keep pod worker running until pod is truly complete
A number of race conditions exist when pods are terminated early in
their lifecycle because components in the kubelet need to know "no
running containers" or "containers can't be started from now on" but
were relying on outdated state.

Only the pod worker knows whether containers are being started for
a given pod, which is required to know when a pod is "terminated"
(no running containers, none coming). Move that responsibility and
podKiller function into the pod workers, and have everything that
was killing the pod go into the UpdatePod loop. Split syncPod into
three phases - setup, terminate containers, and cleanup pod - and
have transitions between those methods be visible to other
components. After this change, to kill a pod you tell the pod worker
to UpdatePod({UpdateType: SyncPodKill, Pod: pod}).

Several places in the kubelet were incorrect about whether they
were handling terminating (should stop running, might have
containers) or terminated (no running containers) pods. The pod worker
exposes methods that allow other loops to know when to set up or tear
down resources based on the state of the pod - these methods remove
the possibility of race conditions by ensuring a single component is
responsible for knowing each pod's allowed state and other components
simply delegate to checking whether they are in the window by UID.

Removing containers now no longer blocks final pod deletion in the
API server and are handled as background cleanup. Node shutdown
no longer marks pods as failed as they can be restarted in the
next step.

See https://docs.google.com/document/d/1Pic5TPntdJnYfIpBeZndDelM-AbS4FN9H2GTLFhoJ04/edit# for details
2021-07-06 15:55:22 -04:00
Elana Hashman
9469756b6c
Ensure kubelet statuses can handle loss of container runtime state 2021-06-15 11:12:55 -07:00
Kubernetes Prow Robot
4d50f2ace0
Merge pull request #101633 from llhuii/kubelet/remove-redundant-code
kubelet_pods.go: clean makeEnvironmentVariables
2021-06-02 13:42:43 -07:00
llhuii
afe28c6fc8 kubelet_pods.go: clean makeEnvironmentVariables
For the simplicity and clarity, I think we can safely delete the
`delete(serviceEnv, envVar.Name)` and the duplicate comments at
function makeEnvironmentVariables of kubelet_pods.go:774-779.

1. `delete(serviceEnv, envVar.Name)` and `if _, present := tmpEnv[k]; !present`
of line 796 are the same logic that is to merge the non-present keys
of serviceEnv into tmpEnv.

2. And the keys deleted from serviceEnv are guarantee to be in tmpEnv,
this doesn't affect mappingFunc.

3. the delete may miss some key from container.EnvFrom
2021-04-30 10:33:13 +08:00
yuzhiquan
bebca30309 comment should have function name as prefix 2021-04-28 15:26:46 +08:00
Elana Hashman
6af7eb6d49
Migrate missed log entries in kubelet
Co-Authored-By: pacoxu <paco.xu@daocloud.io>
2021-03-18 14:26:26 -07:00
JUN YANG
90bfd38b83 Structured Logging migration: modify node and pod part logs of kubelet.
Signed-off-by: JunYang <yang.jun22@zte.com.cn>
2021-03-13 12:31:09 +08:00
Kubernetes Prow Robot
55f255208a
Merge pull request #83730 from claudiubelu/windows/containerd-etc-hosts
Windows: Fixes /etc/hosts file mounting support for containerd
2021-03-05 05:08:22 -08:00
Dan Winship
5fd1651fc1 Make podIPs order match node IP family preference 2021-03-04 15:46:36 -05:00
Jordan Liggitt
4798d0bce2 Avoid kubelet warnings for imagePullSecret entries with empty names 2021-03-01 08:32:09 -05:00
Geonju Kim
b451c15bf7 kubelet: Fix race when KillPod followed by IsPodPendingTermination
Ensures the pod to be pending termination or be killed, after
(*podKillerWithChannel).KillPod has been returned, by limiting
one request per pod in (*podKillerWithChannel).KillPod.
2021-02-14 07:16:49 +09:00
Kubernetes Prow Robot
45d9a13b94
Merge pull request #96451 from ping035627/k8s-201112
Extract the const for ContainerStateReason
2021-02-09 10:25:00 -08:00
Ryan Phillips
f918e11e3a register all pending pod deletions and check for kill
do not delete the cgroup from a pod when it is being killed
2021-02-04 11:45:42 -06:00
PingWang
4103ff490f Extract the const for ContainerStateReason
Signed-off-by: PingWang <wang.ping5@zte.com.cn>

update fmt

Signed-off-by: PingWang <wang.ping5@zte.com.cn>

update test

Signed-off-by: PingWang <wang.ping5@zte.com.cn>
2021-02-04 08:52:13 +08:00
Claudiu Belu
de4602995b Windows: Fixes /etc/hosts file mounting support for containerd
If Containerd is used on Windows, then we can also mount individual
files into containers (e.g.: /etc/hosts), which was not possible with Docker.

Checks if the container runtime is containerd, and if it is, then also
mount /etc/hosts file (to C:\Windows\System32\drivers\etc\hosts).
2021-01-30 04:54:42 -08:00
Sergey Kanzhelev
4c9e96c238 Revert "Merge pull request #92817 from kmala/kubelet"
This reverts commit 88512be213, reversing
changes made to c3b888f647.
2021-01-12 22:27:22 +00:00
saad-ali
6391c97f99 Add more logging for Mount error
Add additional logging for "Mount cannot be satisfied for container"
error to help debug #85330.
2020-12-14 11:58:09 -08:00
Michelle Au
25edb8bc69
Revert "check volume directories instead of mounts for cleanupOrphanedPodDirs" 2020-11-20 09:06:09 -08:00
Mucahit Kurt
6748570724 Change the logic of pod volumes existence check during kubelet cleanupOrphanedPodDirs, cleanupOrphanedPodCgroups and PodResourcesAreReclaimed
check in-memory cache whether volumes are still mounted and check disk directory for the volume paths instead of mounted volumes check

Signed-off-by: Mucahit Kurt <mucahitkurt@gmail.com>
2020-11-10 17:33:01 +03:00
Kubernetes Prow Robot
47943d5f9c
Merge pull request #94109 from derekwaynecarr/cleanup-kubelet-todos
Cleanup kubelet TODOs that are no longer pertinent.
2020-10-26 23:49:59 -07:00
David Eads
ff7d1444f0 kubelet container status calculation doesn't handle suddenly missing data properly 2020-10-15 12:26:16 -04:00
Dan Winship
971477d9b5 kubelet: Set dual-stack hostNetwork pod IPs on dual-stack nodes
Add nodeutil.GetNodeHostIPs to return dual-stack node IPs (in
dual-stack clusters), and make kubelet use it.
2020-10-07 17:26:04 -04:00
David Eads
e0516a3e90 set lastterminationstate for container status even when CRI fails to return termination (or any) data 2020-10-07 11:26:53 -04:00
Kubernetes Prow Robot
88512be213
Merge pull request #92817 from kmala/kubelet
Check for sandboxes before deleting the pod from apiserver
2020-09-10 07:27:45 -07:00
Derek Carr
02daa3ec23 Cleanup kubelet TODOs that are no longer pertinent. 2020-08-19 16:40:54 -04:00
Sergey Kanzhelev
d20fd40884 remove legacy leftovers of portmapping functionality that was moved to CNI 2020-07-30 23:12:16 +00:00
Keerthan Reddy,Mala
d4325f42fb Check for sandboxes before deleting the pod from apiserver 2020-07-22 11:54:56 -07:00
Kubernetes Prow Robot
8398bc3b53
Merge pull request #92916 from joelsmith/count-etc-hosts
Include pod /etc/hosts in ephemeral storage calculation for eviction
2020-07-12 06:59:36 -07:00
Kubernetes Prow Robot
93e76f5081
Merge pull request #92442 from tedyu/grace-period-with-map
Respect grace period when removing mirror pod
2020-07-10 17:49:23 -07:00
Ted Yu
a76a959294 Respect grace period when removing mirror pod
Signed-off-by: Ted Yu <yuzhihong@gmail.com>
2020-07-08 13:38:24 -07:00
Joel Smith
f34b586d01 Include pod /etc/hosts in ephemeral storage calculation for eviction 2020-07-08 12:58:11 -06:00
Kubernetes Prow Robot
5afc42de95
Merge pull request #78373 from tedyu/sort-init-container
Sort init container statuses using non-nested loop
2020-07-07 09:13:58 -07:00
Kubernetes Prow Robot
3b466d1c48
Merge pull request #91971 from SergeyKanzhelev/renamesInContainer
fix linter issues for pkg/kubelet/container
2020-06-19 21:51:32 -07:00
Sergey Kanzhelev
ee53488f19 fix golint issues in pkg/kubelet/container 2020-06-19 15:48:08 +00:00
Javier Diaz-Montes
9743cda4a7 Adding Kubelet changes to enable SetHostnameAsFQDN feature
These changes allow to set FQDN as hostname of pods for pods
that set the new PodSpec field setHostnameAsFQDN to true. The PodSpec
new field was added in related PR.

This is PART2 (last) of the changes to enable KEP #1797 and addresses #91036
2020-06-14 21:26:27 -04:00
David Eads
4da0e64bc1 reduce race risk in kubelet for missing KUBERNETES_SERVICE_HOST 2020-05-29 17:11:19 -04:00
Jordan Liggitt
591e0043c8 Revert "Merge pull request 89667 from kmala/kubelet"
This reverts commit fa785a5706, reversing
changes made to cf13f8d994.
2020-05-21 13:30:14 -04:00
Davanum Srinivas
5692926914
Move packages for slightly better UX for consumers
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2020-05-20 10:57:46 -04:00
Kubernetes Prow Robot
fa785a5706
Merge pull request #89667 from kmala/kubelet
Check for sandboxes before deleting the pod from apiserver
2020-05-19 23:40:18 -07:00
Davanum Srinivas
442a69c3bd
switch over k/k to use klog v2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2020-05-16 07:54:27 -04:00
Keerthan Reddy,Mala
70e2559aca use runtime sandbox status instead of calling cri 2020-04-13 14:36:34 -07:00
Keerthan Reddy,Mala
aae8a2847a Check for sandboxes before deleting the pod from apiserver 2020-04-13 14:36:34 -07:00
Kevin Taylor
9fd48b4039 Remove VolumeSubpathEnvExpansion Feature Gate 2020-03-27 16:28:33 +00:00
Clayton Coleman
c26653ced9
kubelet: Also set PodIPs when assign a host network PodIP
When we clobber PodIP we should also overwrite PodIPs and not rely
on the apiserver to fix it for us - this caused the Kubelet status
manager to report a large string of the following warnings when
it tried to reconcile a host network pod:

```
 I0309 19:41:05.283623    1326 status_manager.go:846] Pod status is inconsistent with cached status for pod "machine-config-daemon-jvwz4_openshift-machine-config-operator(61176279-f752-4e1c-ac8a-b48f0a68d54a)", a reconciliation should be triggered:
   &v1.PodStatus{
           ... // 5 identical fields
           HostIP:                "10.0.32.2",
           PodIP:                 "10.0.32.2",
 -         PodIPs:                []v1.PodIP{{IP: "10.0.32.2"}},
 +         PodIPs:                []v1.PodIP{},
           StartTime:             s"2020-03-09 19:41:05 +0000 UTC",
           InitContainerStatuses: nil,
           ... // 3 identical fields
   }
```

With the changes to the apiserver, this only happens once, but it is
still a bug.
2020-03-09 18:15:32 -04:00
Yu-Ju Hong
2364c10e2e
kubelet: Don't delete pod until all container status is available
After a pod reaches a terminal state and all containers are complete
we can delete the pod from the API server. The dispatchWork method
needs to wait for all container status to be available before invoking
delete. Even after the worker stops, status updates will continue to
be delivered and the sync handler will continue to sync the pods, so
dispatchWork gets multiple opportunities to see status.

The previous code assumed that a pod in Failed or Succeeded had no
running containers, but eviction or deletion of running pods could
still have running containers whose status needed to be reported.

This modifies earlier test to guarantee that the "fallback" exit
code 137 is never reported to match the expectation that all pods
exit with valid status for all containers (unless some exceptional
failure like eviction were to occur while the test is running).
2020-03-04 13:34:25 -05:00
Jan Safranek
2c1b743766 Promote block volume features to GA 2020-02-28 20:48:38 +01:00
Mike Danese
3aa59f7f30 generated: run refactor 2020-02-07 18:16:47 -08:00
Kubernetes Prow Robot
4e45328e65
Merge pull request #83123 from aramase/dualstack-downward-api
Dualstack downward api
2019-11-14 22:13:42 -08:00
Kubernetes Prow Robot
d3593c07de
Merge pull request #83057 from bclau/windows/containerd
Windows: Fixes termination-file mounting support for containerd
2019-11-13 17:27:36 -08:00
Claudiu Belu
d4d7f58362 Windows: Fixes termination-file mounting for containerd
If Containerd is used on Windows, then we can also mount individual
files into containers (e.g.: termination-log files), which was not
possible with Docker.

Checks if the container runtime is containerd, and if it is, then also
mount the termination-log file.
2019-11-12 23:33:55 -08:00
yuxiaobo
81e9f21f83 Correct spelling mistakes
Signed-off-by: yuxiaobo <yuxiaobogo@163.com>
2019-11-06 20:25:19 +08:00
Anish Ramasekar
af4d18ccf9
add status.podIPs in downward api
add host file write for podIPs

update tests

remove import alias

update type check

update type check

remove import alias

update open api spec

add tests

update test

add tests

address review comments

update imports

remove todo and import alias
2019-10-25 09:18:49 -07:00
Travis Rhoden
935c23f2ad
Move HostUtil to pkg/volume/util/hostutil
This patch moves the HostUtil functionality from the util/mount package
to the volume/util/hostutil package.

All `*NewHostUtil*` calls are changed to return concrete types instead
of interfaces.

All callers are changed to use the `*NewHostUtil*` methods instead of
directly instantiating the concrete types.
2019-08-30 10:14:42 -06:00
Tim Allclair
8a495cb5e4 Clean up error messages (ST1005) 2019-08-21 10:40:21 -07:00
Kubernetes Prow Robot
59d29b67d9
Merge pull request #59484 from verb/debug-kubelet-1
Add support for Ephemeral Containers to the kubelet
2019-08-21 00:29:17 -07:00
Lee Verberne
cb3976c02b Fix returning logs from ephemeral containers 2019-08-20 17:45:38 +00:00
Travis Rhoden
14e25b7c04
Rename HostUtils.ExistsPath to PathExists 2019-08-09 12:40:19 -06:00
Lee Verberne
906286c743 Change order kubelet starts containers
This starts ephemeral containers prior to init containers so that
ephemeral containers will still be started when init containers fail to
start.

Also improves tests and comments with review suggestions.
2019-08-02 19:56:38 +00:00
Lee Verberne
ea212d5d49 Add support for ephemeral containers to the kubelet 2019-07-24 16:24:26 +00:00
Kubernetes Prow Robot
fc9db7a042
Merge pull request #79681 from tedyu/clean-pods-param
Pass desiredPods to CleanupPods
2019-07-11 17:01:47 -07:00
Ted Yu
2242e396d4 Pass desiredPods to CleanupPods 2019-07-03 10:35:13 +08:00
Khaled Henidak(Kal)
dba434c4ba kubenet for ipv6 dualstack 2019-07-02 22:26:25 +00:00
Travis Rhoden
be7da5052f Refactor pkg/util/mount to be more reusable
This patch refactors pkg/util/mount to be more usable outside of
Kubernetes. This is done by refactoring mount.Interface to only contain
methods that are not K8s specific. Methods that are not relevant to
basic mount activities but still have OS-specific implementations are
now found in a mount.HostUtils interface.
2019-06-14 09:35:18 -06:00
Ted Yu
3f043dd8a0 Sort init container statuses using non-nested loop 2019-05-28 07:51:30 -07:00
Daniel Mueller
9050c510e6 Remove unused variables from computePodPhase
The initialized and failed variables in the computePodPhase function are
effectively write only. Remove them.
2019-04-08 09:09:09 -07:00
Davanum Srinivas
33081c1f07
New staging repository for cri-api
Change-Id: I2160b0b0ec4b9870a2d4452b428e395bbe12afbb
2019-03-26 18:21:04 -04:00
Wei Huang
c5a96b63f4
Revert "kubelet: return mirror pod in GetActivePods()"
This reverts commit c0c93f4a52.
2019-03-07 11:22:27 -08:00
Kubernetes Prow Robot
98fa2c7d32
Merge pull request #74222 from Huang-Wei/kubelet-mirrorpod
kubelet: return mirror pod in GetActivePods()
2019-03-05 13:22:02 -08:00
Kubernetes Prow Robot
0a4308f641
Merge pull request #74529 from liggitt/kubelet-service-links-error
Kubelet service links error
2019-03-05 09:49:59 -08:00
Travis Rhoden
2c4d748bed Refactor subpath out of pkg/util/mount
This patch moves subpath functionality out of pkg/util/mount and into a
new package pkg/volume/util/subpath. NSEnter funtionality is maintained.
2019-02-26 19:59:53 -07:00
Jordan Liggitt
4ac08be206 prevent panic on nil pod.spec.enableServiceLinks 2019-02-25 10:43:29 -05:00
Jordan Liggitt
9788d401e2 Revert "bug: fix segfault when EnableServiceLinks is nil"
This reverts commit e9f1700512.
2019-02-25 10:35:48 -05:00
Kevin Taylor
a64b854137 Implementation of KEP Feature Gate VolumeSubpathEnvExpansion 2019-02-20 01:37:16 +00:00
Wei Huang
c0c93f4a52
kubelet: return mirror pod in GetActivePods() 2019-02-18 12:06:43 -08:00
Joe Julian
e9f1700512
bug: fix segfault when EnableServiceLinks is nil
When upgrading to 1.13, pods that were created prior to the upgrade have
no pod.Spec.EnableServiceLinks set. This causes a segfault and prevents
the pod from ever starting.

Check and set to the default if nil.

Fixes #71749
2019-01-31 11:07:32 -08:00
Kubernetes Prow Robot
ea6acb34d1
Merge pull request #65132 from stewart-yu/stewart-removeunusedtodo
remove unuse todo
2018-12-19 06:51:29 -08:00
stewart-yu
5f11d089b7 remove unused todo in kubelet_pods.go 2018-11-30 12:51:46 +08:00
xichengliudui
68f9dacabf Fix typo: trus->true 2018-11-15 01:36:15 -05:00
Bill Warshaw
ab507dfc1f Write HostAliases aliases on same line per host IP
* change HostAliases to put all aliases for an IP
  on the same line in /etc/hosts rather than writing
  one line per IP-alias pair
* having multiple entries in /etc/hosts for the same IP
  causes issues with DNS resolution for some software
* https://unix.stackexchange.com/questions/102660/hosts-file-is-it-incorrect-to-have-the-same-ip-address-on-multiple-lines
2018-11-11 20:54:52 -05:00
Davanum Srinivas
954996e231
Move from glog to klog
- Move from the old github.com/golang/glog to k8s.io/klog
- klog as explicit InitFlags() so we add them as necessary
- we update the other repositories that we vendor that made a similar
change from glog to klog
  * github.com/kubernetes/repo-infra
  * k8s.io/gengo/
  * k8s.io/kube-openapi/
  * github.com/google/cadvisor
- Entirely remove all references to glog
- Fix some tests by explicit InitFlags in their init() methods

Change-Id: I92db545ff36fcec83afe98f550c9e630098b3135
2018-11-10 07:50:31 -05:00
k8s-ci-robot
08351b6d6d
Merge pull request #68230 from bertinatto/remove_mount_propagation_gate
Remove mount propagation feature gate
2018-11-02 01:13:43 -07:00
Fabio Bertinatto
6c9b854542 Remove mount propagation feature gate logic 2018-10-31 15:51:37 +01:00
k8s-ci-robot
63a7e06eb5
Merge pull request #69484 from ddebroy/ddebroy-winpipe1
Correctly handle named pipe host mounts for Windows
2018-10-30 16:15:57 -07:00
Deep Debroy
5da66fd65f Address code review comments
Signed-off-by: Deep Debroy <ddebroy@docker.com>
2018-10-27 00:31:16 -07:00
Deep Debroy
119e2a1d43 Address CR comments and add more tests
Signed-off-by: Deep Debroy <ddebroy@docker.com>
2018-10-26 00:29:27 -07:00
Deep Debroy
2e19f70922 Improve comments for when hostPath in Windows needs to be transformed
Signed-off-by: Deep Debroy <ddebroy@docker.com>
2018-10-25 13:58:16 -07:00
k8s-ci-robot
e85cb406eb
Merge pull request #65567 from ceshihao/pod_status_after_eviction
Pod status should contain ContainerStatuses if deadline exceeded
2018-10-17 11:56:41 -07:00
Deep Debroy
f8a69f1086 Broaden scope of host path types to skip processing in Windows
Signed-off-by: Deep Debroy <ddebroy@docker.com>
2018-10-12 19:57:08 -07:00
Deep Debroy
b4bb5dd430 Correctly handle named pipe host mounts for Windows
Signed-off-by: Deep Debroy <ddebroy@docker.com>
2018-10-05 16:46:04 -07:00
k8s-ci-robot
a8e8e891f2
Merge pull request #68289 from denkensk/fix-simple-pkg-kubelet
Simple code fixed in in pkg/kubelet
2018-09-25 06:14:03 -07:00
Brad Hoekstra
69551689d5 Fix spelling 2018-09-22 00:07:08 -04:00
Brad Hoekstra
42da186b62 Address review comments 2018-09-21 20:06:32 -04:00
Brad Hoekstra
c4ec40eca8 Update comment to reflect the new logic 2018-09-21 16:26:37 -04:00
Brad Hoekstra
e8366c8e99 Fix to inject KUBERNETES_ env vars when enableServiceLinks is
false and the pod is in the master namespace.
2018-09-17 16:28:49 -04:00
Brad Hoekstra
ac8799a80d kubelet: Make service environment variables optional 2018-09-17 16:27:36 -04:00
wangqingcan
b0c308f082 Simple code and typo fixed in in pkg/kubelet 2018-09-05 21:51:32 +08:00
Jordan Liggitt
e309bd3abf
Remove deprecated feature flags 2018-08-28 15:25:46 -04:00
Yu-Ju Hong
390b158db9 kubelet: plumb context for log requests
This allows kubelets to stop the necessary work when the context has
been canceled (e.g., connection closed), and not leaking a goroutine
and inotify watcher waiting indefinitely.
2018-08-10 17:35:46 -07:00
Russ Cox
2bd91dda64 kubernetes: fix printf format errors
These are all flagged by Go 1.11's
more accurate printf checking in go vet,
which runs as part of go test.

Lubomir I. Ivanov <neolit123@gmail.com>
applied ammend for:
  pkg/cloudprovider/provivers/vsphere/nodemanager.go
2018-07-11 00:10:15 +03:00