UNPKG

k8ts

Version:

Powerful framework for building Kubernetes manifests in TypeScript.

96 lines 3.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PodScope = exports.Pod_Template = void 0; const instruments_1 = require("@k8ts/instruments"); const metadata_1 = require("@k8ts/metadata"); const doddle_1 = require("doddle"); const lodash_1 = require("lodash"); const default_1 = require("../../kinds/default"); const container_1 = require("./container"); const devices_1 = require("./volume/devices"); const volumes_1 = require("./volume/volumes"); class Pod_Template extends instruments_1.Resource_Child { get kind() { return default_1.v1.PodTemplate._; } containers = (0, doddle_1.seq)(() => this.props.$POD(new PodScope(this))) .map(x => { return x; }) .cache(); mounts = (0, doddle_1.seq)(() => this.containers.concatMap(x => x.mounts)).cache(); volumes = (0, doddle_1.seq)(() => this.containers.concatMap(x => x.volumes)).uniq(); ports = (0, doddle_1.seq)(() => this.containers.map(x => x.ports)).reduce((a, b) => a.union(b)); __kids__() { return [...this.containers, ...this.volumes]; } __metadata__() { return { name: this.name, labels: this.meta.labels, annotations: this.meta.annotations }; } meta = metadata_1.Meta.make(this.props.meta ?? {}).add("name", this.name); __submanifest__() { const self = this; const { props } = self; const containers = self.containers; const initContainers = containers .filter(c => c.subtype === "init") .map(x => x["__submanifest__"]()) .toArray(); const mainContainers = containers .filter(c => c.subtype === "main") .map(x => x["__submanifest__"]()) .toArray(); const volumes = self.volumes .map(x => { if (x instanceof volumes_1.Pod_Volume) { return x["__submanifest__"](); } return x["__submanifest__"](); }) .toArray(); return { metadata: self.__metadata__(), spec: { ...(0, lodash_1.omitBy)(props, (x, k) => k.startsWith("$")), containers: mainContainers.pull(), initContainers: initContainers.pull(), volumes: volumes.pull() } }; } } exports.Pod_Template = Pod_Template; class PodScope { _parent; constructor(_parent) { this._parent = _parent; } Container(name, options) { return new container_1.Container(this._parent, name, "main", options); } InitContainer(name, options) { return new container_1.Container(this._parent, name, "init", options); } Volume(name, options) { const backend = options.$backend; if (backend.is(default_1.v1.ConfigMap._)) { return new volumes_1.Pod_Volume_ConfigMap(this._parent, name, options); } else if (backend.is(default_1.v1.Secret._)) { return new volumes_1.Pod_Volume_Secret(this._parent, name, options); } else if (backend.is(default_1.v1.PersistentVolumeClaim._)) { return new volumes_1.Pod_Volume_Pvc(this._parent, name, options); } throw new Error(`Unsupported volume backend kind: ${backend.kind}`); } Device(name, options) { return new devices_1.Pod_Device(this._parent, name, options); } } exports.PodScope = PodScope; //# sourceMappingURL=pod-template.js.map