Skip to content

Commit 98b028f

Browse files
authored
feat: solo network destroy should update remote-config (#1155)
Signed-off-by: instamenta <[email protected]>
1 parent 1cf5893 commit 98b028f

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/commands/network.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
import {ListrEnquirerPromptAdapter} from '@listr2/prompt-adapter-enquirer';
1818
import chalk from 'chalk';
19-
import {Listr, type ListrTask} from 'listr2';
19+
import {Listr} from 'listr2';
2020
import {IllegalArgumentError, MissingArgumentError, SoloError} from '../core/errors.js';
2121
import {BaseCommand} from './base.js';
2222
import {Flags as flags} from './flags.js';
@@ -40,6 +40,8 @@ import {EnvoyProxyComponent} from '../core/config/remote/components/envoy_proxy_
4040
import {HaProxyComponent} from '../core/config/remote/components/ha_proxy_component.js';
4141
import {v4 as uuidv4} from 'uuid';
4242
import * as Base64 from 'js-base64';
43+
import type {SoloListrTask} from '../types/index.js';
44+
import type {Namespace} from '../core/config/remote/types.js';
4345

4446
export interface NetworkDeployConfigClass {
4547
applicationEnv: string;
@@ -772,10 +774,15 @@ export class NetworkCommand extends BaseCommand {
772774
self.logger.error(message);
773775
self.logger.showUser(chalk.red(message));
774776
networkDestroySuccess = false;
777+
775778
if (ctx.config.deletePvcs && ctx.config.deleteSecrets && ctx.config.force) {
776779
self.k8.deleteNamespace(ctx.config.namespace);
780+
} else {
781+
// If the namespace is not being deleted,
782+
// remove all components data from the remote configuration
783+
self.remoteConfigManager.deleteComponents();
777784
}
778-
}, constants.NETWORK_DESTROY_WAIT_TIMEOUT * 1000);
785+
}, constants.NETWORK_DESTROY_WAIT_TIMEOUT * 1_000);
779786

780787
await self.destroyTask(ctx, task);
781788

@@ -794,7 +801,7 @@ export class NetworkCommand extends BaseCommand {
794801

795802
try {
796803
await tasks.run();
797-
} catch (e: Error | any) {
804+
} catch (e: Error | unknown) {
798805
throw new SoloError('Error destroying network', e);
799806
} finally {
800807
await lease.release();
@@ -947,7 +954,7 @@ export class NetworkCommand extends BaseCommand {
947954
}
948955

949956
/** Adds the consensus node, envoy and haproxy components to remote config. */
950-
public addNodesAndProxies(): ListrTask<any, any, any> {
957+
public addNodesAndProxies(): SoloListrTask<{config: {namespace: Namespace; nodeAliases: NodeAliases}}> {
951958
return {
952959
title: 'Add node and proxies to remote config',
953960
skip: (): boolean => !this.remoteConfigManager.isLoaded(),

src/core/config/local_config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class LocalConfig implements LocalConfigData {
169169
title: 'Prompt local configuration',
170170
skip: this.skipPromptTask,
171171
task: async (_: any, task: SoloListrTaskWrapper<any>): Promise<void> => {
172-
if (self.configFileExists) {
172+
if (self.configFileExists()) {
173173
self.configManager.setFlag(flags.userEmailAddress, self.userEmailAddress);
174174
}
175175

src/core/config/remote/remote_config_manager.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ export class RemoteConfigManager {
221221

222222
/* ---------- Utilities ---------- */
223223

224+
/** Empties the component data inside the remote config */
225+
public async deleteComponents() {
226+
await this.modify(async remoteConfig => {
227+
remoteConfig.components = ComponentsDataWrapper.initializeEmpty();
228+
});
229+
}
230+
224231
public isLoaded(): boolean {
225232
return !!this.remoteConfig;
226233
}

0 commit comments

Comments
 (0)