From 8030c795fb1f46f8113e71ae2d449ed3b0adb27b Mon Sep 17 00:00:00 2001 From: yanmingfan Date: Sat, 2 Jun 2018 13:45:01 +0800 Subject: [PATCH 1/3] alter components status fault to unhealth --- pkg/models/components.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pkg/models/components.go b/pkg/models/components.go index 485a84c92..89f3b7d7d 100644 --- a/pkg/models/components.go +++ b/pkg/models/components.go @@ -150,7 +150,7 @@ func GetComponents() (result []Components, err error) { } else { - components.HealthStatus = "fault" + components.HealthStatus = "unhealth" } components.UpdateTime = pod.Status.Conditions[0].LastTransitionTime.Time @@ -176,10 +176,6 @@ func GetComponents() (result []Components, err error) { for _, ds := range dsList.Items { - if strings.Contains(ds.Name, "fluent-bit") { - - continue - } components.Name = ds.Name components.Kind = "Daemonset" @@ -204,7 +200,7 @@ func GetComponents() (result []Components, err error) { } else { - components.HealthStatus = "fault" + components.HealthStatus = "unhealth" } @@ -260,7 +256,7 @@ func GetComponents() (result []Components, err error) { } else { - components.HealthStatus = "fault" + components.HealthStatus = "unhealth" } From 861971a85e9bd4be50e901f93dc3d4429be1d823 Mon Sep 17 00:00:00 2001 From: yanmingfan Date: Sat, 2 Jun 2018 14:29:11 +0800 Subject: [PATCH 2/3] add label and namespace to components --- pkg/models/components.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/pkg/models/components.go b/pkg/models/components.go index 89f3b7d7d..c76091b5d 100644 --- a/pkg/models/components.go +++ b/pkg/models/components.go @@ -28,13 +28,15 @@ const KUBESYSTEM = "kube-system" const OPENPITRIX = "openpitrix-system" type Components struct { - Name string `json:"name"` - Version string `json:"version"` - Kind string `json:"kind"` - Replicas int `json:"replicas"` - HealthStatus string `json:"healthStatus"` - SelfLink string `json:"selfLink"` - UpdateTime time.Time `json:"updateTime"` + Name string `json:"name"` + Version string `json:"version"` + Kind string `json:"kind"` + Namespace string `json:"namespace"` + Label interface{} `json:"label"` + Replicas int `json:"replicas"` + HealthStatus string `json:"healthStatus"` + SelfLink string `json:"selfLink"` + UpdateTime time.Time `json:"updateTime"` } /*** @@ -77,6 +79,8 @@ func GetComponents() (result []Components, err error) { components.Name = template components.Kind = "Pod" components.SelfLink = pod.SelfLink + components.Label = pod.Labels + components.Namespace = pod.Namespace version := strings.Split(pod.Spec.Containers[0].Image, ":") if len(version) < 2 { @@ -131,6 +135,8 @@ func GetComponents() (result []Components, err error) { components.Name = "kube-addon-manager" components.Kind = "Pod" components.SelfLink = pod.SelfLink + components.Label = pod.Labels + components.Namespace = pod.Namespace version := strings.Split(pod.Spec.Containers[0].Image, ":") if len(version) < 2 { @@ -180,6 +186,8 @@ func GetComponents() (result []Components, err error) { components.Name = ds.Name components.Kind = "Daemonset" components.SelfLink = ds.SelfLink + components.Label = ds.Labels + components.Namespace = ds.Namespace version := strings.Split(ds.Spec.Template.Spec.Containers[0].Image, ":") if len(version) < 2 { @@ -236,6 +244,8 @@ func GetComponents() (result []Components, err error) { components.Name = dm.Name components.Kind = "Deployment" components.SelfLink = dm.SelfLink + components.Label = dm.Labels + components.Namespace = dm.Namespace components.Replicas = int(dm.Status.Replicas) version := strings.Split(dm.Spec.Template.Spec.Containers[0].Image, ":") if len(version) < 2 { From 50228688c258137fe9a7938c6f216edb0afb4e0e Mon Sep 17 00:00:00 2001 From: yanmingfan Date: Sat, 2 Jun 2018 15:13:47 +0800 Subject: [PATCH 3/3] add label and namespace to components --- pkg/models/components.go | 74 ++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/pkg/models/components.go b/pkg/models/components.go index c76091b5d..655e3c292 100644 --- a/pkg/models/components.go +++ b/pkg/models/components.go @@ -28,15 +28,15 @@ const KUBESYSTEM = "kube-system" const OPENPITRIX = "openpitrix-system" type Components struct { - Name string `json:"name"` - Version string `json:"version"` - Kind string `json:"kind"` - Namespace string `json:"namespace"` - Label interface{} `json:"label"` - Replicas int `json:"replicas"` - HealthStatus string `json:"healthStatus"` - SelfLink string `json:"selfLink"` - UpdateTime time.Time `json:"updateTime"` + Name string `json:"name"` + Version string `json:"version"` + Kind string `json:"kind"` + Namespace string `json:"namespace"` + Label interface{} `json:"label"` + Replicas int `json:"replicas"` + HealthStatus string `json:"healthStatus"` + SelfLink string `json:"selfLink"` + UpdateTime time.Time `json:"updateTime"` } /*** @@ -178,41 +178,49 @@ func GetComponents() (result []Components, err error) { return result, err } + templates = []string{"flannel", "kube-proxy", "calico"} + if len(dsList.Items) > 0 { for _, ds := range dsList.Items { + for _, template := range templates { - components.Name = ds.Name - components.Kind = "Daemonset" - components.SelfLink = ds.SelfLink - components.Label = ds.Labels - components.Namespace = ds.Namespace - version := strings.Split(ds.Spec.Template.Spec.Containers[0].Image, ":") + if strings.Contains(ds.Name, template) { - if len(version) < 2 { + components.Name = ds.Name + components.Kind = "Daemonset" + components.SelfLink = ds.SelfLink + components.Label = ds.Labels + components.Namespace = ds.Namespace + version := strings.Split(ds.Spec.Template.Spec.Containers[0].Image, ":") - components.Version = "latest" + if len(version) < 2 { - } else { + components.Version = "latest" - components.Version = version[1] + } else { + + components.Version = version[1] + + } + + components.UpdateTime = ds.CreationTimestamp.Time + components.Replicas = int(ds.Status.DesiredNumberScheduled) + + if ds.Status.NumberAvailable == ds.Status.DesiredNumberScheduled { + + components.HealthStatus = "health" + + } else { + + components.HealthStatus = "unhealth" + + } + result = append(result, components) + } } - components.UpdateTime = ds.CreationTimestamp.Time - components.Replicas = int(ds.Status.DesiredNumberScheduled) - - if ds.Status.NumberAvailable == ds.Status.DesiredNumberScheduled { - - components.HealthStatus = "health" - - } else { - - components.HealthStatus = "unhealth" - - } - - result = append(result, components) }