From c5fc6bc5fa5d83b03e7f9e50f564851db2caceb9 Mon Sep 17 00:00:00 2001 From: TommyLike Date: Thu, 14 Feb 2019 15:01:58 +0800 Subject: [PATCH] Update log format --- pkg/controllers/job/apis/types.go | 7 ++++++ pkg/controllers/job/job_controller_handler.go | 24 +++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/controllers/job/apis/types.go b/pkg/controllers/job/apis/types.go index c1c1583f5..d2d5698d4 100644 --- a/pkg/controllers/job/apis/types.go +++ b/pkg/controllers/job/apis/types.go @@ -17,6 +17,7 @@ limitations under the License. package apis import ( + "fmt" "k8s.io/api/core/v1" vkbatchv1 "hpw.cloud/volcano/pkg/apis/batch/v1alpha1" @@ -35,3 +36,9 @@ type Request struct { Event vkbatchv1.Event Action vkbatchv1.Action } + +func (r Request) String() string { + return fmt.Sprintf( + "Job: %s/%s, Task:%s, Event:%s, Action:%s", + r.Namespace, r.JobName, r.TaskName, r.Event, r.Action) +} diff --git a/pkg/controllers/job/job_controller_handler.go b/pkg/controllers/job/job_controller_handler.go index 755eebb03..5e746096c 100644 --- a/pkg/controllers/job/job_controller_handler.go +++ b/pkg/controllers/job/job_controller_handler.go @@ -74,7 +74,7 @@ func (cc *Controller) addJob(obj interface{}) { // TODO(k82cn): if failed to add job, the cache should be refresh if err := cc.cache.Add(job); err != nil { - glog.Errorf("Failed to add job <%s/%s>: %v", + glog.Errorf("Failed to add job <%s/%s>: %v in cache", job.Namespace, job.Name, err) } cc.queue.Add(req) @@ -95,7 +95,7 @@ func (cc *Controller) updateJob(oldObj, newObj interface{}) { } if err := cc.cache.Update(newJob); err != nil { - glog.Errorf("Failed to update job <%s/%s>: %v", + glog.Errorf("Failed to update job <%s/%s>: %v in cache", newJob.Namespace, newJob.Name, err) } @@ -110,7 +110,7 @@ func (cc *Controller) deleteJob(obj interface{}) { } if err := cc.cache.Delete(job); err != nil { - glog.Errorf("Failed to delete job <%s/%s>: %v", + glog.Errorf("Failed to delete job <%s/%s>: %v in cache", job.Namespace, job.Name, err) } } @@ -124,7 +124,7 @@ func (cc *Controller) addPod(obj interface{}) { jobName, found := pod.Annotations[vkbatchv1.JobNameKey] if !found { - glog.Errorf("Failed to find jobName of Pod <%s/%s>", + glog.Warningf("Failed to find jobName of Pod <%s/%s>, skipping", pod.Namespace, pod.Name) return } @@ -137,7 +137,7 @@ func (cc *Controller) addPod(obj interface{}) { } if err := cc.cache.AddPod(pod); err != nil { - glog.Errorf("Failed to add Pod <%s/%s>: %v", + glog.Errorf("Failed to add Pod <%s/%s>: %v to cache", pod.Namespace, pod.Name, err) } cc.queue.Add(req) @@ -158,14 +158,14 @@ func (cc *Controller) updatePod(oldObj, newObj interface{}) { taskName, found := newPod.Annotations[vkbatchv1.TaskSpecKey] if !found { - glog.Errorf("Failed to find taskName of Pod <%s/%s>", + glog.Warningf("Failed to find taskName of Pod <%s/%s>, skipping", newPod.Namespace, newPod.Name) return } jobName, found := newPod.Annotations[vkbatchv1.JobNameKey] if !found { - glog.Errorf("Failed to find jobName of Pod <%s/%s>", + glog.Warningf("Failed to find jobName of Pod <%s/%s>, skipping", newPod.Namespace, newPod.Name) return } @@ -185,7 +185,7 @@ func (cc *Controller) updatePod(oldObj, newObj interface{}) { } if err := cc.cache.UpdatePod(newPod); err != nil { - glog.Errorf("Failed to update Pod <%s/%s>: %v", + glog.Errorf("Failed to update Pod <%s/%s>: %v in cache", newPod.Namespace, newPod.Name, err) } @@ -211,14 +211,14 @@ func (cc *Controller) deletePod(obj interface{}) { taskName, found := pod.Annotations[vkbatchv1.TaskSpecKey] if !found { - glog.Errorf("Failed to find taskName of Pod <%s/%s>", + glog.Warningf("Failed to find taskName of Pod <%s/%s>, skipping", pod.Namespace, pod.Name) return } jobName, found := pod.Annotations[vkbatchv1.JobNameKey] if !found { - glog.Errorf("Failed to find jobName of Pod <%s/%s>", + glog.Warningf("Failed to find jobName of Pod <%s/%s>, skipping", pod.Namespace, pod.Name) return } @@ -232,11 +232,11 @@ func (cc *Controller) deletePod(obj interface{}) { } if err := cc.cache.DeletePod(pod); err != nil { - glog.Errorf("Failed to update Pod <%s/%s>: %v", + glog.Errorf("Failed to update Pod <%s/%s>: %v in cache", pod.Namespace, pod.Name, err) } cc.queue.Add(req) } -// TODO(k82cn): add handler for PodGroup unschedulable event. +// TODO(k82cn): add handler for PodGroup unscheduable event.