UNPKG

k8s-features

Version:

A Cucumber-js base library for Kubernetes Gherkin tests, with base world class, basic steps, reusable utility functions and k8s client

41 lines (36 loc) 938 B
const { AbstractKubernetesObjectPatcher } = require('./types.cjs'); class PodEnvFixedPatcher extends AbstractKubernetesObjectPatcher { /** * * @param {string} name * @param {string} value */ constructor(name, value) { super(); this.name = name; this.value = value; } /** * * @param {import("@kubernetes/client-node").KubernetesObject} obj */ patch(obj) { if (obj.kind !== 'Pod') { throw new Error(`Expecting Pod kind, but got ${obj.kind}`); } const pod = obj; if (!pod || !pod.spec || !pod.spec.containers || pod.spec.containers.length < 1) { throw new Error('Pod has no container'); } if (!pod.spec.containers[0].env || !Array.isArray(pod.spec.containers[0].env)) { pod.spec.containers[0].env = [] } pod.spec.containers[0].env.push({ name: this.name, value: this.value, }); } } module.exports = { PodEnvFixedPatcher, };