kubernetes/pkg/kubelet/kuberuntime
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
..
logs kubelet: Replace deprecated pointer function 2023-01-08 13:44:09 +01:00
util kubelet: set user namespace options 2022-08-03 19:53:22 +02:00
convert_test.go Make CRI v1 the default and allow a fallback to v1alpha2 2021-11-17 11:05:05 -08:00
convert.go Make CRI v1 the default and allow a fallback to v1alpha2 2021-11-17 11:05:05 -08:00
doc.go
fake_kuberuntime_manager.go Add MaxParallelImagePulls support 2023-03-02 03:57:59 +00:00
helpers_linux_test.go Merge pull request #114785 from TommyStarK/kubelet/replace-deprecated-pointer-function 2023-03-01 18:04:55 -08:00
helpers_linux.go In-place Pod Vertical Scaling - core implementation 2023-02-24 18:21:21 +00:00
helpers_test.go Second attempt: Plumb context to Kubelet CRI calls (#113591) 2022-11-05 06:02:13 -07:00
helpers_unsupported.go Fix cpu share issues on systems with large amounts of cpu 2021-11-14 19:49:19 +00:00
helpers.go In-place Pod Vertical Scaling - core implementation 2023-02-24 18:21:21 +00:00
instrumented_services_test.go Second attempt: Plumb context to Kubelet CRI calls (#113591) 2022-11-05 06:02:13 -07:00
instrumented_services.go Add fake runtimes and CRI changes for KEP-2371 2022-11-08 14:47:08 -05:00
kuberuntime_container_linux_test.go DRA: pass CDI devices through CRI CDIDevice field 2023-02-28 19:21:20 +02:00
kuberuntime_container_linux.go In-place Pod Vertical Scaling - core implementation 2023-02-24 18:21:21 +00:00
kuberuntime_container_test.go This commit contains the following: 2023-02-24 18:21:21 +00:00
kuberuntime_container_unsupported.go In-place Pod Vertical Scaling - core implementation 2023-02-24 18:21:21 +00:00
kuberuntime_container_windows_test.go unittests: Fixes unit tests for Windows (part 6) 2023-01-31 11:49:26 +00:00
kuberuntime_container_windows.go In-place Pod Vertical Scaling - core implementation 2023-02-24 18:21:21 +00:00
kuberuntime_container.go DRA: pass CDI devices through CRI CDIDevice field 2023-02-28 19:21:20 +02:00
kuberuntime_gc_test.go Second attempt: Plumb context to Kubelet CRI calls (#113591) 2022-11-05 06:02:13 -07:00
kuberuntime_gc.go Second attempt: Plumb context to Kubelet CRI calls (#113591) 2022-11-05 06:02:13 -07:00
kuberuntime_image_test.go Second attempt: Plumb context to Kubelet CRI calls (#113591) 2022-11-05 06:02:13 -07:00
kuberuntime_image.go Second attempt: Plumb context to Kubelet CRI calls (#113591) 2022-11-05 06:02:13 -07:00
kuberuntime_logs.go kubelet: plumb context for log requests 2018-08-10 17:35:46 -07:00
kuberuntime_manager_test.go This commit contains the following: 2023-02-24 18:21:21 +00:00
kuberuntime_manager.go kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
kuberuntime_sandbox_linux_test.go Make CRI v1 the default and allow a fallback to v1alpha2 2021-11-17 11:05:05 -08:00
kuberuntime_sandbox_linux.go fix bugs of container cpu shares when cpu request set to zero 2022-03-20 21:53:22 +08:00
kuberuntime_sandbox_test.go kubelet: Replace deprecated pointer function 2023-01-08 13:44:09 +01:00
kuberuntime_sandbox_unsupported.go Make CRI v1 the default and allow a fallback to v1alpha2 2021-11-17 11:05:05 -08:00
kuberuntime_sandbox_windows.go Make CRI v1 the default and allow a fallback to v1alpha2 2021-11-17 11:05:05 -08:00
kuberuntime_sandbox.go Merge pull request #112961 from marosset/windows-hostnetwork-alpha 2022-11-07 12:42:16 -08:00
labels_test.go In-place Pod Vertical Scaling - core implementation 2023-02-24 18:21:21 +00:00
labels.go In-place Pod Vertical Scaling - core implementation 2023-02-24 18:21:21 +00:00
legacy_test.go Replaces path.Operation with filepath.Operation (kubelet) 2022-11-08 16:05:48 +00:00
legacy.go Replaces path.Operation with filepath.Operation (kubelet) 2022-11-08 16:05:48 +00:00
security_context_others_test.go generated: Run hack/update-gofmt.sh 2021-08-24 15:47:49 -04:00
security_context_others.go generated: Run hack/update-gofmt.sh 2021-08-24 15:47:49 -04:00
security_context_windows_test.go Merge pull request #111020 from claudiubelu/adds-unittests-5 2022-07-29 19:29:11 -07:00
security_context_windows.go Windows: ensure runAsNonRoot does case-insensitive comparison on user name 2022-07-18 15:23:13 -07:00
security_context.go kubelet: propagate errors from namespacesForPod 2022-08-03 19:53:22 +02:00