From 4bdb9f6d6f345646ca77d1b4a2a4a07d2f64587a Mon Sep 17 00:00:00 2001 From: richardxz Date: Wed, 20 Jun 2018 16:54:41 +0800 Subject: [PATCH 1/2] fix bug when ns created, role do not create --- pkg/models/controllers/namespaces.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/models/controllers/namespaces.go b/pkg/models/controllers/namespaces.go index 50aa4df66..0bb83401d 100644 --- a/pkg/models/controllers/namespaces.go +++ b/pkg/models/controllers/namespaces.go @@ -208,6 +208,7 @@ func (ctl *NamespaceCtl) createRoleAndRuntime(item v1.Namespace) { resp, err := ctl.createOpRuntime(ns, user) if err != nil { + glog.Error(resp) return } @@ -268,6 +269,7 @@ func (ctl *NamespaceCtl) listAndWatch() { for _, item := range list { obj := ctl.generateObject(*item) db.Create(obj) + ctl.createRoleAndRuntime(*item) } @@ -277,17 +279,20 @@ func (ctl *NamespaceCtl) listAndWatch() { object := obj.(*v1.Namespace) mysqlObject := ctl.generateObject(*object) db.Create(mysqlObject) + ctl.createRoleAndRuntime(*object) }, UpdateFunc: func(old, new interface{}) { object := new.(*v1.Namespace) mysqlObject := ctl.generateObject(*object) db.Save(mysqlObject) + ctl.createRoleAndRuntime(*object) }, DeleteFunc: func(obj interface{}) { var item Namespace object := obj.(*v1.Namespace) db.Where("name=?", object.Name).Find(&item) db.Delete(item) + ctl.deleteOpRuntime(*object) }, }) From 23395a35f1d4e30e96088166abd19076440e126f Mon Sep 17 00:00:00 2001 From: richardxz Date: Wed, 20 Jun 2018 17:07:26 +0800 Subject: [PATCH 2/2] fix bug : pvc is bound, but status still available --- pkg/models/controllers/pods.go | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/pkg/models/controllers/pods.go b/pkg/models/controllers/pods.go index 307c6c119..fd929ad4b 100644 --- a/pkg/models/controllers/pods.go +++ b/pkg/models/controllers/pods.go @@ -27,8 +27,6 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/informers" "k8s.io/client-go/tools/cache" - - "kubesphere.io/kubesphere/pkg/models/metrics" ) const inUse = "in_use_pods" @@ -45,22 +43,24 @@ func (ctl *PodCtl) addAnnotationToPvc(item v1.Pod) { Pvc.Annotations = make(map[string]string) } annotation := Pvc.Annotations + if len(annotation[inUse]) == 0 { pods := []string{item.Name} str, _ := json.Marshal(pods) annotation[inUse] = string(str) } else { var pods []string - json.Unmarshal([]byte(annotation[inUse]), pods) + json.Unmarshal([]byte(annotation[inUse]), &pods) for _, pod := range pods { if pod == item.Name { return } - pods = append(pods, item.Name) - str, _ := json.Marshal(pods) - annotation[inUse] = string(str) } + pods = append(pods, item.Name) + str, _ := json.Marshal(pods) + annotation[inUse] = string(str) } + Pvc.Annotations = annotation ctl.K8sClient.CoreV1().PersistentVolumeClaims(item.Namespace).Update(Pvc) } } @@ -233,7 +233,7 @@ func (ctl *PodCtl) listAndWatch() { UpdateFunc: func(old, new interface{}) { object := new.(*v1.Pod) mysqlObject := ctl.generateObject(*object) - + ctl.addAnnotationToPvc(*object) db.Save(mysqlObject) }, @@ -264,22 +264,6 @@ func (ctl *PodCtl) ListWithConditions(conditions string, paging *Paging) (int, i listWithConditions(ctl.DB, &total, &object, &list, conditions, paging, order) - ch := make(chan metrics.PodMetrics) - - for index, _ := range list { - go metrics.GetSinglePodMetrics(list[index].Namespace, list[index].Name, ch) - } - - var resultMetrics = make(map[string]metrics.PodMetrics) - for range list { - podMetric := <-ch - resultMetrics[podMetric.PodName] = podMetric - } - - for index, _ := range list { - list[index].Metrics = resultMetrics[list[index].Name] - } - return total, list, nil }