改进 状态判断
This commit is contained in:
parent
7115887e90
commit
124c7fbdcd
19
main.go
19
main.go
@ -21,12 +21,14 @@ type Deployment struct {
|
||||
Name string `json:"name"`
|
||||
Namespace string `json:"namespace"`
|
||||
Replicas int32 `json:"replicas"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// Cache 缓存
|
||||
type Cache struct {
|
||||
Deployments *[]Deployment `json:"deployments"`
|
||||
LastUpdated time.Time `json:"lastUpdated"`
|
||||
Deployments *[]Deployment `json:"deployments,omitempty"`
|
||||
|
||||
LastUpdated time.Time `json:"-"`
|
||||
}
|
||||
|
||||
var cachedData *Cache
|
||||
@ -130,12 +132,25 @@ func getNS() *[]Deployment {
|
||||
fmt.Printf("Error listing deployments in namespace %s: %v\n", namespace, err)
|
||||
continue
|
||||
}
|
||||
// 获取状态 progressing
|
||||
|
||||
for _, deployment := range deployments.Items {
|
||||
// get type
|
||||
|
||||
var status string
|
||||
|
||||
// 只有达到最低 available replicas 才能进入 available
|
||||
if deployment.Status.AvailableReplicas >= deployment.Status.Replicas {
|
||||
status = "Available"
|
||||
} else {
|
||||
status = "Progressing"
|
||||
}
|
||||
|
||||
d = append(d, Deployment{
|
||||
Name: deployment.Name,
|
||||
Namespace: deployment.Namespace,
|
||||
Replicas: *deployment.Spec.Replicas,
|
||||
Status: status,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user