Initial port-forward implementation for services (#231)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen authored and GitHub committed 2020-04-10 11:05:37 +03:00
1 parent ec392c3828
commit 806d8c6716
7 files changed
+224 -10

No files matched your search

+30 -5
View File
@@ -2,6 +2,33 @@ import { autobind } from "../../utils";
import { KubeObject } from "../kube-object";
import { KubeApi } from "../kube-api";
export interface IServicePort {
name?: string;
protocol: string;
port: number;
targetPort: number;
}
export class ServicePort implements IServicePort {
name?: string;
protocol: string;
port: number;
targetPort: number;
nodePort?: number;
constructor(data: IServicePort) {
Object.assign(this, data)
}
toString() {
if (this.nodePort) {
return `${this.port}:${this.nodePort}/${this.protocol}`;
} else {
return `${this.port}${this.port === this.targetPort ? "" : ":" + this.targetPort}/${this.protocol}`;
}
}
}
@autobind()
export class Service extends KubeObject {
static kind = "Service"
@@ -13,7 +40,7 @@ export class Service extends KubeObject {
loadBalancerIP?: string;
sessionAffinity: string;
selector: { [key: string]: string };
ports: { name?: string; protocol: string; port: number; targetPort: number }[];
ports: ServicePort[];
externalIPs?: string[]; // https://kubernetes.io/docs/concepts/services-networking/service/#external-ips
}
@@ -47,11 +74,9 @@ export class Service extends KubeObject {
return Object.entries(this.spec.selector).map(val => val.join("="));
}
getPorts(): string[] {
getPorts(): ServicePort[] {
const ports = this.spec.ports || [];
return ports.map(({ port, protocol, targetPort }) => {
return `${port}${port === targetPort ? "" : ":" + targetPort}/${protocol}`
})
return ports.map(p => new ServicePort(p));
}
getLoadBalancer() {