Commit Graph

300 Commits

Author SHA1 Message Date
saad-ali
beb17fe10b Remove VolumeSubpath feature gate
Remove the VolumeSubpath feature gate.

Feature gate convention has been updated since this was introduced to
indicate that they "are intended to be deprecated and removed after a
feature becomes GA or is dropped.".
2021-09-17 01:59:23 -07:00
Clayton Coleman
d5719800bf
kubelet: Handle UID reuse in pod worker
If a pod is killed (no longer wanted) and then a subsequent create/
add/update event is seen in the pod worker, assume that a pod UID
was reused (as it could be in static pods) and have the next
SyncKnownPods after the pod terminates remove the worker history so
that the config loop can restart the static pod, as well as return
to the caller the fact that this termination was not final.

The housekeeping loop then reconciles the desired state of the Kubelet
(pods in pod manager that are not in a terminal state, i.e. admitted
pods) with the pod worker by resubmitting those pods. This adds a
small amount of latency (2s) when a pod UID is reused and the pod
is terminated and restarted.
2021-09-15 14:02:00 -04:00
Clayton Coleman
17d32ed0b8
kubelet: Rejected pods should be filtered from admission
A pod that has been rejected by admission will have status manager
set the phase to Failed locally, which make take some time to
propagate to the apiserver. The rejected pod will be included in
admission until the apiserver propagates the change back, which
was an unintended regression when checking pod worker state as
authoritative.

A pod that is terminal in the API may still be consuming resources
on the system, so it should still be included in admission.
2021-09-08 10:23:45 -04:00
Clayton Coleman
a2ca66d280
kubelet: Admission must exclude completed pods and avoid races
Fixes two issues with how the pod worker refactor calculated the
pods that admission could see (GetActivePods() and
filterOutTerminatedPods())

First, completed pods must be filtered from the "desired" state
for admission, which arguably should be happening earlier in
config. Exclude the two terminal pods states from GetActivePods()

Second, the previous check introduced with the pod worker lifecycle
ownership changes was subtly wrong for the admission use case.
Admission has to include pods that haven't yet hit the pod worker,
which CouldHaveRunningContainers was filtering out (because the
pod worker hasn't seen them). Introduce a weaker check -
IsPodKnownTerminated() - that returns true only if the pod is in
a known terminated state (no running containers AND known to pod
worker). This weaker check may only be called from components that
need admitted pods, not other kubelet subsystems.

This commit does not fix the long standing bug that force deleted
pods are omitted from admission checks, which must be fixed by
having GetActivePods() also include pods "still terminating".
2021-08-25 13:31:02 -04:00
Wesley Williams
ff165c8823
Replace usage of Whitelist with Allowlist within Kubelet's sysctl package (#102298)
* Change uses of whitelist to allowlist in kubelet sysctl

* Rename whitelist files to allowlist in Kubelet sysctl

* Further renames of whitelist to allowlist in Kubelet

* Rename podsecuritypolicy uses of whitelist to allowlist

* Update pkg/kubelet/kubelet.go

Co-authored-by: Danielle <dani@builds.terrible.systems>

Co-authored-by: Danielle <dani@builds.terrible.systems>
2021-08-04 18:59:35 -07:00
Clayton Coleman
d7ee024cc5
kubelet: Make condition processing in one spot
The list of status conditions should be calculated all together,
this made review more complex. Readability only.
2021-07-19 17:56:22 -04:00
Clayton Coleman
c2a6d07b8f
kubelet: Avoid allocating multiple times during status
Noticed while reviewing this code path. We can assume the
temporary slice should be about the same size as it was previously.
2021-07-19 17:55:18 -04:00
Clayton Coleman
9efd40d72a kubelet: Preserve reason/message when phase changes
The Kubelet always clears reason and message in generateAPIPodStatus
even when the phase is unchanged. It is reasonable that we preserve
the previous values when the phase does not change, and clear it
when the phase does change.

When a pod is evicted, this ensurse that the eviction message and
reason are propagated even in the face of subsequent updates. It also
preserves the message and reason if components beyond the Kubelet
choose to set that value.

To preserve the value we need to know the old phase, which requires
a change to convertStatusToAPIStatus so that both methods have
access to it.
2021-07-19 17:54:55 -04:00
Kubernetes Prow Robot
04ef2b115d
Merge pull request #90216 from DataDog/nayef/fix-container-statuses-race
Avoid overwriting podStatus ContainerStatuses in convertToAPIContainerStatuses
2021-07-12 17:02:29 -07:00
Kubernetes Prow Robot
dab6f6a43d
Merge pull request #102344 from smarterclayton/keep_pod_worker
Prevent Kubelet from incorrectly interpreting "not yet started" pods as "ready to terminate pods" by unifying responsibility for pod lifecycle into pod worker
2021-07-08 16:48:53 -07:00
Kubernetes Prow Robot
57716897eb
Merge pull request #103434 from perithompson/windows-etchostcreate-skip
Explicitly skip host file mounting for Windows when HostProcess pod
2021-07-08 15:36:53 -07:00
Peri Thompson
8e2b728c68
Explicitly skip host file mounting for windows 2021-07-08 19:38:49 +01:00
Nayef Ghattas
ab1807f2bc copy podStatus.ContainerStatuses before sorting it 2021-07-07 20:14:53 +02:00
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