Skip to content

Commit 7532208

Browse files
sudhirvermadgolovin
authored andcommitted
Add Show logs command for ReplicationController (#1104)
* Add `Show logs` command for ReplicationController
1 parent 72db938 commit 7532208

4 files changed

Lines changed: 88 additions & 24 deletions

File tree

package.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
"onCommand:clusters.openshift.deploy.dc.showLog.palette",
104104
"onCommand:clusters.openshift.deploy.delete",
105105
"onCommand:clusters.openshift.deploy.delete.palette",
106+
"onCommand:clusters.openshift.deploy.rcShowLog",
107+
"onCommand:clusters.openshift.deploy.rcShowLog.palette",
106108
"onCommand:clusters.openshift.deployment.openConsole",
107109
"onCommand:clusters.openshift.imagestream.openConsole"
108110
],
@@ -484,6 +486,16 @@
484486
"command": "clusters.openshift.build.openConsole",
485487
"title": "Open in Console"
486488
},
489+
{
490+
"command": "clusters.openshift.deploy.rcShowLog.palette",
491+
"title": "Show Replica's Log",
492+
"category": "OpenShift"
493+
},
494+
{
495+
"command": "clusters.openshift.deploy.rcShowLog",
496+
"title": "Show Log",
497+
"category": "OpenShift"
498+
},
487499
{
488500
"command": "clusters.openshift.deploy.delete.palette",
489501
"title": "Delete Replica",
@@ -567,6 +579,10 @@
567579
"command": "openshift.explorer.login",
568580
"when": "view == openshiftProjectExplorer"
569581
},
582+
{
583+
"command": "clusters.openshift.deploy.rcShowLog",
584+
"when": "view == openshiftProjectExplorer"
585+
},
570586
{
571587
"command": "openshift.app.delete",
572588
"when": "view == openshiftProjectExplorer"
@@ -700,9 +716,14 @@
700716
"group": "2@0",
701717
"when": "view == extension.vsKubernetesExplorer && viewItem =~ /openShift\\.resource\\.build.*/i"
702718
},
719+
{
720+
"command": "clusters.openshift.deploy.rcShowLog",
721+
"group": "1@1",
722+
"when": "view == extension.vsKubernetesExplorer && viewItem =~ /openShift\\.resource\\.rc.*/i"
723+
},
703724
{
704725
"command": "clusters.openshift.deploy.delete",
705-
"group": "1",
726+
"group": "2@0",
706727
"when": "view == extension.vsKubernetesExplorer && viewItem =~ /openShift\\.resource\\.rc.*/i"
707728
},
708729
{

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export async function activate(context: vscode.ExtensionContext) {
6565
vscode.commands.registerCommand('clusters.openshift.deploy.dc.showLog.palette', (context) => execute(DeploymentConfig.showLog, context)),
6666
vscode.commands.registerCommand('clusters.openshift.deploy.delete', (context) => execute(DeploymentConfig.delete, context)),
6767
vscode.commands.registerCommand('clusters.openshift.deploy.delete.palette', (context) => execute(DeploymentConfig.delete, context)),
68+
vscode.commands.registerCommand('clusters.openshift.deploy.rcShowLog', (context) => execute(DeploymentConfig.rcShowLog, context)),
69+
vscode.commands.registerCommand('clusters.openshift.deploy.rcShowLog.palette', (context) => execute(DeploymentConfig.rcShowLog, context)),
6870
vscode.commands.registerCommand('clusters.openshift.build.showLog', (context) => execute(Build.showLog, context)),
6971
vscode.commands.registerCommand('clusters.openshift.build.followLog', (context) => execute(Build.followLog, context)),
7072
vscode.commands.registerCommand('clusters.openshift.build.delete', (context) => execute(Build.delete, context)),

src/k8s/deployment.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export class Command {
2828
static delete(replica: String) {
2929
return `oc delete rc ${replica}`;
3030
}
31+
32+
static showLog(replica: string) {
33+
return `oc logs rc/${replica}`;
34+
}
3135
}
3236

3337
export class DeploymentConfigNodeContributor implements ClusterExplorerV1.NodeContributor {
@@ -75,6 +79,14 @@ export class DeploymentConfig {
7579
'You have no replicas available');
7680
}
7781

82+
static async rcShowLog(context: { impl: any; }): Promise<string> {
83+
const replica = await DeploymentConfig.selectReplica(context, "Select a Replica too see the logs");
84+
if (replica) {
85+
DeploymentConfig.odo.executeInTerminal(Command.showLog(replica));
86+
}
87+
return replica;
88+
}
89+
7890
static async showLog(context: { name: string; }): Promise<string> {
7991
let deployName: string = context ? context.name : null;
8092
if (!deployName) deployName = await common.selectResourceByName(DeploymentConfig.getDeploymentConfigNames("You have no DeploymentConfigs available to see log's"), "Select a DeploymentConfig too see log's");

test/unit/k8s/deployment.test.ts

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ suite('K8s/deployment', () => {
6363
}
6464
}`;
6565

66+
const context = {
67+
id: "dummy",
68+
impl: {
69+
id: "rc/comp1-app-2",
70+
kind: {
71+
manifestKind: "ReplicationController",
72+
abbreviation: "rc"
73+
},
74+
namespace: "myproject",
75+
name: "comp1-app-2",
76+
number: 2,
77+
manifest: "ReplicationController",
78+
metadata: undefined,
79+
node: "rc",
80+
resourceId: "rc/comp1-app-2"
81+
},
82+
resourceKind: {
83+
manifestKind: "ReplicationController",
84+
abbreviation: "rc"
85+
},
86+
nodeCategory: "kubernetes-explorer-node",
87+
nodeType: "extension"
88+
};
89+
6690
setup(() => {
6791
sandbox = sinon.createSandbox();
6892
termStub = sandbox.stub(OdoImpl.prototype, 'executeInTerminal');
@@ -167,30 +191,35 @@ suite('K8s/deployment', () => {
167191
});
168192
});
169193

194+
suite('Show Replica Log', () => {
195+
196+
setup(() => {
197+
execStub.resolves({ error: null, stdout: mockData, stderr: '' });
198+
const deploymentConfig = {label: "comp1-app"};
199+
sandbox.stub(DeploymentConfig, 'getReplicaNames').resolves(["comp1-app-1", "comp1-app-2"]);
200+
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
201+
quickPickStub.onFirstCall().resolves(deploymentConfig);
202+
quickPickStub.onSecondCall().resolves("comp1-app-1");
203+
});
204+
205+
test('works from context menu', async () => {
206+
await DeploymentConfig.rcShowLog(context);
207+
expect(termStub).calledOnceWith(Command.showLog("comp1-app-2"));
208+
});
209+
210+
test('works with no context', async () => {
211+
await DeploymentConfig.rcShowLog(null);
212+
expect(termStub).calledOnceWith(Command.showLog('comp1-app-1'));
213+
});
214+
215+
test('returns null when no replica selected', async () => {
216+
quickPickStub.onSecondCall().resolves();
217+
const result = await DeploymentConfig.rcShowLog(null);
218+
expect(result).null;
219+
});
220+
});
221+
170222
suite('Delete', ()=> {
171-
const context = {
172-
id: "dummy",
173-
impl: {
174-
id: "rc/comp1-app-2",
175-
kind: {
176-
manifestKind: "ReplicationController",
177-
abbreviation: "rc"
178-
},
179-
namespace: "myproject",
180-
name: "comp1-app-2",
181-
number: 2,
182-
manifest: "ReplicationController",
183-
metadata: undefined,
184-
node: "rc",
185-
resourceId: "rc/comp1-app-2"
186-
},
187-
resourceKind: {
188-
manifestKind: "ReplicationController",
189-
abbreviation: "rc"
190-
},
191-
nodeCategory: "kubernetes-explorer-node",
192-
nodeType: "extension"
193-
};
194223

195224
const deploymentData = `comp1-app-1\\ncomp1-app-2`;
196225

0 commit comments

Comments
 (0)