Skip to content

Commit

Permalink
fix(cli): invoke helm dependency update when local chart-dir is set (#…
Browse files Browse the repository at this point in the history
…562)

Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com>
  • Loading branch information
leninmehedy authored Nov 16, 2023
1 parent 11d20e6 commit 38dd176
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 87 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/zxc-compile-code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,27 @@ jobs:
if: ${{ inputs.enable-unit-tests && !cancelled() }}
uses: google-github-actions/setup-gcloud@e30db14379863a8c79331b04a9969f4c1e225e0b # v1.1.1

- name: NodeJS CLI Tests
- name: NodeJS CLI Unit Tests
id: nodejs-test
working-directory: fullstack-network-manager
if: ${{ inputs.enable-nodejs-tests && !cancelled() && !failure() }}
run: |
npm i
npm test
# npm run test-e2e # tracked by #https://github.com/hashgraph/full-stack-testing/issues/501
- name: NodeJS CLI E2E Tests
id: nodejs-test-e2e
working-directory: fullstack-network-manager
if: ${{ inputs.enable-nodejs-tests && !cancelled() && !failure() }}
run: |
export DEV_MODE=true
npm i
npm link
fsnetman init -d ../charts
fsnetman cluster create
fsnetman cluster setup
fsnetman chart install
npm run test-e2e
# This step tests the Helm chart direct mode of operation which uses the ubi8-init-java17 image.
- name: Helm Chart Test (Direct Install)
Expand Down
13 changes: 12 additions & 1 deletion fullstack-network-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,19 @@ Select a command
* Note: you need to do it once. If `fsnetman` already exists in your path, you will need to remove it first.
* Alternative way would be to run `npm run fsnetman -- <COMMAND> <ARGS>`
* Run `npm test` or `npm run test` to run the unit tests
* Run `npm run test-e2e` to run the long-running integration tests
* Run `fsnetman` to access the CLI as shown above.
* Note that debug logs are stored at `~/.fsnetman/logs/fst.log`. So you may use `tail -f ~/.fsnetman/logs/fst.log | jq
` in a separate terminal to keep an eye on the logs.
* Before making a commit run `npm run format`

## E2E tests

* In order to run E2E test, we need to set up cluster and install the chart.

```
fsnetman init -d ../charts # use the charts directory
fsnetman cluster create
fsnetman cluster setup
fsnetman chart install
npm run test-e2e
```
4 changes: 2 additions & 2 deletions fullstack-network-manager/package-lock.json

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

33 changes: 33 additions & 0 deletions fullstack-network-manager/resources/templates/hedera.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-----BEGIN CERTIFICATE-----
MIIFpjCCA46gAwIBAgIUdLOB7iQa9RUTU+SBcrJyiCqdJrMwDQYJKoZIhvcNAQEL
BQAwQjESMBAGA1UEAwwJbG9jYWxob3N0MQswCQYDVQQGEwJVUzEQMA4GA1UECwwH
TXkgVW5pdDENMAsGA1UECgwEQUNNRTAgFw0yMjAyMTkwMDA4NDFaGA8yMTIyMDUw
NjAwMDg0MVowQjESMBAGA1UEAwwJbG9jYWxob3N0MQswCQYDVQQGEwJVUzEQMA4G
A1UECwwHTXkgVW5pdDENMAsGA1UECgwEQUNNRTCCAiIwDQYJKoZIhvcNAQEBBQAD
ggIPADCCAgoCggIBAN3w4d7c6Zw9VMg6VIOAFpzbJGcP1uvY76OEINU8pHALz/w8
WSjzXqpcu2L9jgKy67w4FALooXFTyYobTlFgmm4KxbvyHyZJRJvs/UcyZLw7j7tV
JIsziL3EloaLMfzag45CmN1sYnBl1422FIKGRH/8DgGnIWvWOKlkHm9zxWToYVXb
42tsEriig7GatUUhmIjr3S4L17EqZNtCcN4UTXPelwLDD4lsUUwEYXvumnPrscVo
GcskEZPKBHKDySaQCQ3bd30I5NPNkIfLv1rw79t6JFsJvzdchsHfUlVPx3fwpbwS
iPHNFFJgMtRH3gEd0IFQv5fC2Z8x/trCNL/jFhK+2SdRB8t1uS7OYTIdp8RCVJwS
zHzVi3qLN393tv0Biqfsk+R1tS3ono9gzDkuH0A5MoLKPd0w0bJsT6pgSYeqQ4mC
Bf8dEQDnipC5oG0vbLMPNCuObnLxZo2Y0Yui1YhjX7Om9GKeE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bspWSyXTaQiavWnYQ/tTMvtv91o1Q8Cc7xrek/nJ4qPfE
qxD6cDDvXHUriw==
-----END CERTIFICATE-----
20 changes: 17 additions & 3 deletions fullstack-network-manager/src/commands/chart.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from 'chalk'
import { BaseCommand } from './base.mjs'
import * as flags from './flags.mjs'
import { constants } from '../core/index.mjs'
Expand All @@ -21,11 +22,12 @@ export class ChartCommand extends BaseCommand {
return valuesArg
}

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

