Merge pull request #118 from littlebeer2100/master
alter components function
This commit is contained in:
@@ -129,21 +129,33 @@ func GetComponents() (map[string]interface{}, error) {
|
||||
}
|
||||
|
||||
if len(podsList.Items) > 0 {
|
||||
|
||||
var health bool
|
||||
for _, pod := range podsList.Items {
|
||||
|
||||
if pod.Status.Phase == "Running" {
|
||||
for _, status := range pod.Status.ContainerStatuses {
|
||||
|
||||
components.HealthStatus = "health"
|
||||
if status.Ready == false {
|
||||
health = status.Ready
|
||||
break
|
||||
} else {
|
||||
health = status.Ready
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
|
||||
if health == false {
|
||||
components.HealthStatus = "unhealth"
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if health == true {
|
||||
components.HealthStatus = "health"
|
||||
}
|
||||
|
||||
} else {
|
||||
components.HealthStatus = "unhealth"
|
||||
}
|
||||
|
||||
componentsList = append(componentsList, components)
|
||||
@@ -158,91 +170,3 @@ func GetComponents() (map[string]interface{}, error) {
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
func GetComponentsByNamespace(ns string) ([]Components, error) {
|
||||
|
||||
result := make([]Components, 0)
|
||||
k8sClient := client.NewK8sClient()
|
||||
var components Components
|
||||
|
||||
label := "kubernetes.io/cluster-service=true"
|
||||
option := meta_v1.ListOptions{
|
||||
|
||||
LabelSelector: label,
|
||||
}
|
||||
if ns != KUBESYSTEM {
|
||||
option.LabelSelector = ""
|
||||
}
|
||||
servicelists, err := k8sClient.CoreV1().Services(ns).List(option)
|
||||
|
||||
if err != nil {
|
||||
|
||||
glog.Error(err)
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
if len(servicelists.Items) > 0 {
|
||||
|
||||
for _, service := range servicelists.Items {
|
||||
|
||||
components.Name = service.Name
|
||||
components.Namespace = service.Namespace
|
||||
components.CreateTime = service.CreationTimestamp.Time
|
||||
components.SelfLink = service.SelfLink
|
||||
components.Label = service.Spec.Selector
|
||||
label := service.Spec.Selector
|
||||
combination := ""
|
||||
for key, val := range label {
|
||||
|
||||
labelstr := key + "=" + val
|
||||
|
||||
if combination == "" {
|
||||
|
||||
combination = labelstr
|
||||
|
||||
} else {
|
||||
|
||||
combination = combination + "," + labelstr
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
option := meta_v1.ListOptions{
|
||||
LabelSelector: combination,
|
||||
}
|
||||
podsList, err := k8sClient.CoreV1().Pods(ns).List(option)
|
||||
|
||||
if err != nil {
|
||||
|
||||
glog.Error(err)
|
||||
return result, err
|
||||
}
|
||||
|
||||
if len(podsList.Items) > 0 {
|
||||
|
||||
for _, pod := range podsList.Items {
|
||||
|
||||
if pod.Status.Phase == "Running" {
|
||||
|
||||
components.HealthStatus = "health"
|
||||
|
||||
} else {
|
||||
|
||||
components.HealthStatus = "unhealth"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
result = append(result, components)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user