@@ -51,6 +51,8 @@ type Kleaner struct {
51
51
deleteEvictedAfter time.Duration
52
52
53
53
ignoreOwnedByCronjob bool
54
+
55
+ labelSelector string
54
56
55
57
dryRun bool
56
58
ctx context.Context
@@ -60,13 +62,16 @@ type Kleaner struct {
60
62
// NewKleaner creates a new NewKleaner
61
63
func NewKleaner (ctx context.Context , kclient * kubernetes.Clientset , namespace string , dryRun bool , deleteSuccessfulAfter ,
62
64
deleteFailedAfter , deletePendingAfter , deleteOrphanedAfter , deleteEvictedAfter time.Duration , ignoreOwnedByCronjob bool ,
65
+ labelSelector string ,
63
66
stopCh <- chan struct {}) * Kleaner {
64
67
jobInformer := cache .NewSharedIndexInformer (
65
68
& cache.ListWatch {
66
69
ListFunc : func (options metav1.ListOptions ) (runtime.Object , error ) {
70
+ options .LabelSelector = labelSelector
67
71
return kclient .BatchV1 ().Jobs (namespace ).List (ctx , options )
68
72
},
69
73
WatchFunc : func (options metav1.ListOptions ) (watch.Interface , error ) {
74
+ options .LabelSelector = labelSelector
70
75
return kclient .BatchV1 ().Jobs (namespace ).Watch (ctx , options )
71
76
},
72
77
},
@@ -78,9 +83,11 @@ func NewKleaner(ctx context.Context, kclient *kubernetes.Clientset, namespace st
78
83
podInformer := cache .NewSharedIndexInformer (
79
84
& cache.ListWatch {
80
85
ListFunc : func (options metav1.ListOptions ) (runtime.Object , error ) {
86
+ options .LabelSelector = labelSelector
81
87
return kclient .CoreV1 ().Pods (namespace ).List (ctx , options )
82
88
},
83
89
WatchFunc : func (options metav1.ListOptions ) (watch.Interface , error ) {
90
+ options .LabelSelector = labelSelector
84
91
return kclient .CoreV1 ().Pods (namespace ).Watch (ctx , options )
85
92
},
86
93
},
@@ -99,6 +106,7 @@ func NewKleaner(ctx context.Context, kclient *kubernetes.Clientset, namespace st
99
106
deleteOrphanedAfter : deleteOrphanedAfter ,
100
107
deleteEvictedAfter : deleteEvictedAfter ,
101
108
ignoreOwnedByCronjob : ignoreOwnedByCronjob ,
109
+ labelSelector : labelSelector ,
102
110
}
103
111
jobInformer .AddEventHandler (cache.ResourceEventHandlerFuncs {
104
112
UpdateFunc : func (old , new interface {}) {
0 commit comments