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

fix: local chart directory not being taken correctly #983

Merged
merged 12 commits into from
Dec 12, 2024
21 changes: 12 additions & 9 deletions examples/performance-tuning/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# The usage of resources in Solo
## Modify Taskfile.yml, task "network:deploy"
# The usage of resources in Solo

## Modify Taskfile.yml, task "network:deploy"

add "--values-file init-containers-values.yaml"

Example:

> solo:network:deploy:
> internal: true
> cmds:
> - npm run solo-test -- network deploy --namespace "\${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} --solo-chart-version "\${SOLO_CHART_VERSION}" --settings-txt settings.txt --log4j2-xml log4j2.xml --values-file init-containers-values.yaml --application-properties application.properties

> solo:network:deploy:
> internal: true
> cmds:
> \- npm run solo-test -- network deploy --namespace "${SOLO\_NAMESPACE}" --node-aliases-unparsed {{.node\_identifiers}} --solo-chart-version "${SOLO\_CHART\_VERSION}" --settings-txt settings.txt --log4j2-xml log4j2.xml --values-file init-containers-values.yaml --application-properties application.properties

## Provided examples for Consensus nodes:

* HashSphere/init-containers-values.yaml (HashSphere on Google Cloud, for 4-core/32Gb 7-node )
* Latitude/init-containers-values.yaml (Latitude, 128Gb, 10-node)

## and corresponding NetworkLoadGenerator templates:

* HashSphere/nlg-values.yaml
* Latitude/nlg-values.yaml
Start as the following:
> helm upgrade --install nlg oci://swirldslabs.jfrog.io/load-generator-helm-release-local/network-load-generator --version 0.2.1 --values nlg-values.yaml -n solo-hashsphere1
Start as the following:

> helm upgrade --install nlg oci://swirldslabs.jfrog.io/load-generator-helm-release-local/network-load-generator --version 0.2.1 --values nlg-values.yaml -n solo-hashsphere1
3 changes: 2 additions & 1 deletion src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import {type CommandFlag} from '../types/flag_types.js';
import {type Lease} from '../core/lease/lease.js';
import {Listr} from 'listr2';
import path from 'path';

