diff --git a/src/commands/account.ts b/src/commands/account.ts index a8aa851d4..41feb89b2 100644 --- a/src/commands/account.ts +++ b/src/commands/account.ts @@ -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); diff --git a/src/commands/deployment.ts b/src/commands/deployment.ts index 94ca4dd95..2c7f2cfd9 100644 --- a/src/commands/deployment.ts +++ b/src/commands/deployment.ts @@ -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(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}`); @@ -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}`); @@ -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) { diff --git a/src/commands/explorer.ts b/src/commands/explorer.ts index 56c7ae765..7bc27cb86 100644 --- a/src/commands/explorer.ts +++ b/src/commands/explorer.ts @@ -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`); } @@ -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`); } diff --git a/src/commands/mirror_node.ts b/src/commands/mirror_node.ts index 3d919a2d0..b832f27ca 100644 --- a/src/commands/mirror_node.ts +++ b/src/commands/mirror_node.ts @@ -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`); } @@ -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`); } @@ -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))); } } }, diff --git a/src/commands/network.ts b/src/commands/network.ts index 614157555..102dc1b71 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -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); } } } @@ -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 diff --git a/src/commands/node/tasks.ts b/src/commands/node/tasks.ts index 0d8ba5e17..06bab6b0f 100644 --- a/src/commands/node/tasks.ts +++ b/src/commands/node/tasks.ts @@ -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([ @@ -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')) { @@ -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`, diff --git a/src/core/config/remote/remote_config_manager.ts b/src/core/config/remote/remote_config_manager.ts index bb442132a..55639fb81 100644 --- a/src/core/config/remote/remote_config_manager.ts +++ b/src/core/config/remote/remote_config_manager.ts @@ -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(); diff --git a/test/unit/commands/network.test.ts b/test/unit/commands/network.test.ts index 813ce7e43..8ae60df71 100644 --- a/test/unit/commands/network.test.ts +++ b/test/unit/commands/network.test.ts @@ -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; @@ -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;