Skip to content

Commit a4d1595

Browse files
committed
K18
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent e2a9c31 commit a4d1595

File tree

16 files changed

+51
-50
lines changed

16 files changed

+51
-50
lines changed

src/commands/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export abstract class BaseCommand extends ShellRunner {
3939

4040
constructor(opts: Opts) {
4141
if (!opts || !opts.helm) throw new Error('An instance of core/Helm is required');
42-
if (!opts || !opts.k8Factory) throw new Error('An instance of core/K0018 is required');
42+
if (!opts || !opts.k8Factory) throw new Error('An instance of core/K8Factory is required');
4343
if (!opts || !opts.chartManager) throw new Error('An instance of core/ChartManager is required');
4444
if (!opts || !opts.configManager) throw new Error('An instance of core/ConfigManager is required');
4545
if (!opts || !opts.depManager) throw new Error('An instance of core/DependencyManager is required');
@@ -177,7 +177,7 @@ export abstract class BaseCommand extends ShellRunner {
177177
return this._configMaps.get(configName).getUnusedConfigs();
178178
}
179179

180-
getK0018() {
180+
getK8Factory() {
181181
return this.k8Factory;
182182
}
183183

src/commands/cluster/handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class ClusterCommandHandlers implements CommandHandlers {
3131
[
3232
this.tasks.initialize(argv, connectConfigBuilder.bind(this)),
3333
this.parent.setupHomeDirectoryTask(),
34-
this.parent.getLocalConfig().promptLocalConfigTask(this.parent.getK0018()),
34+
this.parent.getLocalConfig().promptLocalConfigTask(this.parent.getK8Factory()),
3535
this.tasks.selectContext(),
3636
ListrRemoteConfig.loadRemoteConfig(this.parent, argv),
3737
this.tasks.readClustersFromRemoteConfig(argv),

src/commands/cluster/tasks.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class ClusterCommandTasks {
3232

3333
constructor(
3434
parent,
35-
private readonly k8Factory: K0018,
35+
private readonly k8Factory: K8Factory,
3636
) {
3737
this.parent = parent;
3838
}
@@ -46,14 +46,14 @@ export class ClusterCommandTasks {
4646
if (!context) {
4747
const isQuiet = self.parent.getConfigManager().getFlag(flags.quiet);
4848
if (isQuiet) {
49-
context = self.parent.getK0018().contexts().readCurrent();
49+
context = self.parent.getK8Factory().contexts().readCurrent();
5050
} else {
5151
context = await self.promptForContext(parentTask, cluster);
5252
}
5353

5454
localConfig.clusterContextMapping[cluster] = context;
5555
}
56-
if (!(await self.parent.getK0018().contexts().testContextConnection(context))) {
56+
if (!(await self.parent.getK8Factory().contexts().testContextConnection(context))) {
5757
subTask.title = `${subTask.title} - ${chalk.red('Cluster connection failed')}`;
5858
throw new SoloError(`${ErrorMessages.INVALID_CONTEXT_FOR_CLUSTER_DETAILED(context, cluster)}`);
5959
}
@@ -72,7 +72,7 @@ export class ClusterCommandTasks {
7272
title: `Pull and validate remote configuration for cluster: ${chalk.cyan(cluster)}`,
7373
task: async (_, subTask: ListrTaskWrapper<any, any, any>) => {
7474
const context = localConfig.clusterContextMapping[cluster];
75-
self.parent.getK0018().contexts().updateCurrent(context);
75+
self.parent.getK8Factory().contexts().updateCurrent(context);
7676
const remoteConfigFromOtherCluster = await self.parent.getRemoteConfigManager().get();
7777
if (!RemoteConfigManager.compare(currentRemoteConfig, remoteConfigFromOtherCluster)) {
7878
throw new SoloError(ErrorMessages.REMOTE_CONFIGS_DO_NOT_MATCH(currentClusterName, cluster));
@@ -87,7 +87,7 @@ export class ClusterCommandTasks {
8787
title: 'Read clusters from remote config',
8888
task: async (ctx, task) => {
8989
const localConfig = this.parent.getLocalConfig();
90-
const currentClusterName = this.parent.getK0018().clusters().readCurrent();
90+
const currentClusterName = this.parent.getK8Factory().clusters().readCurrent();
9191
const currentRemoteConfig: RemoteConfigDataWrapper = await this.parent.getRemoteConfigManager().get();
9292
const subTasks = [];
9393
const remoteConfigClusters = Object.keys(currentRemoteConfig.clusters);
@@ -162,7 +162,7 @@ export class ClusterCommandTasks {
162162
} else if (!localConfig.clusterContextMapping[cluster]) {
163163
// In quiet mode, use the currently selected context to update the mapping
164164
if (isQuiet) {
165-
localConfig.clusterContextMapping[cluster] = this.parent.getK0018().contexts().readCurrent();
165+
localConfig.clusterContextMapping[cluster] = this.parent.getK8Factory().contexts().readCurrent();
166166
}
167167

168168
// Prompt the user to select a context if mapping value is missing
@@ -185,7 +185,7 @@ export class ClusterCommandTasks {
185185
) {
186186
let selectedContext;
187187
if (isQuiet) {
188-
selectedContext = this.parent.getK0018().contexts().readCurrent();
188+
selectedContext = this.parent.getK8Factory().contexts().readCurrent();
189189
} else {
190190
selectedContext = await this.promptForContext(task, selectedCluster);
191191
localConfig.clusterContextMapping[selectedCluster] = selectedContext;
@@ -194,7 +194,7 @@ export class ClusterCommandTasks {
194194
}
195195

196196
private async promptForContext(task: SoloListrTaskWrapper<SelectClusterContextContext>, cluster: string) {
197-
const kubeContexts = this.parent.getK0018().contexts().list();
197+
const kubeContexts = this.parent.getK8Factory().contexts().list();
198198
return flags.context.prompt(task, kubeContexts, cluster);
199199
}
200200

@@ -306,8 +306,8 @@ export class ClusterCommandTasks {
306306
else {
307307
// Add the deployment to the LocalConfig with the currently selected cluster and context in KubeConfig
308308
if (isQuiet) {
309-
selectedContext = this.parent.getK0018().contexts().readCurrent();
310-
selectedCluster = this.parent.getK0018().clusters().readCurrent();
309+
selectedContext = this.parent.getK8Factory().contexts().readCurrent();
310+
selectedCluster = this.parent.getK8Factory().clusters().readCurrent();
311311
localConfig.deployments[deploymentName] = {
312312
clusters: [selectedCluster],
313313
namespace: namespace ? namespace.name : '',
@@ -335,11 +335,11 @@ export class ClusterCommandTasks {
335335
}
336336
}
337337

338-
const connectionValid = await this.parent.getK0018().contexts().testContextConnection(selectedContext);
338+
const connectionValid = await this.parent.getK8Factory().contexts().testContextConnection(selectedContext);
339339
if (!connectionValid) {
340340
throw new SoloError(ErrorMessages.INVALID_CONTEXT_FOR_CLUSTER(selectedContext, selectedCluster));
341341
}
342-
this.parent.getK0018().contexts().updateCurrent(selectedContext);
342+
this.parent.getK8Factory().contexts().updateCurrent(selectedContext);
343343
this.parent.getConfigManager().setFlag(flags.context, selectedContext);
344344
},
345345
};
@@ -361,14 +361,14 @@ export class ClusterCommandTasks {
361361

362362
showClusterList() {
363363
return new Task('List all available clusters', async (ctx: any, task: ListrTaskWrapper<any, any, any>) => {
364-
this.parent.logger.showList('Clusters', this.parent.getK0018().clusters().list());
364+
this.parent.logger.showList('Clusters', this.parent.getK8Factory().clusters().list());
365365
});
366366
}
367367

368368
getClusterInfo() {
369369
return new Task('Get cluster info', async (ctx: any, task: ListrTaskWrapper<any, any, any>) => {
370370
try {
371-
const clusterName = this.parent.getK0018().clusters().readCurrent();
371+
const clusterName = this.parent.getK8Factory().clusters().readCurrent();
372372
this.parent.logger.showUser(`Cluster Name (${clusterName})`);
373373
this.parent.logger.showUser('\n');
374374
} catch (e: Error | unknown) {

src/commands/network.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class NetworkCommand extends BaseCommand {
8484
constructor(opts: Opts) {
8585
super(opts);
8686

87-
if (!opts || !opts.k8Factory) throw new Error('An instance of core/K0018 is required');
87+
if (!opts || !opts.k8Factory) throw new Error('An instance of core/K8Factory is required');
8888
if (!opts || !opts.keyManager)
8989
throw new IllegalArgumentError('An instance of core/KeyManager is required', opts.keyManager);
9090
if (!opts || !opts.platformInstaller)

src/commands/node/handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class NodeCommandHandlers implements CommandHandlers {
6464
if (!opts || !opts.configManager) throw new Error('An instance of core/ConfigManager is required');
6565
if (!opts || !opts.logger) throw new Error('An instance of core/Logger is required');
6666
if (!opts || !opts.tasks) throw new Error('An instance of NodeCommandTasks is required');
67-
if (!opts || !opts.k8Factory) throw new Error('An instance of core/K0018 is required');
67+
if (!opts || !opts.k8Factory) throw new Error('An instance of core/K8Factory is required');
6868
if (!opts || !opts.platformInstaller)
6969
throw new IllegalArgumentError('An instance of core/PlatformInstaller is required', opts.platformInstaller);
7070

src/commands/node/tasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class NodeCommandTasks {
9999
throw new IllegalArgumentError('An instance of core/AccountManager is required', opts.accountManager as any);
100100
if (!opts || !opts.configManager) throw new Error('An instance of core/ConfigManager is required');
101101
if (!opts || !opts.logger) throw new Error('An instance of core/Logger is required');
102-
if (!opts || !opts.k8Factory) throw new Error('An instance of core/K0018 is required');
102+
if (!opts || !opts.k8Factory) throw new Error('An instance of core/K8Factory is required');
103103
if (!opts || !opts.platformInstaller)
104104
throw new IllegalArgumentError('An instance of core/PlatformInstaller is required', opts.platformInstaller);
105105
if (!opts || !opts.keyManager)

src/core/config/local_config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class LocalConfig implements LocalConfigData {
151151
this.logger.info(`Wrote local config to ${this.filePath}: ${yamlContent}`);
152152
}
153153

154-
public promptLocalConfigTask(k8Factory: K0018): SoloListrTask<any> {
154+
public promptLocalConfigTask(k8Factory: K8Factory): SoloListrTask<any> {
155155
const self = this;
156156

157157
return {

src/core/config/remote/remote_config_validator.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ export class RemoteConfigValidator {
2121
* @param namespace - namespace to validate the components in.
2222
* @param components - components which to validate.
2323
* @param k8Factory - to validate the elements.
24-
* TODO: Make compatible with multi-cluster K0018 implementation
24+
* TODO: Make compatible with multi-cluster K8 implementation
2525
*/
2626
public static async validateComponents(
2727
namespace: NamespaceName,
2828
components: ComponentsDataWrapper,
29-
k8Factory: K0018,
29+
k8Factory: K8Factory,
3030
): Promise<void> {
3131
await Promise.all([
3232
...RemoteConfigValidator.validateRelays(namespace, components, k8Factory),
@@ -41,7 +41,7 @@ export class RemoteConfigValidator {
4141
private static validateRelays(
4242
namespace: NamespaceName,
4343
components: ComponentsDataWrapper,
44-
k8Factory: K0018,
44+
k8Factory: K8Factory,
4545
): Promise<void>[] {
4646
return Object.values(components.relays).map(async component => {
4747
try {
@@ -58,7 +58,7 @@ export class RemoteConfigValidator {
5858
private static validateHaProxies(
5959
namespace: NamespaceName,
6060
components: ComponentsDataWrapper,
61-
k8Factory: K0018,
61+
k8Factory: K8Factory,
6262
): Promise<void>[] {
6363
return Object.values(components.haProxies).map(async component => {
6464
try {
@@ -78,7 +78,7 @@ export class RemoteConfigValidator {
7878
private static validateMirrorNodes(
7979
namespace: NamespaceName,
8080
components: ComponentsDataWrapper,
81-
k8Factory: K0018,
81+
k8Factory: K8Factory,
8282
): Promise<void>[] {
8383
return Object.values(components.mirrorNodes).map(async component => {
8484
try {
@@ -95,7 +95,7 @@ export class RemoteConfigValidator {
9595
private static validateEnvoyProxies(
9696
namespace: NamespaceName,
9797
components: ComponentsDataWrapper,
98-
k8Factory: K0018,
98+
k8Factory: K8Factory,
9999
): Promise<void>[] {
100100
return Object.values(components.envoyProxies).map(async component => {
101101
try {
@@ -115,7 +115,7 @@ export class RemoteConfigValidator {
115115
private static validateConsensusNodes(
116116
namespace: NamespaceName,
117117
components: ComponentsDataWrapper,
118-
k8Factory: K0018,
118+
k8Factory: K8Factory,
119119
): Promise<void>[] {
120120
return Object.values(components.consensusNodes).map(async component => {
121121
try {
@@ -135,7 +135,7 @@ export class RemoteConfigValidator {
135135
private static validateMirrorNodeExplorers(
136136
namespace: NamespaceName,
137137
components: ComponentsDataWrapper,
138-
k8Factory: K0018,
138+
k8Factory: K8Factory,
139139
): Promise<void>[] {
140140
return Object.values(components.mirrorNodeExplorers).map(async component => {
141141
try {

src/core/lease/interval_lease.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ export class IntervalLease implements Lease {
4040
private _scheduleId: number | null = null;
4141

4242
/**
43-
* @param client - Injected kubernetes client need by the methods to create, renew, and delete leases.
43+
* @param k8Factory - Injected kubernetes K8Factory need by the methods to create, renew, and delete leases.
4444
* @param renewalService - Injected lease renewal service need to support automatic (background) lease renewals.
4545
* @param leaseHolder - The holder of the lease.
4646
* @param namespace - The namespace in which the lease is to be acquired.
4747
* @param leaseName - The name of the lease to be acquired; if not provided, the namespace is used.
4848
* @param durationSeconds - The duration in seconds for which the lease is to be held; if not provided, the default value is used.
4949
*/
5050
public constructor(
51-
readonly client: K0018,
51+
readonly k8Factory: K8Factory,
5252
readonly renewalService: LeaseRenewalService,
5353
leaseHolder: LeaseHolder,
5454
namespace: NamespaceName,
5555
leaseName: string | null = null,
5656
durationSeconds: number | null = null,
5757
) {
58-
if (!client) throw new MissingArgumentError('client is required');
58+
if (!k8Factory) throw new MissingArgumentError('k8Factory is required');
5959
if (!renewalService) throw new MissingArgumentError('renewalService is required');
6060
if (!leaseHolder) throw new MissingArgumentError('_leaseHolder is required');
6161
if (!namespace) throw new MissingArgumentError('_namespace is required');
@@ -282,7 +282,7 @@ export class IntervalLease implements Lease {
282282
*/
283283
private async retrieveLease(): Promise<V1Lease> {
284284
try {
285-
return await this.client.leases().read(this.namespace, this.leaseName);
285+
return await this.k8Factory.default().leases().read(this.namespace, this.leaseName);
286286
} catch (e: any) {
287287
if (!(e instanceof SoloError)) {
288288
throw new LeaseAcquisitionError(
@@ -311,11 +311,12 @@ export class IntervalLease implements Lease {
311311
private async createOrRenewLease(lease: V1Lease): Promise<void> {
312312
try {
313313
if (!lease) {
314-
await this.client
314+
await this.k8Factory
315+
.default()
315316
.leases()
316317
.create(this.namespace, this.leaseName, this.leaseHolder.toJson(), this.durationSeconds);
317318
} else {
318-
await this.client.leases().renew(this.namespace, this.leaseName, lease);
319+
await this.k8Factory.default().leases().renew(this.namespace, this.leaseName, lease);
319320
}
320321

321322
if (!this.scheduleId) {
@@ -336,7 +337,7 @@ export class IntervalLease implements Lease {
336337
*/
337338
private async transferLease(lease: V1Lease): Promise<void> {
338339
try {
339-
await this.client.leases().transfer(lease, this.leaseHolder.toJson());
340+
await this.k8Factory.default().leases().transfer(lease, this.leaseHolder.toJson());
340341

341342
if (!this.scheduleId) {
342343
this.scheduleId = await this.renewalService.schedule(this);
@@ -354,7 +355,7 @@ export class IntervalLease implements Lease {
354355
*/
355356
private async deleteLease(): Promise<void> {
356357
try {
357-
await this.client.leases().delete(this.namespace, this.leaseName);
358+
await this.k8Factory.default().leases().delete(this.namespace, this.leaseName);
358359
} catch (e: any) {
359360
throw new LeaseRelinquishmentError(
360361
`failed to delete the lease named '${this.leaseName}' in the ` + `'${this.namespace}' namespace`,

src/core/lease/lease.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {type Duration} from '../time/duration.js';
77
import {type NamespaceName} from '../kube/resources/namespace/namespace_name.js';
88

99
export interface Lease {
10-
readonly client: K8Factory;
10+
readonly k8Factory: K8Factory;
1111
readonly renewalService: LeaseRenewalService;
1212
readonly leaseName: string;
1313
readonly leaseHolder: LeaseHolder;

0 commit comments

Comments
 (0)