Merge pull request #47 from littlebeer2100/components
alter Components struct
This commit is contained in:
@@ -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 {
|
||||
@@ -150,7 +156,7 @@ func GetComponents() (result []Components, err error) {
|
||||
|
||||
} else {
|
||||
|
||||
components.HealthStatus = "fault"
|
||||
components.HealthStatus = "unhealth"
|
||||
|
||||
}
|
||||
components.UpdateTime = pod.Status.Conditions[0].LastTransitionTime.Time
|
||||
@@ -172,43 +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 {
|
||||
|
||||
if strings.Contains(ds.Name, "fluent-bit") {
|
||||
for _, template := range templates {
|
||||
|
||||
continue
|
||||
}
|
||||
if strings.Contains(ds.Name, template) {
|
||||
|
||||
components.Name = ds.Name
|
||||
components.Kind = "Daemonset"
|
||||
components.SelfLink = ds.SelfLink
|
||||
version := strings.Split(ds.Spec.Template.Spec.Containers[0].Image, ":")
|
||||
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 {
|
||||
if len(version) < 2 {
|
||||
|
||||
components.Version = "latest"
|
||||
components.Version = "latest"
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
components.Version = version[1]
|
||||
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 = "fault"
|
||||
|
||||
}
|
||||
|
||||
result = append(result, components)
|
||||
|
||||
}
|
||||
|
||||
@@ -240,6 +252,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 {
|
||||
@@ -260,7 +274,7 @@ func GetComponents() (result []Components, err error) {
|
||||
|
||||
} else {
|
||||
|
||||
components.HealthStatus = "fault"
|
||||
components.HealthStatus = "unhealth"
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user