Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 3 additions & 5 deletions controllers/container_image/deployment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,9 @@ func (n *DeploymentHandler) syncCronJob(ctx context.Context) error {
existing.Spec.ConcurrencyPolicy = desired.Spec.ConcurrencyPolicy
existing.SetOwnerReferences(desired.GetOwnerReferences())

// Remove any old jobs because they won't be updated when the cronjob changes
if err := n.KubeClient.DeleteAllOf(ctx, &batchv1.Job{},
client.InNamespace(n.Mondoo.Namespace),
client.MatchingLabels(CronJobLabels(*n.Mondoo)),
client.PropagationPolicy(metav1.DeletePropagationForeground)); err != nil {
// Remove completed/failed jobs because they won't be updated when the cronjob changes.
// Active jobs are preserved to avoid killing in-progress scans.
if err := k8s.DeleteCompletedJobs(ctx, n.KubeClient, n.Mondoo.Namespace, CronJobLabels(*n.Mondoo), logger); err != nil {
return err
}

Expand Down
16 changes: 6 additions & 10 deletions controllers/k8s_scan/deployment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,9 @@ func (n *DeploymentHandler) syncCronJob(ctx context.Context) error {
existing.Spec.ConcurrencyPolicy = desired.Spec.ConcurrencyPolicy
existing.SetOwnerReferences(desired.GetOwnerReferences())

// Remove any old jobs because they won't be updated when the cronjob changes
if err := n.KubeClient.DeleteAllOf(ctx, &batchv1.Job{},
client.InNamespace(n.Mondoo.Namespace),
client.MatchingLabels(CronJobLabels(*n.Mondoo)),
client.PropagationPolicy(metav1.DeletePropagationForeground)); err != nil {
// Remove completed/failed jobs because they won't be updated when the cronjob changes.
// Active jobs are preserved to avoid killing in-progress scans.
if err := k8s.DeleteCompletedJobs(ctx, n.KubeClient, n.Mondoo.Namespace, CronJobLabels(*n.Mondoo), logger); err != nil {
return err
}

Expand Down Expand Up @@ -399,11 +397,9 @@ func (n *DeploymentHandler) syncExternalClusterCronJob(ctx context.Context, imag
existing.Spec.ConcurrencyPolicy = desired.Spec.ConcurrencyPolicy
existing.SetOwnerReferences(desired.GetOwnerReferences())

// Remove any old jobs
if err := n.KubeClient.DeleteAllOf(ctx, &batchv1.Job{},
client.InNamespace(n.Mondoo.Namespace),
client.MatchingLabels(ExternalClusterCronJobLabels(*n.Mondoo, cluster.Name)),
client.PropagationPolicy(metav1.DeletePropagationForeground)); err != nil {
// Remove completed/failed jobs because they won't be updated when the cronjob changes.
// Active jobs are preserved to avoid killing in-progress scans.
if err := k8s.DeleteCompletedJobs(ctx, n.KubeClient, n.Mondoo.Namespace, ExternalClusterCronJobLabels(*n.Mondoo, cluster.Name), logger); err != nil {
return err
}

Expand Down
8 changes: 3 additions & 5 deletions controllers/nodes/deployment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ func (n *DeploymentHandler) syncCronJob(ctx context.Context) error {
}
continue
case controllerutil.OperationResultUpdated:
// Remove any old jobs because they won't be updated when the cronjob changes
if err := n.KubeClient.DeleteAllOf(ctx, &batchv1.Job{},
client.InNamespace(n.Mondoo.Namespace),
client.MatchingLabels(NodeScanningLabels(*n.Mondoo)),
client.PropagationPolicy(metav1.DeletePropagationForeground)); err != nil {
// Remove completed/failed jobs because they won't be updated when the cronjob changes.
// Active jobs are preserved to avoid killing in-progress scans.
if err := k8s.DeleteCompletedJobs(ctx, n.KubeClient, n.Mondoo.Namespace, NodeScanningLabels(*n.Mondoo), logger); err != nil {
return err
}
}
Expand Down
Loading