Skip to content

Commit 40f5cc4

Browse files
committed
added dns templating for fully qualified domain name
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 929fdaa commit 40f5cc4

File tree

13 files changed

+178
-47
lines changed

13 files changed

+178
-47
lines changed

src/commands/base.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {Task} from '../core/task.js';
2424
import {ConsensusNode} from '../core/model/consensus_node.js';
2525
import {type ClusterRef, type ClusterRefs} from '../core/config/remote/types.js';
2626
import {Flags} from './flags.js';
27+
import {type Cluster} from '../core/config/remote/cluster.js';
28+
import {Templates} from '../core/templates.js';
2729

2830
export interface CommandHandlers {
2931
parent: BaseCommand;
@@ -338,6 +340,7 @@ export abstract class BaseCommand extends ShellRunner {
338340
*/
339341
public getConsensusNodes(): ConsensusNode[] {
340342
const consensusNodes: ConsensusNode[] = [];
343+
const clusters: Record<ClusterRef, Cluster> = this.getRemoteConfigManager().clusters;
341344

342345
// using the remoteConfigManager to get the consensus nodes
343346
if (this.getRemoteConfigManager()?.components?.consensusNodes) {
@@ -350,6 +353,16 @@ export abstract class BaseCommand extends ShellRunner {
350353
node.cluster,
351354
// use local config to get the context
352355
this.getLocalConfig().clusterRefs[node.cluster],
356+
clusters[node.cluster].dnsBaseDomain,
357+
clusters[node.cluster].dnsConsensusNodePattern,
358+
Templates.renderConsensusNodeFullyQualifiedDomainName(
359+
node.name,
360+
node.nodeId,
361+
node.namespace,
362+
node.cluster,
363+
clusters[node.cluster].dnsBaseDomain,
364+
clusters[node.cluster].dnsConsensusNodePattern,
365+
),
353366
),
354367
);
355368
});

src/commands/network.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,14 @@ export class NetworkCommand extends BaseCommand {
293293
googleCredential: string;
294294
loadBalancerEnabled: boolean;
295295
clusterRefs: ClusterRefs;
296+
consensusNodes: ConsensusNode[];
296297
}): Promise<Record<ClusterRef, string>> {
297298
const valuesArg = this.prepareValuesArg(config);
298299

299300
// prepare values files for each cluster
300301
const valuesArgMap: Record<ClusterRef, string> = {};
301302
const profileName = this.configManager.getFlag<string>(flags.profileName) as string;
302-
this.profileValuesFile = await this.profileManager.prepareValuesForSoloChart(profileName);
303+
this.profileValuesFile = await this.profileManager.prepareValuesForSoloChart(profileName, config.consensusNodes);
303304
const valuesFiles: Record<ClusterRef, string> = BaseCommand.prepareValuesFilesMap(
304305
config.clusterRefs,
305306
config.chartDirectory,

src/commands/node/configs.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {type NodeAddConfigClass} from './node_add_config.js';
1818
import {type NamespaceName} from '../../core/kube/resources/namespace/namespace_name.js';
1919
import {type PodRef} from '../../core/kube/resources/pod/pod_ref.js';
2020
import {type K8Factory} from '../../core/kube/k8_factory.js';
21+
import {type ConsensusNode} from '../../core/model/consensus_node.js';
2122

2223
export const PREPARE_UPGRADE_CONFIGS_NAME = 'prepareUpgradeConfig';
2324
export const DOWNLOAD_GENERATED_FILES_CONFIGS_NAME = 'downloadGeneratedFilesConfig';
@@ -56,6 +57,8 @@ export const prepareUpgradeConfigBuilder = async function (argv, ctx, task) {
5657
'nodeClient',
5758
'freezeAdminPrivateKey',
5859
'namespace',
60+
'consensusNodes',
61+
'contexts',
5962
]) as NodePrepareUpgradeConfigClass;
6063

6164
config.namespace = await resolveNamespaceFromDeployment(this.parent.localConfig, this.configManager, task);
@@ -75,6 +78,8 @@ export const downloadGeneratedFilesConfigBuilder = async function (argv, ctx, ta
7578
'existingNodeAliases',
7679
'serviceMap',
7780
'namespace',
81+
'consensusNodes',
82+
'contexts',
7883
]) as NodeDownloadGeneratedFilesConfigClass;
7984

