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

refactor: add k8.PodRef class and implement it across the codebase #1290

Merged
merged 5 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as path from 'node:path';
import {type Optional, type SoloListrTask} from '../types/index.js';
import * as Base64 from 'js-base64';
import {type NamespaceName} from '../core/kube/namespace_name.js';
import {PodRef} from '../core/kube/pod_ref.js';

interface MirrorNodeDeployConfigClass {
chartDirectory: string;
Expand Down Expand Up @@ -357,8 +358,9 @@ export class MirrorNodeCommand extends BaseCommand {
}
const postgresPodName = PodName.of(pods[0].metadata.name);
const postgresContainerName = 'postgresql';
const postgresPodRef = PodRef.of(namespace, postgresPodName);
const mirrorEnvVars = await self.k8.execContainer(
postgresPodName,
postgresPodRef,
postgresContainerName,
'/bin/bash -c printenv',
);
Expand All @@ -376,7 +378,7 @@ export class MirrorNodeCommand extends BaseCommand {
'HEDERA_MIRROR_IMPORTER_DB_NAME',
);

await self.k8.execContainer(postgresPodName, postgresContainerName, [
await self.k8.execContainer(postgresPodRef, postgresContainerName, [
'psql',
`postgresql://${HEDERA_MIRROR_IMPORTER_DB_OWNER}:${HEDERA_MIRROR_IMPORTER_DB_OWNERPASSWORD}@localhost:5432/${HEDERA_MIRROR_IMPORTER_DB_NAME}`,
'-c',
Expand Down
31 changes: 13 additions & 18 deletions src/commands/node/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {type PodName} from '../../core/kube/pod_name.js';
import {type NetworkNodeServices} from '../../core/network_node_services.js';
import {type NodeAddConfigClass} from './node_add_config.js';
import {type NamespaceName} from '../../core/kube/namespace_name.js';
import {type PodRef} from '../../core/kube/pod_ref.js';

export const PREPARE_UPGRADE_CONFIGS_NAME = 'prepareUpgradeConfig';
export const DOWNLOAD_GENERATED_FILES_CONFIGS_NAME = 'downloadGeneratedFilesConfig';
Expand Down Expand Up @@ -83,7 +84,7 @@ export const upgradeConfigBuilder = async function (argv, ctx, task, shouldLoadN
'existingNodeAliases',
'keysDir',
'nodeClient',
'podNames',
'podRefs',
'stagingDir',
'stagingKeysDir',
]) as NodeUpgradeConfigClass;
Expand Down Expand Up @@ -118,7 +119,7 @@ export const updateConfigBuilder = async function (argv, ctx, task, shouldLoadNo
'freezeAdminPrivateKey',
'keysDir',
'nodeClient',
'podNames',
'podRefs',
'serviceMap',
'stagingDir',
'stagingKeysDir',
Expand Down Expand Up @@ -161,7 +162,7 @@ export const deleteConfigBuilder = async function (argv, ctx, task, shouldLoadNo
'freezeAdminPrivateKey',
'keysDir',
'nodeClient',
'podNames',
'podRefs',
'serviceMap',
'stagingDir',
'stagingKeysDir',
Expand Down Expand Up @@ -206,7 +207,7 @@ export const addConfigBuilder = async function (argv, ctx, task, shouldLoadNodeC
'keysDir',
'lastStateZipPath',
'nodeClient',
'podNames',
'podRefs',
'serviceMap',
'stagingDir',
'stagingKeysDir',
Expand Down Expand Up @@ -269,7 +270,7 @@ export const statesConfigBuilder = function (argv, ctx, task) {
};

export const refreshConfigBuilder = async function (argv, ctx, task) {
ctx.config = this.getConfig(REFRESH_CONFIGS_NAME, argv.flags, ['nodeAliases', 'podNames']) as NodeRefreshConfigClass;
ctx.config = this.getConfig(REFRESH_CONFIGS_NAME, argv.flags, ['nodeAliases', 'podRefs']) as NodeRefreshConfigClass;

ctx.config.nodeAliases = helpers.parseNodeAliases(ctx.config.nodeAliasesUnparsed);

Expand Down Expand Up @@ -323,7 +324,7 @@ export const startConfigBuilder = async function (argv, ctx, task) {
};

export const setupConfigBuilder = async function (argv, ctx, task) {
const config = this.getConfig(SETUP_CONFIGS_NAME, argv.flags, ['nodeAliases', 'podNames']) as NodeSetupConfigClass;
const config = this.getConfig(SETUP_CONFIGS_NAME, argv.flags, ['nodeAliases', 'podRefs']) as NodeSetupConfigClass;

config.nodeAliases = helpers.parseNodeAliases(config.nodeAliasesUnparsed);

Expand All @@ -349,7 +350,7 @@ export interface NodeRefreshConfigClass {
nodeAliasesUnparsed: string;
releaseTag: string;
nodeAliases: NodeAliases;
podNames: Record<NodeAlias, PodName>;
podRefs: Record<NodeAlias, PodRef>;
getUnusedConfigs: () => string[];
}

Expand All @@ -365,20 +366,14 @@ export interface NodeKeysConfigClass {
getUnusedConfigs: () => string[];
}

export interface NodeStopConfigClass {
namespace: string;
nodeAliases: NodeAliases;
podNames: Record<NetworkNodePodNameAsString, NodeAlias>;
}

export interface NodeStartConfigClass {
app: string;
cacheDir: string;
debugNodeAlias: NodeAlias;
namespace: string;
nodeAliases: NodeAliases;
stagingDir: string;
podNames: Record<NodeAlias, PodName>;
podRefs: Record<NodeAlias, PodRef>;
nodeAliasesUnparsed: string;
}

Expand All @@ -401,7 +396,7 @@ export interface NodeDeleteConfigClass {
freezeAdminPrivateKey: string;
keysDir: string;
nodeClient: any;
podNames: Record<NodeAlias, PodName>;
podRefs: Record<NodeAlias, PodRef>;
serviceMap: Map<string, NetworkNodeServices>;
stagingDir: string;
stagingKeysDir: string;
Expand All @@ -421,7 +416,7 @@ export interface NodeSetupConfigClass {
nodeAliasesUnparsed: string;
releaseTag: string;
nodeAliases: NodeAliases;
podNames: object;
podRefs: Record<NodeAlias, PodRef>;
getUnusedConfigs: () => string[];
}

Expand All @@ -444,7 +439,7 @@ export interface NodeUpgradeConfigClass {
freezeAdminPrivateKey: PrivateKey | string;
keysDir: string;
nodeClient: any;
podNames: Record<NodeAlias, PodName>;
podRefs: Record<NodeAlias, PodRef>;
stagingDir: string;
stagingKeysDir: string;
treasuryKey: PrivateKey;
Expand Down Expand Up @@ -479,7 +474,7 @@ export interface NodeUpdateConfigClass {
freezeAdminPrivateKey: PrivateKey | string;
keysDir: string;
nodeClient: any;
podNames: Record<NodeAlias, PodName>;
podRefs: Record<NodeAlias, PodRef>;
serviceMap: Map<string, NetworkNodeServices>;
stagingDir: string;
stagingKeysDir: string;
Expand Down
6 changes: 3 additions & 3 deletions src/commands/node/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class NodeHelper {
config.existingNodeAliases = ctxData.existingNodeAliases;
config.allNodeAliases = ctxData.existingNodeAliases;
ctx.upgradeZipHash = ctxData.upgradeZipHash;
config.podNames = {};
config.podRefs = {};
}

/**
Expand Down Expand Up @@ -106,7 +106,7 @@ export class NodeHelper {
config.existingNodeAliases = ctxData.existingNodeAliases;
config.allNodeAliases = ctxData.allNodeAliases;
ctx.upgradeZipHash = ctxData.upgradeZipHash;
config.podNames = {};
config.podRefs = {};
}

/**
Expand Down Expand Up @@ -135,6 +135,6 @@ export class NodeHelper {
config.gossipPrivateKey = ctxData.gossipPrivateKey;
config.allNodeAliases = ctxData.allNodeAliases;
ctx.upgradeZipHash = ctxData.upgradeZipHash;
config.podNames = {};
config.podRefs = {};
}
}
4 changes: 2 additions & 2 deletions src/commands/node/node_add_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import {type NodeAlias, type NodeAliases} from '../../types/aliases.js';
import {type PodName} from '../../core/kube/pod_name.js';
import {type PodRef} from '../../core/kube/pod_ref.js';
import {type NetworkNodeServices} from '../../core/network_node_services.js';
import {type PrivateKey} from '@hashgraph/sdk';

Expand Down Expand Up @@ -32,7 +32,7 @@ export interface NodeAddConfigClass {
keysDir: string;
lastStateZipPath: string;
nodeClient: any;
podNames: Record<NodeAlias, PodName>;
podRefs: Record<NodeAlias, PodRef>;
serviceMap: Map<string, NetworkNodeServices>;
treasuryKey: PrivateKey;
stagingDir: string;
Expand Down
Loading
Loading