don't return default value when varible is null, and change service type as k8s display

This commit is contained in:
richardxz
2018-06-26 09:49:34 +08:00
parent 471c5d7b48
commit 0631ca8b2f
7 changed files with 7 additions and 33 deletions

View File

@@ -43,8 +43,6 @@ func (ctl *DaemonsetCtl) generateObject(item v1.DaemonSet) *Daemonset {
if len(release) > 0 && len(chart) > 0 {
app = release + "/" + chart
} else {
app = "-"
}
if createTime.IsZero() {

View File

@@ -40,8 +40,6 @@ func (ctl *DeploymentCtl) generateObject(item v1.Deployment) *Deployment {
if len(release) > 0 && len(chart) > 0 {
app = release + "/" + chart
} else {
app = "-"
}
for _, conditon := range item.Status.Conditions {

View File

@@ -30,8 +30,7 @@ import (
func (ctl *IngressCtl) generateObject(item v1beta1.Ingress) *Ingress {
name := item.Name
namespace := item.Namespace
ip := "-"
tls := "-"
var ip, tls string
createTime := item.CreationTimestamp.Time
if createTime.IsZero() {
createTime = time.Now()

View File

@@ -75,6 +75,9 @@ func (ctl *PodCtl) delAnnotationFromPvc(item v1.Pod) {
if pvc != nil {
name := pvc.ClaimName
Pvc, _ := ctl.K8sClient.CoreV1().PersistentVolumeClaims(item.Namespace).Get(name, metaV1.GetOptions{})
if Pvc.Annotations == nil {
Pvc.Annotations = make(map[string]string)
}
annotation := Pvc.Annotations
var pods []string
json.Unmarshal([]byte(annotation[inUse]), pods)

View File

@@ -29,14 +29,12 @@ import (
"k8s.io/client-go/tools/cache"
)
const creator = "creator"
func (ctl *PvcCtl) generateObject(item *v1.PersistentVolumeClaim) *Pvc {
name := item.Name
namespace := item.Namespace
status := fmt.Sprintf("%s", item.Status.Phase)
createTime := item.CreationTimestamp.Time
capacity := "-"
var capacity, storageClass, accessModeStr string
if createTime.IsZero() {
createTime = time.Now()
@@ -46,7 +44,6 @@ func (ctl *PvcCtl) generateObject(item *v1.PersistentVolumeClaim) *Pvc {
capacity = storage.String()
}
storageClass := "-"
if len(item.Annotations["volume.beta.kubernetes.io/storage-class"]) > 0 {
storageClass = item.Annotations["volume.beta.kubernetes.io/storage-class"]
}
@@ -54,8 +51,6 @@ func (ctl *PvcCtl) generateObject(item *v1.PersistentVolumeClaim) *Pvc {
storageClass = *item.Spec.StorageClassName
}
accessModeStr := "-"
var accessModeList []string
for _, accessMode := range item.Status.AccessModes {
accessModeList = append(accessModeList, string(accessMode))

View File

@@ -1,12 +1,9 @@
/*
Copyright 2018 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,12 +28,6 @@ import (
"k8s.io/client-go/tools/cache"
)
const (
headlessSelector = "Headless(Selector)"
headlessExternal = "Headless(ExternalName)"
virtualIp = "Virtual IP"
)
func (ctl *ServiceCtl) loadBalancerStatusStringer(item v1.Service) string {
ingress := item.Status.LoadBalancer.Ingress
result := sets.NewString()
@@ -85,7 +76,7 @@ func (ctl *ServiceCtl) generateObject(item v1.Service) *Service {
namespace := item.Namespace
createTime := item.CreationTimestamp.Time
externalIp := ctl.getExternalIp(item)
serviceType := virtualIp
serviceType := item.Spec.Type
vip := item.Spec.ClusterIP
ports := ""
var nodePorts []string
@@ -94,14 +85,6 @@ func (ctl *ServiceCtl) generateObject(item v1.Service) *Service {
createTime = time.Now()
}
if item.Spec.ClusterIP == "None" {
serviceType = headlessSelector
}
if len(item.Spec.ExternalName) > 0 {
serviceType = headlessExternal
}
if len(item.Spec.ExternalIPs) > 0 {
externalIp = strings.Join(item.Spec.ExternalIPs, ",")
}
@@ -126,7 +109,7 @@ func (ctl *ServiceCtl) generateObject(item v1.Service) *Service {
object := &Service{
Namespace: namespace,
Name: name,
ServiceType: serviceType,
ServiceType: string(serviceType),
ExternalIp: externalIp,
VirtualIp: vip,
CreateTime: createTime,

View File

@@ -44,8 +44,6 @@ func (ctl *StatefulsetCtl) generateObject(item v1.StatefulSet) *Statefulset {
if len(release) > 0 && len(chart) > 0 {
app = release + "/" + chart
} else {
app = "-"
}
if item.Annotations["state"] == "stop" {