alter components function
This commit is contained in:
@@ -30,11 +30,6 @@ func Register(ws *restful.WebService, subPath string) {
|
|||||||
ws.Route(ws.GET(subPath).To(handleGetComponents).Filter(route.RouteLogging)).
|
ws.Route(ws.GET(subPath).To(handleGetComponents).Filter(route.RouteLogging)).
|
||||||
Consumes(restful.MIME_JSON, restful.MIME_XML).
|
Consumes(restful.MIME_JSON, restful.MIME_XML).
|
||||||
Produces(restful.MIME_JSON)
|
Produces(restful.MIME_JSON)
|
||||||
|
|
||||||
ws.Route(ws.GET(subPath+"/{namespace}").To(handleGetComponentsByNamespace).Filter(route.RouteLogging)).
|
|
||||||
Consumes(restful.MIME_JSON, restful.MIME_XML).
|
|
||||||
Produces(restful.MIME_JSON)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//get all components
|
//get all components
|
||||||
@@ -54,22 +49,3 @@ func handleGetComponents(request *restful.Request, response *restful.Response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//get components from ns
|
|
||||||
|
|
||||||
func handleGetComponentsByNamespace(request *restful.Request, response *restful.Response) {
|
|
||||||
|
|
||||||
ns := request.PathParameter("namespace")
|
|
||||||
|
|
||||||
result, err := models.GetComponentsByNamespace(ns)
|
|
||||||
if err != nil {
|
|
||||||
|
|
||||||
response.WriteHeaderAndEntity(http.StatusInternalServerError, constants.MessageResponse{Message: err.Error()})
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
response.WriteAsJson(result)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -129,21 +129,33 @@ func GetComponents() (map[string]interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(podsList.Items) > 0 {
|
if len(podsList.Items) > 0 {
|
||||||
|
var health bool
|
||||||
for _, pod := range podsList.Items {
|
for _, pod := range podsList.Items {
|
||||||
|
|
||||||
if pod.Status.Phase == "Running" {
|
for _, status := range pod.Status.ContainerStatuses {
|
||||||
|
|
||||||
|
if status.Ready == false {
|
||||||
|
health = status.Ready
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
health = status.Ready
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if health == false {
|
||||||
|
components.HealthStatus = "unhealth"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if health == true {
|
||||||
components.HealthStatus = "health"
|
components.HealthStatus = "health"
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
components.HealthStatus = "unhealth"
|
components.HealthStatus = "unhealth"
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentsList = append(componentsList, components)
|
componentsList = append(componentsList, components)
|
||||||
@@ -158,91 +170,3 @@ func GetComponents() (map[string]interface{}, error) {
|
|||||||
return result, nil
|
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