8085
config.namespace = await resolveNamespaceFromDeployment(this.parent.localConfig, this.configManager, task);
@@ -94,6 +99,8 @@ export const upgradeConfigBuilder = async function (argv, ctx, task, shouldLoadN
9499
'stagingDir',
95100
'stagingKeysDir',
96101
'namespace',
102+
'consensusNodes',
103+
'contexts',
97104
]) as NodeUpgradeConfigClass;
98105

99106
config.namespace = await resolveNamespaceFromDeployment(this.parent.localConfig, this.configManager, task);
@@ -133,6 +140,8 @@ export const updateConfigBuilder = async function (argv, ctx, task, shouldLoadNo
133140
'stagingKeysDir',
134141
'treasuryKey',
135142
'namespace',
143+
'consensusNodes',
144+
'contexts',
136145
]) as NodeUpdateConfigClass;
137146

138147
config.namespace = await resolveNamespaceFromDeployment(this.parent.localConfig, this.configManager, task);
@@ -178,6 +187,8 @@ export const deleteConfigBuilder = async function (argv, ctx, task, shouldLoadNo
178187
'stagingKeysDir',
179188
'treasuryKey',
180189
'namespace',
190+
'consensusNodes',
191+
'contexts',
181192
]) as NodeDeleteConfigClass;
182193

183194
config.curDate = new Date();
@@ -226,6 +237,7 @@ export const addConfigBuilder = async function (argv, ctx, task, shouldLoadNodeC
226237
'treasuryKey',
227238
'namespace',
228239
'consensusNodes',
240+
'contexts',
229241
]) as NodeAddConfigClass;
230242

231243
ctx.adminKey = argv[flags.adminKey.name]
@@ -271,6 +283,8 @@ export const logsConfigBuilder = async function (argv, ctx, task) {
271283
nodeAliases: helpers.parseNodeAliases(this.configManager.getFlag(flags.nodeAliasesUnparsed)),
272284
nodeAliasesUnparsed: this.configManager.getFlag(flags.nodeAliasesUnparsed),
273285
deployment: this.configManager.getFlag(flags.deployment),
286+
consensusNodes: this.parent.getConsensusNodes(),
287+
contexts: this.parent.getContexts(),
274288
} as NodeLogsConfigClass;
275289
ctx.config = config;
276290
return config;
@@ -282,6 +296,8 @@ export const statesConfigBuilder = async function (argv, ctx, task) {
282296
nodeAliases: helpers.parseNodeAliases(this.configManager.getFlag(flags.nodeAliasesUnparsed)),
283297
nodeAliasesUnparsed: this.configManager.getFlag(flags.nodeAliasesUnparsed),
284298
deployment: this.configManager.getFlag(flags.deployment),
299+
consensusNodes: this.parent.getConsensusNodes(),
300+
contexts: this.parent.getContexts(),
285301
};
286302
ctx.config = config;
287303
return config;
@@ -292,6 +308,8 @@ export const refreshConfigBuilder = async function (argv, ctx, task) {
292308
'nodeAliases',
293309
'podRefs',
294310
'namespace',
311+
'consensusNodes',
312+
'contexts',
295313
]) as NodeRefreshConfigClass;
296314

297315
ctx.config.namespace = await resolveNamespaceFromDeployment(this.parent.localConfig, this.configManager, task);
@@ -307,6 +325,8 @@ export const keysConfigBuilder = function (argv, ctx, task) {
307325
'curDate',
308326
'keysDir',
309327
'nodeAliases',
328+
'consensusNodes',
329+
'contexts',
310330
]) as NodeKeysConfigClass;
311331

312332
config.curDate = new Date();
@@ -333,6 +353,8 @@ export const stopConfigBuilder = async function (argv, ctx, task) {
333353
nodeAliases: helpers.parseNodeAliases(this.configManager.getFlag(flags.nodeAliasesUnparsed)),
334354
nodeAliasesUnparsed: this.configManager.getFlag(flags.nodeAliasesUnparsed),
335355
deployment: this.configManager.getFlag(flags.deployment),
356+
consensusNodes: this.parent.getConsensusNodes(),
357+
contexts: this.parent.getContexts(),
336358
};
337359

