1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/dashboard/client/api/endpoints/network-policy.api.ts
Sebastian Malton b1ff34879a cleanup Lens repo with tighter linting
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
2020-07-09 17:00:23 -04:00

77 lines
1.5 KiB
TypeScript

import { KubeObject } from "../kube-object";
import { autobind } from "../../utils";
import { KubeApi } from "../kube-api";
export interface PolicyIpBlock {
cidr: string;
except?: string[];
}
export interface PolicySelector {
matchLabels: {
[label: string]: string;
};
}
export interface PolicyIngress {
from: {
ipBlock?: PolicyIpBlock;
namespaceSelector?: PolicySelector;
podSelector?: PolicySelector;
}[];
ports: {
protocol: string;
port: number;
}[];
}
export interface PolicyEgress {
to: {
ipBlock: PolicyIpBlock;
}[];
ports: {
protocol: string;
port: number;
}[];
}
@autobind()
export class NetworkPolicy extends KubeObject {
static kind = "NetworkPolicy"
spec: {
podSelector: {
matchLabels: {
[label: string]: string;
role: string;
};
};
policyTypes: string[];
ingress: PolicyIngress[];
egress: PolicyEgress[];
}
getMatchLabels(): string[] {
if (!this.spec.podSelector || !this.spec.podSelector.matchLabels) {
return [];
}
return Object
.entries(this.spec.podSelector.matchLabels)
.map(data => data.join(":"));
}
getTypes(): string[] {
if (!this.spec.policyTypes) {
return [];
}
return this.spec.policyTypes;
}
}
export const networkPolicyApi = new KubeApi({
kind: NetworkPolicy.kind,
apiBase: "/apis/networking.k8s.io/v1/networkpolicies",
isNamespaced: true,
objectConstructor: NetworkPolicy,
});