@@ -404,10 +404,7 @@ func (n *DeploymentHandler) cleanupOrphanedExternalClusterResources(ctx context.
404404 cronJobs := & batchv1.CronJobList {}
405405 listOpts := & client.ListOptions {
406406 Namespace : n .Mondoo .Namespace ,
407- LabelSelector : labels .SelectorFromSet (map [string ]string {
408- "app" : "mondoo-k8s-scan" ,
409- "mondoo_cr" : n .Mondoo .Name ,
410- }),
407+ LabelSelector : labels .SelectorFromSet (CronJobLabels (* n .Mondoo )),
411408 }
412409 if err := n .KubeClient .List (ctx , cronJobs , listOpts ); err != nil {
413410 return err
@@ -573,10 +570,7 @@ func (n *DeploymentHandler) garbageCollectIfNeeded(ctx context.Context, clusterU
573570 cronJobs := & batchv1.CronJobList {}
574571 listOpts := & client.ListOptions {
575572 Namespace : n .Mondoo .Namespace ,
576- LabelSelector : labels .SelectorFromSet (map [string ]string {
577- "app" : "mondoo-k8s-scan" ,
578- "mondoo_cr" : n .Mondoo .Name ,
579- }),
573+ LabelSelector : labels .SelectorFromSet (CronJobLabels (* n .Mondoo )),
580574 }
581575 if err := n .KubeClient .List (ctx , cronJobs , listOpts ); err != nil {
582576 logger .Error (err , "Failed to list CronJobs for garbage collection" )
@@ -731,10 +725,7 @@ func (n *DeploymentHandler) cleanupStaleCronJobs(ctx context.Context) error {
731725 cronJobs := & batchv1.CronJobList {}
732726 listOpts := & client.ListOptions {
733727 Namespace : n .Mondoo .Namespace ,
734- LabelSelector : labels .SelectorFromSet (map [string ]string {
735- "app" : "mondoo-k8s-scan" ,
736- "mondoo_cr" : n .Mondoo .Name ,
737- }),
728+ LabelSelector : labels .SelectorFromSet (CronJobLabels (* n .Mondoo )),
738729 }
739730 if err := n .KubeClient .List (ctx , cronJobs , listOpts ); err != nil {
740731 return err
0 commit comments