diff --git a/src/core/config/remote/remote_config_manager.ts b/src/core/config/remote/remote_config_manager.ts index b45324e39..39accdf7a 100644 --- a/src/core/config/remote/remote_config_manager.ts +++ b/src/core/config/remote/remote_config_manager.ts @@ -162,13 +162,15 @@ export class RemoteConfigManager { /** * Loads the remote configuration from the Kubernetes cluster if it exists. + * @param namespace - The namespace to search for the ConfigMap. + * @param context - The context to use for the Kubernetes client. * @returns true if the configuration is loaded successfully. */ - private async load(): Promise { + private async load(namespace?: NamespaceName, context?: string): Promise { if (this.remoteConfig) return true; try { - const configMap = await this.getConfigMap(); + const configMap = await this.getConfigMap(namespace, context); if (configMap) { this.remoteConfig = RemoteConfigDataWrapper.fromConfigmap(this.configManager, configMap); @@ -361,15 +363,24 @@ export class RemoteConfigManager { /** * Retrieves the ConfigMap containing the remote configuration from the Kubernetes cluster. * + * @param namespace - The namespace to search for the ConfigMap. + * @param context - The context to use for the Kubernetes client. * @returns the remote configuration data. * @throws {@link SoloError} if the ConfigMap could not be read and the error is not a 404 status. */ - public async getConfigMap(): Promise { + public async getConfigMap(namespace?: NamespaceName, context?: string): Promise { + if (!namespace) { + namespace = await this.getNamespace(); + } + if (!context) { + const contexts: string[] = this.getContexts(); + if (contexts.length > 0) { + context = contexts[0]; + } + } + try { - return await this.k8Factory - .default() - .configMaps() - .read(await this.getNamespace(), constants.SOLO_REMOTE_CONFIGMAP_NAME); + return await this.k8Factory.getK8(context).configMaps().read(namespace, constants.SOLO_REMOTE_CONFIGMAP_NAME); } catch (e) { if (!(e instanceof ResourceNotFoundError)) { throw new SoloError('Failed to read remote config from cluster', e); diff --git a/src/core/resolvers.ts b/src/core/resolvers.ts index 7eb58850e..0d97f6d0e 100644 --- a/src/core/resolvers.ts +++ b/src/core/resolvers.ts @@ -31,7 +31,9 @@ export async function promptTheUserForDeployment( configManager: ConfigManager, task?: SoloListrTaskWrapper, ): Promise> { - if (configManager.getFlag(flags.deployment)) return undefined; + if (configManager.getFlag(flags.deployment)) { + return configManager.getFlag(flags.deployment); + } if (!task) { const isQuiet = configManager.getFlag(flags.quiet); diff --git a/test/e2e/commands/dual_cluster_full.test.ts b/test/e2e/commands/dual_cluster_full.test.ts index 557076fa2..b1a783cdb 100644 --- a/test/e2e/commands/dual_cluster_full.test.ts +++ b/test/e2e/commands/dual_cluster_full.test.ts @@ -241,8 +241,10 @@ describe('Dual Cluster Full E2E Test', async function dualClusterFullE2eTest(): expect(remoteConfigManager.isLoaded(), 'remote config manager should not be loaded').to.be.false; const configManager: ConfigManager = container.resolve(InjectTokens.ConfigManager); configManager.setFlag(Flags.namespace, namespace); + configManager.setFlag(Flags.deployment, deployment); + // @ts-ignore - await remoteConfigManager.load(); + await remoteConfigManager.load(namespace, contexts[0]); expect(remoteConfigManager.isLoaded(), 'remote config manager should be loaded').to.be.true; expect( Object.entries(remoteConfigManager.components.consensusNodes).length, diff --git a/test/test_container.ts b/test/test_container.ts index 7b977d742..41475d2fa 100644 --- a/test/test_container.ts +++ b/test/test_container.ts @@ -30,6 +30,6 @@ export function resetForTest(namespace?: NamespaceNameAsString, cacheDir: string // need to init the container prior to using K8Client for dependency injection to work resetTestContainer(cacheDir); - parsedData.clusterRefs['cluster-1'] = new K8Client(undefined).contexts().readCurrent(); + parsedData.clusterRefs['cluster-1'] = new K8Client('kind-solo-e2e').contexts().readCurrent(); fs.writeFileSync(path.join(cacheDirectory, localConfigFile), yaml.stringify(parsedData)); }