338360
if (!(await this.k8Factory.default().namespaces().has(ctx.config.namespace))) {
@@ -343,7 +365,12 @@ export const stopConfigBuilder = async function (argv, ctx, task) {
343365
};
344366

345367
export const startConfigBuilder = async function (argv, ctx, task) {
346-
const config = this.getConfig(START_CONFIGS_NAME, argv.flags, ['nodeAliases', 'namespace']) as NodeStartConfigClass;
368+
const config = this.getConfig(START_CONFIGS_NAME, argv.flags, [
369+
'nodeAliases',
370+
'namespace',
371+
'consensusNodes',
372+
'contexts',
373+
]) as NodeStartConfigClass;
347374
config.namespace = await resolveNamespaceFromDeployment(this.parent.localConfig, this.configManager, task);
348375

349376
if (!(await this.k8Factory.default().namespaces().has(config.namespace))) {
@@ -360,6 +387,8 @@ export const setupConfigBuilder = async function (argv, ctx, task) {
360387
'nodeAliases',
361388
'podRefs',
362389
'namespace',
390+
'consensusNodes',
391+
'contexts',
363392
]) as NodeSetupConfigClass;
364393

365394
config.namespace = await resolveNamespaceFromDeployment(this.parent.localConfig, this.configManager, task);
@@ -377,6 +406,8 @@ export interface NodeLogsConfigClass {
377406
namespace: NamespaceName;
378407
deployment: string;
379408
nodeAliases: string[];
409+
consensusNodes: ConsensusNode[];
410+
contexts: string[];
380411
}
381412

382413
export interface NodeRefreshConfigClass {
@@ -391,6 +422,8 @@ export interface NodeRefreshConfigClass {
391422
nodeAliases: NodeAliases;
392423
podRefs: Record<NodeAlias, PodRef>;
393424
getUnusedConfigs: () => string[];
425+
consensusNodes: ConsensusNode[];
426+
contexts: string[];
394427
}
395428

396429
export interface NodeKeysConfigClass {
@@ -403,6 +436,8 @@ export interface NodeKeysConfigClass {
403436
keysDir: string;
404437
nodeAliases: NodeAliases;
405438
getUnusedConfigs: () => string[];
439+
consensusNodes: ConsensusNode[];
440+
contexts: string[];
406441
}
407442

408443
export interface NodeStartConfigClass {
@@ -415,6 +450,8 @@ export interface NodeStartConfigClass {
415450
stagingDir: string;
416451
podRefs: Record<NodeAlias, PodRef>;
417452
nodeAliasesUnparsed: string;
453+
consensusNodes: ConsensusNode[];
454+
contexts: string[];
418455
}
419456

420457
export interface NodeDeleteConfigClass {
@@ -444,6 +481,8 @@ export interface NodeDeleteConfigClass {
444481
treasuryKey: PrivateKey;
445482
getUnusedConfigs: () => string[];
446483
curDate: Date;
484+
consensusNodes: ConsensusNode[];
485+
contexts: string[];
447486
}
448487

449488
export interface NodeSetupConfigClass {
@@ -460,6 +499,8 @@ export interface NodeSetupConfigClass {
460499
nodeAliases: NodeAliases;
461500
podRefs: Record<NodeAlias, PodRef>;
462501
getUnusedConfigs: () => string[];
502+
consensusNodes: ConsensusNode[];
503+
contexts: string[];
463504
}
464505

465506
export interface NodeUpgradeConfigClass {
@@ -488,6 +529,8 @@ export interface NodeUpgradeConfigClass {
488529
treasuryKey: PrivateKey;
489530
getUnusedConfigs: () => string[];
490531
curDate: Date;
532+
consensusNodes: ConsensusNode[];
533+
contexts: string[];
491534
}
492535

493536
export interface NodeUpdateConfigClass {
@@ -525,6 +568,8 @@ export interface NodeUpdateConfigClass {
525568
treasuryKey: PrivateKey;
526569
getUnusedConfigs: () => string[];
527570
curDate: Date;
571+
consensusNodes: ConsensusNode[];
572+
contexts: string[];
528573
}
529574

530575
interface NodePrepareUpgradeConfigClass {
@@ -535,6 +580,8 @@ interface NodePrepareUpgradeConfigClass {
535580
freezeAdminPrivateKey: string;
536581
nodeClient: any;
537582
getUnusedConfigs: () => string[];
583+
consensusNodes: ConsensusNode[];
584+
contexts: string[];
538585
}
539586

540587
interface NodeDownloadGeneratedFilesConfigClass {
@@ -548,4 +595,6 @@ interface NodeDownloadGeneratedFilesConfigClass {
548595
existingNodeAliases: NodeAliases[];
549596
allNodeAliases: NodeAliases[];
550597
serviceMap: Map<string, NetworkNodeServices>;
598+
consensusNodes: ConsensusNode[];
599+
contexts: string[];
551600
}

src/commands/node/tasks.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import {ContainerRef} from '../../core/kube/resources/container/container_ref.js
6868
import {NetworkNodes} from '../../core/network_nodes.js';
6969
import {container} from 'tsyringe-neo';
7070
import * as helpers from '../../core/helpers.js';
71+
import {type ConsensusNode} from '../../core/model/consensus_node.js';
7172

7273
export class NodeCommandTasks {
7374
private readonly accountManager: AccountManager;
@@ -108,6 +109,8 @@ export class NodeCommandTasks {
108109
throw new IllegalArgumentError('An instance of ProfileManager is required', opts.profileManager);
109110
if (!opts || !opts.certificateManager)
110111
throw new IllegalArgumentError('An instance of CertificateManager is required', opts.certificateManager);
112+
if (!opts || !opts.parent)
113+
throw new IllegalArgumentError('An instance of parents as BaseCommand is required', opts.parent);
111114

112115
this.accountManager = opts.accountManager;
113116
this.configManager = opts.configManager;
@@ -120,6 +123,7 @@ export class NodeCommandTasks {
120123
this.chartManager = opts.chartManager;
121124
this.certificateManager = opts.certificateManager;
122125
this.prepareValuesFiles = opts.parent.prepareValuesFiles.bind(opts.parent);
126+
this.parent = opts.parent;
123127
}
124128

125129
private async _prepareUpgradeZip(stagingDir: string) {
@@ -947,7 +951,7 @@ export class NodeCommandTasks {
947951
if (isGenesis) {
948952
await this.generateGenesisNetworkJson(
949953
ctx.config.namespace,
950-
ctx.config.nodeAliases,
954+
ctx.config.consensusNodes,
951955
ctx.config.keysDir,
952956
ctx.config.stagingDir,
953957
);
@@ -985,21 +989,21 @@ export class NodeCommandTasks {
985989
* Generate genesis network json file
986990
* @private
987991
* @param namespace - namespace
988-
* @param nodeAliases - node aliases
992+
* @param consensusNodes - consensus nodes
989993
* @param keysDir - keys directory
990994
* @param stagingDir - staging directory
991995
*/
992996
private async generateGenesisNetworkJson(
993997
namespace: NamespaceName,
994-
nodeAliases: NodeAliases,
998+
consensusNodes: ConsensusNode[],
995999
keysDir: string,
9961000
stagingDir: string,
9971001
) {
9981002
const networkNodeServiceMap = await this.accountManager.getNodeServiceMap(namespace);
9991003

10001004
const adminPublicKeys = splitFlagInput(this.configManager.getFlag(flags.adminPublicKeys));
10011005
const genesisNetworkData = await GenesisNetworkDataConstructor.initialize(
1002-
nodeAliases,
1006+
consensusNodes,
10031007
this.keyManager,
10041008
this.accountManager,
10051009
keysDir,
@@ -1822,6 +1826,8 @@ export class NodeCommandTasks {
18221826

18231827
const config = await configInit(argv, ctx, task, shouldLoadNodeClient);
18241828
ctx.config = config;
1829+
config.consensusNodes = this.parent.getConsensusNodes();
1830+
config.contexts = this.parent.getContexts();
18251831

18261832
for (const flag of allRequiredFlags) {
18271833
if (typeof config[flag.constName] === 'undefined') {

src/core/config/remote/remote_config_manager.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ export class RemoteConfigManager {
6767
return this.remoteConfig?.components?.clone();
6868
}
6969

70+
/**
71+
* @returns the remote configuration data's clusters cloned
72+
*/
73+
public get clusters(): Record<ClusterRef, Cluster> {
74+
return Object.assign({}, this.remoteConfig?.clusters);
75+
}
76+
7077
/* ---------- Readers and Modifiers ---------- */
7178

7279
/**

0 commit comments

Comments
 (0)