@@ -32,7 +32,7 @@ import {
32
32
33
33
import { kindPart } from '../fqn'
34
34
import { getKind } from '../explain'
35
- import { formatOf , getLabel , getNamespace , KubeOptions , KubeExecOptions } from '../options'
35
+ import { formatOf , getLabel , getNamespace , getResourceNamesForArgv , KubeOptions , KubeExecOptions } from '../options'
36
36
37
37
import { getCommandFromArgs } from '../../../lib/util/util'
38
38
import { Pair , getNamespaceBreadcrumbs } from '../../../lib/view/formatTable'
@@ -100,7 +100,7 @@ export class EventWatcher implements Abortable, Watcher {
100
100
private readonly args : Arguments ,
101
101
private readonly command : string ,
102
102
private readonly kindByUser : string ,
103
- private readonly name : string ,
103
+ private readonly name : string [ ] ,
104
104
private readonly namespace : string ,
105
105
private readonly watchOnly : boolean ,
106
106
private readonly pusher : WatchPusher
@@ -128,12 +128,15 @@ export class EventWatcher implements Abortable, Watcher {
128
128
debug ( 'rawData' , rawData )
129
129
this . eventLeftover = preprocessed . leftover === '\n' ? undefined : preprocessed . leftover
130
130
131
- // format the row as `[ago] involvedObject.name: message`
132
- const sortedRows = preprocessed . rows . filter ( notEmpty ) . sort ( ( rowA , rowB ) => {
133
- const lastSeenA = new Date ( rowA [ 0 ] . value ) . getTime ( )
134
- const lastSeenB = new Date ( rowB [ 0 ] . value ) . getTime ( )
135
- return lastSeenA - lastSeenB
136
- } )
131
+ // filter and format the row as `[ago] involvedObject.name: message`
132
+ const sortedRows = preprocessed . rows
133
+ . filter ( notEmpty )
134
+ . filter ( row => ! this . name || this . name . length === 0 || this . name . includes ( row [ 1 ] . value ) ) // filter the rows with `involvedObject.name` specified by `this.name`
135
+ . sort ( ( rowA , rowB ) => {
136
+ const lastSeenA = new Date ( rowA [ 0 ] . value ) . getTime ( )
137
+ const lastSeenB = new Date ( rowB [ 0 ] . value ) . getTime ( )
138
+ return lastSeenA - lastSeenB
139
+ } )
137
140
138
141
const agos = sortedRows . map ( row => {
139
142
const ago = Date . now ( ) - new Date ( row [ 0 ] . value ) . getTime ( )
@@ -175,9 +178,7 @@ export class EventWatcher implements Abortable, Watcher {
175
178
176
179
public async init ( ) {
177
180
const fullKind = await getKind ( this . command , this . args , this . kindByUser )
178
- const filter = this . name
179
- ? `--field-selector=involvedObject.kind=${ fullKind } ,involvedObject.name=${ this . name } `
180
- : `--field-selector=involvedObject.kind=${ fullKind } `
181
+ const filter = `--field-selector=involvedObject.kind=${ fullKind } `
181
182
182
183
const output = `--no-headers -o jsonpath='{.lastTimestamp}{"|"}{.involvedObject.name}{"|"}{.message}{"|"}{.metadata.name}{"|\\n"}'`
183
184
const watch = this . watchOnly ? '--watch-only' : '-w'
@@ -422,12 +423,19 @@ class KubectlWatcher implements Abortable, Watcher {
422
423
const cmd = getCommandFromArgs ( this . args )
423
424
const namespace = await getNamespace ( this . args )
424
425
const kindByUser = this . args . argvNoOptions [ this . args . argvNoOptions . indexOf ( 'get' ) + 1 ]
425
- const getWithResourceName = this . args . argvNoOptions . indexOf ( kindByUser ) !== this . args . argvNoOptions . length - 1
426
426
427
- if ( getWithResourceName || getLabel ( this . args ) || this . args . parsedOptions [ 'field-selector' ] ) {
428
- debug ( 'event watch not support' )
427
+ if ( getLabel ( this . args ) || this . args . parsedOptions [ 'field-selector' ] ) {
428
+ debug ( 'event watcher does not support label and field selector ' )
429
429
} else {
430
- const eventWatcher = new EventWatcher ( this . args , cmd , kindByUser , undefined , namespace , false , this . pusher )
430
+ const eventWatcher = new EventWatcher (
431
+ this . args ,
432
+ cmd ,
433
+ kindByUser ,
434
+ getResourceNamesForArgv ( kindByUser , this . args ) ,
435
+ namespace ,
436
+ false ,
437
+ this . pusher
438
+ )
431
439
eventWatcher . init ( )
432
440
this . ptyJob . push ( eventWatcher )
433
441
}
0 commit comments