return chartPath
Expand All @@ -37,14 +39,26 @@ export class ChartCommand extends BaseCommand {

const config = await this.configManager.setupConfig(argv)
const valuesArg = this.prepareValuesArg(argv, config)
const chartPath = this.prepareChartPath(config)
const chartPath = await 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))

this.logger.showUser(chalk.cyan('> waiting for network-node pods to be active (first deployment takes ~10m) ...'))
await this.kubectl.wait('pod',
'--for=jsonpath=\'{.status.phase}\'=Running',
'-l fullstack.hedera.com/type=network-node',
'--timeout=900s'
)
this.logger.showUser(chalk.green('OK'), 'network-node pods are running')

return true
} catch (e) {
this.logger.showUserError(e)
}

return false
}

async uninstall (argv) {
Expand All @@ -58,7 +72,7 @@ export class ChartCommand extends BaseCommand {

const config = await this.configManager.setupConfig(argv)
const valuesArg = this.prepareValuesArg(argv, config)
const chartPath = this.prepareChartPath(config)
const chartPath = await this.prepareChartPath(config)

return await this.chartManager.upgrade(namespace, constants.FST_CHART_DEPLOYMENT_NAME, chartPath, valuesArg)
}
Expand Down
8 changes: 3 additions & 5 deletions fullstack-network-manager/src/commands/cluster.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,8 @@ export class ClusterCommand extends BaseCommand {
const config = await this.configManager.setupConfig(argv)
const namespace = argv.namespace

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

// install fullstack-cluster-setup chart
const chartPath = this.prepareChartPath(config)
const chartPath = await 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)))
Expand Down Expand Up @@ -311,11 +308,12 @@ export class ClusterCommand extends BaseCommand {
return valuesArg
}

