-
Notifications
You must be signed in to change notification settings - Fork 594
/
index.ts
51 lines (46 loc) · 1.27 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* eslint-disable no-console */
import { K8sResourceKind, PodKind } from '@console/internal/module/k8s';
import { VMIKind } from '../../../types';
import { findRDPServiceAndPort } from '../../vmi';
export const getRdpAddressPort = (
vmi: VMIKind,
services: K8sResourceKind[],
launcherPod: PodKind,
) => {
const [rdpService, rdpPortObj] = findRDPServiceAndPort(vmi, services);
if (!rdpService || !rdpPortObj) {
return null;
}
let { port } = rdpPortObj;
let address: number;
switch (rdpService.spec?.type) {
case 'LoadBalancer':
address = rdpService.spec.externalIPs?.[0];
if (!address) {
console.warn('External IP is not defined for the LoadBalancer RDP Service: ', rdpService);
}
break;
case 'NodePort':
port = rdpPortObj.nodePort;
if (launcherPod) {
address = launcherPod.status?.hostIP;
}
if (!address) {
console.warn(
'Node IP (launcherpod.status.hostIP) is not yet known for NodePort RDP Service: ',
rdpService,
);
}
break;
default:
console.error('Unrecognized Service type: ', rdpService);
}
if (!address || !port) {
return null;
}
console.log('RDP requested for: ', address, port);
return {
address,
port,
};
};