@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
83 lines (82 loc) • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createKubeValues = void 0;
const lodash_es_1 = require("lodash-es");
const utils_1 = require("../../utils");
const types_1 = require("../types");
const cloudSql_1 = require("./cloudSql");
const kubeEnv_1 = require("./kubeEnv");
const mongodb_1 = require("./mongodb");
const createAppConfig = (context, application) => {
if (application === false) {
return {
enabled: false
};
}
const {
healthRoute,
command,
...rest
} = application !== null && application !== void 0 ? application : {};
return (0, utils_1.mergeWithMergingArrays)({
host: context.environment.envVars.HOSTNAME,
command: command !== null && command !== void 0 ? command : context.build.type !== "disabled" ? context.build.config.startCommand : undefined,
livenessProbe: {
httpGet: {
path: healthRoute !== null && healthRoute !== void 0 ? healthRoute : "__health"
}
},
readinessProbe: {
httpGet: {
path: healthRoute !== null && healthRoute !== void 0 ? healthRoute : "__health"
}
},
startupProbe: {
httpGet: {
path: healthRoute !== null && healthRoute !== void 0 ? healthRoute : "__health"
}
}
},
// default
rest);
};
const removeFalsy = record => {
if (!record) return undefined;
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== false));
};
const createKubeValues = context => {
var _a, _b, _c;
const deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
if (!deployConfig) {
return [];
}
if (!(0, types_1.isOfDeployType)(deployConfig, "kubernetes")) {
// should not happen
throw new Error("deploy config is not kubernetes");
}
const {
values
} = deployConfig;
// we remove the application config because it can be just the value `false` which is a convenience feature, but not supported in the helm chart
// we only merge the rest of the values in
const {
application,
jobs,
cronjobs,
...rest
} = values !== null && values !== void 0 ? values : {};
const env = (0, kubeEnv_1.createKubeEnv)(context);
const defaultKubeValues = (0, lodash_es_1.merge)({
env,
application: createAppConfig(context, application)
}, (0, cloudSql_1.hasKubernetesCloudSQL)(context) ? (0, cloudSql_1.createKubernetesCloudsqlBaseValues)(context) : {}, ((_c = (_b = deployConfig.values) === null || _b === void 0 ? void 0 : _b.mongodb) === null || _c === void 0 ? void 0 : _c.enabled) ? (0, mongodb_1.createMongodbBaseConfig)(context) : {});
const kubeValues = (0, utils_1.mergeWithMergingArrays)(defaultKubeValues, {
jobs: removeFalsy(jobs),
cronjobs: removeFalsy(cronjobs),
...rest
});
return kubeValues;
};
exports.createKubeValues = createKubeValues;