Skip to content

Commit

Permalink
Merge pull request Mirantis#168 from prezha/check-ip-for-readiness
Browse files Browse the repository at this point in the history
check if running container also has ip address to return ready state
  • Loading branch information
evol262 authored Mar 24, 2023
2 parents 6daf9ac + 64619c7 commit 47abdab
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions core/sandbox_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package core
import (
"context"
"fmt"

v1 "k8s.io/cri-api/pkg/apis/runtime/v1"
)

Expand All @@ -41,12 +42,6 @@ func (ds *dockerService) PodSandboxStatus(
}
ct := createdAt.UnixNano()

// Translate container to sandbox state.
state := v1.PodSandboxState_SANDBOX_NOTREADY
if r.State.Running {
state = v1.PodSandboxState_SANDBOX_READY
}

var ips []string
// This is a workaround for windows, where sandbox is not in use, and pod IP is determined through containers belonging to the Pod.
if ips = ds.determinePodIPBySandboxID(podSandboxID); len(ips) == 0 {
Expand All @@ -61,6 +56,13 @@ func (ds *dockerService) PodSandboxStatus(
ips = ips[1:]
}

// Translate container to sandbox state.
// For a sandbox to be in the Ready state, the container needs to be in the Running state and it also needs to have an IP address.
state := v1.PodSandboxState_SANDBOX_NOTREADY
if r.State.Running && len(ips) > 0 {
state = v1.PodSandboxState_SANDBOX_READY
}

labels, annotations := extractLabels(r.Config.Labels)
status := &v1.PodSandboxStatus{
Id: r.ID,
Expand Down

0 comments on commit 47abdab

Please sign in to comment.