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: integrated lease methods & moved leases to resources/lease #1328

Merged
merged 12 commits into from
Feb 9, 2025
58 changes: 31 additions & 27 deletions src/commands/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,17 @@
}

// wait cert-manager to be ready to proceed, otherwise may get error of "failed calling webhook"
await self.k8.waitForPodReady(
[
'app.kubernetes.io/component=webhook',
`app.kubernetes.io/instance=${constants.SOLO_CLUSTER_SETUP_CHART}`,
],
1,
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
constants.DEFAULT_CERT_MANAGER_NAMESPACE,
);
await self.k8
.pods()
.waitForReadyStatus(
constants.DEFAULT_CERT_MANAGER_NAMESPACE,
[
'app.kubernetes.io/component=webhook',
`app.kubernetes.io/instance=${constants.SOLO_CLUSTER_SETUP_CHART}`,
],
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
);

// sleep for a few seconds to allow cert-manager to be ready
await new Promise(resolve => setTimeout(resolve, 10000));
Expand Down Expand Up @@ -295,28 +296,31 @@
},
{
title: 'Check explorer pod is ready',
task: async () => {
await self.k8.waitForPodReady(
[constants.SOLO_HEDERA_EXPLORER_LABEL],
1,
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
);
task: async ctx => {
await self.k8
.pods()
.waitForReadyStatus(
ctx.config.namespace,
[constants.SOLO_HEDERA_EXPLORER_LABEL],
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
);
},
},
{
title: 'Check haproxy ingress controller pod is ready',
task: async () => {
await self.k8.waitForPodReady(
[
'app.kubernetes.io/name=haproxy-ingress',
`app.kubernetes.io/instance=${constants.SOLO_CLUSTER_SETUP_CHART}`,
],
1,
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
constants.SOLO_SETUP_NAMESPACE,
);
await self.k8
.pods()
.waitForReadyStatus(
constants.SOLO_SETUP_NAMESPACE,
[
'app.kubernetes.io/name=haproxy-ingress',
`app.kubernetes.io/instance=${constants.SOLO_CLUSTER_SETUP_CHART}`,
],
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
);

Check warning on line 323 in src/commands/explorer.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/explorer.ts#L313-L323

Added lines #L313 - L323 were not covered by tests
},
skip: ctx => !ctx.config.enableIngress,
},
Expand Down
88 changes: 49 additions & 39 deletions src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {Flags as flags} from './flags.js';
import {getEnvValue} from '../core/helpers.js';
import {resolveNamespaceFromDeployment} from '../core/resolvers.js';
import {type CommandBuilder} from '../types/aliases.js';
import {PodName} from '../core/kube/pod_name.js';
import {PodName} from '../core/kube/resources/pod/pod_name.js';
import {type Opts} from '../types/command_types.js';
import {ListrLease} from '../core/lease/listr_lease.js';
import {ComponentType} from '../core/config/remote/enumerations.js';
Expand All @@ -22,7 +22,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/resources/namespace/namespace_name.js';
import {PodRef} from '../core/kube/pod_ref.js';
import {PodRef} from '../core/kube/resources/pod/pod_ref.js';
import {ContainerName} from '../core/kube/container_name.js';
import {ContainerRef} from '../core/kube/container_ref.js';

Expand Down Expand Up @@ -181,7 +181,7 @@ export class MirrorNodeCommand extends BaseCommand {

if (ctx.config.pinger) {
const startAccId = constants.HEDERA_NODE_ACCOUNT_ID_START;
const networkPods = await this.k8.getPodsByLabel(['solo.hedera.com/type=network-node']);
const networkPods = await this.k8.pods().list(namespace, ['solo.hedera.com/type=network-node']);

if (networkPods.length) {
const pod = networkPods[0];
Expand Down Expand Up @@ -276,54 +276,64 @@ export class MirrorNodeCommand extends BaseCommand {
[
{
title: 'Check Postgres DB',
task: async () =>
await self.k8.waitForPodReady(
['app.kubernetes.io/component=postgresql', 'app.kubernetes.io/name=postgres'],
1,
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
),
task: async ctx =>
await self.k8
.pods()
.waitForReadyStatus(
ctx.config.namespace,
['app.kubernetes.io/component=postgresql', 'app.kubernetes.io/name=postgres'],
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
),
skip: ctx => !!ctx.config.customMirrorNodeDatabaseValuePath,
},
{
title: 'Check REST API',
task: async () =>
await self.k8.waitForPodReady(
['app.kubernetes.io/component=rest', 'app.kubernetes.io/name=rest'],
1,
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
),
task: async ctx =>
await self.k8
.pods()
.waitForReadyStatus(
ctx.config.namespace,
['app.kubernetes.io/component=rest', 'app.kubernetes.io/name=rest'],
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
),
},
{
title: 'Check GRPC',
task: async () =>
await self.k8.waitForPodReady(
['app.kubernetes.io/component=grpc', 'app.kubernetes.io/name=grpc'],
1,
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
),
task: async ctx =>
await self.k8
.pods()
.waitForReadyStatus(
ctx.config.namespace,
['app.kubernetes.io/component=grpc', 'app.kubernetes.io/name=grpc'],
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
),
},
{
title: 'Check Monitor',
task: async () =>
await self.k8.waitForPodReady(
['app.kubernetes.io/component=monitor', 'app.kubernetes.io/name=monitor'],
1,
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
),
task: async ctx =>
await self.k8
.pods()
.waitForReadyStatus(
ctx.config.namespace,
['app.kubernetes.io/component=monitor', 'app.kubernetes.io/name=monitor'],
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
),
},
{
title: 'Check Importer',
task: async () =>
await self.k8.waitForPodReady(
['app.kubernetes.io/component=importer', 'app.kubernetes.io/name=importer'],
1,
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
),
task: async ctx =>
await self.k8
.pods()
.waitForReadyStatus(
ctx.config.namespace,
['app.kubernetes.io/component=importer', 'app.kubernetes.io/name=importer'],
constants.PODS_READY_MAX_ATTEMPTS,
constants.PODS_READY_DELAY,
),
},
],
{
Expand Down Expand Up @@ -366,7 +376,7 @@ export class MirrorNodeCommand extends BaseCommand {
return;
}

const pods = await this.k8.getPodsByLabel(['app.kubernetes.io/name=postgres']);
const pods = await this.k8.pods().list(namespace, ['app.kubernetes.io/name=postgres']);
if (pods.length === 0) {
throw new SoloError('postgres pod not found');
}
Expand Down
77 changes: 43 additions & 34 deletions src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,13 +588,14 @@
subTasks.push({
title: `Check Node: ${chalk.yellow(nodeAlias)}`,
task: async () =>
await self.k8.waitForPods(
[constants.POD_PHASE_RUNNING],
[`solo.hedera.com/node-name=${nodeAlias}`, 'solo.hedera.com/type=network-node'],
1,
constants.PODS_RUNNING_MAX_ATTEMPTS,
constants.PODS_RUNNING_DELAY,
),
await self.k8
.pods()
.waitForRunningPhase(
config.namespace,
[`solo.hedera.com/node-name=${nodeAlias}`, 'solo.hedera.com/type=network-node'],
constants.PODS_RUNNING_MAX_ATTEMPTS,
constants.PODS_RUNNING_DELAY,
),
});
}

Expand All @@ -618,13 +619,14 @@
subTasks.push({
title: `Check HAProxy for: ${chalk.yellow(nodeAlias)}`,
task: async () =>
await self.k8.waitForPods(
[constants.POD_PHASE_RUNNING],
['solo.hedera.com/type=haproxy'],
1,
constants.PODS_RUNNING_MAX_ATTEMPTS,
constants.PODS_RUNNING_DELAY,
),
await self.k8
.pods()
.waitForRunningPhase(
config.namespace,
['solo.hedera.com/type=haproxy'],
constants.PODS_RUNNING_MAX_ATTEMPTS,
constants.PODS_RUNNING_DELAY,
),
});
}

Expand All @@ -633,13 +635,14 @@
subTasks.push({
title: `Check Envoy Proxy for: ${chalk.yellow(nodeAlias)}`,
task: async () =>
await self.k8.waitForPods(
[constants.POD_PHASE_RUNNING],
['solo.hedera.com/type=envoy-proxy'],
1,
constants.PODS_RUNNING_MAX_ATTEMPTS,
constants.PODS_RUNNING_DELAY,
),
await self.k8
.pods()
.waitForRunningPhase(
ctx.config.namespace,
['solo.hedera.com/type=envoy-proxy'],
constants.PODS_RUNNING_MAX_ATTEMPTS,
constants.PODS_RUNNING_DELAY,
),
});
}

Expand All @@ -660,13 +663,15 @@
// minio
subTasks.push({
title: 'Check MinIO',
task: async () =>
await self.k8.waitForPodReady(
['v1.min.io/tenant=minio'],
1,
constants.PODS_RUNNING_MAX_ATTEMPTS,
constants.PODS_RUNNING_DELAY,
),
task: async ctx =>
await self.k8
.pods()
.waitForReadyStatus(
ctx.config.namespace,
['v1.min.io/tenant=minio'],
constants.PODS_RUNNING_MAX_ATTEMPTS,
constants.PODS_RUNNING_DELAY,
),
// skip if only cloud storage is/are used
skip: ctx =>
ctx.config.storageType === constants.StorageType.GCS_ONLY ||
Expand Down Expand Up @@ -828,12 +833,16 @@
},
{
title: 'Waiting for network pods to be running',
task: async () => {
await this.k8.waitForPods(
[constants.POD_PHASE_RUNNING],
['solo.hedera.com/type=network-node', 'solo.hedera.com/type=network-node'],
1,
);
task: async ctx => {
const config = ctx.config;
await this.k8
.pods()
.waitForRunningPhase(
config.namespace,
['solo.hedera.com/type=network-node', 'solo.hedera.com/type=network-node'],
constants.PODS_RUNNING_MAX_ATTEMPTS,
constants.PODS_RUNNING_DELAY,
);

Check warning on line 845 in src/commands/network.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/network.ts#L836-L845

Added lines #L836 - L845 were not covered by tests
},
},
],
Expand Down
5 changes: 2 additions & 3 deletions src/commands/node/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import fs from 'fs';
import {validatePath} from '../../core/helpers.js';
import {resolveNamespaceFromDeployment} from '../../core/resolvers.js';
import {Flags as flags} from '../flags.js';
import {type NetworkNodePodNameAsString, type NodeAlias, type NodeAliases} from '../../types/aliases.js';
import {type PodName} from '../../core/kube/pod_name.js';
import {type NodeAlias, type NodeAliases} from '../../types/aliases.js';
import {type NetworkNodeServices} from '../../core/network_node_services.js';
import {type NodeAddConfigClass} from './node_add_config.js';
import {type NamespaceName} from '../../core/kube/resources/namespace/namespace_name.js';
import {type PodRef} from '../../core/kube/pod_ref.js';
import {type PodRef} from '../../core/kube/resources/pod/pod_ref.js';

export const PREPARE_UPGRADE_CONFIGS_NAME = 'prepareUpgradeConfig';
export const DOWNLOAD_GENERATED_FILES_CONFIGS_NAME = 'downloadGeneratedFilesConfig';
Expand Down
4 changes: 2 additions & 2 deletions src/commands/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@
/**
* stops and closes the port forwards
* - calls the accountManager.close()
* - for all portForwards, calls k8.stopPortForward(srv)
* - for all portForwards, calls k8.pods().readByRef(null).stopPortForward(srv)
*/
async close() {
await this.accountManager.close();
if (this._portForwards) {
for (const srv of this._portForwards) {
await this.k8.stopPortForward(srv);
await this.k8.pods().readByRef(null).stopPortForward(srv);

Check warning on line 78 in src/commands/node/index.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/node/index.ts#L78

Added line #L78 was not covered by tests
}
}

Expand Down
2 changes: 1 addition & 1 deletion 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 PodRef} from '../../core/kube/pod_ref.js';
import {type PodRef} from '../../core/kube/resources/pod/pod_ref.js';
import {type NetworkNodeServices} from '../../core/network_node_services.js';
import {type PrivateKey} from '@hashgraph/sdk';
import {type NamespaceName} from '../../core/kube/resources/namespace/namespace_name.js';
Expand Down
Loading
Loading