From 82c28ae4309971ec2f6147b1aef589ac19cbe33f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 15 Dec 2025 15:24:28 +0000 Subject: [PATCH 1/3] Fix pod Ready condition for pods with init containers Previously, pods with init containers were incorrectly set to phase="Running" with Ready=True immediately upon creation, even though their containers were still in "Waiting" state with reason "Remote pod submitted". This fix changes the behavior so that pods with init containers: - Start in phase="Pending" (not "Running") - Have Ready=False (not True) - Have PodInitialized=False (correctly indicates init containers not complete) This aligns with standard Kubernetes behavior where pods should only be marked as Ready when their containers are actually ready to serve traffic. Signed-off-by: Diego Ciangottini --- pkg/virtualkubelet/virtualkubelet.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/virtualkubelet/virtualkubelet.go b/pkg/virtualkubelet/virtualkubelet.go index e4d455ce..e1c43cc5 100644 --- a/pkg/virtualkubelet/virtualkubelet.go +++ b/pkg/virtualkubelet/virtualkubelet.go @@ -1485,12 +1485,19 @@ func (p *Provider) CreatePod(ctx context.Context, pod *v1.Pod) error { if len(pod.Spec.InitContainers) > 0 { hasInitContainers = true - // we put the phase in running but initialization phase to false - status, err := PodPhase(*p, "Running", podIP) + // Pods with init containers should be Pending until init containers complete + status, err := PodPhase(*p, "Pending", podIP) if err != nil { log.G(ctx).Error(err) return err } + // Set PodInitialized to False since init containers haven't completed yet + for i := range status.Conditions { + if status.Conditions[i].Type == v1.PodInitialized { + status.Conditions[i].Status = v1.ConditionFalse + break + } + } pod.Status = status err = p.UpdatePod(ctx, pod) if err != nil { From 070ec66706be590c57412c6e7108efae1623ae72 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 15 Dec 2025 15:27:02 +0000 Subject: [PATCH 2/3] Fix container Ready status for all newly created pods Previously, containers in pods without init containers were incorrectly marked as Ready=true immediately upon creation, even though they were still in "Waiting" state with reason "Remote pod submitted". This fix ensures that all containers start with Ready=false when created, since they are in Waiting state. The status will be updated to Ready=true later by the status polling loop once the containers are actually running. This change affects both pods with and without init containers, ensuring consistent behavior where containers are only marked Ready when they are actually ready to serve traffic, not just when they're submitted. Signed-off-by: Diego Ciangottini --- pkg/virtualkubelet/virtualkubelet.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/virtualkubelet/virtualkubelet.go b/pkg/virtualkubelet/virtualkubelet.go index e1c43cc5..c37e5a51 100644 --- a/pkg/virtualkubelet/virtualkubelet.go +++ b/pkg/virtualkubelet/virtualkubelet.go @@ -1564,12 +1564,12 @@ func (p *Provider) CreatePod(ctx context.Context, pod *v1.Pod) error { } }() - // set pod containers status to notReady and waiting if there is an initContainer to be executed first + // set pod containers status to notReady and waiting since they haven't started yet for _, container := range pod.Spec.Containers { pod.Status.ContainerStatuses = append(pod.Status.ContainerStatuses, v1.ContainerStatus{ Name: container.Name, Image: container.Image, - Ready: !hasInitContainers, + Ready: false, RestartCount: 0, State: state, }) From 1adc5a868110f6853d3b45bd6cbafc498f005860 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 15 Dec 2025 15:38:53 +0000 Subject: [PATCH 3/3] Remove unused hasInitContainers variable The hasInitContainers variable was no longer needed after fixing the container Ready status to always be false at creation time. This commit removes the unused variable declaration to fix compilation. Signed-off-by: Diego Ciangottini --- pkg/virtualkubelet/virtualkubelet.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/virtualkubelet/virtualkubelet.go b/pkg/virtualkubelet/virtualkubelet.go index c37e5a51..4d91fc97 100644 --- a/pkg/virtualkubelet/virtualkubelet.go +++ b/pkg/virtualkubelet/virtualkubelet.go @@ -1388,7 +1388,6 @@ func (p *Provider) waitForWstunnelPodIP(ctx context.Context, dummyPod *v1.Pod, t func (p *Provider) CreatePod(ctx context.Context, pod *v1.Pod) error { TracerUpdate(&ctx, "CreatePodVK", pod) - hasInitContainers := false var state v1.ContainerState key := pod.UID @@ -1483,8 +1482,6 @@ func (p *Provider) CreatePod(ctx context.Context, pod *v1.Pod) error { // in case we have initContainers we need to stop main containers from executing for now ... if len(pod.Spec.InitContainers) > 0 { - hasInitContainers = true - // Pods with init containers should be Pending until init containers complete status, err := PodPhase(*p, "Pending", podIP) if err != nil {