Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions internal/controller/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ func containerCounts(pod *v1.Pod) (amaltheadevv1alpha1.ContainerCounts, amalthea
if pod == nil {
return initCounts, counts
}

for _, container := range pod.Status.InitContainerStatuses {
containerCompleted := container.State.Terminated != nil && container.State.Terminated.ExitCode == 0 && container.State.Terminated.Reason == "Completed"
var containerOk bool
if isContainerSidecar(container, *pod) {
containerOk = container.Ready && container.State.Running != nil
} else {
containerOk = container.State.Terminated != nil && container.State.Terminated.ExitCode == 0 && container.State.Terminated.Reason == "Completed"
}

initCounts.Total += 1
if containerCompleted {
if containerOk {
initCounts.Ready += 1
}
}
Expand All @@ -39,14 +46,38 @@ func containerCounts(pod *v1.Pod) (amaltheadevv1alpha1.ContainerCounts, amalthea
return initCounts, counts
}

func containerRestartPolicy(status v1.ContainerStatus, pod v1.Pod) *v1.ContainerRestartPolicy {
for _, c := range pod.Spec.Containers {
if c.Name == status.Name {
return c.RestartPolicy
}
}
return nil
}

func isContainerSidecar(status v1.ContainerStatus, pod v1.Pod) bool {
restartPolicy := containerRestartPolicy(status, pod)
if restartPolicy != nil {
switch *restartPolicy {
case v1.ContainerRestartPolicyAlways:
return true
}
}
return false
}

func podIsReady(pod *v1.Pod) bool {
if pod == nil || pod.GetDeletionTimestamp() != nil {
// A missing pod or a pod being deleted is not considered ready
return false
}
phaseOk := pod.Status.Phase == v1.PodSucceeded || pod.Status.Phase == v1.PodRunning
initCounts, counts := containerCounts(pod)
return initCounts.Ok() && counts.Ok() && phaseOk
condOk := false
for _, c := range pod.Status.Conditions {
if c.Type == v1.PodReady && c.Status == v1.ConditionTrue {
condOk = true
}
}
return phaseOk && condOk
}

func podIsCompleted(pod *v1.Pod) bool {
Expand Down
Loading