@@ -32,10 +32,15 @@ import {
32
32
33
33
import { kindPart } from '../fqn'
34
34
import { getKind } from '../explain'
35
- import { formatOf , getLabel , getNamespace , getResourceNamesForArgv , KubeOptions , KubeExecOptions } from '../options'
35
+ import { formatOf , isForAllNamespaces , getLabel , getNamespace , getResourceNamesForArgv , KubeOptions , KubeExecOptions } from '../options'
36
36
37
37
import { getCommandFromArgs } from '../../../lib/util/util'
38
- import { Pair , getNamespaceBreadcrumbs } from '../../../lib/view/formatTable'
38
+ import {
39
+ Pair ,
40
+ getNamespaceBreadcrumbs ,
41
+ preprocessTable as preFormatTables ,
42
+ formatTable
43
+ } from '../../../lib/view/formatTable'
39
44
40
45
const strings = i18n ( 'plugin-kubectl' , 'events' )
41
46
const debug = Debug ( 'plugin-kubectl/controller/watch/watcher' )
@@ -260,6 +265,27 @@ class KubectlWatcher implements Abortable, Watcher {
260
265
} , { } as Record < string , Pair [ ] [ ] > )
261
266
}
262
267
268
+ /**
269
+ * a resource cannot be retrieved by name across all namespaces,
270
+ * so we need to append the namespace column to match the inital
271
+ * all-namespaces table
272
+ * see issue: https://github.com/IBM/kui/issues/5169
273
+ *
274
+ */
275
+ private async allNamespaceOverride ( namespace : string , getCommand : string , kind : string ) {
276
+ const rawData = await this . args . REPL . qexec < string > ( `sendtopty ${ getCommand . replace ( / ^ k ( \s ) / , 'kubectl$1' ) } ` )
277
+ const preTables = preFormatTables ( rawData . split ( / ^ (? = L A S T S E E N | N A M E S P A C E | N A M E \s + ) / m) )
278
+ const allNamespacesTable = preTables [ 0 ] . map ( ( pairs , idx ) => {
279
+ if ( idx === 0 ) {
280
+ return [ { key : 'NAMESPACE' , value : 'NAMESPACE' } ] . concat ( pairs )
281
+ } else {
282
+ return [ { key : 'NAMESPACE' , value : namespace } ] . concat ( pairs )
283
+ }
284
+ } )
285
+
286
+ return formatTable ( getCommandFromArgs ( this . args ) , 'get' , kind , this . args , allNamespacesTable )
287
+ }
288
+
263
289
/**
264
290
* Fetch the user-formatted rows for the so-named resources in the
265
291
* given namespace.
@@ -275,17 +301,21 @@ class KubectlWatcher implements Abortable, Watcher {
275
301
' '
276
302
) } -n ${ namespace } ${ this . output ? `-o ${ this . output } ` : '' } `
277
303
278
- return this . args . REPL . qexec < Table > ( getCommand ) . catch ( ( err : CodedError ) => {
279
- if ( err . code !== 404 ) {
280
- console . error ( err )
281
- }
282
- // mark as all offline, if we got a 404 for the bulk get
283
- if ( typeof rowNames === 'string' ) {
284
- this . pusher . offline ( rowNames )
285
- } else {
286
- rowNames . forEach ( name => this . pusher . offline ( name ) )
287
- }
288
- } )
304
+ if ( isForAllNamespaces ( this . args . parsedOptions ) ) {
305
+ return this . allNamespaceOverride ( namespace , getCommand , kind )
306
+ } else {
307
+ return this . args . REPL . qexec < Table > ( getCommand ) . catch ( ( err : CodedError ) => {
308
+ if ( err . code !== 404 ) {
309
+ console . error ( err )
310
+ }
311
+ // mark as all offline, if we got a 404 for the bulk get
312
+ if ( typeof rowNames === 'string' ) {
313
+ this . pusher . offline ( rowNames )
314
+ } else {
315
+ rowNames . forEach ( name => this . pusher . offline ( name ) )
316
+ }
317
+ } )
318
+ }
289
319
}
290
320
291
321
/** Get rows as specified by user's -o */
0 commit comments