Skip to content

Commit

Permalink
Open a Deployment in shell from Application Explorer
Browse files Browse the repository at this point in the history
Right click on a Deployment in the Application Explorer and select "Open
Shell to Container" to open a terminal connection to the running container
in the 'OpenShift Terminal'.

Closes #3825

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Jan 19, 2024
1 parent e9d3ead commit e328aa3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
23 changes: 18 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,11 @@
"title": "Create Deployment from Container Image URL",
"category": "OpenShift"
},
{
"command": "openshift.deployment.shell",
"title": "Open Shell to Container",
"category": "OpenShift"
},
{
"command": "openshift.resource.load",
"title": "Load",
Expand Down Expand Up @@ -1265,6 +1270,10 @@
"command": "openshift.resource.watchLogs",
"when": "false"
},
{
"command": "openshift.deployment.shell",
"when": "false"
},
{
"command": "openshift.resource.unInstall",
"when": "false"
Expand Down Expand Up @@ -1778,27 +1787,31 @@
},
{
"command": "openshift.resource.load",
"when": "view == openshiftProjectExplorer && viewItem == openshift.k8sObject || viewItem == openshift.k8sObject.route"
"when": "view == openshiftProjectExplorer && viewItem =~ /^openshift\\.k8sObject\\.(?!helm)/"
},
{
"command": "openshift.resource.delete",
"when": "view == openshiftProjectExplorer && viewItem == openshift.k8sObject || viewItem == openshift.k8sObject.route"
"when": "view == openshiftProjectExplorer && viewItem =~ /^openshift\\.k8sObject\\.(?!helm)/"
},
{
"command": "openshift.resource.watchLogs",
"when": "view == openshiftProjectExplorer && viewItem == openshift.k8sObject || viewItem == openshift.k8sObject.route"
"when": "view == openshiftProjectExplorer && viewItem =~ /^openshift\\.k8sObject\\.(?!helm)/"
},
{
"command": "openshift.deployment.shell",
"when": "view == openshiftProjectExplorer && viewItem =~ /^openshift\\.k8sObject\\.Deployment/"
},
{
"command": "openshift.resource.unInstall",
"when": "view == openshiftProjectExplorer && viewItem == openshift.k8sObject.helm"
},
{
"command": "openshift.resource.openInDeveloperConsole",
"when": "view == openshiftProjectExplorer && (viewItem == openshift.k8sObject || openshift.k8sObject.helm || viewItem == openshift.k8sObject.route) && isOpenshiftCluster"
"when": "view == openshiftProjectExplorer && viewItem =~ /^openshift\\.k8sObject/ && isOpenshiftCluster"
},
{
"command": "openshift.resource.openInBrowser",
"when": "view == openshiftProjectExplorer && viewItem == openshift.k8sObject.route && isOpenshiftCluster"
"when": "view == openshiftProjectExplorer && viewItem =~ /^openshift\\.k8sObject\\..*route$/ && isOpenshiftCluster"
},
{
"command": "openshift.Serverless.buildAndRun",
Expand Down
9 changes: 9 additions & 0 deletions src/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/

import { KubernetesObject } from '@kubernetes/client-node';
import * as path from 'path';
import validator from 'validator';
import { Disposable, QuickInputButtons, ThemeIcon, TreeItem, window } from 'vscode';
import { CommandText } from './base/command';
import { OpenShiftExplorer } from './explorer';
import { Oc } from './oc/ocWrapper';
import { validateRFC1123DNSLabel } from './openshift/nameValidator';
import { quickBtn } from './util/inputValue';
import { vsCommand } from './vscommand';
import { OpenShiftTerminalManager } from './webview/openshift-terminal/openShiftTerminal';

export class Deployment {

Expand Down Expand Up @@ -78,6 +81,12 @@ export class Deployment {

}

@vsCommand('openshift.deployment.shell')
static shellIntoDeployment(component: KubernetesObject): Promise<void> {
void OpenShiftTerminalManager.getInstance().createTerminal(new CommandText('oc', `exec -it ${component.kind}/${component.metadata.name} -- /bin/sh`), `Shell to '${component.metadata.name}'`);
return Promise.resolve();

Check warning on line 87 in src/deployment.ts

View check run for this annotation

Codecov / codecov/patch

src/deployment.ts#L86-L87

Added lines #L86 - L87 were not covered by tests
}

/**
* Prompt the user for the URL of a container image.
*
Expand Down
2 changes: 1 addition & 1 deletion src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos

const routeURL = await Oc.Instance.getRouteURL(element.metadata.name);
return {
contextValue: !routeURL ? 'openshift.k8sObject' : 'openshift.k8sObject.route',
contextValue: `openshift.k8sObject.${element.kind}${routeURL ? '.route' : ''}`,

Check warning on line 203 in src/explorer.ts

View check run for this annotation

Codecov / codecov/patch

src/explorer.ts#L203

Added line #L203 was not covered by tests
label: element.metadata.name,
description: `${element.kind.substring(0, 1).toLocaleUpperCase()}${element.kind.substring(1)}`,
collapsibleState: TreeItemCollapsibleState.None,
Expand Down

0 comments on commit e328aa3

Please sign in to comment.