改进 状态判断

This commit is contained in:
ivamp 2024-07-18 00:41:33 +08:00
parent 7115887e90
commit 124c7fbdcd

19
main.go
View File

@ -21,12 +21,14 @@ type Deployment struct {
Name string `json:"name"` Name string `json:"name"`
Namespace string `json:"namespace"` Namespace string `json:"namespace"`
Replicas int32 `json:"replicas"` Replicas int32 `json:"replicas"`
Status string `json:"status"`
} }
// Cache 缓存 // Cache 缓存
type Cache struct { type Cache struct {
Deployments *[]Deployment `json:"deployments"` Deployments *[]Deployment `json:"deployments,omitempty"`
LastUpdated time.Time `json:"lastUpdated"`
LastUpdated time.Time `json:"-"`
} }
var cachedData *Cache var cachedData *Cache
@ -130,12 +132,25 @@ func getNS() *[]Deployment {
fmt.Printf("Error listing deployments in namespace %s: %v\n", namespace, err) fmt.Printf("Error listing deployments in namespace %s: %v\n", namespace, err)
continue continue
} }
// 获取状态 progressing
for _, deployment := range deployments.Items { 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{ d = append(d, Deployment{
Name: deployment.Name, Name: deployment.Name,
Namespace: deployment.Namespace, Namespace: deployment.Namespace,
Replicas: *deployment.Spec.Replicas, Replicas: *deployment.Spec.Replicas,
Status: status,
}) })
} }
} }