Skip to content

Commit 58e96e1

Browse files
fix: local chart directory not being taken correctly (#983)
Signed-off-by: Jeffrey Tang <[email protected]>
1 parent 437bbc6 commit 58e96e1

File tree

13 files changed

+272
-42
lines changed

13 files changed

+272
-42
lines changed

examples/performance-tuning/README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
# The usage of resources in Solo
2-
## Modify Taskfile.yml, task "network:deploy"
1+
# The usage of resources in Solo
2+
3+
## Modify Taskfile.yml, task "network:deploy"
4+
35
add "--values-file init-containers-values.yaml"
46

57
Example:
68

7-
> solo:network:deploy:
8-
> internal: true
9-
> cmds:
10-
> - 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
11-
9+
> solo:network:deploy:
10+
> internal: true
11+
> cmds:
12+
> \- 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
1213
1314
## Provided examples for Consensus nodes:
15+
1416
* HashSphere/init-containers-values.yaml (HashSphere on Google Cloud, for 4-core/32Gb 7-node )
1517
* Latitude/init-containers-values.yaml (Latitude, 128Gb, 10-node)
1618

1719
## and corresponding NetworkLoadGenerator templates:
1820

1921
* HashSphere/nlg-values.yaml
2022
* Latitude/nlg-values.yaml
21-
Start as the following:
22-
> 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
23+
Start as the following:
24+
25+
> 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

src/commands/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {type Opts} from '../types/command_types.js';
3030
import {type CommandFlag} from '../types/flag_types.js';
3131
import {type Lease} from '../core/lease/lease.js';
3232
import {Listr} from 'listr2';
33+
import path from 'path';
3334

3435
export interface CommandHandlers {
3536
parent: BaseCommand;
@@ -74,7 +75,7 @@ export abstract class BaseCommand extends ShellRunner {
7475
if (!chartReleaseName) throw new MissingArgumentError('chart release name is required');
7576

7677
if (chartDir) {
77-
const chartPath = `${chartDir}/${chartReleaseName}`;
78+
const chartPath = path.join(chartDir, chartReleaseName);
7879
await this.helm.dependency('update', chartPath);
7980
return chartPath;
8081
}

src/commands/cluster.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export class ClusterCommand extends BaseCommand {
7878
title: 'Initialize',
7979
task: async (ctx, task) => {
8080
self.configManager.update(argv);
81+
flags.disablePrompts([flags.chartDirectory]);
82+
8183
await self.configManager.executePrompt(task, [
8284
flags.chartDirectory,
8385
flags.clusterSetupNamespace,
@@ -108,7 +110,11 @@ export class ClusterCommand extends BaseCommand {
108110
{
109111
title: 'Prepare chart values',
110112
task: async (ctx, _) => {
111-
ctx.chartPath = await this.prepareChartPath(ctx.config.chartDir);
113+
ctx.chartPath = await this.prepareChartPath(
114+
ctx.config.chartDir,
115+
constants.SOLO_TESTING_CHART_URL,
116+
constants.SOLO_CLUSTER_SETUP_CHART,
117+
);
112118
ctx.valuesArg = this.prepareValuesArg(
113119
ctx.config.chartDir,
114120
ctx.config.deployPrometheusStack,
@@ -124,16 +130,14 @@ export class ClusterCommand extends BaseCommand {
124130
task: async (ctx, _) => {
125131
const clusterSetupNamespace = ctx.config.clusterSetupNamespace;
126132
const version = ctx.config.soloChartVersion;
127-
128-
const chartPath = constants.SOLO_TESTING_CHART_URL + constants.SOLO_CLUSTER_SETUP_CHART;
129133
const valuesArg = ctx.valuesArg;
130134

131135
try {
132-
self.logger.debug(`Installing chart chartPath = ${chartPath}, version = ${version}`);
136+
self.logger.debug(`Installing chart chartPath = ${ctx.chartPath}, version = ${version}`);
133137
await self.chartManager.install(
134138
clusterSetupNamespace,
135139
constants.SOLO_CLUSTER_SETUP_CHART,
136-
chartPath,
140+
ctx.chartPath,
137141
version,
138142
valuesArg,
139143
);
@@ -381,20 +385,6 @@ export class ClusterCommand extends BaseCommand {
381385
return valuesArg;
382386
}
383387

384-
/**
385-
* Prepare chart path
386-
* @param [chartDir] - local charts directory (default is empty)
387-
*/
388-
async prepareChartPath(chartDir = flags.chartDirectory.definition.defaultValue as string) {
389-
let chartPath = 'solo-charts/solo-cluster-setup';
390-
if (chartDir) {
391-
chartPath = path.join(chartDir, 'solo-cluster-setup');
392-
await this.helm.dependency('update', chartPath);
393-
}
394-
395-
return chartPath;
396-
}
397-
398388
close(): Promise<void> {
399389
// no-op
400390
return Promise.resolve();

src/commands/network.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ export class NetworkCommand extends BaseCommand {
214214
flags.bootstrapProperties,
215215
flags.cacheDir,
216216
flags.chainId,
217+
flags.chartDirectory,
217218
flags.debugNodeAlias,
218219
flags.log4j2Xml,
219220
flags.persistentVolumeClaims,
@@ -253,7 +254,7 @@ export class NetworkCommand extends BaseCommand {
253254
// compute values
254255
config.chartPath = await this.prepareChartPath(
255256
config.chartDirectory,
256-
constants.SOLO_TESTING_CHART,
257+
constants.SOLO_TESTING_CHART_URL,
257258
constants.SOLO_DEPLOYMENT_CHART,
258259
);
259260

@@ -408,7 +409,7 @@ export class NetworkCommand extends BaseCommand {
408409
await this.chartManager.install(
409410
config.namespace,
410411
constants.SOLO_DEPLOYMENT_CHART,
411-
constants.SOLO_TESTING_CHART_URL + constants.SOLO_DEPLOYMENT_CHART,
412+
ctx.config.chartPath,
412413
config.soloChartVersion,
413414
config.valuesArg,
414415
);
@@ -645,7 +646,7 @@ export class NetworkCommand extends BaseCommand {
645646
await this.chartManager.upgrade(
646647
config.namespace,
647648
constants.SOLO_DEPLOYMENT_CHART,
648-
constants.SOLO_TESTING_CHART_URL + constants.SOLO_DEPLOYMENT_CHART,
649+
ctx.config.chartPath,
649650
config.soloChartVersion,
650651
config.valuesArg,
651652
);

src/commands/node/configs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const updateConfigBuilder = async function (argv, ctx, task) {
110110

111111
ctx.config.chartPath = await this.prepareChartPath(
112112
ctx.config.chartDirectory,
113-
constants.SOLO_TESTING_CHART,
113+
constants.SOLO_TESTING_CHART_URL,
114114
constants.SOLO_DEPLOYMENT_CHART,
115115
);
116116

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

153153
ctx.config.chartPath = await this.prepareChartPath(
154154
ctx.config.chartDirectory,
155-
constants.SOLO_TESTING_CHART,
155+
constants.SOLO_TESTING_CHART_URL,
156156
constants.SOLO_DEPLOYMENT_CHART,
157157
);
158158

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

200200
ctx.config.chartPath = await this.prepareChartPath(
201201
ctx.config.chartDirectory,
202-
constants.SOLO_TESTING_CHART,
202+
constants.SOLO_TESTING_CHART_URL,
203203
constants.SOLO_DEPLOYMENT_CHART,
204204
);
205205

src/commands/node/tasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ export class NodeCommandTasks {
14411441
await self.chartManager.upgrade(
14421442
config.namespace,
14431443
constants.SOLO_DEPLOYMENT_CHART,
1444-
constants.SOLO_TESTING_CHART_URL + constants.SOLO_DEPLOYMENT_CHART,
1444+
ctx.config.chartPath,
14451445
config.soloChartVersion,
14461446
valuesArg,
14471447
);

src/core/constants.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ export const HEDERA_NODE_DEFAULT_STAKE_AMOUNT = +process.env.SOLO_NODE_DEFAULT_S
5353

5454
// --------------- Charts related constants ----------------------------------------------------------------------------
5555
export const SOLO_SETUP_NAMESPACE = 'solo-setup';
56-
export const SOLO_TESTING_CHART_URL = 'oci://ghcr.io/hashgraph/solo-charts/';
57-
export const SOLO_TESTING_CHART = 'solo-charts';
56+
export const SOLO_TESTING_CHART_URL = 'oci://ghcr.io/hashgraph/solo-charts';
5857
export const SOLO_CLUSTER_SETUP_CHART = 'solo-cluster-setup';
5958
export const SOLO_DEPLOYMENT_CHART = 'solo-deployment';
6059
export const JSON_RPC_RELAY_CHART_URL = 'https://hashgraph.github.io/hedera-json-rpc-relay/charts';

test/e2e/commands/network.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ describe('NetworkCommand', () => {
102102
flags.settingTxt.constName,
103103
flags.grpcTlsKeyPath.constName,
104104
flags.grpcWebTlsKeyPath.constName,
105-
'chartPath',
106105
]);
107106
} catch (e) {
108107
networkCmd.logger.showUserError(e);

test/e2e/commands/separate_node_add.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ e2eTestSuite(namespace, argv, undefined, undefined, undefined, undefined, undefi
101101
flags.devMode.constName,
102102
flags.force.constName,
103103
flags.quiet.constName,
104-
'chartPath',
105104
'curDate',
106105
'freezeAdminPrivateKey',
107106
]);

test/test_add.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ export function testNodeAdd(
105105
flags.force.constName,
106106
flags.quiet.constName,
107107
flags.adminKey.constName,
108-
'chartPath',
109108
]);
110109
await bootstrapResp.opts.accountManager.close();
111110
}).timeout(Duration.ofMinutes(12).toMillis());

test/test_util.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ export function e2eTestSuite(
288288
flags.settingTxt.constName,
289289
flags.grpcTlsKeyPath.constName,
290290
flags.grpcWebTlsKeyPath.constName,
291-
'chartPath',
292291
]);
293292
}).timeout(Duration.ofMinutes(5).toMillis());
294293

test/unit/commands/cluster.test.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* Copyright (C) 2024 Hedera Hashgraph, LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the ""License"");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an ""AS IS"" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
import sinon from 'sinon';
18+
import {describe, it, beforeEach} from 'mocha';
19+
import {expect} from 'chai';
20+
21+
import {ClusterCommand} from '../../../src/commands/cluster.js';
22+
import {getDefaultArgv, HEDERA_PLATFORM_VERSION_TAG, TEST_CLUSTER} from '../../test_util.js';
23+
import {Flags as flags} from '../../../src/commands/flags.js';
24+
import * as version from '../../../version.js';
25+
import * as constants from '../../../src/core/constants.js';
26+
import {ConfigManager} from '../../../src/core/config_manager.js';
27+
import {SoloLogger} from '../../../src/core/logging.js';
28+
import {ChartManager} from '../../../src/core/chart_manager.js';
29+
import {Helm} from '../../../src/core/helm.js';
30+
import {ROOT_DIR} from '../../../src/core/constants.js';
31+
import path from 'path';
32+
33+
const getBaseCommandOpts = () => ({
34+
logger: sinon.stub(),
35+
helm: sinon.stub(),
36+
k8: sinon.stub(),
37+
chartManager: sinon.stub(),
38+
configManager: sinon.stub(),
39+
depManager: sinon.stub(),
40+
localConfig: sinon.stub(),
41+
});
42+
43+
const testName = 'cluster-cmd-unit';
44+
const namespace = testName;
45+
const argv = getDefaultArgv();
46+
47+
argv[flags.namespace.name] = namespace;
48+
argv[flags.releaseTag.name] = HEDERA_PLATFORM_VERSION_TAG;
49+
argv[flags.nodeAliasesUnparsed.name] = 'node1';
50+
argv[flags.generateGossipKeys.name] = true;
51+
argv[flags.generateTlsKeys.name] = true;
52+
argv[flags.clusterName.name] = TEST_CLUSTER;
53+
argv[flags.soloChartVersion.name] = version.SOLO_CHART_VERSION;
54+
argv[flags.force.name] = true;
55+
argv[flags.clusterSetupNamespace.name] = constants.SOLO_SETUP_NAMESPACE;
56+
57+
describe('ClusterCommand unit tests', () => {
58+
describe('Chart Install Function is called correctly', () => {
59+
let opts: any;
60+
61+
beforeEach(() => {
62+
opts = getBaseCommandOpts();
63+
opts.logger = new SoloLogger();
64+
opts.helm = new Helm(opts.logger);
65+
opts.helm.dependency = sinon.stub();
66+
opts.chartManager = new ChartManager(opts.helm, opts.logger);
67+
opts.chartManager.isChartInstalled = sinon.stub().returns(false);
68+
opts.chartManager.install = sinon.stub().returns(true);
69+
70+
opts.configManager = new ConfigManager(opts.logger);
71+
opts.remoteConfigManager = sinon.stub();
72+
});
73+
74+
it('Install function is called with expected parameters', async () => {
75+
const clusterCommand = new ClusterCommand(opts);
76+
await clusterCommand.setup(argv);
77+
78+
expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE);
79+
expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART);
80+
expect(opts.chartManager.install.args[0][2]).to.equal(
81+
constants.SOLO_TESTING_CHART_URL + '/' + constants.SOLO_CLUSTER_SETUP_CHART,
82+
);
83+
expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION);
84+
});
85+
86+
it('Should use local chart directory', async () => {
87+
argv[flags.chartDirectory.name] = 'test-directory';
88+
argv[flags.force.name] = true;
89+
90+
const clusterCommand = new ClusterCommand(opts);
91+
await clusterCommand.setup(argv);
92+
93+
expect(opts.chartManager.install.args[0][2]).to.equal(
94+
path.join(ROOT_DIR, 'test-directory', constants.SOLO_CLUSTER_SETUP_CHART),
95+
);
96+
});
97+
});
98+
});

0 commit comments

Comments
 (0)