kubernetes/pkg
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
..
api In-place Pod Vertical Scaling - API changes 2023-02-24 17:18:04 +00:00
apis Merge pull request #115816 from ivelichkovich/celrefactor 2023-03-01 20:22:54 -08:00
auth
capabilities
client delete unused functions in pkg directory 2023-01-16 21:43:36 +08:00
cloudprovider archived design proposals are now moved to Design Proposals Archive Repo. 2023-02-08 11:12:22 +08:00
cluster/ports e2e_node/{service,util}: use kubelet healthz port. 2022-04-22 16:14:31 -07:00
controller Merge pull request #115861 from JayKayy/inform-unsupported-pdb 2023-03-03 03:16:58 -08:00
controlplane update lease controller 2023-03-02 15:06:00 +01:00
credentialprovider delete unused functions in pkg directory 2023-01-16 21:43:36 +08:00
features Graduate JobMutableNodeSchedulingDirectives feature to GA 2023-02-28 15:47:13 +00:00
fieldpath Improved FormatMap: Improves performance by about 4x, or nearly 2x in the worst case (#112661) 2023-03-01 22:26:55 -08:00
generated Merge pull request #115402 from p0lyn0mial/upstream-sendinitialevents-take-2 2023-03-02 01:58:55 -08:00
kubeapiserver authenticator config: use static CA reader for OIDC CA 2023-02-14 13:43:58 +01:00
kubectl Refactor to simplify factory Validator 2022-12-11 18:20:28 -08:00
kubelet kubelet: Force deleted pods can fail to move out of terminating 2023-03-08 22:03:51 -06:00
kubemark Merge pull request #114725 from danwinship/kube-proxy-startup-cleanup 2023-01-05 13:57:59 -08:00
printers Merge pull request #114759 from my-git9/chore/k8staint 2023-01-31 21:01:17 -08:00
probe Document risk of HTTP response body in probe failure msg 2023-02-09 16:37:32 -08:00
proxy proxier: track metrics before conntrack cleaning 2023-03-02 20:56:05 +05:30
quota/v1 In-place Pod Vertical Scaling - API changes 2023-02-24 17:18:04 +00:00
registry update documentation on generateSelector for manual selector case 2023-03-02 19:47:58 +00:00
routes unittests: Fixes unit tests for Windows (part 3) 2022-10-21 19:25:48 +03:00
scheduler Merge pull request #102884 from vinaykul/restart-free-pod-vertical-scaling 2023-02-27 22:53:15 -08:00
security changes in NewValidator 2023-02-21 13:02:30 +05:30
securitycontext Merge pull request #112037 from mingweishih/update_default_proc_mount 2023-02-14 23:28:24 -08:00
serviceaccount handle new error where sa jwt issued in the future 2023-03-02 03:15:13 +01:00
util Merge pull request #115527 from sondinht/ipvs_sh 2023-02-14 04:25:30 -08:00
volume Remove check for CSI driver running on node for CSI migration attach operations 2023-02-09 02:45:02 +00:00
windows/service Fix typo at pkg/windows/service/service.go:94 2022-03-24 07:25:33 -04:00
.import-restrictions
OWNERS Move root approvers to subdirs 2022-10-10 13:43:03 -04:00