Skip to content

Commit

Permalink
load the remote config
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 20, 2025
1 parent c1852d1 commit 5ad515d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
25 changes: 18 additions & 7 deletions src/core/config/remote/remote_config_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
private async load(namespace?: NamespaceName, context?: string): Promise<boolean> {
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);
Expand Down Expand Up @@ -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<k8s.V1ConfigMap> {
public async getConfigMap(namespace?: NamespaceName, context?: string): Promise<k8s.V1ConfigMap> {
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);
Expand Down
4 changes: 3 additions & 1 deletion src/core/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export async function promptTheUserForDeployment(
configManager: ConfigManager,
task?: SoloListrTaskWrapper<any>,
): Promise<Optional<DeploymentName>> {
if (configManager.getFlag(flags.deployment)) return undefined;
if (configManager.getFlag(flags.deployment)) {
return configManager.getFlag<DeploymentName>(flags.deployment);
}

if (!task) {
const isQuiet = configManager.getFlag<boolean>(flags.quiet);
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/commands/dual_cluster_full.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/test_container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 5ad515d

Please sign in to comment.