@@ -93,7 +93,8 @@ func Run(ctx context.Context, config *Config) error {
93
93
}
94
94
resource .kind , resource .name = parts [0 ], parts [1 ]
95
95
if PodMatcher .Matches (resource .kind ) {
96
- // Pods can share the same labels, so we also set the pod query.
96
+ // Pods might have no labels or share the same labels,
97
+ // so we use an exact match instead.
97
98
podName , err := regexp .Compile ("^" + resource .name + "$" )
98
99
if err != nil {
99
100
return errors .Wrap (err , "failed to compile regular expression for pod" )
@@ -244,6 +245,10 @@ func chooseSelector(ctx context.Context, client clientset.Interface, namespace,
244
245
if kind == "" {
245
246
return selector , nil
246
247
}
248
+ if PodMatcher .Matches (kind ) {
249
+ // We use an exact match for pods instead of a label to select pods without labels.
250
+ return labels .Everything (), nil
251
+ }
247
252
labelMap , err := retrieveLabelsFromResource (ctx , client , namespace , kind , name )
248
253
if err != nil {
249
254
return nil , err
@@ -258,12 +263,6 @@ func retrieveLabelsFromResource(ctx context.Context, client clientset.Interface,
258
263
opt := metav1.GetOptions {}
259
264
switch {
260
265
// core
261
- case PodMatcher .Matches (kind ):
262
- o , err := client .CoreV1 ().Pods (namespace ).Get (ctx , name , opt )
263
- if err != nil {
264
- return nil , err
265
- }
266
- return o .Labels , nil
267
266
case ReplicationControllerMatcher .Matches (kind ):
268
267
o , err := client .CoreV1 ().ReplicationControllers (namespace ).Get (ctx , name , opt )
269
268
if err != nil {
0 commit comments