Skip to content

Commit

Permalink
refactor: minor refactors to K8 setting private and public modifiers (#…
Browse files Browse the repository at this point in the history
…1234)

Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon authored Jan 30, 2025
1 parent 9c31b6c commit 6f43952
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 149 deletions.
22 changes: 9 additions & 13 deletions src/commands/cluster/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {SoloError} from '../../core/errors.js';
import {RemoteConfigManager} from '../../core/config/remote/remote_config_manager.js';
import type {RemoteConfigDataWrapper} from '../../core/config/remote/remote_config_data_wrapper.js';
import type {K8} from '../../core/k8.js';
import type {Cluster} from '@kubernetes/client-node/dist/config_types.js';
import type {SoloListrTask, SoloListrTaskWrapper} from '../../types/index.js';
import type {SelectClusterContextContext} from './configs.js';
import type {Namespace} from '../../core/config/remote/types.js';
Expand Down Expand Up @@ -59,7 +58,7 @@ export class ClusterCommandTasks {

validateRemoteConfigForCluster(
cluster: string,
currentCluster: Cluster,
currentClusterName: string,
localConfig: LocalConfig,
currentRemoteConfig: RemoteConfigDataWrapper,
) {
Expand All @@ -71,7 +70,7 @@ export class ClusterCommandTasks {
self.parent.getK8().setCurrentContext(context);
const remoteConfigFromOtherCluster = await self.parent.getRemoteConfigManager().get();
if (!RemoteConfigManager.compare(currentRemoteConfig, remoteConfigFromOtherCluster)) {
throw new SoloError(ErrorMessages.REMOTE_CONFIGS_DO_NOT_MATCH(currentCluster.name, cluster));
throw new SoloError(ErrorMessages.REMOTE_CONFIGS_DO_NOT_MATCH(currentClusterName, cluster));
}
},
};
Expand All @@ -83,7 +82,6 @@ export class ClusterCommandTasks {
title: 'Read clusters from remote config',
task: async (ctx, task) => {
const localConfig = this.parent.getLocalConfig();
const currentCluster = this.parent.getK8().getCurrentCluster();
const currentClusterName = this.parent.getK8().getCurrentClusterName();
const currentRemoteConfig: RemoteConfigDataWrapper = await this.parent.getRemoteConfigManager().get();
const subTasks = [];
Expand All @@ -97,7 +95,9 @@ export class ClusterCommandTasks {

// Pull and validate RemoteConfigs from the other clusters
for (const cluster of otherRemoteConfigClusters) {
subTasks.push(self.validateRemoteConfigForCluster(cluster, currentCluster, localConfig, currentRemoteConfig));
subTasks.push(
self.validateRemoteConfigForCluster(cluster, currentClusterName, localConfig, currentRemoteConfig),
);
}

return task.newListr(subTasks, {
Expand Down Expand Up @@ -183,12 +183,8 @@ export class ClusterCommandTasks {
}

private async promptForContext(task: SoloListrTaskWrapper<SelectClusterContextContext>, cluster: string) {
const kubeContexts = this.parent.getK8().getContexts();
return flags.context.prompt(
task,
kubeContexts.map(c => c.name),
cluster,
);
const kubeContexts = this.parent.getK8().getContextNames();
return flags.context.prompt(task, kubeContexts, cluster);
}

private async selectContextForFirstCluster(
Expand Down Expand Up @@ -359,8 +355,8 @@ export class ClusterCommandTasks {
getClusterInfo() {
return new Task('Get cluster info', async (ctx: any, task: ListrTaskWrapper<any, any, any>) => {
try {
const cluster = this.parent.getK8().getCurrentCluster();
this.parent.logger.showJSON(`Cluster Information (${cluster.name})`, cluster);
const clusterName = this.parent.getK8().getCurrentClusterName();
this.parent.logger.showUser(`Cluster Name (${clusterName})`);
this.parent.logger.showUser('\n');
} catch (e: Error | unknown) {
this.parent.logger.showUserError(e);
Expand Down
8 changes: 2 additions & 6 deletions src/core/config/local_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,8 @@ export class LocalConfig implements LocalConfigData {
if (!isQuiet) {
const promptedContexts: string[] = [];
for (const cluster of parsedClusters) {
const kubeContexts = k8.getContexts();
const context: string = await flags.context.prompt(
task,
kubeContexts.map(c => c.name),
cluster,
);
const kubeContexts = k8.getContextNames();
const context: string = await flags.context.prompt(task, kubeContexts, cluster);
self.clusterContextMapping[cluster] = context;
promptedContexts.push(context);

Expand Down
Loading

0 comments on commit 6f43952

Please sign in to comment.