export interface CommandHandlers {
parent: BaseCommand;
Expand Down Expand Up @@ -74,7 +75,7 @@
if (!chartReleaseName) throw new MissingArgumentError('chart release name is required');

if (chartDir) {
const chartPath = `${chartDir}/${chartReleaseName}`;
const chartPath = path.join(chartDir, chartReleaseName);

Check warning on line 78 in src/commands/base.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/commands/base.ts#L78

Detected possible user input going into a `path.join` or `path.resolve` function.
await this.helm.dependency('update', chartPath);
return chartPath;
}
Expand Down
28 changes: 9 additions & 19 deletions src/commands/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export class ClusterCommand extends BaseCommand {
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.update(argv);
flags.disablePrompts([flags.chartDirectory]);

await self.configManager.executePrompt(task, [
flags.chartDirectory,
flags.clusterSetupNamespace,
Expand Down Expand Up @@ -108,7 +110,11 @@ export class ClusterCommand extends BaseCommand {
{
title: 'Prepare chart values',
task: async (ctx, _) => {
ctx.chartPath = await this.prepareChartPath(ctx.config.chartDir);
ctx.chartPath = await this.prepareChartPath(
ctx.config.chartDir,
constants.SOLO_TESTING_CHART_URL,
constants.SOLO_CLUSTER_SETUP_CHART,
);
ctx.valuesArg = this.prepareValuesArg(
ctx.config.chartDir,
ctx.config.deployPrometheusStack,
Expand All @@ -124,16 +130,14 @@ export class ClusterCommand extends BaseCommand {
task: async (ctx, _) => {
const clusterSetupNamespace = ctx.config.clusterSetupNamespace;
const version = ctx.config.soloChartVersion;

const chartPath = constants.SOLO_TESTING_CHART_URL + constants.SOLO_CLUSTER_SETUP_CHART;
const valuesArg = ctx.valuesArg;

try {
self.logger.debug(`Installing chart chartPath = ${chartPath}, version = ${version}`);
self.logger.debug(`Installing chart chartPath = ${ctx.chartPath}, version = ${version}`);
await self.chartManager.install(
clusterSetupNamespace,
constants.SOLO_CLUSTER_SETUP_CHART,
chartPath,
ctx.chartPath,
version,
valuesArg,
);
Expand Down Expand Up @@ -381,20 +385,6 @@ export class ClusterCommand extends BaseCommand {
return valuesArg;
}

/**
* Prepare chart path
* @param [chartDir] - local charts directory (default is empty)
*/
async prepareChartPath(chartDir = flags.chartDirectory.definition.defaultValue as string) {
let chartPath = 'solo-charts/solo-cluster-setup';
if (chartDir) {
chartPath = path.join(chartDir, 'solo-cluster-setup');
await this.helm.dependency('update', chartPath);
}

return chartPath;
}

close(): Promise<void> {
// no-op
return Promise.resolve();
Expand Down
7 changes: 4 additions & 3 deletions src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
flags.bootstrapProperties,
flags.cacheDir,
flags.chainId,
flags.chartDirectory,
flags.debugNodeAlias,
flags.log4j2Xml,
flags.persistentVolumeClaims,
Expand Down Expand Up @@ -253,7 +254,7 @@
// compute values
config.chartPath = await this.prepareChartPath(
config.chartDirectory,
constants.SOLO_TESTING_CHART,
constants.SOLO_TESTING_CHART_URL,
constants.SOLO_DEPLOYMENT_CHART,
);

Expand Down Expand Up @@ -408,7 +409,7 @@
await this.chartManager.install(
config.namespace,
constants.SOLO_DEPLOYMENT_CHART,
constants.SOLO_TESTING_CHART_URL + constants.SOLO_DEPLOYMENT_CHART,
ctx.config.chartPath,
config.soloChartVersion,
config.valuesArg,
);
Expand Down Expand Up @@ -645,7 +646,7 @@
await this.chartManager.upgrade(
config.namespace,
constants.SOLO_DEPLOYMENT_CHART,
constants.SOLO_TESTING_CHART_URL + constants.SOLO_DEPLOYMENT_CHART,
ctx.config.chartPath,

Check warning on line 649 in src/commands/network.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/network.ts#L649

Added line #L649 was not covered by tests
config.soloChartVersion,
config.valuesArg,
);
Expand Down
6 changes: 3 additions & 3 deletions src/commands/node/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const updateConfigBuilder = async function (argv, ctx, task) {

ctx.config.chartPath = await this.prepareChartPath(
ctx.config.chartDirectory,
constants.SOLO_TESTING_CHART,
constants.SOLO_TESTING_CHART_URL,
constants.SOLO_DEPLOYMENT_CHART,
);

Expand Down Expand Up @@ -152,7 +152,7 @@ export const deleteConfigBuilder = async function (argv, ctx, task) {

ctx.config.chartPath = await this.prepareChartPath(
ctx.config.chartDirectory,
constants.SOLO_TESTING_CHART,
constants.SOLO_TESTING_CHART_URL,
constants.SOLO_DEPLOYMENT_CHART,
);

Expand Down Expand Up @@ -199,7 +199,7 @@ export const addConfigBuilder = async function (argv, ctx, task) {

ctx.config.chartPath = await this.prepareChartPath(
ctx.config.chartDirectory,
constants.SOLO_TESTING_CHART,
constants.SOLO_TESTING_CHART_URL,
constants.SOLO_DEPLOYMENT_CHART,
);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/node/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ export class NodeCommandTasks {
await self.chartManager.upgrade(
config.namespace,
constants.SOLO_DEPLOYMENT_CHART,
constants.SOLO_TESTING_CHART_URL + constants.SOLO_DEPLOYMENT_CHART,
ctx.config.chartPath,
config.soloChartVersion,
valuesArg,
);
Expand Down
3 changes: 1 addition & 2 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ export const HEDERA_NODE_DEFAULT_STAKE_AMOUNT = +process.env.SOLO_NODE_DEFAULT_S

// --------------- Charts related constants ----------------------------------------------------------------------------
export const SOLO_SETUP_NAMESPACE = 'solo-setup';
export const SOLO_TESTING_CHART_URL = 'oci://ghcr.io/hashgraph/solo-charts/';
export const SOLO_TESTING_CHART = 'solo-charts';
export const SOLO_TESTING_CHART_URL = 'oci://ghcr.io/hashgraph/solo-charts';
export const SOLO_CLUSTER_SETUP_CHART = 'solo-cluster-setup';
export const SOLO_DEPLOYMENT_CHART = 'solo-deployment';
export const JSON_RPC_RELAY_CHART_URL = 'https://hashgraph.github.io/hedera-json-rpc-relay/charts';
Expand Down
1 change: 0 additions & 1 deletion test/e2e/commands/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ describe('NetworkCommand', () => {
flags.settingTxt.constName,
flags.grpcTlsKeyPath.constName,
flags.grpcWebTlsKeyPath.constName,
'chartPath',
]);
} catch (e) {
networkCmd.logger.showUserError(e);
Expand Down
1 change: 0 additions & 1 deletion test/e2e/commands/separate_node_add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ e2eTestSuite(namespace, argv, undefined, undefined, undefined, undefined, undefi
flags.devMode.constName,
flags.force.constName,
flags.quiet.constName,
'chartPath',
'curDate',
'freezeAdminPrivateKey',
]);
Expand Down
1 change: 0 additions & 1 deletion test/test_add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export function testNodeAdd(
flags.force.constName,
flags.quiet.constName,
flags.adminKey.constName,
'chartPath',
]);
await bootstrapResp.opts.accountManager.close();
}).timeout(Duration.ofMinutes(12).toMillis());
Expand Down
1 change: 0 additions & 1 deletion test/test_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ export function e2eTestSuite(
flags.settingTxt.constName,
flags.grpcTlsKeyPath.constName,
flags.grpcWebTlsKeyPath.constName,
'chartPath',
]);
}).timeout(Duration.ofMinutes(5).toMillis());

Expand Down
98 changes: 98 additions & 0 deletions test/unit/commands/cluster.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the ""License"");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an ""AS IS"" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import sinon from 'sinon';
import {describe, it, beforeEach} from 'mocha';
import {expect} from 'chai';

import {ClusterCommand} from '../../../src/commands/cluster.js';
import {getDefaultArgv, HEDERA_PLATFORM_VERSION_TAG, TEST_CLUSTER} from '../../test_util.js';
import {Flags as flags} from '../../../src/commands/flags.js';
import * as version from '../../../version.js';
import * as constants from '../../../src/core/constants.js';
import {ConfigManager} from '../../../src/core/config_manager.js';
import {SoloLogger} from '../../../src/core/logging.js';
import {ChartManager} from '../../../src/core/chart_manager.js';
import {Helm} from '../../../src/core/helm.js';
import {ROOT_DIR} from '../../../src/core/constants.js';
import path from 'path';

const getBaseCommandOpts = () => ({
logger: sinon.stub(),
helm: sinon.stub(),
k8: sinon.stub(),
chartManager: sinon.stub(),
configManager: sinon.stub(),
depManager: sinon.stub(),
localConfig: sinon.stub(),
});

const testName = 'cluster-cmd-unit';
const namespace = testName;
const argv = getDefaultArgv();

argv[flags.namespace.name] = namespace;
argv[flags.releaseTag.name] = HEDERA_PLATFORM_VERSION_TAG;
argv[flags.nodeAliasesUnparsed.name] = 'node1';
argv[flags.generateGossipKeys.name] = true;
argv[flags.generateTlsKeys.name] = true;
argv[flags.clusterName.name] = TEST_CLUSTER;
argv[flags.soloChartVersion.name] = version.SOLO_CHART_VERSION;
argv[flags.force.name] = true;
argv[flags.clusterSetupNamespace.name] = constants.SOLO_SETUP_NAMESPACE;

describe('ClusterCommand unit tests', () => {
describe('Chart Install Function is called correctly', () => {
let opts: any;

beforeEach(() => {
opts = getBaseCommandOpts();
opts.logger = new SoloLogger();
opts.helm = new Helm(opts.logger);
opts.helm.dependency = sinon.stub();
opts.chartManager = new ChartManager(opts.helm, opts.logger);
opts.chartManager.isChartInstalled = sinon.stub().returns(false);
opts.chartManager.install = sinon.stub().returns(true);

opts.configManager = new ConfigManager(opts.logger);
opts.remoteConfigManager = sinon.stub();
});

it('Install function is called with expected parameters', async () => {
const clusterCommand = new ClusterCommand(opts);
await clusterCommand.setup(argv);

expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE);
expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART);
expect(opts.chartManager.install.args[0][2]).to.equal(
constants.SOLO_TESTING_CHART_URL + '/' + constants.SOLO_CLUSTER_SETUP_CHART,
);
expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION);
});

it('Should use local chart directory', async () => {
argv[flags.chartDirectory.name] = 'test-directory';
argv[flags.force.name] = true;

const clusterCommand = new ClusterCommand(opts);
await clusterCommand.setup(argv);

expect(opts.chartManager.install.args[0][2]).to.equal(
path.join(ROOT_DIR, 'test-directory', constants.SOLO_CLUSTER_SETUP_CHART),
);
});
});
});
Loading
Loading