@starship-ci/generator
Version:
Kubernetes manifest generator for Starship deployments
159 lines (158 loc) • 5.37 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CosmosServiceGenerator = void 0;
const helpers = __importStar(require("../../../helpers"));
class CosmosGenesisServiceGenerator {
config;
chain;
constructor(chain, config) {
this.config = config;
this.chain = chain;
}
labels() {
return {
...helpers.getCommonLabels(this.config),
'app.kubernetes.io/component': 'chain',
'app.kubernetes.io/name': `${helpers.getHostname(this.chain)}-genesis`,
'app.kubernetes.io/type': `${helpers.getChainId(this.chain)}-service`,
'app.kubernetes.io/role': 'genesis',
'starship.io/chain-name': this.chain.name,
'starship.io/chain-id': helpers.getChainId(this.chain)
};
}
generate() {
const portMap = helpers.getPortMap();
const ports = Object.entries(portMap).map(([name, port]) => ({
name,
port,
protocol: 'TCP',
targetPort: String(port)
}));
// Add metrics port if enabled
if (this.chain.metrics) {
ports.push({
name: 'metrics',
port: 26660,
protocol: 'TCP',
targetPort: '26660'
});
}
return [
{
apiVersion: 'v1',
kind: 'Service',
metadata: {
name: `${helpers.getHostname(this.chain)}-genesis`,
labels: this.labels()
},
spec: {
clusterIP: 'None',
ports,
selector: {
'app.kubernetes.io/name': `${helpers.getHostname(this.chain)}-genesis`
}
}
}
];
}
}
class CosmosValidatorServiceGenerator {
config;
chain;
constructor(chain, config) {
this.config = config;
this.chain = chain;
}
labels() {
return {
...helpers.getCommonLabels(this.config),
'app.kubernetes.io/component': 'chain',
'app.kubernetes.io/name': `${helpers.getHostname(this.chain)}-validator`,
'app.kubernetes.io/role': 'validator',
'app.kubernetes.io/type': `${helpers.getChainId(this.chain)}-service`,
'starship.io/chain-name': this.chain.name,
'starship.io/chain-id': helpers.getChainId(this.chain)
};
}
generate() {
const portMap = helpers.getPortMap();
const ports = Object.entries(portMap).map(([name, port]) => ({
name,
port,
protocol: 'TCP',
targetPort: String(port)
}));
if (this.chain.metrics) {
ports.push({
name: 'metrics',
port: 26660,
protocol: 'TCP',
targetPort: '26660'
});
}
return [
{
apiVersion: 'v1',
kind: 'Service',
metadata: {
name: `${helpers.getHostname(this.chain)}-validator`,
labels: this.labels()
},
spec: {
clusterIP: 'None',
ports,
selector: {
'app.kubernetes.io/name': `${helpers.getHostname(this.chain)}-validator`
}
}
}
];
}
}
/**
* Service generator for Cosmos chains
* Handles genesis and validator services
*/
class CosmosServiceGenerator {
config;
chain;
serviceGenerators;
constructor(chain, config) {
this.config = config;
this.chain = chain;
this.serviceGenerators = [
new CosmosGenesisServiceGenerator(this.chain, this.config)
];
// Add validator service if numValidators > 1
if (this.chain.numValidators && this.chain.numValidators > 1) {
this.serviceGenerators.push(new CosmosValidatorServiceGenerator(this.chain, this.config));
}
}
generate() {
return this.serviceGenerators.flatMap((generator) => generator.generate());
}
}
exports.CosmosServiceGenerator = CosmosServiceGenerator;