Skip to content

Commit

Permalink
feat: add logic to check node readiness
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanGalloway authored Jan 4, 2022
1 parent fd94515 commit b03a5b2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ func IsImage(obj *unstructured.Unstructured) bool {
return obj.GetKind() == "Image"
}

func IsNode(obj *unstructured.Unstructured) bool {
return obj.GetKind() == "Node"
}

func NewDeployment(ns, name, image string, labels map[string]string, port int32, args ...string) *apps.Deployment {
if labels == nil {
labels = make(map[string]string)
Expand Down
39 changes: 39 additions & 0 deletions wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ func (c *Client) IsReady(item *unstructured.Unstructured) (bool, string) {
return IsBuilderReady(item)
case IsImage(item):
return IsImageReady(item)
case IsNode(item):
return IsNodeReady(item)
}

if item.Object["status"] == nil {
Expand All @@ -275,6 +277,43 @@ func (c *Client) IsReady(item *unstructured.Unstructured) (bool, string) {
return true, ""
}

func IsNodeReady(item *unstructured.Unstructured) (bool, string) {
if item.Object["status"] == nil {
return false, "⏳ waiting to report status"
}

status := item.Object["status"].(map[string]interface{})

if _, found := status["conditions"]; !found {
return false, "⏳ waiting to report status"
}

conditions := status["conditions"].([]interface{})
if len(conditions) == 0 {
return false, "⏳ waiting to report status"
}
message := ""
ready := true
for _, raw := range conditions {
condition := raw.(map[string]interface{})
if condition["type"] != "Ready" {
if condition["status"] == "True" {
ready = false
if message != "" {
message += ", "
}
message += fmt.Sprintf("%s: %s", condition["type"], condition["message"])
}
} else {
if condition["status"] == "False" {
ready = false
message += fmt.Sprintf("%s: %s", condition["type"], condition["message"])
}
}
}
return ready, message
}

func IsBuilderReady(item *unstructured.Unstructured) (bool, string) {
if item.Object["status"] == nil {
return false, "⏳ waiting to become ready"
Expand Down

0 comments on commit b03a5b2

Please sign in to comment.