forked from janus-idp/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web-terminal): impr README, add isWebTerminalAvailable util and …
…fix some other small bugs (janus-idp#1036)
- Loading branch information
1 parent
d148b72
commit a3d6d86
Showing
10 changed files
with
167 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,100 @@ | ||
# Web terminal plugin for Backstage | ||
# Web Terminal plugin for Backstage | ||
|
||
This plugin provides a frontend for [`webterminal proxy`](https://github.com/janus-idp/webterminal-proxy) and shows a terminal for catalog entities with an Kubernetes API-Server annotation (`kubernetes.io/api-server`). | ||
|
||
Users first enter their user token from the cluster, and then the plugin setups environment. Once it is set up, it connects to `webterminal-proxy`, which finishes setups and passes data between the frontend plugin and pod. | ||
|
||
This plugin provides a frontend for [`webterminal proxy`](https://github.com/janus-idp/webterminal-proxy). Users first enter their user token from the cluster, and then the plugin setups environment. Once it is set up, it connects to `webterminal-proxy`, which finishes setups and passes data between the frontend plugin and pod. | ||
This plugin uses [`xterm.js`](http://xtermjs.org/) to simulate a regular terminal. | ||
|
||
## Prerequisites | ||
|
||
Before we can install this plugin, we need to fulfill the following requirements: | ||
|
||
1. Deployed [`webterminal-proxy`](https://github.com/janus-idp/webterminal-proxy) | ||
2. Installed [Web terminal operator](https://docs.openshift.com/container-platform/4.8/web_console/odc-about-web-terminal.html#odc-installing-web-terminal_odc-about-web-terminal) | ||
1. Installed [Web Terminal operator](https://docs.openshift.com/container-platform/latest/web_console/web_terminal/installing-web-terminal.html) | ||
2. Deployed [`webterminal-proxy`](https://github.com/janus-idp/webterminal-proxy) | ||
|
||
## Installation | ||
|
||
1. Install the Web Terminal plugin using the following command: | ||
|
||
```console | ||
yarn workspace app add @janus-idp/backstage-plugin-web-terminal | ||
``` | ||
|
||
2. Enable an additional tab on the entity view page using the `packages/app/src/components/catalog/EntityPage.tsx` file as follows: | ||
|
||
```tsx title="packages/app/src/components/catalog/EntityPage.tsx" | ||
/* highlight-add-start */ | ||
import { | ||
isWebTerminalAvailable, | ||
WebTerminal, | ||
} from '@janus-idp/backstage-plugin-web-terminal'; | ||
|
||
/* highlight-add-end */ | ||
|
||
const serviceEntityPage = ( | ||
<EntityLayout> | ||
// ... | ||
{/* highlight-add-start */} | ||
<EntityLayout.Route | ||
if={isWebTerminalAvailable} | ||
path="/webterminal" | ||
title="Web Terminal" | ||
> | ||
<WebTerminal /> | ||
</EntityLayout.Route> | ||
{/* highlight-add-end */} | ||
</EntityLayout> | ||
); | ||
``` | ||
|
||
## Usage | ||
3. Alternative you can add the WebTerminal to an existing page: | ||
|
||
```tsx title="packages/app/src/components/catalog/EntityPage.tsx" | ||
/* highlight-add-start */ | ||
import { | ||
isWebTerminalAvailable, | ||
WebTerminal, | ||
} from '@janus-idp/backstage-plugin-web-terminal'; | ||
|
||
/* highlight-add-end */ | ||
|
||
<Grid container spacing={3}> | ||
{/* highlight-add-start */} | ||
<EntitySwitch> | ||
<EntitySwitch.Case if={isWebTerminalAvailable}> | ||
<Grid item md={6}> | ||
<WebTerminal /> | ||
</Grid> | ||
</EntitySwitch.Case> | ||
</EntitySwitch> | ||
{/* highlight-add-end */} | ||
</Grid>; | ||
``` | ||
|
||
4. Annotate your entity using the following annotations: | ||
|
||
```yaml | ||
metadata: | ||
annotations: | ||
'kubernetes.io/api-server': `<CLUSTER-URL>', | ||
``` | ||
|
||
## Configuration | ||
|
||
You have to define the location of the `webterminal-proxy` in `app-config.yaml`: | ||
|
||
```yaml | ||
webTerminal: | ||
webSocketUrl: 'wss://example.com:3000' | ||
restServerUrl: 'https://example.com:3000/rest' | ||
webSocketUrl: 'wss://example.com:3000/webterminal' | ||
restServerUrl: 'https://example.com:3000/webterminal/rest' | ||
``` | ||
|
||
Optionally, you can also define the default namespace for the terminal; otherwise, `openshift-terminal` will be used: | ||
|
||
```yaml | ||
webTerminal: | ||
webSocketUrl: 'wss://example.com:3000' | ||
restServerUrl: 'https://example.com:3000/rest' | ||
webSocketUrl: 'wss://example.com:3000/webterminal' | ||
restServerUrl: 'https://example.com:3000/webterminal/rest' | ||
defaultNamespace: 'default' | ||
``` | ||
|
||
Next, you can include the `WebTerminal` component in your catalog resource page within the entity context: | ||
|
||
```typescript | ||
<Grid item> | ||
<WebTerminal /> | ||
</Grid> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
plugins/web-terminal/src/components/TerminalComponent/utils/annotations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Entity } from '@backstage/catalog-model'; | ||
|
||
export const KUBERNETES_API_SERVER = 'kubernetes.io/api-server'; | ||
|
||
/** @public */ | ||
export const isWebTerminalAvailable = (entity: Entity): boolean => | ||
Boolean(entity.metadata.annotations?.[KUBERNETES_API_SERVER]); |
19 changes: 19 additions & 0 deletions
19
plugins/web-terminal/src/components/TerminalComponent/utils/helpers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getTimeInMsBetweenRetries } from './helpers'; | ||
|
||
describe('getTimeInMsBetweenRetries', () => { | ||
it('should return 0 for retry 0', () => { | ||
expect(getTimeInMsBetweenRetries(0)).toBe(0); | ||
}); | ||
|
||
it('should return more then 0 for the next retries', () => { | ||
expect(getTimeInMsBetweenRetries(1)).toBeGreaterThan(0); | ||
expect(getTimeInMsBetweenRetries(2)).toBeGreaterThan(0); | ||
}); | ||
|
||
it('should return not go above 5 seconds', () => { | ||
expect(getTimeInMsBetweenRetries(9)).toBe(3000); | ||
expect(getTimeInMsBetweenRetries(10)).toBe(5000); | ||
expect(getTimeInMsBetweenRetries(11)).toBe(5000); | ||
expect(getTimeInMsBetweenRetries(100)).toBe(5000); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
plugins/web-terminal/src/components/TerminalComponent/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { createWorkspace, getWorkspace, getNamespaces } from './requests'; | ||
export { getDefaultNamespace } from './helpers'; | ||
export { getDefaultNamespace, waitBetweenRetries } from './helpers'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { webTerminalPlugin, WebTerminal } from './plugin'; | ||
export { isWebTerminalAvailable } from './components/TerminalComponent/utils/annotations'; |