UNPKG

@provisioner/appengine

Version:

CodeZero provisioner for appengine

238 lines 10.5 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createApplyMixin = void 0; const debug_1 = __importDefault(require("debug")); const templates = __importStar(require("../templates/")); const debug = debug_1.default('@appengine:createApply'); exports.createApplyMixin = (base) => class extends base { get createDeploymentVolumes() { return this.createDeploymentDocument.spec.template.spec.volumes = this.createDeploymentDocument.spec.template.spec.volumes || []; } get createDeploymentVolumeMounts() { return this.createDeploymentContainer.volumeMounts = this.createDeploymentContainer.volumeMounts || []; } get createDeploymentContainer() { return this.createDeploymentDocument.spec.template.spec.containers[0]; } get createDeploymentContainerEnvFrom() { return this.createDeploymentDocument.spec.template.spec.containers[0].envFrom = this.createDeploymentDocument.spec.template.spec.containers[0].envFrom || []; } async createApply() { var _a, _b; try { (_a = this.controller.status) === null || _a === void 0 ? void 0 : _a.push(`Applying App Engine to ${this.documentHelper.name}`); await this.ensureCreateDeployment(); await this.processTemplates(); await this.createConfigs(); await this.createSecrets(); await this.createSecretRefs(); await this.createConfigMapRefs(); await this.createServices(); await this.createVolumes(); await this.createDeployment(); await this.ensureAppIsRunning(); } finally { (_b = this.controller.status) === null || _b === void 0 ? void 0 : _b.pop(); } } async processTemplates() { var _a, _b; try { (_a = this.controller.status) === null || _a === void 0 ? void 0 : _a.push('Processing templates'); await this.processTemplate(this.documentHelper.configs, 'Processing configs templates'); await this.processTemplate(this.documentHelper.secrets, 'Processing secrets templates'); } finally { (_b = this.controller.status) === null || _b === void 0 ? void 0 : _b.pop(); } } async ensureCreateDeployment() { if (this.createDeploymentDocument) return; this.createDeploymentDocument = await templates.getDeploymentTemplate(this.documentHelper.name, this.documentHelper.namespace, this.documentHelper.image, this.documentHelper.componentLabels, this.documentHelper.tag, this.documentHelper.imagePullPolicy, this.documentHelper.command); } async createConfigs() { var _a, _b; let skipped = false; try { (_a = this.controller.status) === null || _a === void 0 ? void 0 : _a.push('Installing configuration settings'); if (!this.documentHelper.hasConfigs) { skipped = true; return; } const configs = {}; for (const key of Object.keys(this.documentHelper.configs)) { configs[key] = String(this.documentHelper.configs[key]); } const createConfigMap = templates.getConfigTemplate(this.documentHelper.name, this.documentHelper.namespace, configs); await this.controller.cluster .begin() .addOwner(this.controller.resource) .mergeWith(this.documentHelper.appComponentMergeDocument) .upsert(createConfigMap) .end(); this.createDeploymentContainerEnvFrom.push({ configMapRef: { name: createConfigMap.metadata.name } }); } finally { (_b = this.controller.status) === null || _b === void 0 ? void 0 : _b.pop(skipped); } } async createSecrets() { var _a, _b; let skipped = false; try { (_a = this.controller.status) === null || _a === void 0 ? void 0 : _a.push('Installing secret settings'); if (!this.documentHelper.hasSecrets) { skipped = true; return; } const base64Secrets = {}; for (const key in this.documentHelper.secrets) base64Secrets[key] = Buffer.from(this.documentHelper.secrets[key]).toString('base64'); const createSecrets = templates.getSecretTemplate(this.documentHelper.name, this.documentHelper.namespace, base64Secrets); await this.controller.cluster .begin() .addOwner(this.controller.resource) .mergeWith(this.documentHelper.appComponentMergeDocument) .upsert(createSecrets) .end(); this.createDeploymentContainerEnvFrom.push({ secretRef: { name: createSecrets.metadata.name } }); } finally { (_b = this.controller.status) === null || _b === void 0 ? void 0 : _b.pop(skipped); } } async createConfigMapRefs() { var _a, _b; let skipped = false; try { (_a = this.controller.status) === null || _a === void 0 ? void 0 : _a.push('Installing configMap refs'); if (!this.documentHelper.hasConfigMapRefs) { skipped = true; return; } const configMapRefs = this.documentHelper.configMapRefs.map(name => ({ configMapRef: { name } })); this.createDeploymentContainerEnvFrom.push(...configMapRefs); } finally { (_b = this.controller.status) === null || _b === void 0 ? void 0 : _b.pop(skipped); } } async createSecretRefs() { var _a, _b; let skipped = false; try { (_a = this.controller.status) === null || _a === void 0 ? void 0 : _a.push('Installing secret refs'); if (!this.documentHelper.hasSecretRefs) { skipped = true; return; } const secretRefs = this.documentHelper.secretRefs.map(name => ({ secretRef: { name } })); this.createDeploymentContainerEnvFrom.push(...secretRefs); } finally { (_b = this.controller.status) === null || _b === void 0 ? void 0 : _b.pop(skipped); } } async createVolumes() { var _a, _b; let skipped = false; try { (_a = this.controller.status) === null || _a === void 0 ? void 0 : _a.push('Installing volumes'); if (!this.documentHelper.hasVolumes) { skipped = true; return; } for (const volume of this.documentHelper.volumes) { volume.name = volume.name.toLowerCase(); const createVolume = templates.getPVCTemplate(volume, this.documentHelper.namespace); await this.controller.cluster .begin() .addOwner(this.controller.resource) .mergeWith(this.documentHelper.appComponentMergeDocument) .upsert(createVolume) .end(); this.createDeploymentVolumes.push({ name: volume.name, persistentVolumeClaim: { claimName: volume.name } }); if (volume.mountPath) { const mount = { name: volume.name, mountPath: volume.mountPath }; if (volume.subPath) mount.subPath = volume.subPath; this.createDeploymentVolumeMounts.push(mount); } } } finally { (_b = this.controller.status) === null || _b === void 0 ? void 0 : _b.pop(skipped); } } async createServices() { var _a, _b; let skipped = false; try { (_a = this.controller.status) === null || _a === void 0 ? void 0 : _a.push('Installing networking services'); if (!this.documentHelper.hasPorts) { skipped = true; return; } const createService = templates.getServiceTemplate(this.documentHelper.name, this.documentHelper.namespace, this.documentHelper.getServicePorts()); await this.controller.cluster .begin() .addOwner(this.controller.resource) .mergeWith(this.documentHelper.appComponentMergeDocument) .upsert(createService) .end(); this.createDeploymentContainer.ports = this.documentHelper.getDeploymentPorts(); } finally { (_b = this.controller.status) === null || _b === void 0 ? void 0 : _b.pop(skipped); } } async createDeployment() { await this.controller.cluster .begin('Creating the deployment') .addOwner(this.controller.resource) .upsert(this.createDeploymentDocument) .end(); } async ensureAppIsRunning() { await this.controller.cluster. begin(`Ensure ${this.documentHelper.name} services are running`) .beginWatch(templates.getPodTemplate(this.documentHelper.name, this.documentHelper.namespace)) .whenWatch(({ condition }) => condition.Ready === 'True', (processor) => { processor.endWatch(); }) .end(); } }; //# sourceMappingURL=createApply.js.map