Skip to content

Commit 289f405

Browse files
committed
Improve logging
Signed-off-by: ccremer <[email protected]>
1 parent 19891f1 commit 289f405

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

operator/archivecontroller/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ArchiveReconciler struct {
2020

2121
// Reconcile is the entrypoint to manage the given resource.
2222
func (r *ArchiveReconciler) Reconcile(ctx context.Context, req controllerruntime.Request) (controllerruntime.Result, error) {
23-
log := controllerruntime.LoggerFrom(ctx).WithValues("archive", req.NamespacedName)
23+
log := controllerruntime.LoggerFrom(ctx)
2424

2525
archive := &k8upv1.Archive{}
2626
err := r.Kube.Get(ctx, req.NamespacedName, archive)

operator/backupcontroller/executor.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (b *BackupExecutor) listAndFilterPVCs(annotation string) ([]corev1.Volume,
7373
volumes := make([]corev1.Volume, 0)
7474
claimlist := &corev1.PersistentVolumeClaimList{}
7575

76-
b.Log.Info("Listing all PVCs", "annotation", annotation, "namespace", b.Obj.GetNamespace())
76+
b.Log.Info("Listing all PVCs", "annotation", annotation)
7777
if err := b.fetchPVCs(claimlist); err != nil {
7878
return volumes, err
7979
}
@@ -84,17 +84,17 @@ func (b *BackupExecutor) listAndFilterPVCs(annotation string) ([]corev1.Volume,
8484
tmpAnnotation, ok := annotations[annotation]
8585

8686
if !containsAccessMode(item.Spec.AccessModes, "ReadWriteMany") && !ok {
87-
b.Log.Info("PVC isn't RWX", "namespace", item.GetNamespace(), "name", item.GetName())
87+
b.Log.Info("PVC isn't RWX", "pvc", item.GetName())
8888
continue
8989
}
9090

9191
if !ok {
92-
b.Log.Info("PVC doesn't have annotation, adding to list", "namespace", item.GetNamespace(), "name", item.GetName())
92+
b.Log.Info("PVC doesn't have annotation, adding to list", "pvc", item.GetName())
9393
} else if anno, _ := strconv.ParseBool(tmpAnnotation); !anno {
94-
b.Log.Info("PVC skipped due to annotation", "namespace", item.GetNamespace(), "name", item.GetName(), "annotation", tmpAnnotation)
94+
b.Log.Info("PVC skipped due to annotation", "pvc", item.GetName(), "annotation", tmpAnnotation)
9595
continue
9696
} else {
97-
b.Log.Info("Adding to list", "namespace", item.GetNamespace(), "name", item.Name)
97+
b.Log.Info("Adding to list", "pvc", item.Name)
9898
}
9999

100100
tmpVol := corev1.Volume{

operator/backupcontroller/setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package backupcontroller
22

33
import (
44
"github.com/go-logr/logr"
5-
"github.com/k8up-io/k8up/v2/api/v1"
5+
k8upv1 "github.com/k8up-io/k8up/v2/api/v1"
66
"sigs.k8s.io/controller-runtime"
77
"sigs.k8s.io/controller-runtime/pkg/predicate"
88
)
@@ -25,7 +25,7 @@ func (r *BackupReconciler) SetupWithManager(mgr controllerruntime.Manager, _ log
2525
r.Kube = mgr.GetClient()
2626
return controllerruntime.NewControllerManagedBy(mgr).
2727
Named(name).
28-
For(&v1.Backup{}).
28+
For(&k8upv1.Backup{}).
2929
WithEventFilter(predicate.GenerationChangedPredicate{}).
3030
Complete(r)
3131
}

operator/jobcontroller/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,20 @@ func (r *JobReconciler) updateOwner(ctx context.Context, batchJob *batchv1.Job)
151151
if !ownerStatus.HasSucceeded() {
152152
// only increase success counter if new condition
153153
monitoring.IncSuccessCounters(batchJob.Namespace, jobType)
154+
log.Info("Job succeeded")
154155
}
155156
ownerStatus.SetSucceeded(message)
156157
ownerStatus.SetFinished(fmt.Sprintf("job '%s' completed successfully", batchJob.Name))
157-
log.Info("job succeeded", "jobName", batchJob.Name)
158158
}
159159
failedCond := FindStatusCondition(batchJob.Status.Conditions, batchv1.JobFailed)
160160
if failedCond != nil && failedCond.Status == corev1.ConditionTrue {
161161
if !ownerStatus.HasFailed() {
162162
// only increase fail counter if new condition
163163
monitoring.IncFailureCounters(batchJob.Namespace, jobType)
164+
log.Info("Job failed")
164165
}
165166
ownerStatus.SetFailed(message)
166167
ownerStatus.SetFinished(fmt.Sprintf("job '%s' has failed", batchJob.Name))
167-
log.Info("job failed", "jobName", batchJob.Name)
168168
}
169169
if successCond == nil && failedCond == nil {
170170
ownerStatus.SetStarted(message)

0 commit comments

Comments
 (0)