Skip to content

Commit b7e701b

Browse files
committed
Try to make log more common and more easily grepable
Signed-off-by: Benoit Tigeot <benoit.tigeot@lifen.fr>
1 parent af1013b commit b7e701b

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

pkg/kube/client.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (c *Client) IsReachable() error {
137137

138138
// Create creates Kubernetes resources specified in the resource list.
139139
func (c *Client) Create(resources ResourceList) (*Result, error) {
140-
c.Log.Debug("creating resource(s)", "resources", resources)
140+
c.Log.Debug("creating resource(s)", "resources", len(resources))
141141
if err := perform(resources, createResource); err != nil {
142142
return nil, err
143143
}
@@ -207,7 +207,7 @@ func (c *Client) getSelectRelationPod(info *resource.Info, objs map[string][]run
207207
if info == nil {
208208
return objs, nil
209209
}
210-
c.Log.Debug("get relation pod of object", "namespace", info.Namespace, "kind", info.Mapping.GroupVersionKind.Kind, "name", info.Name)
210+
c.Log.Debug("get relation pod of object", "namespace", info.Namespace, "name", info.Name, "kind", info.Mapping.GroupVersionKind.Kind)
211211
selector, ok, _ := getSelectorFromObject(info.Object)
212212
if !ok {
213213
return objs, nil
@@ -388,7 +388,7 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
388388
updateErrors := []string{}
389389
res := &Result{}
390390

391-
c.Log.Debug("checking resources for changes", "original", original, "target", target)
391+
c.Log.Debug("checking resources for changes", "resources", len(target))
392392
err := target.Visit(func(info *resource.Info, err error) error {
393393
if err != nil {
394394
return err
@@ -409,7 +409,7 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
409409
}
410410

411411
kind := info.Mapping.GroupVersionKind.Kind
412-
c.Log.Debug("created a new resource", "kind", kind, "name", info.Name, "namespace", info.Namespace)
412+
c.Log.Debug("created a new resource", "namespace", info.Namespace, "name", info.Name, "kind", kind)
413413
return nil
414414
}
415415

@@ -420,7 +420,7 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
420420
}
421421

422422
if err := updateResource(c, info, originalInfo.Object, force); err != nil {
423-
c.Log.Debug("error updating the resource", "kind", info.Mapping.GroupVersionKind.Kind, "name", info.Name, "error", err)
423+
c.Log.Debug("error updating the resource", "namespace", info.Namespace, "name", info.Name, "kind", info.Mapping.GroupVersionKind.Kind, "error", err)
424424
updateErrors = append(updateErrors, err.Error())
425425
}
426426
// Because we check for errors later, append the info regardless
@@ -437,22 +437,22 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
437437
}
438438

439439
for _, info := range original.Difference(target) {
440-
c.Log.Debug("deleting resource", "kind", info.Mapping.GroupVersionKind.Kind, "name", info.Name, "namespace", info.Namespace)
440+
c.Log.Debug("deleting resource", "namespace", info.Namespace, "name", info.Name, "kind", info.Mapping.GroupVersionKind.Kind)
441441

442442
if err := info.Get(); err != nil {
443-
c.Log.Debug("unable to get object", "name", info.Name, "error", err)
443+
c.Log.Debug("unable to get object", "namespace", info.Namespace, "name", info.Name, "kind", info.Mapping.GroupVersionKind.Kind, "error", err)
444444
continue
445445
}
446446
annotations, err := metadataAccessor.Annotations(info.Object)
447447
if err != nil {
448-
c.Log.Debug("unable to get annotations", "name", info.Name, "error", err)
448+
c.Log.Debug("unable to get annotations", "namespace", info.Namespace, "name", info.Name, "kind", info.Mapping.GroupVersionKind.Kind, "error", err)
449449
}
450450
if annotations != nil && annotations[ResourcePolicyAnno] == KeepPolicy {
451-
c.Log.Debug("skipping delete due to annotation", "name", info.Name, "annotation", ResourcePolicyAnno, "value", KeepPolicy)
451+
c.Log.Debug("skipping delete due to annotation", "namespace", info.Namespace, "name", info.Name, "kind", info.Mapping.GroupVersionKind.Kind, "annotation", ResourcePolicyAnno, "value", KeepPolicy)
452452
continue
453453
}
454454
if err := deleteResource(info, metav1.DeletePropagationBackground); err != nil {
455-
c.Log.Debug("failed to delete resource", "name", info.Name, "error", err)
455+
c.Log.Debug("failed to delete resource", "namespace", info.Namespace, "name", info.Name, "kind", info.Mapping.GroupVersionKind.Kind, "error", err)
456456
continue
457457
}
458458
res.Deleted = append(res.Deleted, info)
@@ -481,11 +481,11 @@ func rdelete(c *Client, resources ResourceList, propagation metav1.DeletionPropa
481481
res := &Result{}
482482
mtx := sync.Mutex{}
483483
err := perform(resources, func(info *resource.Info) error {
484-
c.Log.Debug("starting delete resource", "kind", info.Mapping.GroupVersionKind.Kind, "name", info.Name, "namespace", info.Namespace)
484+
c.Log.Debug("starting delete resource", "namespace", info.Namespace, "name", info.Name, "kind", info.Mapping.GroupVersionKind.Kind)
485485
err := deleteResource(info, propagation)
486486
if err == nil || apierrors.IsNotFound(err) {
487487
if err != nil {
488-
c.Log.Debug("ignoring delete failure", "name", info.Name, "kind", info.Mapping.GroupVersionKind.Kind, "error", err)
488+
c.Log.Debug("ignoring delete failure", "namespace", info.Namespace, "name", info.Name, "kind", info.Mapping.GroupVersionKind.Kind, "error", err)
489489
}
490490
mtx.Lock()
491491
defer mtx.Unlock()
@@ -715,7 +715,7 @@ func (c *Client) watchUntilReady(timeout time.Duration, info *resource.Info) err
715715
return nil
716716
}
717717

718-
c.Log.Debug("watching for changes", "kind", kind, "name", info.Name, "timeout", timeout)
718+
c.Log.Debug("watching for changes", "namespace", info.Namespace, "name", info.Name, "timeout", timeout)
719719

720720
// Use a selector on the name of the resource. This should be unique for the
721721
// given version and kind
@@ -743,7 +743,7 @@ func (c *Client) watchUntilReady(timeout time.Duration, info *resource.Info) err
743743
// we get. We care mostly about jobs, where what we want to see is
744744
// the status go into a good state. For other types, like ReplicaSet
745745
// we don't really do anything to support these as hooks.
746-
c.Log.Debug("add/modify event received", "name", info.Name, "type", e.Type)
746+
c.Log.Debug("add/modify event received", "namespace", info.Namespace, "name", info.Name, "type", e.Type)
747747
switch kind {
748748
case "Job":
749749
return c.waitForJob(obj, info.Name)
@@ -752,12 +752,12 @@ func (c *Client) watchUntilReady(timeout time.Duration, info *resource.Info) err
752752
}
753753
return true, nil
754754
case watch.Deleted:
755-
c.Log.Debug("deleted event received", "name", info.Name)
755+
c.Log.Debug("deleted event received", "namespace", info.Namespace, "name", info.Name)
756756
return true, nil
757757
case watch.Error:
758758
// Handle error and return with an error.
759759
// c.Log("Error event for %s", info.Name)
760-
c.Log.Debug("error event received", "name", info.Name)
760+
c.Log.Debug("error event received", "namespace", info.Namespace, "name", info.Name)
761761
return true, errors.Errorf("failed to deploy %s", info.Name)
762762
default:
763763
return false, nil
@@ -784,7 +784,7 @@ func (c *Client) waitForJob(obj runtime.Object, name string) (bool, error) {
784784
}
785785

786786
// c.Log("%s: Jobs active: %d, jobs failed: %d, jobs succeeded: %d", name, o.Status.Active, o.Status.Failed, o.Status.Succeeded)
787-
c.Log.Debug("job status", "name", name, "active", o.Status.Active, "failed", o.Status.Failed, "succeeded", o.Status.Succeeded)
787+
c.Log.Debug("job status", "namespace", o.Namespace, "name", name, "active", o.Status.Active, "failed", o.Status.Failed, "succeeded", o.Status.Succeeded)
788788
return false, nil
789789
}
790790

@@ -799,14 +799,14 @@ func (c *Client) waitForPodSuccess(obj runtime.Object, name string) (bool, error
799799

800800
switch o.Status.Phase {
801801
case v1.PodSucceeded:
802-
c.Log.Debug("Pod succeeded", "name", o.Name)
802+
c.Log.Debug("Pod succeeded", "namespace", o.Namespace, "name", o.Name)
803803
return true, nil
804804
case v1.PodFailed:
805805
return true, errors.Errorf("pod %s failed", o.Name)
806806
case v1.PodPending:
807-
c.Log.Debug("Pod pending", "name", o.Name)
807+
c.Log.Debug("Pod pending", "namespace", o.Namespace, "name", o.Name)
808808
case v1.PodRunning:
809-
c.Log.Debug("Pod running", "name", o.Name)
809+
c.Log.Debug("Pod running", "namespace", o.Namespace, "name", o.Name)
810810
}
811811

812812
return false, nil

pkg/kube/wait.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (w *waiter) isRetryableError(err error, resource *resource.Info) bool {
8585
if err == nil {
8686
return false
8787
}
88-
w.log.Debug("error received when checking status of resource", "error", err, "resourceName", resource.Name, "resourceDetails", resource)
88+
w.log.Debug("error received when checking status of resource", "error", err, "resourceNamespace", resource.Namespace, "resourceName", resource.Name, "resourceDetails", resource)
8989
if ev, ok := err.(*apierrors.StatusError); ok {
9090
statusCode := ev.Status().Code
9191
retryable := w.isRetryableHTTPStatusCode(statusCode)

0 commit comments

Comments
 (0)