kubernetes/pkg/kubelet
Clayton Coleman 6b9a381185
kubelet: Force deleted pods can fail to move out of terminating
If a CRI error occurs during the terminating phase after a pod is
force deleted (API or static) then the housekeeping loop will not
deliver updates to the pod worker which prevents the pod's state
machine from progressing. The pod will remain in the terminating
phase but no further attempts to terminate or cleanup will occur
until the kubelet is restarted.

The pod worker now maintains a store of the pods state that it is
attempting to reconcile and uses that to resync unknown pods when
SyncKnownPods() is invoked, so that failures in sync methods for
unknown pods no longer hang forever.

The pod worker's store tracks desired updates and the last update
applied on podSyncStatuses. Each goroutine now synchronizes to
acquire the next work item, context, and whether the pod can start.
This synchronization moves the pending update to the stored last
update, which will ensure third parties accessing pod worker state
don't see updates before the pod worker begins synchronizing them.

As a consequence, the update channel becomes a simple notifier
(struct{}) so that SyncKnownPods can coordinate with the pod worker
to create a synthetic pending update for unknown pods (i.e. no one
besides the pod worker has data about those pods). Otherwise the
pending update info would be hidden inside the channel.

In order to properly track pending updates, we have to be very
careful not to mix RunningPods (which are calculated from the
container runtime and are missing all spec info) and config-
sourced pods. Update the pod worker to avoid using ToAPIPod()
and instead require the pod worker to directly use
update.Options.Pod or update.Options.RunningPod for the
correct methods. Add a new SyncTerminatingRuntimePod to prevent
accidental invocations of runtime only pod data.

Finally, fix SyncKnownPods to replay the last valid update for
undesired pods which drives the pod state machine towards
termination, and alter HandlePodCleanups to:

- terminate runtime pods that aren't known to the pod worker
- launch admitted pods that aren't known to the pod worker

Any started pods receive a replay until they reach the finished
state, and then are removed from the pod worker. When a desired
pod is detected as not being in the worker, the usual cause is
that the pod was deleted and recreated with the same UID (almost
always a static pod since API UID reuse is statistically
unlikely). This simplifies the previous restartable pod support.
We are careful to filter for active pods (those not already
terminal or those which have been previously rejected by
admission). We also force a refresh of the runtime cache to
ensure we don't see an older version of the state.

Future changes will allow other components that need to view the
pod worker's actual state (not the desired state the podManager
represents) to retrieve that info from the pod worker.

Several bugs in pod lifecycle have been undetectable at runtime
because the kubelet does not clearly describe the number of pods
in use. To better report, add the following metrics:

  kubelet_desired_pods: Pods the pod manager sees
  kubelet_active_pods: "Admitted" pods that gate new pods
  kubelet_mirror_pods: Mirror pods the kubelet is tracking
  kubelet_working_pods: Breakdown of pods from the last sync in
    each phase, orphaned state, and static or not
  kubelet_restarted_pods_total: A counter for pods that saw a
    CREATE before the previous pod with the same UID was finished
  kubelet_orphaned_runtime_pods_total: A counter for pods detected
    at runtime that were not known to the kubelet. Will be
    populated at Kubelet startup and should never be incremented
    after.

Add a metric check to our e2e tests that verifies the values are
captured correctly during a serial test, and then verify them in
detail in unit tests.