prepareChartPath (config) {
async 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`
await this.helm.dependency('update', chartPath)
}

return chartPath
Expand Down
1 change: 1 addition & 0 deletions fullstack-network-manager/src/commands/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class InitCommand extends BaseCommand {
async init (argv) {
try {
await this.setupHomeDirectory()
await this.configManager.setupConfig(argv, true)

const deps = [
core.constants.HELM,
Expand Down
111 changes: 55 additions & 56 deletions fullstack-network-manager/src/core/config_manager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class ConfigManager {
}

/**
* load package.json
* @returns {any}
*/
* load package.json
* @returns {any}
*/
loadPackageJSON () {
try {
const raw = fs.readFileSync(`${CUR_FILE_DIR}/../../package.json`)
Expand All @@ -42,70 +42,69 @@ export class ConfigManager {
}

/**
* Load and store config
*
* It overwrites previous config values using opts and store in the config file if any value has been changed.
*
* @param opts object containing various config related fields (e.g. argv)
* @param reset if we should reset old values
* @returns {Promise<unknown>}
*/
* Load and store config
*
* It overwrites previous config values using opts and store in the config file if any value has been changed.
*
* @param opts object containing various config related fields (e.g. argv)
* @param reset if we should reset old values
* @returns {Promise<unknown>}
*/
async setupConfig (opts, reset = false) {
const self = this

return new Promise((resolve, reject) => {
try {
let config = {}
let writeConfig = false
const packageJSON = self.loadPackageJSON()

// if config exist, then load it first
if (!reset && fs.existsSync(constants.FST_CONFIG_FILE)) {
const configJSON = fs.readFileSync(constants.FST_CONFIG_FILE)
config = JSON.parse(configJSON.toString())
}

if (!config.flags) {
config.flags = {}
}

// we always use packageJSON version as the version, so overwrite.
config.version = packageJSON.version
try {
let config = {}
let writeConfig = false
const packageJSON = self.loadPackageJSON()

// if config exist, then load it first
if (!reset && fs.existsSync(constants.FST_CONFIG_FILE)) {
const configJSON = fs.readFileSync(constants.FST_CONFIG_FILE)
config = JSON.parse(configJSON.toString())
}

// extract flags from argv
if (opts) {
flags.allFlags.forEach(flag => {
if (opts && opts[flag.name]) {
let val = opts[flag.name]
if (val && flag.name === flags.chartDirectory.name) {
val = paths.resolve(val)
}
if (!config.flags) {
config.flags = {}
}

config.flags[flag.name] = val
writeConfig = true
// we always use packageJSON version as the version, so overwrite.
config.version = packageJSON.version

// extract flags from argv
if (opts) {
flags.allFlags.forEach(flag => {
if (opts && opts[flag.name]) {
let val = opts[flag.name]
if (val && flag.name === flags.chartDirectory.name) {
console.log(val)
val = paths.resolve(val)
}
})

// store last command that was run
if (opts._) {
config.lastCommand = opts._
config.flags[flag.name] = val
writeConfig = true
}
}

// store CLI config
if (reset || writeConfig) {
config.updatedAt = new Date().toISOString()
})

let configJSON = JSON.stringify(config)
fs.writeFileSync(`${constants.FST_CONFIG_FILE}`, configJSON)
configJSON = fs.readFileSync(constants.FST_CONFIG_FILE)
config = JSON.parse(configJSON.toString())
// store last command that was run
if (opts._) {
config.lastCommand = opts._
}
}

// store CLI config
if (reset || writeConfig) {
config.updatedAt = new Date().toISOString()

resolve(config)
} catch (e) {
reject(new FullstackTestingError(`failed to load config: ${e.message}`, e))
let configJSON = JSON.stringify(config)
fs.writeFileSync(`${constants.FST_CONFIG_FILE}`, configJSON)
configJSON = fs.readFileSync(constants.FST_CONFIG_FILE)
config = JSON.parse(configJSON.toString())
}
})

return config
} catch (e) {
throw new FullstackTestingError(`failed to load config: ${e.message}`, e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ describe('PackageDownloaderE2E', () => {
testLogger.showUser(destPath)

// remove the downloaded files to reduce disk usage
fs.rmSync(`${tmpDir}/v0.42/build-${tag}.zip`)
fs.rmSync(`${tmpDir}/v0.42/build-${tag}.sha384`)
fs.rmdirSync(`${tmpDir}/v0.42`)
fs.rmdirSync(tmpDir)
fs.rmSync(`${tmpDir}`, { recursive: true })
}, 100000)
})
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('PackageInstallerE2E', () => {
console.error(e)
expect(e).toBeNull()
}
})
}, 20000)
})

describe('prepareConfigTxt', () => {
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('PackageInstallerE2E', () => {
// verify file content matches
expect(fileContents).toBe(configLines.join('\n'))

fs.rmdirSync(tmpDir, { recursive: true })
fs.rmSync(tmpDir, { recursive: true })
})
})

Expand All @@ -88,7 +88,7 @@ describe('PackageInstallerE2E', () => {
// verify copy of local-node data is at staging area
expect(fs.existsSync(`${tmpDir}/templates`)).toBeTruthy()

fs.rmdirSync(tmpDir, { recursive: true })
fs.rmSync(tmpDir, { recursive: true })
})
})

Expand Down Expand Up @@ -159,7 +159,7 @@ describe('PackageInstallerE2E', () => {
expect(fileList).toContain(`${constants.HAPI_PATH}/data/config/api-permission.properties`)
expect(fileList).toContain(`${constants.HAPI_PATH}/data/config/application.properties`)
expect(fileList).toContain(`${constants.HAPI_PATH}/data/config/bootstrap.properties`)
fs.rmdirSync(tmpDir, { recursive: true })
})
fs.rmSync(tmpDir, { recursive: true })
}, 10000)
})
})
Loading

0 comments on commit 38dd176

Please sign in to comment.