Skip to content

Commit

Permalink
K14
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon committed Feb 11, 2025
1 parent e4ac40c commit 304557a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 31 deletions.
5 changes: 4 additions & 1 deletion src/commands/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ export class AccountCommand extends BaseCommand {
title: 'Prepare for account key updates',
task: async ctx => {
const namespace = await resolveNamespaceFromDeployment(this.localConfig, this.configManager, task);
const secrets = await self.K0014.secrets().list(namespace, ['solo.hedera.com/account-id']);
const secrets = await self.k8Factory
.default()
.secrets()
.list(namespace, ['solo.hedera.com/account-id']);
ctx.updateSecrets = secrets.length > 0;

ctx.accountsBatchedSet = self.accountManager.batchAccounts(this.systemAccounts);
Expand Down
8 changes: 4 additions & 4 deletions src/commands/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class DeploymentCommand extends BaseCommand {
title: 'Validate context',
task: async (ctx, task) => {
ctx.config.context = ctx.config.context ?? self.configManager.getFlag<string>(flags.context);
const availableContexts = self.K0014.contexts().list();
const availableContexts = self.k8Factory.default().contexts().list();

if (availableContexts.includes(ctx.config.context)) {
task.title += chalk.green(`- validated context ${ctx.config.context}`);
Expand All @@ -132,7 +132,7 @@ export class DeploymentCommand extends BaseCommand {
subTasks.push({
title: `Testing connection to cluster: ${chalk.cyan(cluster)}`,
task: async (_, task) => {
if (!(await self.K0014.contexts().testContextConnection(context))) {
if (!(await self.k8Factory.default().contexts().testContextConnection(context))) {
task.title = `${task.title} - ${chalk.red('Cluster connection failed')}`;

throw new SoloError(`Cluster connection failed for: ${cluster}`);
Expand Down Expand Up @@ -199,9 +199,9 @@ export class DeploymentCommand extends BaseCommand {

const context = self.localConfig.clusterContextMapping[clusterName];

self.K0014.contexts().updateCurrent(context);
self.k8Factory.default().contexts().updateCurrent(context);

const namespaces = await self.K0014.namespaces().list();
const namespaces = await self.k8Factory.default().namespaces().list();
const namespacesWithRemoteConfigs: NamespaceNameAsString[] = [];

for (const namespace of namespaces) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class ExplorerCommand extends BaseCommand {

ctx.config.valuesArg += await self.prepareValuesArg(ctx.config);

if (!(await self.K0014.namespaces().has(ctx.config.namespace))) {
if (!(await self.k8Factory.default().namespaces().has(ctx.config.namespace))) {
throw new SoloError(`namespace ${ctx.config.namespace} does not exist`);
}

Expand Down Expand Up @@ -380,7 +380,7 @@ export class ExplorerCommand extends BaseCommand {
self.configManager.update(argv);
const namespace = await resolveNamespaceFromDeployment(this.localConfig, this.configManager, task);

if (!(await self.K0014.namespaces().has(namespace))) {
if (!(await self.k8Factory.default().namespaces().has(namespace))) {
throw new SoloError(`namespace ${namespace} does not exist`);
}

Expand Down
9 changes: 6 additions & 3 deletions src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export class MirrorNodeCommand extends BaseCommand {
}
}

if (!(await self.K0014.namespaces().has(ctx.config.namespace))) {
if (!(await self.k8Factory.default().namespaces().has(ctx.config.namespace))) {
throw new SoloError(`namespace ${ctx.config.namespace} does not exist`);
}

Expand Down Expand Up @@ -556,7 +556,7 @@ export class MirrorNodeCommand extends BaseCommand {
self.configManager.update(argv);
const namespace = await resolveNamespaceFromDeployment(this.localConfig, this.configManager, task);

if (!(await self.K0014.namespaces().has(namespace))) {
if (!(await self.k8Factory.default().namespaces().has(namespace))) {
throw new SoloError(`namespace ${namespace} does not exist`);
}

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

if (pvcs) {
for (const pvc of pvcs) {
await self.K0014.pvcs().delete(PvcRef.of(ctx.config.namespace, PvcName.of(pvc)));
await self.k8Factory
.default()
.pvcs()
.delete(PvcRef.of(ctx.config.namespace, PvcName.of(pvc)));
}
}
},
Expand Down
13 changes: 8 additions & 5 deletions src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,22 +469,25 @@ export class NetworkCommand extends BaseCommand {
await self.chartManager.uninstall(ctx.config.namespace, constants.SOLO_DEPLOYMENT_CHART);

if (ctx.config.deletePvcs) {
const pvcs = await self.K0014.pvcs().list(ctx.config.namespace, []);
const pvcs = await self.k8Factory.default().pvcs().list(ctx.config.namespace, []);
task.title = `Deleting PVCs in namespace ${ctx.config.namespace}`;
if (pvcs) {
for (const pvc of pvcs) {
await self.K0014.pvcs().delete(PvcRef.of(ctx.config.namespace, PvcName.of(pvc)));
await self.k8Factory
.default()
.pvcs()
.delete(PvcRef.of(ctx.config.namespace, PvcName.of(pvc)));
}
}
}

if (ctx.config.deleteSecrets) {
task.title = `Deleting secrets in namespace ${ctx.config.namespace}`;
const secrets = await self.K0014.secrets().list(ctx.config.namespace);
const secrets = await self.k8Factory.default().secrets().list(ctx.config.namespace);

if (secrets) {
for (const secret of secrets) {
await self.K0014.secrets().delete(ctx.config.namespace, secret.name);
await self.k8Factory.default().secrets().delete(ctx.config.namespace, secret.name);
}
}
}
Expand Down Expand Up @@ -772,7 +775,7 @@ export class NetworkCommand extends BaseCommand {
networkDestroySuccess = false;

if (ctx.config.deletePvcs && ctx.config.deleteSecrets && ctx.config.force) {
self.K0014.namespaces().delete(ctx.config.namespace);
self.k8Factory.default().namespaces().delete(ctx.config.namespace);
} else {
// If the namespace is not being deleted,
// remove all components data from the remote configuration
Expand Down
18 changes: 11 additions & 7 deletions src/commands/node/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,12 @@ export class NodeCommandTasks {

// if directory data/upgrade/current/data/keys does not exist, then use data/upgrade/current
let keyDir = `${constants.HEDERA_HAPI_PATH}/data/upgrade/current/data/keys`;
if (!(await self.K0014.containers().readByRef(containerRef).hasDir(keyDir))) {
if (!(await self.k8Factory.default().containers().readByRef(containerRef).hasDir(keyDir))) {
keyDir = `${constants.HEDERA_HAPI_PATH}/data/upgrade/current`;
}
const signedKeyFiles = (await self.K0014.containers().readByRef(containerRef).listDir(keyDir)).filter(file =>
file.name.startsWith(constants.SIGNING_KEY_PREFIX),
);
const signedKeyFiles = (
await self.k8Factory.default().containers().readByRef(containerRef).listDir(keyDir)
).filter(file => file.name.startsWith(constants.SIGNING_KEY_PREFIX));
await self.K0015.containers()
.readByRef(containerRef)
.execContainer([
Expand Down Expand Up @@ -745,10 +745,10 @@ export class NodeCommandTasks {
const containerRef = ContainerRef.of(podRef, constants.ROOT_CONTAINER);
for (const upgradeDir of upgradeDirectories) {
// check if directory upgradeDir exist in root container
if (!(await self.K0014.containers().readByRef(containerRef).hasDir(upgradeDir))) {
if (!(await self.k8Factory.default().containers().readByRef(containerRef).hasDir(upgradeDir))) {
continue;
}
const files = await self.K0014.containers().readByRef(containerRef).listDir(upgradeDir);
const files = await self.k8Factory.default().containers().readByRef(containerRef).listDir(upgradeDir);
// iterate all files and copy them to the staging directory
for (const file of files) {
if (file.name.endsWith('.mf')) {
Expand Down Expand Up @@ -857,7 +857,11 @@ export class NodeCommandTasks {
const podRef = ctx.config.podRefs[nodeAlias];
const containerRef = ContainerRef.of(podRef, constants.ROOT_CONTAINER);
self.logger.debug(`Uploading state files to pod ${podRef.name}`);
await self.K0014.containers().readByRef(containerRef).copyTo(zipFile, `${constants.HEDERA_HAPI_PATH}/data`);
await self.k8Factory
.default()
.containers()
.readByRef(containerRef)
.copyTo(zipFile, `${constants.HEDERA_HAPI_PATH}/data`);

self.logger.info(
`Deleting the previous state files in pod ${podRef.name} directory ${constants.HEDERA_HAPI_PATH}/data/saved`,
Expand Down
6 changes: 3 additions & 3 deletions src/core/config/remote/remote_config_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ export class RemoteConfigManager {
argv: AnyObject,
) {
const self = this;
self.K0014.contexts().updateCurrent(context);
self.k8Factory.default().contexts().updateCurrent(context);

if (!(await self.K0014.namespaces().has(NamespaceName.of(namespace)))) {
await self.K0014.namespaces().create(NamespaceName.of(namespace));
if (!(await self.k8Factory.default().namespaces().has(NamespaceName.of(namespace)))) {
await self.k8Factory.default().namespaces().create(NamespaceName.of(namespace));
}

const localConfigExists = this.localConfig.configFileExists();
Expand Down
12 changes: 6 additions & 6 deletions test/unit/commands/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ describe('NetworkCommand unit tests', () => {
opts.configManager.update(argv);

opts.k8Factory = sinon.stub() as unknown as K8Factory;
opts.K0014.namespaces = sinon.stub().returns({
opts.k8Factory.default().namespaces = sinon.stub().returns({
has: sinon.stub().returns(true),
});
opts.K0014.configMaps = sinon.stub() as unknown as K8ClientConfigMaps;
opts.K0014.configMaps.read = sinon.stub();
opts.K0014.pods = sinon.stub().returns({
opts.k8Factory.default().configMaps = sinon.stub() as unknown as K8ClientConfigMaps;
opts.k8Factory.default().configMaps.read = sinon.stub();
opts.k8Factory.default().pods = sinon.stub().returns({
waitForRunningPhase: sinon.stub(),
waitForReadyStatus: sinon.stub(),
});
opts.K0014.leases = sinon.stub().returns({
opts.k8Factory.default().leases = sinon.stub().returns({
read: sinon.stub(),
});
const clusterChecksStub = sinon.stub() as unknown as ClusterChecks;
Expand All @@ -79,7 +79,7 @@ describe('NetworkCommand unit tests', () => {
clusterChecksStub.isCertManagerInstalled = sinon.stub();
container.registerInstance(InjectTokens.ClusterChecks, clusterChecksStub);

opts.K0014.logger = opts.logger;
opts.k8Factory.default().logger = opts.logger;
container.registerInstance(InjectTokens.K8Factory, opts.k8Factory);

opts.depManager = sinon.stub() as unknown as DependencyManager;
Expand Down

0 comments on commit 304557a

Please sign in to comment.