Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): support config persistence and local chart directory for fst charts #535

Merged
merged 14 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion fullstack-network-manager/src/commands/base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import * as core from "../core/index.mjs"
import chalk from "chalk";
import {ShellRunner} from "../core/shell_runner.mjs";
import {constants} from "../core/index.mjs";

export class BaseCommand extends ShellRunner {

async checkDep(cmd) {
try {
this.logger.debug(cmd)
Expand Down Expand Up @@ -78,13 +78,15 @@ export class BaseCommand extends ShellRunner {
if (!opts || !opts.helm) throw new Error('An instance of core/Helm is required')
if (!opts || !opts.kubectl) throw new Error('An instance of core/Kubectl is required')
if (!opts || !opts.chartManager) throw new Error('An instance of core/ChartManager is required')
if (!opts || !opts.configManager) throw new Error('An instance of core/ConfigManager is required')

super(opts.logger);

this.kind = opts.kind
this.helm = opts.helm
this.kubectl = opts.kubectl
this.chartManager = opts.chartManager
this.configManager = opts.configManager

// map of dependency checks
this.checks = new Map()
Expand Down
62 changes: 41 additions & 21 deletions fullstack-network-manager/src/commands/chart.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import {constants} from "../core/index.mjs";


export class ChartCommand extends BaseCommand {
chartPath = `full-stack-testing/fullstack-deployment`

prepareValuesArg(argv) {
prepareValuesArg(argv, config) {
const {valuesFile, mirrorNode, hederaExplorer} = argv

let valuesArg = ''
let chartDir = this.configManager.flagValue(config, flags.chartDirectory)
if (chartDir) {
valuesArg = `-f ${chartDir}/fullstack-deployment/values.yaml`
}

if (valuesFile) {
valuesArg += `--values ${valuesFile}`
}
Expand All @@ -20,12 +24,25 @@ export class ChartCommand extends BaseCommand {
return valuesArg
}

prepareChartPath(config) {
const chartDir = this.configManager.flagValue(config, flags.chartDirectory)
let chartPath = `full-stack-testing/fullstack-deployment`
if (chartDir) {
chartPath = `${chartDir}/fullstack-deployment`
}

return chartPath
}

async install(argv) {
try {
const namespace = argv.namespace
const valuesArg = this.prepareValuesArg(argv)

await this.chartManager.install(namespace, constants.FST_CHART_DEPLOYMENT_NAME, this.chartPath, valuesArg)
const config = await this.configManager.setupConfig(argv)
const valuesArg = this.prepareValuesArg(argv, config)
const chartPath = this.prepareChartPath(config)

await this.chartManager.install(namespace, constants.FST_CHART_DEPLOYMENT_NAME, chartPath, config.version, valuesArg)

this.logger.showList('charts', await this.chartManager.getInstalledCharts(namespace))
} catch (e) {
Expand All @@ -41,9 +58,12 @@ export class ChartCommand extends BaseCommand {

async upgrade(argv) {
const namespace = argv.namespace
const valuesArg = this.prepareValuesArg(argv)

return await this.chartManager.upgrade(namespace, constants.FST_CHART_DEPLOYMENT_NAME, this.chartPath, valuesArg)
const config = await this.configManager.setupConfig(argv)
const valuesArg = this.prepareValuesArg(argv, config)
const chartPath = this.prepareChartPath(config)

return await this.chartManager.upgrade(namespace, constants.FST_CHART_DEPLOYMENT_NAME, chartPath, valuesArg)
}

static getCommandDefinition(chartCmd) {
Expand All @@ -55,12 +75,13 @@ export class ChartCommand extends BaseCommand {
.command({
command: 'install',
desc: 'Install FST network deployment chart',
builder: yargs => {
yargs.option('namespace', flags.namespaceFlag)
yargs.option('mirror-node', flags.deployMirrorNode)
yargs.option('hedera-explorer', flags.deployHederaExplorer)
yargs.option('values-file', flags.valuesFile)
},
builder: y => flags.setCommandFlags(y,
flags.namespace,
flags.deployMirrorNode,
flags.deployHederaExplorer,
flags.valuesFile,
flags.chartDirectory,
),
handler: argv => {
chartCmd.logger.debug("==== Running 'chart install' ===")
chartCmd.logger.debug(argv)
Expand All @@ -76,9 +97,7 @@ export class ChartCommand extends BaseCommand {
.command({
command: 'uninstall',
desc: 'Uninstall FST network deployment chart',
builder: yargs => {
yargs.option('namespace', flags.namespaceFlag)
},
builder: y => flags.setCommandFlags(y, flags.namespace),
handler: argv => {
chartCmd.logger.debug("==== Running 'chart uninstall' ===")
chartCmd.logger.debug(argv)
Expand All @@ -94,12 +113,13 @@ export class ChartCommand extends BaseCommand {
.command({
command: 'upgrade',
desc: 'Refresh existing FST network deployment with new values',
builder: yargs => {
yargs.option('namespace', flags.namespaceFlag)
yargs.option('mirror-node', flags.deployMirrorNode)
yargs.option('hedera-explorer', flags.deployHederaExplorer)
yargs.option('values-file', flags.valuesFile)
},
builder: y => flags.setCommandFlags(y,
flags.namespace,
flags.deployMirrorNode,
flags.deployHederaExplorer,
flags.valuesFile,
flags.chartDirectory,
),
handler: argv => {
chartCmd.logger.debug("==== Running 'chart upgrade' ===")
chartCmd.logger.debug(argv)
Expand Down
80 changes: 50 additions & 30 deletions fullstack-network-manager/src/commands/cluster.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@ export class ClusterCommand extends BaseCommand {

/**
* Create a cluster
* @param argv
* @param argv command arguments
* @param config config object
* @returns {Promise<boolean>}
*/
async create(argv) {
async create(argv, config = {}) {
try {
const clusterName = argv.clusterName
const clusters = await this.getClusters()

if (!config) {
config = this.configManager.setupConfig(argv)
}

this.logger.showUser(chalk.cyan('> checking cluster:'), chalk.yellow(`${clusterName}`))
if (!clusters.includes(clusterName)) {
this.logger.showUser(chalk.cyan('> creating cluster:'), chalk.yellow(`${clusterName} ...`))
Expand Down Expand Up @@ -166,17 +171,19 @@ export class ClusterCommand extends BaseCommand {
*/
async setup(argv) {
try {
// create cluster
await this.create(argv)

const config = await this.configManager.setupConfig(argv)
const clusterName = argv.clusterName
const namespace = argv.namespace
const chartPath = `full-stack-testing/fullstack-cluster-setup`
const valuesArg = this.prepareValuesArg(argv.prometheusStack,
argv.minio, argv.envoyGateway, argv.certManager, argv.certManagerCrds)

// create cluster
await this.create(argv, config)

// install fullstack-cluster-setup chart
const chartPath = this.prepareChartPath(config)
const valuesArg = this.prepareValuesArg(config, argv.prometheusStack, argv.minio, argv.envoyGateway,
argv.certManager, argv.certManagerCrds)
this.logger.showUser(chalk.cyan('> setting up cluster:'), chalk.yellow(`${chartPath}`, chalk.yellow(valuesArg)))
await this.chartManager.install(namespace, constants.FST_CHART_SETUP_NAME, chartPath, valuesArg)
await this.chartManager.install(namespace, constants.FST_CHART_SETUP_NAME, chartPath, config.version, valuesArg)
await this.showInstalledChartList(namespace)

return true
Expand All @@ -200,10 +207,7 @@ export class ClusterCommand extends BaseCommand {
.command({
command: 'create',
desc: 'Create a cluster',
builder: yargs => {
yargs.option('cluster-name', flags.clusterNameFlag)
yargs.option('namespace', flags.namespaceFlag)
},
builder: y => flags.setCommandFlags(y, flags.clusterName, flags.namespace),
handler: argv => {
clusterCmd.logger.debug("==== Running 'cluster create' ===")
clusterCmd.logger.debug(argv)
Expand All @@ -219,9 +223,7 @@ export class ClusterCommand extends BaseCommand {
.command({
command: 'delete',
desc: 'Delete a cluster',
builder: yargs => {
yargs.option('cluster-name', flags.clusterNameFlag)
},
builder: y => flags.setCommandFlags(y, flags.clusterName),
handler: argv => {
clusterCmd.logger.debug("==== Running 'cluster delete' ===")
clusterCmd.logger.debug(argv)
Expand Down Expand Up @@ -252,9 +254,7 @@ export class ClusterCommand extends BaseCommand {
.command({
command: 'info',
desc: 'Get cluster info',
builder: yargs => {
yargs.option('cluster-name', flags.clusterNameFlag)
},
builder: y => flags.setCommandFlags(y, flags.clusterName),
handler: argv => {
clusterCmd.logger.debug("==== Running 'cluster info' ===")
clusterCmd.logger.debug(argv)
Expand All @@ -270,15 +270,16 @@ export class ClusterCommand extends BaseCommand {
.command({
command: 'setup',
desc: 'Setup cluster with shared components',
builder: yargs => {
yargs.option('cluster-name', flags.clusterNameFlag)
yargs.option('namespace', flags.namespaceFlag)
yargs.option('prometheus-stack', flags.deployPrometheusStack)
yargs.option('minio', flags.deployMinio)
yargs.option('envoy-gateway', flags.deployEnvoyGateway)
yargs.option('cert-manager', flags.deployCertManager)
yargs.option('cert-manager-crds', flags.deployCertManagerCRDs)
},
builder: y => flags.setCommandFlags(y,
flags.clusterName,
flags.namespace,
flags.chartDirectory,
flags.deployPrometheusStack,
flags.deployMinio,
flags.deployEnvoyGateway,
flags.deployCertManager,
flags.deployCertManagerCRDs,
),
handler: argv => {
clusterCmd.logger.debug("==== Running 'cluster setup' ===")
clusterCmd.logger.debug(argv)
Expand All @@ -296,18 +297,37 @@ export class ClusterCommand extends BaseCommand {
}
}

prepareValuesArg(prometheusStackEnabled, minioEnabled, envoyGatewayEnabled,
certManagerEnabled, certManagerCrdsEnabled) {
prepareValuesArg(config, prometheusStackEnabled, minioEnabled, envoyGatewayEnabled,
certManagerEnabled, certManagerCrdsEnabled) {

let valuesArg = ''
let chartDir = this.configManager.flagValue(config, flags.chartDirectory)
if (chartDir) {
valuesArg = `-f ${chartDir}/fullstack-cluster-setup/values.yaml`
}

valuesArg += ` --set cloud.prometheusStack.enabled=${prometheusStackEnabled}`
valuesArg += ` --set cloud.minio.enabled=${minioEnabled}`
valuesArg += ` --set cloud.envoyGateway.enabled=${envoyGatewayEnabled}`
valuesArg += ` --set cloud.certManager.enabled=${certManagerEnabled}`
valuesArg += ` --set cert-manager.installCRDs=${certManagerCrdsEnabled}`

if (certManagerEnabled && !certManagerCrdsEnabled) {
this.logger.showUser(chalk.yellowBright('> WARNING:'), chalk.yellow(
'cert-manager CRDs are required for cert-manager, please enable it if you have not installed it independently.'))
}

return valuesArg

}

prepareChartPath(config) {
const chartDir = this.configManager.flagValue(config, flags.chartDirectory)
let chartPath = `full-stack-testing/fullstack-cluster-setup`
if (chartDir) {
chartPath = `${chartDir}/fullstack-cluster-setup`
}

return chartPath
}
}
Loading