CSI is used by both the kubelet and kube-controller-manager. Both
components will initialize the csiPlugin with different VolumeHost
objects. The csiPlugin will then assign a global variable for
the node info manager. It is then possible that the kubelet gets
the credentials of the kube-controller-manager and that will cause
CSI to fail.
Currently the provider that the podresources API
consumes does *not* obviously filters out the terminal
pod, and this is corroborated by the fact the related
e2e test starts to fail.
We had a bug in the test which masked the real failure,
but now it's evident.
So we perform a trivial extraction of the kubelet filtering
code and we apply in both places.
Note that the existing flow is unaffected except for the
trivial code extraciton.
Signed-off-by: Francesco Romani <fromani@redhat.com>
When a container restarts before kubelet restarts, containerMap has
multiple entries (old exited + new running). GetContainerID() may
return the exited container, causing the running check to fail. Fixed
by checking if ANY container for the pod/name is running.
Also filter terminal pods from podresources since they no longer
consume resources, and fix test error handling to avoid exiting
Eventually immediately on transient errors.
Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
- Code generator: use len() != 0 for slice/map member extractors
instead of != nil, so empty slice/map are treated as "not set"
- Add slice and map members to union test types (both discriminated
and undiscriminated)
- Add test coverage for nil vs empty, ratcheting, and nil oldObj
with slice/map members
Co-authored-by: Tim Hockin <thockin@google.com>
- Use reflect.ValueOf(oldObj).IsZero() instead of IsNil() so union
validation works with non-nilable T (e.g. value types)
- Remove hasOldValue guard from inner loop conditionals; only check
at the final ratcheting skip point
- Add doc comments explaining T is "any" rather than "comparable"
because union members can be slices
- Add value-type subtests for Union and DiscriminatedUnion
Co-authored-by: Tim Hockin <thockin@google.com>
Test that declarative validation catches a DeviceAttribute with no
value fields set, which was the original bug scenario where union
ratcheting incorrectly skipped validation for new map entries.
Add tests for Union, DiscriminatedUnion, and ZeroOrOneOfUnion
validating that nil oldObj (new map entry or newly-set pointer
field during update) does not skip validation via ratcheting.
When oldObj is nil (e.g. new map entry added during update), union
ratcheting incorrectly treats nil old and empty new as unchanged
membership, skipping validation entirely. Fix by checking
reflect.ValueOf(oldObj).IsNil() and disabling ratcheting when
oldObj is nil, so the new value is fully validated.
This affects Union, DiscriminatedUnion, and ZeroOrOneOfUnion
(via unionValidate).
When a pod has a sidecar (initContainer with restartPolicy: Always) with
a startupProbe, and one or more regular containers crash after a kubelet
restart, the kubelet fails to restart the regular containers. RestartCount
stays at 0 indefinitely.
When ChangeContainerStatusOnKubeletRestart is disabled (default in v1.35),
the prober worker skips seeding probe results for containers that predate
the kubelet restart. For a sidecar with a startupProbe this means
startupManager.Get() returns found=false permanently. In
computeInitContainerActions, the sidecar Running case breaks out early at
the !found check, leaving podHasInitialized=false. computePodActions then
returns early at the !hasInitialized guard without restarting the crashed
regular containers.
Fix: when the gate is off and a restartable init container's startup probe
is being seeded for the first time after a kubelet restart, check the
container's Started field in the pod status. If Started=true, the sidecar
had already passed startup before the restart, so seed the startup manager
with Success. This allows computeInitContainerActions to detect pod
initialization via the sidecar Running path without altering readiness or
liveness probe seeding behaviour.
Add and update tests to cover the fix:
- worker unit tests for sidecar startup/readiness/liveness restart behaviour
- e2e node regression test for sidecar with startupProbe across kubelet restart
Fixes: https://github.com/kubernetes/kubernetes/issues/136910