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: Remove job deletion for jobs with TTLSecondsAfterFinished set #2375

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tom1299
Copy link
Contributor

@tom1299 tom1299 commented Jan 14, 2025

Description

Currently jobs are directly deleted after they are completed by the trivy-operator without honouring the jobs ttlSecondsAfterFinished and thus also the helm configuration parameter operator.scanJobTTL.
The change introduced in this PR will only delete the job if it has no ttlSecondsAfterFinished.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@tom1299 tom1299 changed the title Remove job deletion for jobs with TTLSecondsAfterFinished set fix: Remove job deletion for jobs with TTLSecondsAfterFinished set Jan 14, 2025
@github-actions github-actions bot added the bug label Jan 14, 2025
@@ -357,6 +357,10 @@ func (r *ScanJobController) completedContainers(ctx context.Context, scanJob *ba
}

func (r *ScanJobController) deleteJob(ctx context.Context, job *batchv1.Job) error {
if job.Spec.TTLSecondsAfterFinished != nil && *job.Spec.TTLSecondsAfterFinished != 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I read through the docs but it wasn't clear to me why we should check for both !=nil and !=0. Could you explain that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually now that you mentioned it, it seems to me that the !=0 is superfluous / not really necessary. I would remove this from the if statement.

Copy link
Member

Choose a reason for hiding this comment

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

Could you update your PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@simar7 I'm sorry but somehow I totally forgot to do the update. I made the change and squashed the commits so that the commit history looks better.

@tom1299 tom1299 force-pushed the vulnerability-scanjob-is-immediately-deleted branch from 4a7e50a to 92f70f0 Compare January 21, 2025 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vulnerability ScanJob is immediately deleted
2 participants