Skip to content

Commit d6ca20e

Browse files
committed
Squashed commit of the following:
commit 5b3d68a Author: Lenin Mehedy <[email protected]> Date: Wed Feb 12 23:37:56 2025 +1100 feat: handle multiple contexts during network deploy (#1369) Signed-off-by: Lenin Mehedy <[email protected]> commit ea24bc4 Author: Jeromy Cannon <[email protected]> Date: Wed Feb 12 00:19:23 2025 +0000 more todos Signed-off-by: Jeromy Cannon <[email protected]> commit 71388dd Author: Jeromy Cannon <[email protected]> Date: Wed Feb 12 00:10:26 2025 +0000 pushing latest Signed-off-by: Jeromy Cannon <[email protected]> commit 209c2cd Author: Jeromy Cannon <[email protected]> Date: Tue Feb 11 21:53:15 2025 +0000 updated cluster ref flag description Signed-off-by: Jeromy Cannon <[email protected]> commit 1a0a337 Author: Jeromy Cannon <[email protected]> Date: Tue Feb 11 21:52:12 2025 +0000 renamed flag clusterName to clusterRef Signed-off-by: Jeromy Cannon <[email protected]> commit f4087bf Author: Jeromy Cannon <[email protected]> Date: Tue Feb 11 21:41:02 2025 +0000 saving progress Signed-off-by: Jeromy Cannon <[email protected]> commit 537fc1a Author: Jeromy Cannon <[email protected]> Date: Tue Feb 11 20:51:03 2025 +0000 set the networks deploy config with the contexts and the consensus nodes for later use Signed-off-by: Jeromy Cannon <[email protected]> commit e86e94c Author: Jeromy Cannon <[email protected]> Date: Tue Feb 11 20:07:53 2025 +0000 added base test for getContexts Signed-off-by: Jeromy Cannon <[email protected]> Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 8411ff3 commit d6ca20e

36 files changed

+625
-214
lines changed

src/commands/base.ts

Lines changed: 93 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import paths from 'path';
6+
import path from 'path';
67
import {MissingArgumentError, SoloError} from '../core/errors.js';
78
import {ShellRunner} from '../core/shell_runner.js';
89
import {type LeaseManager} from '../core/lease/lease_manager.js';
@@ -17,11 +18,12 @@ import {type Opts} from '../types/command_types.js';
1718
import {type CommandFlag} from '../types/flag_types.js';
1819
import {type Lease} from '../core/lease/lease.js';
1920
import {Listr} from 'listr2';
20-
import path from 'path';
2121
import * as constants from '../core/constants.js';
2222
import fs from 'fs';
2323
import {Task} from '../core/task.js';
2424
import {ConsensusNode} from '../core/model/consensus_node.js';
25+
import {type ClusterRef, type ClusterRefs} from '../core/config/remote/types.js';
26+
import {Flags} from './flags.js';
2527

2628
export interface CommandHandlers {
2729
parent: BaseCommand;
@@ -72,6 +74,7 @@ export abstract class BaseCommand extends ShellRunner {
7274
return `${chartRepo}/${chartReleaseName}`;
7375
}
7476

77+
// FIXME @Deprecated. Use prepareValuesFilesMap instead to support multi-cluster
7578
public prepareValuesFiles(valuesFile: string) {
7679
let valuesArg = '';
7780
if (valuesFile) {
@@ -85,6 +88,80 @@ export abstract class BaseCommand extends ShellRunner {
8588
return valuesArg;
8689
}
8790

91+
/**
92+
* Prepare the values files map for each cluster
93+
*
94+
* <p> Order of precedence:
95+
* <ol>
96+
* <li> Chart's default values file (if chartDirectory is set) </li>
97+
* <li> Profile values file </li>
98+
* <li> User's values file </li>
99+
* </ol>
100+
* @param contextRefs - the map of cluster references
101+
* @param valuesFileInput - the values file input string
102+
* @param chartDirectory - the chart directory
103+
* @param profileValuesFile - the profile values file
104+
*/
105+
static prepareValuesFilesMap(
106+
contextRefs: ClusterRefs,
107+
chartDirectory?: string,
108+
profileValuesFile?: string,
109+
valuesFileInput?: string,
110+
): Record<ClusterRef, string> {
111+
// initialize the map with an empty array for each cluster-ref
112+
const valuesFiles: Record<ClusterRef, string> = {};
113+
Object.entries(contextRefs).forEach(([clusterRef]) => {
114+
valuesFiles[clusterRef] = '';
115+
});
116+
117+
// add the chart's default values file for each cluster-ref if chartDirectory is set
118+
// this should be the first in the list of values files as it will be overridden by user's input
119+
if (chartDirectory) {
120+
const chartValuesFile = path.join(chartDirectory, 'solo-deployment', 'values.yaml');
121+
for (const clusterRef in valuesFiles) {
122+
valuesFiles[clusterRef] += ` --values ${chartValuesFile}`;
123+
}
124+
}
125+
126+
if (profileValuesFile) {
127+
const parsed = Flags.parseValuesFilesInput(profileValuesFile);
128+
Object.entries(parsed).forEach(([clusterRef, files]) => {
129+
let vf = '';
130+
files.forEach(file => {
131+
vf += ` --values ${file}`;
132+
});
133+
134+
if (clusterRef === Flags.KEY_COMMON) {
135+
Object.entries(valuesFiles).forEach(([cf]) => {
136+
valuesFiles[cf] += vf;
137+
});
138+
} else {
139+
valuesFiles[clusterRef] += vf;
140+
}
141+
});
142+
}
143+
144+
if (valuesFileInput) {
145+
const parsed = Flags.parseValuesFilesInput(valuesFileInput);
146+
Object.entries(parsed).forEach(([clusterRef, files]) => {
147+
let vf = '';
148+
files.forEach(file => {
149+
vf += ` --values ${file}`;
150+
});
151+
152+
if (clusterRef === Flags.KEY_COMMON) {
153+
Object.entries(valuesFiles).forEach(([clusterRef]) => {
154+
valuesFiles[clusterRef] += vf;
155+
});
156+
} else {
157+
valuesFiles[clusterRef] += vf;
158+
}
159+
});
160+
}
161+
162+
return valuesFiles;
163+
}
164+
88165
public getConfigManager(): ConfigManager {
89166
return this.configManager;
90167
}
@@ -104,6 +181,7 @@ export abstract class BaseCommand extends ShellRunner {
104181
// build the dynamic class that will keep track of which properties are used
105182
const NewConfigClass = class {
106183
private usedConfigs: Map<string, number>;
184+
107185
constructor() {
108186
// the map to keep track of which properties are used
109187
this.usedConfigs = new Map();
@@ -255,18 +333,20 @@ export abstract class BaseCommand extends ShellRunner {
255333
const consensusNodes: ConsensusNode[] = [];
256334

257335
// using the remoteConfigManager to get the consensus nodes
258-
Object.values(this.getRemoteConfigManager().components.consensusNodes).forEach(node => {
259-
consensusNodes.push(
260-
new ConsensusNode(
261-
node.name,
262-
node.nodeId,
263-
node.namespace,
264-
node.cluster,
265-
// use local config to get the context
266-
this.getLocalConfig().clusterRefs[node.cluster],
267-
),
268-
);
269-
});
336+
if (this.getRemoteConfigManager()?.components?.consensusNodes) {
337+
Object.values(this.getRemoteConfigManager().components.consensusNodes).forEach(node => {
338+
consensusNodes.push(
339+
new ConsensusNode(
340+
node.name,
341+
node.nodeId,
342+
node.namespace,
343+
node.cluster,
344+
// use local config to get the context
345+
this.getLocalConfig().clusterRefs[node.cluster],
346+
),
347+
);
348+
});
349+
}
270350

271351
// return the consensus nodes
272352
return consensusNodes;

src/commands/cluster/configs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const resetConfigBuilder = async function (argv, ctx, task) {
7272
this.parent.getConfigManager().update(argv);
7373

7474
ctx.config = {
75-
clusterName: this.parent.getConfigManager().getFlag(flags.clusterName) as string,
75+
clusterName: this.parent.getConfigManager().getFlag(flags.clusterRef) as string,
7676
clusterSetupNamespace: this.parent.getConfigManager().getFlag(flags.clusterSetupNamespace) as string,
7777
} as ClusterResetConfigClass;
7878

src/commands/cluster/flags.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const SETUP_FLAGS = {
1515
requiredFlagsWithDisabledPrompt: [],
1616
optionalFlags: [
1717
flags.chartDirectory,
18-
flags.clusterName,
18+
flags.clusterRef,
1919
flags.clusterSetupNamespace,
2020
flags.deployCertManager,
2121
flags.deployCertManagerCrds,
@@ -29,7 +29,7 @@ export const SETUP_FLAGS = {
2929
export const RESET_FLAGS = {
3030
requiredFlags: [],
3131
requiredFlagsWithDisabledPrompt: [],
32-
optionalFlags: [flags.clusterName, flags.clusterSetupNamespace, flags.force, flags.quiet],
32+
optionalFlags: [flags.clusterRef, flags.clusterSetupNamespace, flags.force, flags.quiet],
3333
};
3434

3535
export const CONNECT_FLAGS = {
@@ -39,7 +39,7 @@ export const CONNECT_FLAGS = {
3939
flags.devMode,
4040
flags.deployment,
4141
flags.quiet,
42-
flags.clusterName,
42+
flags.clusterRef,
4343
flags.context,
4444
flags.namespace,
4545
flags.userEmailAddress,

src/commands/cluster/tasks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export class ClusterCommandTasks {
266266
const configManager = this.parent.getConfigManager();
267267
const isQuiet = configManager.getFlag<boolean>(flags.quiet);
268268
const deploymentName: string = configManager.getFlag<DeploymentName>(flags.deployment);
269-
let clusters = splitFlagInput(configManager.getFlag<string>(flags.clusterName));
269+
let clusters = splitFlagInput(configManager.getFlag<string>(flags.clusterRef));
270270
const contexts = splitFlagInput(configManager.getFlag<string>(flags.context));
271271
const namespace = configManager.getFlag<NamespaceName>(flags.namespace);
272272
const localConfig = this.parent.getLocalConfig();
@@ -319,7 +319,7 @@ export class ClusterCommandTasks {
319319

320320
// Prompt user for clusters and contexts
321321
else {
322-
const promptedClusters = await flags.clusterName.prompt(task, '');
322+
const promptedClusters = await flags.clusterRef.prompt(task, '');
323323
clusters = splitFlagInput(promptedClusters);
324324

325325
for (const cluster of clusters) {

src/commands/deployment.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {type SoloListrTask} from '../types/index.js';
1616
import {type Opts} from '../types/command_types.js';
1717
import {ErrorMessages} from '../core/error_messages.js';
1818
import {splitFlagInput} from '../core/helpers.js';
19-
import {type NamespaceName} from '../core/kube/resources/namespace/namespace_name.js';
19+
import {NamespaceName} from '../core/kube/resources/namespace/namespace_name.js';
2020
import {type ClusterChecks} from '../core/cluster_checks.js';
2121
import {container} from 'tsyringe-neo';
2222
import {InjectTokens} from '../core/dependency_injection/inject_tokens.js';
@@ -35,18 +35,19 @@ export class DeploymentCommand extends BaseCommand {
3535
flags.quiet,
3636
flags.context,
3737
flags.namespace,
38-
flags.clusterName,
38+
flags.clusterRef,
3939
flags.userEmailAddress,
4040
flags.deployment,
4141
flags.deploymentClusters,
42+
flags.nodeAliasesUnparsed,
4243
];
4344
}
4445

4546
private static get LIST_DEPLOYMENTS_FLAGS_LIST(): CommandFlag[] {
46-
return [flags.quiet, flags.clusterName];
47+
return [flags.quiet, flags.clusterRef];
4748
}
4849

49-
private async create(argv: any): Promise<boolean> {
50+
public async create(argv: any): Promise<boolean> {
5051
const self = this;
5152

5253
interface Config {
@@ -57,6 +58,7 @@ export class DeploymentCommand extends BaseCommand {
5758
namespace: NamespaceName;
5859
deployment: DeploymentName;
5960
deploymentClusters: string[];
61+
nodeAliases: string[];
6062
}
6163

6264
interface Context {
@@ -82,6 +84,7 @@ export class DeploymentCommand extends BaseCommand {
8284
namespace: self.configManager.getFlag<NamespaceName>(flags.namespace),
8385
deployment: self.configManager.getFlag<DeploymentName>(flags.deployment),
8486
deploymentClusters: splitFlagInput(self.configManager.getFlag<string>(flags.deploymentClusters)),
87+
nodeAliases: splitFlagInput(self.configManager.getFlag<string>(flags.nodeAliasesUnparsed)),
8588
} as Config;
8689

8790
self.logger.debug('Prepared config', {config: ctx.config, cachedConfig: self.configManager.config});
@@ -93,7 +96,13 @@ export class DeploymentCommand extends BaseCommand {
9396
title: 'Add new deployment to local config',
9497
task: async (ctx, task) => {
9598
const {deployments} = this.localConfig;
96-
const {deployment, namespace, deploymentClusters} = ctx.config;
99+
const {deployment, namespace: configNamespace, deploymentClusters} = ctx.config;
100+
let namespace = configNamespace;
101+
if (!namespace?.name) {
102+
namespace = NamespaceName.of(deployment);
103+
ctx.config.namespace = namespace;
104+
this.configManager.setFlag(flags.namespace, namespace);
105+
}
97106
deployments[deployment] = {
98107
namespace: namespace.name,
99108
clusters: deploymentClusters,
@@ -183,10 +192,10 @@ export class DeploymentCommand extends BaseCommand {
183192
self.configManager.update(argv);
184193
self.logger.debug('Updated config with argv', {config: self.configManager.config});
185194

186-
await self.configManager.executePrompt(task, [flags.clusterName]);
195+
await self.configManager.executePrompt(task, [flags.clusterRef]);
187196

188197
ctx.config = {
189-
clusterName: self.configManager.getFlag<ClusterRef>(flags.clusterName),
198+
clusterName: self.configManager.getFlag<ClusterRef>(flags.clusterRef),
190199
} as Config;
191200

192201
self.logger.debug('Prepared config', {config: ctx.config, cachedConfig: self.configManager.config});

0 commit comments

Comments
 (0)