Skip to content

Commit

Permalink
ci(debug-test): add debug lines to aide with debugging (#124)
Browse files Browse the repository at this point in the history
Co-authored-by: Erik Godding Boye <egboye@gmail.com>
  • Loading branch information
padlar and erikgb authored Jan 24, 2023
1 parent d51e2a9 commit e6132db
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/controller/stas/scan_job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (r *ScanJobReconciler) reconcileCompleteJob(ctx context.Context, jobName st
cis.Status.LastScanTime = &now
cis.Status.LastScanJobName = jobName
err = r.Status().Patch(ctx, cis, client.MergeFrom(cleanCis))
logf.FromContext(ctx).V(3).Info("Patched CIS %q status with reason: %q patchStatus: %s\n", cis.Name, condition.Reason, err)

return err
}
Expand Down Expand Up @@ -114,6 +115,7 @@ func (r *ScanJobReconciler) reconcileCompleteJob(ctx context.Context, jobName st
cis.Status.LastScanTime = &now
cis.Status.LastScanJobName = jobName
err = r.Status().Patch(ctx, cis, client.MergeFrom(cleanCis))
logf.FromContext(ctx).V(3).Info("Patched CIS %q status with reason: %q patchStatus: %s\n", cis.Name, condition.Reason, err)
}

return err
Expand Down Expand Up @@ -169,6 +171,8 @@ func (r *ScanJobReconciler) reconcile() reconcile.Func {
func (r *ScanJobReconciler) reconcileJob(ctx context.Context, job *batchv1.Job) error {
cisList := &stasv1alpha1.ContainerImageScanList{}

logf.FromContext(ctx).V(3).Info("Reconciling job %q with status %+v", job.Name, job.Status)

listOps := []client.ListOption{
client.InNamespace(job.Labels[stasv1alpha1.LabelStatnettControllerNamespace]),
client.MatchingFields{indexUID: job.Labels[stasv1alpha1.LabelStatnettControllerUID]},
Expand Down Expand Up @@ -197,6 +201,7 @@ func (r *ScanJobReconciler) reconcileJob(ctx context.Context, job *batchv1.Job)
if err != nil {
switch {
case staserrors.IsJobPodNotFound(err), staserrors.IsScanJobContainerWaiting(err):
logf.FromContext(ctx).V(3).Info("Failed to get job %q logs %s", job.Name, err)
return r.reconcileFailedJob(ctx, job.Name, strings.NewReader(err.Error()), cis)
default:
return err
Expand All @@ -211,8 +216,10 @@ func (r *ScanJobReconciler) reconcileJob(ctx context.Context, job *batchv1.Job)
}(logs)

if job.Status.Succeeded > 0 {
logf.FromContext(ctx).V(3).Info("Patching CIS %q status with success job status", cis.Name)
return r.reconcileCompleteJob(ctx, job.Name, logs, cis)
} else {
logf.FromContext(ctx).V(3).Info("Patching CIS %q status with failed job status", cis.Name)
return r.reconcileFailedJob(ctx, job.Name, logs, cis)
}
}
Expand Down

0 comments on commit e6132db

Please sign in to comment.