Skip to content

Commit

Permalink
use pod phase/status (micro#1356)
Browse files Browse the repository at this point in the history
  • Loading branch information
asim committed Mar 16, 2020
1 parent 5712aaf commit 03031a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
25 changes: 14 additions & 11 deletions runtime/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,22 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) {
}

// get the status from the pods
status := "unknown"
if len(podList.Items) > 0 {
switch podList.Items[0].Status.Conditions[0].Type {
case "PodScheduled":
status = "starting"
case "Initialized":
status = "starting"
case "Ready":
status = "ready"
case "ContainersReady":
status = "ready"
var status string

for _, item := range podList.Items {
switch item.Status.Phase {
case "Failed":
status = item.Status.Reason
default:
status = item.Status.Phase
}
}

// unknown status
if len(status) == 0 {
status = "n/a"
}

if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debugf("Runtime setting %s service deployment status: %v", name, status)
}
Expand Down
3 changes: 2 additions & 1 deletion util/kubernetes/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ type Pod struct {

// PodStatus
type PodStatus struct {
Conditions []PodCondition `json:"conditions,omitempty"`
PodIP string `json:"podIP"`
Phase string `json:"phase"`
Conditions []PodCondition `json:"conditions,omitempty"`
Reason string `json:"reason"`
}

// PodCondition describes the state of pod
Expand Down

0 comments on commit 03031a6

Please sign in to comment.