Skip to content

Commit

Permalink
feat: use k8s configMaps to mount files during solo network deploy (#345
Browse files Browse the repository at this point in the history
)

Signed-off-by: Jeromy Cannon <jeromy@swirldslabs.com>
  • Loading branch information
jeromy-cannon authored Aug 19, 2024
1 parent aa31301 commit af27f16
Show file tree
Hide file tree
Showing 25 changed files with 553 additions and 451 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
env:
browser: true
es2021: true
jest: true
extends: standard
parserOptions:
ecmaVersion: latest
Expand Down Expand Up @@ -30,4 +31,4 @@ overrides:
- files: ["*.mjs"]
parserOptions:
ecmaVersion: latest
sourceType: module
sourceType: module
3 changes: 2 additions & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const config = {
moduleFileExtensions: ['js', 'mjs'],
verbose: true,
reporters: [['default', { summaryThreshold: 1 }], 'jest-junit'],
testSequencer: './test/testSequencer.mjs'
testSequencer: './test/testSequencer.mjs',
setupFilesAfterEnv: ['jest-expect-message']
}

export default config
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"eslint-plugin-promise": "^6.6.0",
"jest": "^29.7.0",
"jest-environment-steps": "^1.1.1",
"jest-expect-message": "^1.1.3",
"jest-junit": "^16.0.0",
"nyc": "^17.0.0",
"remark-cli": "^12.0.1",
Expand Down
2 changes: 2 additions & 0 deletions resources/templates/bootstrap.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# TODO: bootstrap.properties is scheduled to go away, will need to delete this and related code
ledger.id=0x01
netty.mode=DEV
# TODO: if chain ID is passed in as a flag, this is not getting updated
contracts.chainId=298
hedera.recordStream.logPeriod=1
balances.exportPeriodSecs=400
Expand Down
2 changes: 1 addition & 1 deletion src/commands/base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class BaseCommand extends ShellRunner {
super(opts.logger)

this.helm = opts.helm
this.k8 = opts.k8
this.k8 = /** @type {K8} **/ opts.k8
this.chartManager = opts.chartManager
this.configManager = opts.configManager
this.depManager = opts.depManager
Expand Down
16 changes: 14 additions & 2 deletions src/commands/flags.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export const chainId = {
name: 'ledger-id',
definition: {
describe: 'Ledger ID (a.k.a. Chain ID)',
defaultValue: '298', // Ref: https://github.com/hashgraph/hedera-json-rpc-relay#configuration
defaultValue: constants.HEDERA_CHAIN_ID, // Ref: https://github.com/hashgraph/hedera-json-rpc-relay#configuration
alias: 'l',
type: 'string'
}
Expand Down Expand Up @@ -511,7 +511,7 @@ export const app = {
name: 'app',
definition: {
describe: 'Testing app name',
defaultValue: '',
defaultValue: constants.HEDERA_APP_NAME,
type: 'string'
}
}
Expand Down Expand Up @@ -656,6 +656,17 @@ export const endpointType = {
}
}

/** @type {CommandFlag} **/
export const persistentVolumeClaims = {
constName: 'persistentVolumeClaims',
name: 'pvcs',
definition: {
describe: 'Enable persistent volume claims to store data outside the pod, required for node add',
defaultValue: false,
type: 'boolean'
}
}

/** @type {CommandFlag[]} **/
export const allFlags = [
accountId,
Expand Down Expand Up @@ -700,6 +711,7 @@ export const allFlags = [
nodeIDs,
operatorId,
operatorKey,
persistentVolumeClaims,
privateKey,
profileFile,
profileName,
Expand Down
57 changes: 41 additions & 16 deletions src/commands/network.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ export class NetworkCommand extends BaseCommand {

static get DEPLOY_FLAGS_LIST () {
return [
flags.apiPermissionProperties,
flags.app,
flags.applicationEnv,
flags.applicationProperties,
flags.bootstrapProperties,
flags.chainId,
flags.chartDirectory,
flags.deployHederaExplorer,
flags.deployMirrorNode,
Expand All @@ -49,11 +54,14 @@ export class NetworkCommand extends BaseCommand {
flags.fstChartVersion,
flags.hederaExplorerTlsHostName,
flags.hederaExplorerTlsLoadBalancerIp,
flags.log4j2Xml,
flags.namespace,
flags.nodeIDs,
flags.persistentVolumeClaims,
flags.profileFile,
flags.profileName,
flags.releaseTag,
flags.settingTxt,
flags.tlsClusterIssuerType,
flags.valuesFile
]
Expand Down Expand Up @@ -99,7 +107,7 @@ export class NetworkCommand extends BaseCommand {
}

const profileName = this.configManager.getFlag(flags.profileName)
this.profileValuesFile = await this.profileManager.prepareValuesForFstChart(profileName, config.applicationEnv)
this.profileValuesFile = await this.profileManager.prepareValuesForFstChart(profileName)
if (this.profileValuesFile) {
valuesArg += this.prepareValuesFiles(this.profileValuesFile)
}
Expand All @@ -118,6 +126,8 @@ export class NetworkCommand extends BaseCommand {
valuesArg += ` --set "defaults.root.image.repository=${rootImage}"`
}

valuesArg += ` --set "defaults.volumeClaims.enabled=${config.persistentVolumeClaims}"`

this.logger.debug('Prepared helm chart values', { valuesArg })
return valuesArg
}
Expand All @@ -128,10 +138,20 @@ export class NetworkCommand extends BaseCommand {

// disable the prompts that we don't want to prompt the user for
prompts.disablePrompts([
flags.apiPermissionProperties,
flags.app,
flags.applicationEnv,
flags.applicationProperties,
flags.bootstrapProperties,
flags.chainId,
flags.deployHederaExplorer,
flags.deployMirrorNode,
flags.hederaExplorerTlsLoadBalancerIp
flags.hederaExplorerTlsLoadBalancerIp,
flags.log4j2Xml,
flags.persistentVolumeClaims,
flags.profileName,
flags.profileFile,
flags.settingTxt
])

await prompts.execute(task, this.configManager, NetworkCommand.DEPLOY_FLAGS_LIST)
Expand All @@ -150,6 +170,7 @@ export class NetworkCommand extends BaseCommand {
* @property {string} hederaExplorerTlsLoadBalancerIp
* @property {string} namespace
* @property {string} nodeIDs
* @property {string} persistentVolumeClaims
* @property {string} profileFile
* @property {string} profileName
* @property {string} releaseTag
Expand Down Expand Up @@ -197,32 +218,34 @@ export class NetworkCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
ctx.config = await self.prepareConfig(task, argv)
ctx.config = /** @type {NetworkDeployConfigClass} **/ await self.prepareConfig(task, argv)
}
},
{
title: `Install chart '${constants.FULLSTACK_DEPLOYMENT_CHART}'`,
task: async (ctx, _) => {
if (await self.chartManager.isChartInstalled(ctx.config.namespace, constants.FULLSTACK_DEPLOYMENT_CHART)) {
await self.chartManager.uninstall(ctx.config.namespace, constants.FULLSTACK_DEPLOYMENT_CHART)
const config = /** @type {NetworkDeployConfigClass} **/ ctx.config
if (await self.chartManager.isChartInstalled(config.namespace, constants.FULLSTACK_DEPLOYMENT_CHART)) {
await self.chartManager.uninstall(config.namespace, constants.FULLSTACK_DEPLOYMENT_CHART)
}

await this.chartManager.install(
ctx.config.namespace,
config.namespace,
constants.FULLSTACK_DEPLOYMENT_CHART,
ctx.config.chartPath,
ctx.config.fstChartVersion,
ctx.config.valuesArg)
config.chartPath,
config.fstChartVersion,
config.valuesArg)
}
},
{
title: 'Check node pods are running',
task:
async (ctx, task) => {
const subTasks = []
const config = /** @type {NetworkDeployConfigClass} **/ ctx.config

// nodes
for (const nodeId of ctx.config.nodeIds) {
for (const nodeId of config.nodeIds) {
subTasks.push({
title: `Check Node: ${chalk.yellow(nodeId)}`,
task: () =>
Expand All @@ -247,9 +270,10 @@ export class NetworkCommand extends BaseCommand {
task:
async (ctx, task) => {
const subTasks = []
const config = /** @type {NetworkDeployConfigClass} **/ ctx.config

// HAProxy
for (const nodeId of ctx.config.nodeIds) {
for (const nodeId of config.nodeIds) {
subTasks.push({
title: `Check HAProxy for: ${chalk.yellow(nodeId)}`,
task: () =>
Expand All @@ -260,7 +284,7 @@ export class NetworkCommand extends BaseCommand {
}

// Envoy Proxy
for (const nodeId of ctx.config.nodeIds) {
for (const nodeId of config.nodeIds) {
subTasks.push({
title: `Check Envoy Proxy for: ${chalk.yellow(nodeId)}`,
task: () =>
Expand Down Expand Up @@ -419,12 +443,13 @@ export class NetworkCommand extends BaseCommand {
{
title: `Upgrade chart '${constants.FULLSTACK_DEPLOYMENT_CHART}'`,
task: async (ctx, _) => {
const config = ctx.config
await this.chartManager.upgrade(
ctx.config.namespace,
config.namespace,
constants.FULLSTACK_DEPLOYMENT_CHART,
ctx.config.chartPath,
ctx.config.valuesArg,
ctx.config.fstChartVersion
config.chartPath,
config.valuesArg,
config.fstChartVersion
)
}
},
Expand Down
Loading

0 comments on commit af27f16

Please sign in to comment.