Adds 23 series to the kubelet /metrics endpoint.
2023-03-08 22:03:51 -06:00
..
apis Add MaxParallelImagePulls support 2023-03-02 03:57:59 +00:00
cadvisor Merge pull request #114785 from TommyStarK/kubelet/replace-deprecated-pointer-function 2023-03-01 18:04:55 -08:00
certificate Merge pull request #114367 from liggitt/kubelet-csr-init 2023-01-30 09:07:05 -08:00
checkpointmanager
client kubelet/client: collapse transport wiring onto standard approach 2023-02-06 20:34:49 -05:00
cloudresource
cm Merge pull request #114114 from ffromani/full-pcpus-stricter-precheck-issue113537 2023-03-02 09:04:56 -08:00
config Merge pull request #112021 from mrunalp/test_host_path_pv_selinux_fix 2022-12-23 12:35:27 -08:00
configmap Generate and format files 2022-07-26 13:14:05 -04:00
container kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
cri Merge pull request #115101 from HirazawaUi/delte-pkg-kubelet-unused-functions 2023-01-29 17:21:08 -08:00
envvars
events
eviction This commit contains the following: 2023-02-24 18:21:21 +00:00
images Add MaxParallelImagePulls support 2023-03-02 03:57:59 +00:00
kubeletconfig Merge pull request #115101 from HirazawaUi/delte-pkg-kubelet-unused-functions 2023-01-29 17:21:08 -08:00
kuberuntime kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
leaky
lifecycle Fix indentation/spacing in comments to render correctly in godoc 2022-12-17 23:27:38 -05:00
logs Second attempt: Plumb context to Kubelet CRI calls (#113591) 2022-11-05 06:02:13 -07:00
metrics kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
network Skip failing Windows unit tests 2023-01-18 14:18:41 +02:00
nodeshutdown dependencies: update klog v2.90.1 2023-03-01 19:03:50 +01:00
nodestatus Second attempt: Plumb context to Kubelet CRI calls (#113591) 2022-11-05 06:02:13 -07:00
oom linux: fix kubelet start unit test 2022-11-09 07:17:05 +08:00
pleg This commit contains the following: 2023-02-24 18:21:21 +00:00
pluginmanager close grpc server in test file to avoid goroutine leak 2023-02-10 09:51:26 +08:00
pod kubelet: Replace deprecated pointer function 2023-01-08 13:44:09 +01:00
preemption feat: improve naming 2022-07-24 19:04:08 +09:00
prober This commit contains the following: 2023-02-24 18:21:21 +00:00
qos In-place Pod Vertical Scaling - core implementation 2023-02-24 18:21:21 +00:00
runtimeclass kubelet: Replace deprecated pointer function 2023-01-08 13:44:09 +01:00
secret Generate and format files 2022-07-26 13:14:05 -04:00
server Merge pull request #114785 from TommyStarK/kubelet/replace-deprecated-pointer-function 2023-03-01 18:04:55 -08:00
stats *: Fix linter warnings 2023-02-07 13:01:41 +05:30
status In-place Pod Vertical Scaling - core implementation 2023-02-24 18:21:21 +00:00
sysctl impove the coverage 2023-02-01 10:47:38 +08:00
token Merge pull request #99685 from yangjunmyfm192085/run-test24 2022-05-03 17:16:47 -07:00
types Enable the feature into beta 2022-11-09 09:02:40 +01:00
util Merge pull request #115101 from HirazawaUi/delte-pkg-kubelet-unused-functions 2023-01-29 17:21:08 -08:00
volumemanager Merge pull request #111982 from cvvz/kubelet-del-unnecessary-code 2023-02-14 10:31:31 -08:00
winstats win: fix cpu count to calculate cpu_maximum 2022-12-14 13:56:31 +01:00
active_deadline_test.go Add comment for 0th case 2022-10-08 12:06:42 +03:00
active_deadline.go
doc.go
errors.go
kubelet_getters_test.go Add test case for getPodVolumeSubpathsDir 2022-04-27 16:33:28 +08:00
kubelet_getters.go Second attempt: Plumb context to Kubelet CRI calls (#113591) 2022-11-05 06:02:13 -07:00
kubelet_network_linux.go Add IPTablesOwnershipCleanup feature to disable kubelet iptables setup 2022-07-27 13:33:09 -04:00
kubelet_network_others.go
kubelet_network_test.go
kubelet_network.go Second attempt: Plumb context to Kubelet CRI calls (#113591) 2022-11-05 06:02:13 -07:00
kubelet_node_status_others.go
kubelet_node_status_test.go kubelet: Keep trying fast status update at startup until node is ready 2022-11-09 15:55:20 +00:00
kubelet_node_status_windows.go
kubelet_node_status.go kubelet: Keep trying fast status update at startup until node is ready 2022-11-09 15:55:20 +00:00
kubelet_pods_linux_test.go Promote Local storage capacity isolation feature to GA 2022-08-02 23:45:48 -07:00
kubelet_pods_test.go kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
kubelet_pods_windows_test.go unittests: Fixes unit tests for Windows 2022-10-25 23:46:56 +03:00
kubelet_pods.go kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
kubelet_resources_test.go
kubelet_resources.go
kubelet_test.go kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
kubelet_volumes_linux_test.go Remove ioutil in kubelet and its tests 2022-07-30 12:35:26 +09:00
kubelet_volumes_test.go Upgrade CSIMigrationGCE feature gate to GA 2022-08-02 09:14:27 -07:00
kubelet_volumes.go remove ioutil in kubelet 2022-04-27 21:08:42 +08:00
kubelet.go kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
OWNERS
pod_container_deletor_test.go
pod_container_deletor.go Second attempt: Plumb context to Kubelet CRI calls (#113591) 2022-11-05 06:02:13 -07:00
pod_workers_test.go kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
pod_workers.go kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
reason_cache_test.go
reason_cache.go Generate and format files 2022-07-26 13:14:05 -04:00
runonce_test.go In-place Pod Vertical Scaling - core implementation 2023-02-24 18:21:21 +00:00
runonce.go kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
runtime.go
userns_manager_test.go kubelet: drop bitArray implementation 2022-08-19 16:55:15 +02:00
userns_manager.go kubelet: drop bitArray implementation 2022-08-19 16:55:15 +02:00
volume_host.go linux: fix kubelet start unit test 2022-11-09 07:17:05 +08:00