@starship-ci/generator
Version:
Kubernetes manifest generator for Starship deployments
132 lines (131 loc) • 4.16 kB
JavaScript
import * as helpers from '../../../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
*/
export 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());
}
}