Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 40f5cc4
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 23:00:17 2025 +0000

    added dns templating for fully qualified domain name

    Signed-off-by: Jeromy Cannon <[email protected]>

commit 929fdaa
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 19:10:33 2025 +0000

    got further into node add

    Signed-off-by: Jeromy Cannon <[email protected]>

commit b9f6d10
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 17:24:29 2025 +0000

    removed final todo for network deploy

    Signed-off-by: Jeromy Cannon <[email protected]>

commit 03ad78f
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 16:55:15 2025 +0000

    removed todo in addNodesAndProxies

    Signed-off-by: Jeromy Cannon <[email protected]>

commit 54cc58f
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 16:42:13 2025 +0000

    removed todo in title: 'Check auxiliary pods are ready'

    Signed-off-by: Jeromy Cannon <[email protected]>

commit e060218
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 16:38:09 2025 +0000

    removed todo in title: 'Check proxy pods are running', envoy proxy

    Signed-off-by: Jeromy Cannon <[email protected]>

commit 9b43649
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 16:36:45 2025 +0000

    removed todo in title: 'Check proxy pods are running'

    Signed-off-by: Jeromy Cannon <[email protected]>

commit d08a239
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 16:28:25 2025 +0000

    removed todo in           title: 'Check node pods are running',

    Signed-off-by: Jeromy Cannon <[email protected]>

commit 075051d
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 16:25:16 2025 +0000

    removed todo in           title: 'Check if cluster setup chart is installed',

    Signed-off-by: Jeromy Cannon <[email protected]>

commit ad56068
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 16:10:16 2025 +0000

    fixed minor issue

    Signed-off-by: Jeromy Cannon <[email protected]>

commit 310a1cb
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 15:36:06 2025 +0000

    patched NetworkCommand to work for test cases

    Signed-off-by: Jeromy Cannon <[email protected]>

commit 98ba704
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 14:40:42 2025 +0000

    fixed keysConfigBuilder

    Signed-off-by: Jeromy Cannon <[email protected]>

commit 04dce8d
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 14:34:45 2025 +0000

    fixed import error

    Signed-off-by: Jeromy Cannon <[email protected]>

commit d15efd7
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 14:34:23 2025 +0000

    fixed unit test cases

    Signed-off-by: Jeromy Cannon <[email protected]>

commit 40200a7
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 13:26:24 2025 +0000

    fixed some unit test cases

    Signed-off-by: Jeromy Cannon <[email protected]>

commit d6ca20e
Author: Jeromy Cannon <[email protected]>
Date:   Wed Feb 12 12:38:54 2025 +0000

    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]>

Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon committed Feb 12, 2025
1 parent 8411ff3 commit ab64862
Show file tree
Hide file tree
Showing 46 changed files with 972 additions and 357 deletions.
138 changes: 126 additions & 12 deletions src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import * as constants from '../core/constants.js';
import fs from 'fs';
import {Task} from '../core/task.js';
import {ConsensusNode} from '../core/model/consensus_node.js';
import {type ClusterRef, type ClusterRefs} from '../core/config/remote/types.js';
import {Flags} from './flags.js';
import {type Cluster} from '../core/config/remote/cluster.js';
import {Templates} from '../core/templates.js';

