|
17 | 17 | import Debug from 'debug'
|
18 | 18 | import { Table, Arguments, CodedError, Streamable, Abortable, Watchable, Watcher, WatchPusher } from '@kui-shell/core'
|
19 | 19 |
|
20 |
| -import fqn from '../fqn' |
| 20 | +import { kindPart } from '../fqn' |
21 | 21 | import { formatOf, KubeOptions, KubeExecOptions } from '../options'
|
22 | 22 |
|
23 | 23 | import { Pair } from '../../../lib/view/formatTable'
|
@@ -146,56 +146,47 @@ class KubectlWatcher implements Abortable, Watcher {
|
146 | 146 | const { rows } = preprocessed
|
147 | 147 |
|
148 | 148 | // now process the full rows into table view updates
|
149 |
| - const tables = await Promise.all( |
150 |
| - rows.map(async row => { |
151 |
| - try { |
152 |
| - const [{ value: name }, { value: kind }, { value: apiVersion }, { value: namespace }] = row |
| 149 | + const kind = rows[0][1].value |
| 150 | + const apiVersion = rows[0][2].value |
| 151 | + const namespace = rows[0][3].value || 'default' |
| 152 | + const rowNames = rows.map(_ => _[0].value) |
153 | 153 |
|
154 |
| - const getCommand = `${getCommandFromArgs(this.args)} get ${fqn(apiVersion, kind, name, namespace)} ${ |
155 |
| - this.output ? `-o ${this.output}` : '' |
156 |
| - }` |
| 154 | + const getCommand = `${getCommandFromArgs(this.args)} get ${kindPart(apiVersion, kind)} ${rowNames.join( |
| 155 | + ' ' |
| 156 | + )} -n ${namespace} ${this.output ? `-o ${this.output}` : ''}` |
157 | 157 |
|
158 |
| - // this is where we fetch the table columns the user |
159 |
| - // requested; note our use of the "output" variable, |
160 |
| - // which (above) we defined to be the user's schema |
161 |
| - // request |
162 |
| - return this.args.REPL.qexec<Table>(getCommand).catch((err: CodedError) => { |
163 |
| - // error fetching the row data |
164 |
| - // const rowKey = fqn(apiVersion, kind, name, namespace) |
165 |
| - if (err.code !== 404) { |
166 |
| - console.error(err) |
167 |
| - } |
168 |
| - this.pusher.offline(name) |
169 |
| - }) |
170 |
| - } catch (err) { |
171 |
| - console.error('error handling watched row', err) |
172 |
| - } |
173 |
| - }) |
174 |
| - ) |
| 158 | + const table = await this.args.REPL.qexec<Table>(getCommand).catch((err: CodedError) => { |
| 159 | + if (err.code !== 404) { |
| 160 | + console.error(err) |
| 161 | + } |
| 162 | + // mark as all offline, if we got a 404 for the bulk get |
| 163 | + rowNames.forEach(name => this.pusher.offline(name)) |
| 164 | + }) |
175 | 165 |
|
176 |
| - // in case the initial get was empty, we add the header to the |
177 |
| - // table; see https://github.com/kui-shell/plugin-kubeui/issues/219 |
178 |
| - const tableWithHeader = tables.find(table => table && table.header) |
179 |
| - if (tableWithHeader && tableWithHeader.header) { |
180 |
| - // yup, we have a header; push it to the view |
181 |
| - this.pusher.header(tableWithHeader.header) |
182 |
| - } |
| 166 | + if (table) { |
| 167 | + // in case the initial get was empty, we add the header to the |
| 168 | + // table; see https://github.com/kui-shell/plugin-kubeui/issues/219 |
| 169 | + if (table.header) { |
| 170 | + // yup, we have a header; push it to the view |
| 171 | + this.pusher.header(table.header) |
| 172 | + } |
183 | 173 |
|
184 |
| - // based on the information we got back, 1) we push updates to |
185 |
| - // the table model; and 2) we may be able to discern that we |
186 |
| - // can stop watching |
187 |
| - tables.forEach(table => { |
188 |
| - if (table) { |
189 |
| - table.body.forEach(row => { |
190 |
| - // push an update to the table model |
191 |
| - // true means we want to do a batch update |
| 174 | + // based on the information we got back, 1) we push updates to |
| 175 | + // the table model; and 2) we may be able to discern that we |
| 176 | + // can stop watching |
| 177 | + table.body.forEach(row => { |
| 178 | + // push an update to the table model |
| 179 | + // true means we want to do a batch update |
| 180 | + if (row.isDeleted) { |
| 181 | + this.pusher.offline(row.name) |
| 182 | + } else { |
192 | 183 | this.pusher.update(row, true)
|
193 |
| - }) |
| 184 | + } |
| 185 | + }) |
194 | 186 |
|
195 |
| - // batch update done! |
196 |
| - this.pusher.batchUpdateDone() |
197 |
| - } |
198 |
| - }) |
| 187 | + // batch update done! |
| 188 | + this.pusher.batchUpdateDone() |
| 189 | + } |
199 | 190 | } else {
|
200 | 191 | console.error('unknown streamable type', _)
|
201 | 192 | }
|
|
0 commit comments