Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add krew support #4200

Merged
merged 1 commit into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export abstract class BaseSidecar<
}
}

public componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error(error, errorInfo)
}

/** @return a `HistoryEntry` for the given `Response` */
protected abstract getState(
tab: KuiTab,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default class ComboSidecar extends React.PureComponent<Props, State> {
// this.cleaners.push(() => eventChannelUnsafe.off(channel1, onResponse))
}

public componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error(error, errorInfo)
}

private onResponse(tab: Tab, response: MultiModalResponse | NavResponse) {
this.setState({
tab,
Expand Down
7 changes: 6 additions & 1 deletion plugins/plugin-client-common/web/css/static/ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -1033,9 +1033,11 @@ body.oops-total-catastrophe #restart-needed-warning {
.page-content code {
font-family: var(--font-monospace);
}
.page-content p > code {
.page-content p > code,
.page-content li > code {
color: var(--color-base0F);
opacity: 0.875;
word-break: break-all;
}
.page-content p:not(:last-child) {
padding-bottom: 0.5em;
Expand Down Expand Up @@ -1103,6 +1105,9 @@ body.oops-total-catastrophe #restart-needed-warning {
font-weight: 400;
list-style-type: none;
position: relative;
&:not(:first-child) {
margin-top: 0.5em;
}
}
.page-content li:before {
content: "\002013";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ body .bx--data-table-container {
padding-right: 1em;
}

td [data-key='NAME'] {
td [data-key='NAME'],
td .kui--table-cell-is-name {
font-weight: 700;
}

Expand Down
10 changes: 5 additions & 5 deletions plugins/plugin-kubectl/helm/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@kui-shell/plugin-helmui",
"name": "@kui-shell/plugin-helm",
"version": "1.0.1",
"description": "Kubernetes visualization plugin for helm",
"license": "Apache-2.0",
Expand All @@ -16,20 +16,20 @@
"contributors": [
"Mengting Yan"
],
"homepage": "https://github.com/kui-shell/plugin-kubeui#readme",
"homepage": "https://github.com/IBM/kui#readme",
"bugs": {
"url": "https://github.com/kui-shell/plugin-kubeui/issues/new"
"url": "https://github.com/IBM/kui/issues/new"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kui-shell/plugin-kubeui.git"
"url": "git+https://github.com/IBM/kui.git"
},
"main": "dist/index.js",
"module": "mdist/index.js",
"types": "mdist/index.d.ts",
"dependencies": {
"@kui-shell/core": "8.0.6",
"@kui-shell/plugin-kubeui": "*",
"@IBM/kui": "*",
"debug": "4.1.1"
},
"krew": {
Expand Down
7 changes: 7 additions & 0 deletions plugins/plugin-kubectl/i18n/krew_en_US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Plugin": "Plugin",
"Caveats": "Caveats",
"Overview": "Overview",
"Download": "Download",
"Home Page": "Home Page"
}
42 changes: 42 additions & 0 deletions plugins/plugin-kubectl/krew/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@kui-shell/plugin-krew",
"version": "1.0.1",
"description": "Kubernetes visualization plugin for krew",
"license": "Apache-2.0",
"keywords": [
"kubernetes",
"kubectl",
"krew",
"cli",
"ui",
"kui",
"plugin"
],
"author": "@starpit",
"contributors": [
"Mengting Yan"
],
"homepage": "https://github.com/IBM/kui#readme",
"bugs": {
"url": "https://github.com/IBM/kui/issues/new"
},
"repository": {
"type": "git",
"url": "git+https://github.com/IBM/kui.git"
},
"main": "dist/index.js",
"module": "mdist/index.js",
"types": "mdist/index.d.ts",
"dependencies": {
"@kui-shell/core": "*",
"@kui-shell/plugin-kubectl": "*",
"debug": "4.1.1"
},
"krew": {
"commandPrefix": "kubeui"
},
"publishConfig": {
"access": "public"
},
"gitHead": "89de9f78e8a1a2bdd29d2e17d7c608ab006c6d32"
}
28 changes: 28 additions & 0 deletions plugins/plugin-kubectl/krew/src/controller/generic-table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2020 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Arguments } from '@kui-shell/core'

import { isUsage, doHelp, KubeOptions, doExecWithTable } from '@kui-shell/plugin-kubectl'

export default (command: string) => (args: Arguments<KubeOptions>) => {
if (isUsage(args)) {
// special case: get --help/-h
return doHelp(command, args)
} else {
return doExecWithTable(args, undefined, command, { verb: 'krew', entityType: 'info' })
}
}
23 changes: 23 additions & 0 deletions plugins/plugin-kubectl/krew/src/controller/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2020 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Arguments } from '@kui-shell/core'

import { doHelp, KubeOptions } from '@kui-shell/plugin-kubectl'

export default (command: string) => (args: Arguments<KubeOptions>) => {
return doHelp(command, args)
}
103 changes: 103 additions & 0 deletions plugins/plugin-kubectl/krew/src/controller/info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright 2020 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Arguments, Menu, NavResponse, i18n } from '@kui-shell/core'

import { isUsage, doHelp, KubeOptions, doExecWithStdout } from '@kui-shell/plugin-kubectl'

const strings = i18n('plugin-kubectl', 'krew')

export default (command: string) => async (args: Arguments<KubeOptions>) => {
if (isUsage(args)) {
// special case: get --help/-h
return doHelp(command, args)
} else {
// re: the usePty; oddly krew list only emits a subset of the
// information if it sees a non-pty; so we have to force the use
// of a pty

// re: nameColumn; the krew list table diverges from the kubectl
// standard, and instead uses PLUGIN as the "name" column key
const stdout = await doExecWithStdout(args)

const keys = stdout.match(/^\S+:/gm)
const indices = keys.map(key => {
return stdout.indexOf(key)
})
const values = indices.map((keyIdx, idx, A) => {
return stdout.slice(keyIdx + keys[idx].length, A[idx + 1]).trim()
})
const kv = keys.reduce((M, key, idx) => {
M[key] = values[idx]
return M
}, {})

const uri = !kv['URI:'] ? [] : [{ label: strings('Download'), href: kv['URI:'] }]
const homepage = !kv['HOMEPAGE:'] ? [] : [{ label: strings('Home Page'), href: kv['HOMEPAGE:'] }]
const links = uri.concat(homepage)

const menus: Menu[] = [
{
[strings('Plugin')]: {
modes: [
{
mode: 'overview',
label: strings('Overview'),
content: keys
.filter(_ => _ !== 'HOMEPAGE:' && _ !== 'CAVEATS:' && _ !== 'URI:')
.reduce((M, key) => {
return (
M +
`
### ${key}
${key === 'NAME:' ? '#### ' : ''}${key === 'SHA256:' ? '`' : ''}${kv[key]}${key === 'SHA256:' ? '`' : ''}`
)
}, ''),
contentType: 'text/markdown'
}
].concat(
!kv['CAVEATS:']
? []
: [
{
mode: 'caveats',
label: strings('Caveats'),
contentType: 'text/markdown',
content: kv['CAVEATS:']
.replace(/^\\\n/, '')
.replace(/\n\/$/, '')
.replace(/ \| /g, '')
.replace(/(export \S+=.*)/g, '`$1`')
.replace(/(%USERPROFILE\S+)/g, '`$1`')
.replace(/\n\s+\$(.*)/g, '\n ```\n$1\n ```\n')
}
]
)
}
}
]

const response: NavResponse = {
apiVersion: 'kui-shell/v1',
kind: 'NavResponse',
menus,
links,
breadcrumbs: [{ label: 'krew', command: `kubectl krew list` }, { label: 'info' }, { label: values[0] }]
}

return response
}
}
39 changes: 39 additions & 0 deletions plugins/plugin-kubectl/krew/src/controller/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2020 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Arguments } from '@kui-shell/core'

import { isUsage, doHelp, KubeOptions, doExecWithTable } from '@kui-shell/plugin-kubectl'

export default (command: string) => (args: Arguments<KubeOptions>) => {
if (isUsage(args)) {
// special case: get --help/-h
return doHelp(command, args)
} else {
// re: the usePty; oddly krew list only emits a subset of the
// information if it sees a non-pty; so we have to force the use
// of a pty

// re: nameColumn; the krew list table diverges from the kubectl
// standard, and instead uses PLUGIN as the "name" column key
return doExecWithTable(args, undefined, command, {
usePty: true,
nameColumn: 'PLUGIN',
verb: 'krew',
entityType: 'info'
})
}
}
36 changes: 36 additions & 0 deletions plugins/plugin-kubectl/krew/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2020 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Registrar } from '@kui-shell/core'
import { defaultFlags, commandPrefix } from '@kui-shell/plugin-kubectl'

import help from './controller/help'
import info from './controller/info'
import list from './controller/list'
import genericTable from './controller/generic-table'

const aliases = ['k', 'kubectl']
const canonical = 'kubectl'

export default async (registrar: Registrar) => {
aliases.forEach(command => {
registrar.listen(`/${commandPrefix}/${command}/krew/help`, help(canonical), defaultFlags)
registrar.listen(`/${commandPrefix}/${command}/krew/info`, info(canonical), defaultFlags)
registrar.listen(`/${commandPrefix}/${command}/krew/list`, list(canonical), defaultFlags)
registrar.listen(`/${commandPrefix}/${command}/krew/search`, genericTable(canonical), defaultFlags)
registrar.listen(`/${commandPrefix}/${command}/krew/version`, genericTable(canonical), defaultFlags)
})
}
9 changes: 9 additions & 0 deletions plugins/plugin-kubectl/krew/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../../node_modules/@kui-shell/builder/tsconfig-base.json",
"include": ["src/**/*"],
"compilerOptions": {
"composite": true,
"outDir": "mdist",
"rootDir": "src"
}
}
Loading