export interface CommandHandlers {
parent: BaseCommand;
Expand Down Expand Up @@ -72,6 +76,7 @@ export abstract class BaseCommand extends ShellRunner {
return `${chartRepo}/${chartReleaseName}`;
}

// FIXME @Deprecated. Use prepareValuesFilesMap instead to support multi-cluster
public prepareValuesFiles(valuesFile: string) {
let valuesArg = '';
if (valuesFile) {
Expand All @@ -85,6 +90,87 @@ export abstract class BaseCommand extends ShellRunner {
return valuesArg;
}

/**
* Prepare the values files map for each cluster
*
* <p> Order of precedence:
* <ol>
* <li> Chart's default values file (if chartDirectory is set) </li>
* <li> Profile values file </li>
* <li> User's values file </li>
* </ol>
* @param clusterRefs - the map of cluster references
* @param valuesFileInput - the values file input string
* @param chartDirectory - the chart directory
* @param profileValuesFile - the profile values file
*/
static prepareValuesFilesMap(
clusterRefs: ClusterRefs,
chartDirectory?: string,
profileValuesFile?: string,
valuesFileInput?: string,
): Record<ClusterRef, string> {
// initialize the map with an empty array for each cluster-ref
const valuesFiles: Record<ClusterRef, string> = {
[Flags.KEY_COMMON]: '',
};
Object.keys(clusterRefs).forEach(clusterRef => {
valuesFiles[clusterRef] = '';
});

// add the chart's default values file for each cluster-ref if chartDirectory is set
// this should be the first in the list of values files as it will be overridden by user's input
if (chartDirectory) {
const chartValuesFile = path.join(chartDirectory, 'solo-deployment', 'values.yaml');
for (const clusterRef in valuesFiles) {
valuesFiles[clusterRef] += ` --values ${chartValuesFile}`;
}
}

if (profileValuesFile) {
const parsed = Flags.parseValuesFilesInput(profileValuesFile);
Object.entries(parsed).forEach(([clusterRef, files]) => {
let vf = '';
files.forEach(file => {
vf += ` --values ${file}`;
});

if (clusterRef === Flags.KEY_COMMON) {
Object.entries(valuesFiles).forEach(([cf]) => {
valuesFiles[cf] += vf;
});
} else {
valuesFiles[clusterRef] += vf;
}
});
}

if (valuesFileInput) {
const parsed = Flags.parseValuesFilesInput(valuesFileInput);
Object.entries(parsed).forEach(([clusterRef, files]) => {
let vf = '';
files.forEach(file => {
vf += ` --values ${file}`;
});

if (clusterRef === Flags.KEY_COMMON) {
Object.entries(valuesFiles).forEach(([clusterRef]) => {
valuesFiles[clusterRef] += vf;
});
} else {
valuesFiles[clusterRef] += vf;
}
});
}

if (Object.keys(valuesFiles).length > 1) {
// delete the common key if there is another cluster to use
delete valuesFiles[Flags.KEY_COMMON];
}

return valuesFiles;
}

public getConfigManager(): ConfigManager {
return this.configManager;
}
Expand All @@ -104,6 +190,7 @@ export abstract class BaseCommand extends ShellRunner {
// build the dynamic class that will keep track of which properties are used
const NewConfigClass = class {
private usedConfigs: Map<string, number>;

constructor() {
// the map to keep track of which properties are used
this.usedConfigs = new Map();
Expand Down Expand Up @@ -253,20 +340,33 @@ export abstract class BaseCommand extends ShellRunner {
*/
public getConsensusNodes(): ConsensusNode[] {
const consensusNodes: ConsensusNode[] = [];
const clusters: Record<ClusterRef, Cluster> = this.getRemoteConfigManager().clusters;

// using the remoteConfigManager to get the consensus nodes
Object.values(this.getRemoteConfigManager().components.consensusNodes).forEach(node => {
consensusNodes.push(
new ConsensusNode(
node.name,
node.nodeId,
node.namespace,
node.cluster,
// use local config to get the context
this.getLocalConfig().clusterRefs[node.cluster],
),
);
});
if (this.getRemoteConfigManager()?.components?.consensusNodes) {
Object.values(this.getRemoteConfigManager().components.consensusNodes).forEach(node => {
consensusNodes.push(
new ConsensusNode(
node.name,
node.nodeId,
node.namespace,
node.cluster,
// use local config to get the context
this.getLocalConfig().clusterRefs[node.cluster],
clusters[node.cluster].dnsBaseDomain,
clusters[node.cluster].dnsConsensusNodePattern,
Templates.renderConsensusNodeFullyQualifiedDomainName(
node.name,
node.nodeId,
node.namespace,
node.cluster,
clusters[node.cluster].dnsBaseDomain,
clusters[node.cluster].dnsConsensusNodePattern,
),
),
);
});
}

// return the consensus nodes
return consensusNodes;
Expand All @@ -285,4 +385,18 @@ export abstract class BaseCommand extends ShellRunner {
});
return contexts;
}

/**
* Gets a list of distinct cluster references from the consensus nodes
* @returns an object of cluster references
*/
public getClusterRefs(): ClusterRefs {
const clustersRefs: ClusterRefs = {};
this.getConsensusNodes().forEach(node => {
if (!Object.keys(clustersRefs).includes(node.cluster)) {
clustersRefs[node.cluster] = node.context;
}
});
return clustersRefs;
}
}
2 changes: 1 addition & 1 deletion src/commands/cluster/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const resetConfigBuilder = async function (argv, ctx, task) {
this.parent.getConfigManager().update(argv);

ctx.config = {
clusterName: this.parent.getConfigManager().getFlag(flags.clusterName) as string,
clusterName: this.parent.getConfigManager().getFlag(flags.clusterRef) as string,
clusterSetupNamespace: this.parent.getConfigManager().getFlag(flags.clusterSetupNamespace) as string,
} as ClusterResetConfigClass;

Expand Down
6 changes: 3 additions & 3 deletions src/commands/cluster/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const SETUP_FLAGS = {
requiredFlagsWithDisabledPrompt: [],
optionalFlags: [
flags.chartDirectory,
flags.clusterName,
flags.clusterRef,
flags.clusterSetupNamespace,
flags.deployCertManager,
flags.deployCertManagerCrds,
Expand All @@ -29,7 +29,7 @@ export const SETUP_FLAGS = {
export const RESET_FLAGS = {
requiredFlags: [],
requiredFlagsWithDisabledPrompt: [],
optionalFlags: [flags.clusterName, flags.clusterSetupNamespace, flags.force, flags.quiet],
optionalFlags: [flags.clusterRef, flags.clusterSetupNamespace, flags.force, flags.quiet],
};

export const CONNECT_FLAGS = {
Expand All @@ -39,7 +39,7 @@ export const CONNECT_FLAGS = {
flags.devMode,
flags.deployment,
flags.quiet,
flags.clusterName,
flags.clusterRef,
flags.context,
flags.namespace,
flags.userEmailAddress,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/cluster/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class ClusterCommandTasks {
const configManager = this.parent.getConfigManager();
const isQuiet = configManager.getFlag<boolean>(flags.quiet);
const deploymentName: string = configManager.getFlag<DeploymentName>(flags.deployment);
let clusters = splitFlagInput(configManager.getFlag<string>(flags.clusterName));
let clusters = splitFlagInput(configManager.getFlag<string>(flags.clusterRef));
const contexts = splitFlagInput(configManager.getFlag<string>(flags.context));
const namespace = configManager.getFlag<NamespaceName>(flags.namespace);
const localConfig = this.parent.getLocalConfig();
Expand Down Expand Up @@ -319,7 +319,7 @@ export class ClusterCommandTasks {

// Prompt user for clusters and contexts
else {
const promptedClusters = await flags.clusterName.prompt(task, '');
const promptedClusters = await flags.clusterRef.prompt(task, '');
clusters = splitFlagInput(promptedClusters);

for (const cluster of clusters) {
Expand Down
23 changes: 16 additions & 7 deletions src/commands/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {type SoloListrTask} from '../types/index.js';
import {type Opts} from '../types/command_types.js';
import {ErrorMessages} from '../core/error_messages.js';
import {splitFlagInput} from '../core/helpers.js';
import {type NamespaceName} from '../core/kube/resources/namespace/namespace_name.js';
import {NamespaceName} from '../core/kube/resources/namespace/namespace_name.js';
import {type ClusterChecks} from '../core/cluster_checks.js';
import {container} from 'tsyringe-neo';
import {InjectTokens} from '../core/dependency_injection/inject_tokens.js';
Expand All @@ -35,18 +35,19 @@ export class DeploymentCommand extends BaseCommand {
flags.quiet,
flags.context,
flags.namespace,
flags.clusterName,
flags.clusterRef,
flags.userEmailAddress,
flags.deployment,
flags.deploymentClusters,
flags.nodeAliasesUnparsed,
];
}

private static get LIST_DEPLOYMENTS_FLAGS_LIST(): CommandFlag[] {
return [flags.quiet, flags.clusterName];
return [flags.quiet, flags.clusterRef];
}

private async create(argv: any): Promise<boolean> {
public async create(argv: any): Promise<boolean> {
const self = this;

interface Config {
Expand All @@ -57,6 +58,7 @@ export class DeploymentCommand extends BaseCommand {
namespace: NamespaceName;
deployment: DeploymentName;
deploymentClusters: string[];
nodeAliases: string[];
}

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

self.logger.debug('Prepared config', {config: ctx.config, cachedConfig: self.configManager.config});
Expand All @@ -93,7 +96,13 @@ export class DeploymentCommand extends BaseCommand {
title: 'Add new deployment to local config',
task: async (ctx, task) => {
const {deployments} = this.localConfig;
const {deployment, namespace, deploymentClusters} = ctx.config;
const {deployment, namespace: configNamespace, deploymentClusters} = ctx.config;
let namespace = configNamespace;
if (!namespace?.name) {
namespace = NamespaceName.of(deployment);
ctx.config.namespace = namespace;
this.configManager.setFlag(flags.namespace, namespace);
}
deployments[deployment] = {
namespace: namespace.name,
clusters: deploymentClusters,
Expand Down Expand Up @@ -183,10 +192,10 @@ export class DeploymentCommand extends BaseCommand {
self.configManager.update(argv);
self.logger.debug('Updated config with argv', {config: self.configManager.config});

await self.configManager.executePrompt(task, [flags.clusterName]);
await self.configManager.executePrompt(task, [flags.clusterRef]);

ctx.config = {
clusterName: self.configManager.getFlag<ClusterRef>(flags.clusterName),
clusterName: self.configManager.getFlag<ClusterRef>(flags.clusterRef),
} as Config;

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

0 comments on commit ab64862

Please sign in to comment.