From cda4f4f05ae1d5c653e7158b8de0164f92341e5c Mon Sep 17 00:00:00 2001 From: magicsong Date: Tue, 23 Jul 2019 17:10:30 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=92=20add=20error=20message=20in=20con?= =?UTF-8?q?troller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- pkg/controller/application/application_controller.go | 12 ++++++------ .../destinationrule/destinationrule_controller.go | 9 ++++----- pkg/controller/job/job_controller.go | 9 ++++----- .../virtualservice/virtualservice_controller.go | 8 ++++---- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 23cca5298..bd906f8e2 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ BIN ?= ks-apiserver IMG ?= kubespheredev/ks-apiserver OUTPUT_DIR=bin - +GOFLAGS=-mod=vendor define ALL_HELP_INFO # Build code. # diff --git a/pkg/controller/application/application_controller.go b/pkg/controller/application/application_controller.go index f852c1816..299067df7 100644 --- a/pkg/controller/application/application_controller.go +++ b/pkg/controller/application/application_controller.go @@ -2,6 +2,8 @@ package application import ( "fmt" + "time" + applicationclient "github.com/kubernetes-sigs/application/pkg/client/clientset/versioned" applicationinformers "github.com/kubernetes-sigs/application/pkg/client/informers/externalversions/app/v1beta1" applicationlister "github.com/kubernetes-sigs/application/pkg/client/listers/app/v1beta1" @@ -25,7 +27,6 @@ import ( servicemeshlisters "kubesphere.io/kubesphere/pkg/client/listers/servicemesh/v1alpha2" "kubesphere.io/kubesphere/pkg/controller/virtualservice/util" logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" - "time" ) const ( @@ -148,11 +149,10 @@ func NewApplicationController(serviceInformer coreinformers.ServiceInformer, } func (v *ApplicationController) Start(stopCh <-chan struct{}) error { - v.Run(2, stopCh) - return nil + return v.Run(2, stopCh) } -func (v *ApplicationController) Run(workers int, stopCh <-chan struct{}) { +func (v *ApplicationController) Run(workers int, stopCh <-chan struct{}) error { defer utilruntime.HandleCrash() defer v.queue.ShutDown() @@ -160,14 +160,14 @@ func (v *ApplicationController) Run(workers int, stopCh <-chan struct{}) { defer log.Info("shutting down application controller") if !cache.WaitForCacheSync(stopCh, v.deploymentSynced, v.statefulSetSynced, v.serviceSynced, v.strategySynced, v.servicePolicySynced, v.applicationSynced) { - return + return fmt.Errorf("failed to wait for caches to sync") } for i := 0; i < workers; i++ { go wait.Until(v.worker, v.workerLoopPeriod, stopCh) } - <-stopCh + return nil } func (v *ApplicationController) worker() { diff --git a/pkg/controller/destinationrule/destinationrule_controller.go b/pkg/controller/destinationrule/destinationrule_controller.go index ca23f7bed..c3c1c54c0 100644 --- a/pkg/controller/destinationrule/destinationrule_controller.go +++ b/pkg/controller/destinationrule/destinationrule_controller.go @@ -148,12 +148,10 @@ func NewDestinationRuleController(deploymentInformer informersv1.DeploymentInfor } func (v *DestinationRuleController) Start(stopCh <-chan struct{}) error { - v.Run(5, stopCh) - - return nil + return v.Run(5, stopCh) } -func (v *DestinationRuleController) Run(workers int, stopCh <-chan struct{}) { +func (v *DestinationRuleController) Run(workers int, stopCh <-chan struct{}) error { defer utilruntime.HandleCrash() defer v.queue.ShutDown() @@ -161,7 +159,7 @@ func (v *DestinationRuleController) Run(workers int, stopCh <-chan struct{}) { defer log.Info("shutting down destinationrule controller") if !cache.WaitForCacheSync(stopCh, v.serviceSynced, v.destinationRuleSynced, v.deploymentSynced, v.servicePolicySynced) { - return + return fmt.Errorf("failed to wait for caches to sync") } for i := 0; i < workers; i++ { @@ -169,6 +167,7 @@ func (v *DestinationRuleController) Run(workers int, stopCh <-chan struct{}) { } <-stopCh + return nil } func (v *DestinationRuleController) enqueueService(obj interface{}) { diff --git a/pkg/controller/job/job_controller.go b/pkg/controller/job/job_controller.go index 1247179bd..8d7e0cc2d 100644 --- a/pkg/controller/job/job_controller.go +++ b/pkg/controller/job/job_controller.go @@ -95,12 +95,10 @@ func NewJobController(jobInformer batchv1informers.JobInformer, client clientset } func (v *JobController) Start(stopCh <-chan struct{}) error { - v.Run(5, stopCh) - - return nil + return v.Run(5, stopCh) } -func (v *JobController) Run(workers int, stopCh <-chan struct{}) { +func (v *JobController) Run(workers int, stopCh <-chan struct{}) error { defer utilruntime.HandleCrash() defer v.queue.ShutDown() @@ -108,7 +106,7 @@ func (v *JobController) Run(workers int, stopCh <-chan struct{}) { defer log.Info("shutting down job controller") if !cache.WaitForCacheSync(stopCh, v.jobSynced) { - return + return fmt.Errorf("failed to wait for caches to sync") } for i := 0; i < workers; i++ { @@ -116,6 +114,7 @@ func (v *JobController) Run(workers int, stopCh <-chan struct{}) { } <-stopCh + return nil } func (v *JobController) enqueueJob(obj interface{}) { diff --git a/pkg/controller/virtualservice/virtualservice_controller.go b/pkg/controller/virtualservice/virtualservice_controller.go index b3820c3cc..92caaf993 100644 --- a/pkg/controller/virtualservice/virtualservice_controller.go +++ b/pkg/controller/virtualservice/virtualservice_controller.go @@ -145,11 +145,10 @@ func NewVirtualServiceController(serviceInformer coreinformers.ServiceInformer, } func (v *VirtualServiceController) Start(stopCh <-chan struct{}) error { - v.Run(5, stopCh) - return nil + return v.Run(5, stopCh) } -func (v *VirtualServiceController) Run(workers int, stopCh <-chan struct{}) { +func (v *VirtualServiceController) Run(workers int, stopCh <-chan struct{}) error { defer utilruntime.HandleCrash() defer v.queue.ShutDown() @@ -157,7 +156,7 @@ func (v *VirtualServiceController) Run(workers int, stopCh <-chan struct{}) { defer log.Info("shutting down virtualservice controller") if !cache.WaitForCacheSync(stopCh, v.serviceSynced, v.virtualServiceSynced, v.destinationRuleSynced, v.strategySynced) { - return + return fmt.Errorf("failed to wait for caches to sync") } for i := 0; i < workers; i++ { @@ -165,6 +164,7 @@ func (v *VirtualServiceController) Run(workers int, stopCh <-chan struct{}) { } <-stopCh + return nil } func (v *VirtualServiceController) enqueueService(obj interface{}) {