Skip to content

Commit 6064113

Browse files
committed
working console
1 parent 8949292 commit 6064113

File tree

6 files changed

+48
-35
lines changed

6 files changed

+48
-35
lines changed

client/src/components/apps/console.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default defineComponent({
109109
}),
110110
methods: {
111111
loadPods() {
112-
axios.get(`/api/status/pods/${this.pipeline}/${this.phase}`).then((response) => {
112+
axios.get(`/api/status/pods/${this.pipeline}/${this.phase}/${this.app}`).then((response) => {
113113
//this.loadContainers();
114114
for (let pod of response.data) {
115115
const p = {name: pod.name, containers: pod.containers.map((c: any) => c.name)} as Pod;
@@ -123,13 +123,17 @@ export default defineComponent({
123123
socket.emit("terminal", {
124124
room: this.room,
125125
data: "exit\r\nexit\r\nexit\r\nexit\r\nexit\r\n",
126+
//data: "exit\r\n",
126127
});
127128
// wait a bit for the exit to be processed
128129
setTimeout(() => {
129130
this.socketLeave()
130131
}, 1000);
131-
this.connected = false;
132+
//this.connected = false;
132133
term.dispose()
134+
135+
// close popup window
136+
window.close()
133137
},
134138
connect() {
135139
this.createTerminal()

client/src/components/apps/detail.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,17 @@ export default defineComponent({
202202
this.loadingState = false;
203203
},
204204
openConsole() {
205+
/*
205206
Swal.fire({
206207
title: "Open Console",
207208
text: "This feature is not yet implemented. It will be available in a future release.",
208209
icon: "info",
209210
background: "rgb(var(--v-theme-cardBackground))",
210-
/*background: "rgb(var(--v-theme-on-surface-variant))",*/
211+
/*background: "rgb(var(--v-theme-on-surface-variant))",
211212
color: "rgba(var(--v-theme-on-background),var(--v-high-emphasis-opacity));",
212213
})
213-
//window.open(`https://${this.appData.spec.domain}`, '_blank');
214+
*/
215+
window.open(`/popup/console/${this.pipeline}/${this.phase}/${this.app}`, '_blank', 'popup=yes,location=no,height=1000,width=1000,scrollbars=yes,status=no');
214216
},
215217
},
216218

server/src/kubero.ts

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class Kubero {
3737
private podLogStreams: string[]= []
3838
public config: IKuberoConfig;
3939
private audit: Audit;
40-
private execStreams: {[key: string]: {websocket: WebSocket, stream: Stream}} = {};
40+
private execStreams: {[key: string]: {websocket: WebSocket, stream: any}} = {};
4141

4242
constructor(io: Server, audit: Audit) {
4343
this.config = this.loadConfig(process.env.KUBERO_CONFIG_PATH as string || './config.yaml');
@@ -52,6 +52,22 @@ export class Kubero {
5252
debug.debug('Kubero Config: '+JSON.stringify(this.config));
5353

5454
this.audit = audit;
55+
56+
57+
this._io.on('connection', client => {
58+
client.on('terminal', (data: any) => {
59+
//console.log('terminal input', data.data);
60+
//console.log('ws.OPEN', ws.readyState == ws.OPEN);
61+
//console.log(ws.url);
62+
//console.log(ws.eventNames());
63+
//execStream.write(data.data);
64+
if (this.execStreams[data.room]) {
65+
this.execStreams[data.room].stream.write(data.data);
66+
}
67+
//this.execStreams[data.room].stream.write(data.data);
68+
}
69+
)}
70+
);
5571
}
5672

5773
public getKubernetesVersion() {
@@ -981,7 +997,7 @@ export class Kubero {
981997
public async execInContainer(pipelineName: string, phaseName: string, appName: string, podName: string, containerName: string, command: string, user: User) {
982998
const contextName = this.getContext(pipelineName, phaseName);
983999
if (contextName) {
984-
const streamname = `${pipelineName}-${phaseName}-${appName}-${podName}-${containerName}`;
1000+
const streamname = `${pipelineName}-${phaseName}-${appName}-${podName}-${containerName}-terminal`;
9851001

9861002
if ( process.env.KUBERO_READONLY == 'true'){
9871003
console.log('KUBERO_READONLY is set to true, not deleting app');
@@ -993,8 +1009,12 @@ export class Kubero {
9931009
console.log('execInContainer: execStream already running');
9941010
return;
9951011
} else {
996-
console.log('execInContainer: execStream already running but not open, deleting');
1012+
console.log('CLOSED', this.execStreams[streamname].websocket.CLOSED)
1013+
console.log('execInContainer: execStream already running but not open, deleting :', this.execStreams[streamname].websocket.readyState);
9971014
delete this.execStreams[streamname];
1015+
1016+
// wait a bit to make sure the stream is closed
1017+
await new Promise(resolve => setTimeout(resolve, 3000));
9981018
}
9991019
}
10001020

@@ -1014,29 +1034,14 @@ export class Kubero {
10141034

10151035
let stream = {
10161036
websocket: ws as unknown as WebSocket,
1017-
stream: execStream as Stream
1037+
stream: execStream
10181038
};
10191039
this.execStreams[streamname] = stream;
10201040

10211041
// sending the terminal output to the client
10221042
ws.on('message', (data: Buffer) => {
1023-
const roomname = `${pipelineName}-${phaseName}-${appName}-${podName}-${containerName}-terminal`;
1024-
//console.log('execInContainer message', roomname, data.toString());
1025-
this._io.to(roomname).emit('consoleresponse', data.toString())
1043+
this._io.to(streamname).emit('consoleresponse', data.toString())
10261044
});
1027-
1028-
// Sending the terminal input to the container
1029-
this._io.on('connection', client => {
1030-
//console.log('connection');
1031-
client.on('terminal', (data: any) => {
1032-
//console.log('terminal input', data.data);
1033-
//console.log('ws.OPEN', ws.readyState == ws.OPEN);
1034-
//console.log(ws.url);
1035-
//console.log(ws.eventNames());
1036-
execStream.write(data.data);
1037-
}
1038-
)}
1039-
);
10401045
}
10411046
}
10421047

@@ -1497,7 +1502,7 @@ export class Kubero {
14971502
}
14981503
}
14991504

1500-
public async getPods(pipelineName: string, phaseName: string): Promise<Workload[]> {
1505+
public async getPods(pipelineName: string, phaseName: string, appName: string): Promise<Workload[]> {
15011506
const contextName = this.getContext(pipelineName, phaseName);
15021507
const namespace = pipelineName+'-'+phaseName;
15031508

@@ -1508,6 +1513,11 @@ export class Kubero {
15081513
const workload = await this.kubectl.getPods(namespace, contextName);
15091514
//return workload
15101515
for (const pod of workload) {
1516+
// check if app label name starts with appName
1517+
if (!pod.metadata?.generateName?.startsWith(appName+'-kuberoapp')) {
1518+
continue;
1519+
}
1520+
15111521
let workload = {
15121522
name: pod.metadata?.name,
15131523
namespace: pod.metadata?.namespace,

server/src/modules/kubectl.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ debug('app:kubectl')
33

44
import {
55
KubeConfig,
6-
Attach,
76
Exec,
87
VersionApi,
98
CoreV1Api,
@@ -50,7 +49,6 @@ export class Kubectl {
5049
private patchUtils: PatchUtils = {} as PatchUtils;
5150
public log: KubeLog;
5251
public config: IKuberoConfig;
53-
private attach: Attach = {} as Attach;
5452
private exec: Exec = {} as Exec;
5553

5654
constructor(config: IKuberoConfig) {
@@ -85,7 +83,6 @@ export class Kubectl {
8583
this.networkingV1Api = this.kc.makeApiClient(NetworkingV1Api);
8684
this.metricsApi = new Metrics(this.kc);
8785
this.patchUtils = new PatchUtils();
88-
this.attach = new Attach(this.kc);
8986
this.exec = new Exec(this.kc)
9087
this.customObjectsApi = this.kc.makeApiClient(CustomObjectsApi);
9188
} catch (error) {

server/src/routes/logs.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@ Router.post('/console/:pipeline/:phase/:app/exec', authMiddleware, async functio
142142

143143
// #swagger.tags = ['UI']
144144
// #swagger.summary = 'Start a container console'
145-
req.params.pipeline = "test";
146-
req.params.phase = "production";
147-
req.params.app = "go-httpbin";
148-
149145
const user = 'nobody'
150146

151147
const podName = req.body.podName;
@@ -156,11 +152,11 @@ Router.post('/console/:pipeline/:phase/:app/exec', authMiddleware, async functio
156152
res.send(console);
157153
});
158154

159-
Router.get('/status/pods/:pipeline/:phase', authMiddleware, async function (req: Request, res: Response) {
155+
Router.get('/status/pods/:pipeline/:phase/:app', authMiddleware, async function (req: Request, res: Response) {
160156
// #swagger.tags = ['UI']
161157
// #swagger.summary = 'Get the Pod workload from an Namespace'
162158

163-
req.app.locals.kubero.getPods(req.params.pipeline, req.params.phase)
159+
req.app.locals.kubero.getPods(req.params.pipeline, req.params.phase, req.params.app)
164160
.then((result: any) => {
165161
res.send(result);
166162
})

server/src/socket.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ export function init(httpServer: HttpServer, authentication: boolean = false) {
3434
debug.log('joining room', join.room)
3535
client.join(join.room);
3636
});
37-
37+
/*
38+
client.on('terminal', terminal => {
39+
console.log('main terminal', terminal)
40+
});
41+
*/
3842
client.on('leave', leave => {
3943
debug.log('leaving room', leave.room)
4044
client.leave(leave.room);

0 commit comments

Comments
 (0)