Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore parsing logs of deleted scan jobs #950

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: ignore parsing logs of deleted scan jobs
  • Loading branch information
mycodeself committed Feb 6, 2022
commit 64d0ea6d58556e13f4cf6fff4643db4d92b48ad9
2 changes: 1 addition & 1 deletion pkg/kube/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewLogsReader(clientset kubernetes.Interface) LogsReader {
func (r *logsReader) GetLogsByJobAndContainerName(ctx context.Context, job *batchv1.Job, containerName string) (io.ReadCloser, error) {
pod, err := r.getPodByJob(ctx, job)
if err != nil {
return nil, fmt.Errorf("getting pod controlled by job: %q: %w", job.Namespace+"/"+job.Name, err)
return nil, err
}
if pod == nil {
return nil, fmt.Errorf("getting pod controlled by job: %q: pod not found", job.Namespace+"/"+job.Name)
Expand Down
7 changes: 6 additions & 1 deletion pkg/operator/controller/configauditreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,12 @@ func (r *ConfigAuditReportReconciler) processCompleteScanJob(ctx context.Context

logsStream, err := r.LogsReader.GetLogsByJobAndContainerName(ctx, job, r.Plugin.GetContainerName())
if err != nil {
return fmt.Errorf("getting logs: %w", err)
if errors.IsNotFound(err) {
log.V(1).Info("Ignoring not found job", "job", fmt.Sprintf("%s/%s", job.Namespace, job.Name), "owner", owner)
log.V(1).Info("Deleting complete scan job", "owner", owner)
return r.deleteJob(ctx, job)
Copy link
Contributor

@chen-keinan chen-keinan Feb 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mycodeself Probably r.deleteJob will not find a job to delete, due to job not found.

Maybe it is better to return ctrl.Result{}, nil to remove it from the cache :
https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/internal/controller/controller.go#L332

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chen-keinan but return ctrl.Result{}, nil doesn't fit the signature of processCompleteScanJob it just returns an error. I guess that I should just return nil right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mycodeself FYI, The complete solution has been implemented by #956

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok @chen-keinan thanks for letting me know! I'll watch this PR to continue learning!

}
return fmt.Errorf("getting pod controlled by job: %q: %w", job.Namespace+"/"+job.Name, err)
}

reportData, err := r.Plugin.ParseConfigAuditReportData(r.PluginContext, logsStream)
Expand Down