Skip to content

Commit 98e1e9f

Browse files
committed
removed caching of configmanager, expect a lot of test cases that need to be fixed
Signed-off-by: Jeromy Cannon <jeromy@swirldslabs.com>
1 parent 3d868e6 commit 98e1e9f

15 files changed

+55
-271
lines changed

src/commands/node.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,9 @@ export class NodeCommand extends BaseCommand {
798798
const self = this
799799
if (localBuildPath !== '') {
800800
return self.uploadPlatformSoftware(nodeAliases, podNames, task, localBuildPath)
801-
}
801+
}
802802
return self.fetchPlatformSoftware(nodeAliases, podNames, releaseTag, task, self.platformInstaller)
803-
803+
804804
}
805805

806806
fetchPlatformSoftware (nodeAliases: NodeAliases, podNames: Record<NodeAlias, PodName>, releaseTag: string,
@@ -1214,7 +1214,6 @@ export class NodeCommand extends BaseCommand {
12141214
// reset flags so that keys are not regenerated later
12151215
self.configManager.setFlag(flags.generateGossipKeys, false)
12161216
self.configManager.setFlag(flags.generateTlsKeys, false)
1217-
self.configManager.persist()
12181217
}
12191218
}
12201219
])
@@ -1844,7 +1843,6 @@ export class NodeCommand extends BaseCommand {
18441843
// reset flags so that keys are not regenerated later
18451844
self.configManager.setFlag(flags.generateGossipKeys, false)
18461845
self.configManager.setFlag(flags.generateTlsKeys, false)
1847-
self.configManager.persist()
18481846
}
18491847
}
18501848
]
@@ -2652,7 +2650,6 @@ export class NodeCommand extends BaseCommand {
26522650
// reset flags so that keys are not regenerated later
26532651
self.configManager.setFlag(flags.generateGossipKeys, false)
26542652
self.configManager.setFlag(flags.generateTlsKeys, false)
2655-
self.configManager.persist()
26562653
}
26572654
}
26582655
], {
@@ -2869,7 +2866,6 @@ export class NodeCommand extends BaseCommand {
28692866
// reset flags so that keys are not regenerated later
28702867
self.configManager.setFlag(flags.generateGossipKeys, false)
28712868
self.configManager.setFlag(flags.generateTlsKeys, false)
2872-
self.configManager.persist()
28732869
}
28742870
}
28752871
]

src/commands/prompts.ts

-2
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,6 @@ export async function execute (task: ListrTaskWrapper<any, any, any>, configMana
503503
const input = await prompt(task, configManager.getFlag(flag))
504504
configManager.setFlag(flag, input)
505505
}
506-
507-
configManager.persist()
508506
}
509507

510508
/**

src/commands/relay.ts

-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ export class RelayCommand extends BaseCommand {
236236

237237
// reset nodeAlias
238238
self.configManager.setFlag(flags.nodeAliasesUnparsed, '')
239-
self.configManager.persist()
240239
}
241240
},
242241
{
@@ -316,7 +315,6 @@ export class RelayCommand extends BaseCommand {
316315

317316
// reset nodeAliasesUnparsed
318317
self.configManager.setFlag(flags.nodeAliasesUnparsed, '')
319-
self.configManager.persist()
320318
},
321319
skip: (ctx) => !ctx.config.isChartInstalled
322320
}

src/core/config_manager.ts

+3-44
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
import fs from 'fs'
1817
import { SoloError, MissingArgumentError } from './errors.ts'
19-
import { constants } from './index.ts'
2018
import { SoloLogger } from './logging.ts'
2119
import * as flags from '../commands/flags.ts'
2220
import * as paths from 'path'
2321
import * as helpers from './helpers.ts'
24-
import * as yaml from 'js-yaml'
25-
import { yamlToObject } from './helpers.ts'
2622
import type * as yargs from 'yargs'
2723
import { type CommandFlag } from '../types/index.js'
2824

@@ -35,26 +31,12 @@ import { type CommandFlag } from '../types/index.js'
3531
export class ConfigManager {
3632
config!: Record<string, any>
3733

38-
constructor (private readonly logger: SoloLogger, private readonly cachedConfigFile = constants.SOLO_CONFIG_FILE) {
34+
constructor (private readonly logger: SoloLogger) {
3935
if (!logger || !(logger instanceof SoloLogger)) throw new MissingArgumentError('An instance of core/SoloLogger is required')
40-
if (!cachedConfigFile) throw new MissingArgumentError('cached config file path is required')
4136

4237
this.reset()
4338
}
4439

45-
/**
46-
* Load the cached config
47-
*/
48-
load () {
49-
try {
50-
if (fs.existsSync(this.cachedConfigFile)) {
51-
this.config = yamlToObject(this.cachedConfigFile) as Record<string, any>
52-
}
53-
} catch (e: Error | any) {
54-
throw new SoloError(`failed to initialize config manager: ${e.message}`, e)
55-
}
56-
}
57-
5840
/** Reset config */
5941
reset () {
6042
this.config = {
@@ -69,8 +51,7 @@ export class ConfigManager {
6951
*
7052
* It uses the below precedence for command flag values:
7153
* 1. User input of the command flag
72-
* 2. Cached config value of the command flag.
73-
* 3. Default value of the command flag if the command is not 'init'.
54+
* 2. Default value of the command flag if the command is not 'init'.
7455
*/
7556
applyPrecedence (argv: yargs.Argv<any>, aliases: any): yargs.Argv<any> {
7657
for (const key of Object.keys(aliases)) {
@@ -93,7 +74,7 @@ export class ConfigManager {
9374
}
9475

9576
/** Update the config using the argv */
96-
update (argv: object | any = {}, persist: boolean = false) {
77+
update (argv: object | any = {}) {
9778
if (argv && Object.keys(argv).length > 0) {
9879
for (const flag of flags.allFlags) {
9980
if (flag.name === flags.force.name) {
@@ -147,23 +128,6 @@ export class ConfigManager {
147128
}
148129

149130
this.config.updatedAt = new Date().toISOString()
150-
151-
if (persist) {
152-
this.persist()
153-
}
154-
}
155-
}
156-
157-
/** Persist the config in the cached config file */
158-
persist () {
159-
try {
160-
this.config.updatedAt = new Date().toISOString()
161-
const newYaml = yaml.dump(this.config)
162-
fs.writeFileSync(this.cachedConfigFile, newYaml)
163-
// refresh config with the file contents
164-
this.load()
165-
} catch (e: Error | any) {
166-
throw new SoloError(`failed to persis config: ${e.message}`, e)
167131
}
168132
}
169133

@@ -194,9 +158,4 @@ export class ConfigManager {
194158
getVersion (): string {
195159
return this.config.version
196160
}
197-
198-
/** Get last updated at timestamp */
199-
getUpdatedAt (): string {
200-
return this.config.updatedAt
201-
}
202161
}

src/core/constants.ts

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const SOLO_CACHE_DIR = path.join(SOLO_HOME_DIR, 'cache')
3030
export const SOLO_VALUES_DIR = path.join(SOLO_CACHE_DIR, 'values-files')
3131
export const DEFAULT_NAMESPACE = 'default'
3232
export const HELM = 'helm'
33-
export const SOLO_CONFIG_FILE = path.join(SOLO_HOME_DIR, 'solo.yaml')
3433
export const RESOURCES_DIR = normalize(path.join(ROOT_DIR, 'resources'))
3534
export const TEMP_DIR = normalize(path.join(ROOT_DIR, 'temp'))
3635

src/index.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function main (argv: any) {
4646
const zippy = new Zippy(logger)
4747
const helmDepManager = new HelmDependencyManager(downloader, zippy, logger)
4848
const depManagerMap = new Map()
49-
.set(constants.HELM, helmDepManager)
49+
.set(constants.HELM, helmDepManager)
5050
const depManager = new DependencyManager(logger, depManagerMap)
5151

5252
const helm = new Helm(logger)
@@ -79,7 +79,9 @@ export function main (argv: any) {
7979
}
8080

8181
const processArguments = (argv: any, yargs: any) => {
82-
argv._[0] === 'init' ? configManager.reset() : configManager.load()
82+
if (argv._[0] === 'init') {
83+
configManager.reset()
84+
}
8385

8486
// Set default cluster name and namespace from kubernetes context
8587
// these will be overwritten if user has entered the flag values explicitly
@@ -92,7 +94,7 @@ export function main (argv: any) {
9294
argv = configManager.applyPrecedence(argv, yargs.parsed.aliases)
9395

9496
// update and persist config
95-
configManager.update(argv, true)
97+
configManager.update(argv)
9698

9799
logger.showUser(chalk.cyan('\n******************************* Solo *********************************************'))
98100
logger.showUser(chalk.cyan('Version\t\t\t:'), chalk.yellow(configManager.getVersion()))
@@ -105,19 +107,19 @@ export function main (argv: any) {
105107
}
106108

107109
return yargs(hideBin(argv))
108-
.usage('Usage:\n $0 <command> [options]')
109-
.alias('h', 'help')
110-
.alias('v', 'version')
111-
// @ts-ignore
112-
.command(commands.Initialize(opts))
113-
.strict()
114-
// @ts-ignore
115-
.option(flags.devMode.name, flags.devMode.definition)
116-
.wrap(120)
117-
.demand(1, 'Select a command')
118-
// @ts-ignore
119-
.middleware(processArguments, false) // applyBeforeValidate = false as otherwise middleware is called twice
120-
.parse()
110+
.usage('Usage:\n $0 <command> [options]')
111+
.alias('h', 'help')
112+
.alias('v', 'version')
113+
// @ts-ignore
114+
.command(commands.Initialize(opts))
115+
.strict()
116+
// @ts-ignore
117+
.option(flags.devMode.name, flags.devMode.definition)
118+
.wrap(120)
119+
.demand(1, 'Select a command')
120+
// @ts-ignore
121+
.middleware(processArguments, false) // applyBeforeValidate = false as otherwise middleware is called twice
122+
.parse()
121123
} catch (e: Error | any) {
122124
logger.showUserError(e)
123125
process.exit(1)

test/e2e/commands/account.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin
144144
try {
145145
argv[flags.privateKey.name] = constants.GENESIS_KEY
146146
argv[flags.amount.name] = 777
147-
configManager.update(argv, true)
147+
configManager.update(argv)
148148

149149
await expect(accountCmd.create(argv)).to.eventually.be.ok
150150

@@ -166,7 +166,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin
166166
try {
167167
argv[flags.amount.name] = 0
168168
argv[flags.accountId.name] = accountId1
169-
configManager.update(argv, true)
169+
configManager.update(argv)
170170

171171
await expect(accountCmd.update(argv)).to.eventually.be.ok
172172

@@ -188,7 +188,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin
188188
argv[flags.accountId.name] = accountId2
189189
argv[flags.privateKey.name] = constants.GENESIS_KEY
190190
argv[flags.amount.name] = 333
191-
configManager.update(argv, true)
191+
configManager.update(argv)
192192

193193
await expect(accountCmd.update(argv)).to.eventually.be.ok
194194

@@ -208,7 +208,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin
208208
it('should be able to get account-1', async () => {
209209
try {
210210
argv[flags.accountId.name] = accountId1
211-
configManager.update(argv, true)
211+
configManager.update(argv)
212212

213213
await expect(accountCmd.get(argv)).to.eventually.be.ok
214214
// @ts-ignore to access the private property
@@ -227,7 +227,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin
227227
it('should be able to get account-2', async () => {
228228
try {
229229
argv[flags.accountId.name] = accountId2
230-
configManager.update(argv, true)
230+
configManager.update(argv)
231231

232232
await expect(accountCmd.get(argv)).to.eventually.be.ok
233233
// @ts-ignore to access the private property
@@ -249,7 +249,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin
249249
try {
250250
argv[flags.ecdsaPrivateKey.name] = ecdsaPrivateKey.toString()
251251
argv[flags.setAlias.name] = true
252-
configManager.update(argv, true)
252+
configManager.update(argv)
253253

254254
await expect(accountCmd.create(argv)).to.eventually.be.ok
255255

test/e2e/commands/cluster.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('ClusterCommand', () => {
6565

6666
await k8.deleteNamespace(namespace)
6767
argv[flags.clusterSetupNamespace.name] = constants.SOLO_SETUP_NAMESPACE
68-
configManager.update(argv, true)
68+
configManager.update(argv)
6969
await clusterCmd.setup(argv) // restore solo-cluster-setup for other e2e tests to leverage
7070
do {
7171
await sleep(5 * SECONDS)
@@ -85,13 +85,13 @@ describe('ClusterCommand', () => {
8585

8686
it('solo cluster setup should fail with invalid cluster name', async () => {
8787
argv[flags.clusterSetupNamespace.name] = 'INVALID'
88-
configManager.update(argv, true)
88+
configManager.update(argv)
8989
await expect(clusterCmd.setup(argv)).to.be.rejectedWith('Error on cluster setup')
9090
}).timeout(MINUTES)
9191

9292
it('solo cluster setup should work with valid args', async () => {
9393
argv[flags.clusterSetupNamespace.name] = namespace
94-
configManager.update(argv, true)
94+
configManager.update(argv)
9595
await expect(clusterCmd.setup(argv)).to.eventually.be.ok
9696
}).timeout(MINUTES)
9797

@@ -111,7 +111,7 @@ describe('ClusterCommand', () => {
111111
// helm list would return an empty list if given invalid namespace
112112
it('solo cluster reset should fail with invalid cluster name', async () => {
113113
argv[flags.clusterSetupNamespace.name] = 'INVALID'
114-
configManager.update(argv, true)
114+
configManager.update(argv)
115115

116116
try {
117117
await expect(clusterCmd.reset(argv)).to.be.rejectedWith('Error on cluster reset')
@@ -123,7 +123,7 @@ describe('ClusterCommand', () => {
123123

124124
it('solo cluster reset should work with valid args', async () => {
125125
argv[flags.clusterSetupNamespace.name] = namespace
126-
configManager.update(argv, true)
126+
configManager.update(argv)
127127
await expect(clusterCmd.reset(argv)).to.eventually.be.ok
128128
}).timeout(MINUTES)
129129
})

test/e2e/commands/network.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('NetworkCommand', () => {
123123
argv[flags.deletePvcs.name] = true
124124
argv[flags.deleteSecrets.name] = true
125125
argv[flags.force.name] = true
126-
configManager.update(argv, true)
126+
configManager.update(argv)
127127

128128
try {
129129
await expect(networkCmd.destroy(argv)).to.eventually.be.ok

test/e2e/e2e_node_util.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ import {
2323
balanceQueryShouldSucceed,
2424
e2eTestSuite,
2525
getDefaultArgv,
26-
getTestConfigManager,
2726
HEDERA_PLATFORM_VERSION_TAG,
28-
TEST_CLUSTER
27+
TEST_CLUSTER, testLogger
2928
} from '../test_util.ts'
3029
import { getNodeLogs, sleep } from '../../src/core/helpers.ts'
3130
import { NodeCommand } from '../../src/commands/node.ts'
3231
import { MINUTES, SECONDS } from '../../src/core/constants.ts'
3332
import type { NodeAlias } from '../../src/types/aliases.ts'
34-
import { NodeAliases } from '../../src/types/aliases.ts'
3533
import type { ListrTaskWrapper } from 'listr2'
36-
import type { K8 } from '../../src/core/index.ts'
34+
import { ConfigManager, type K8 } from '../../src/core/index.ts'
3735

3836
export function e2eNodeKeyRefreshTest (testName: string, mode: string, releaseTag = HEDERA_PLATFORM_VERSION_TAG) {
3937
const namespace = testName
@@ -174,8 +172,8 @@ export function e2eNodeKeyRefreshTest (testName: string, mode: string, releaseTa
174172

175173
async function nodeRefreshTestSetup (argv: Record<any, any>, testName: string, k8: K8, nodeAliases: string) {
176174
argv[flags.nodeAliasesUnparsed.name] = nodeAliases
177-
const configManager = getTestConfigManager(`${testName}-solo.yaml`)
178-
configManager.update(argv, true)
175+
const configManager = new ConfigManager(testLogger)
176+
configManager.update(argv)
179177

180178
const podArray = await k8.getPodsByLabel(
181179
[`app=network-${nodeAliases}`,

test/e2e/integration/core/platform_installer_e2e.test.ts

-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ e2eTestSuite(namespace, argv, undefined, undefined, undefined, undefined, undefi
5050
describe('PackageInstallerE2E', async () => {
5151
const k8 = bootstrapResp.opts.k8
5252
const accountManager = bootstrapResp.opts.accountManager
53-
const configManager = bootstrapResp.opts.configManager
5453
const installer = bootstrapResp.opts.platformInstaller
5554
const podName = 'network-node1-0'
5655
const packageVersion = 'v0.42.5'
@@ -68,7 +67,6 @@ e2eTestSuite(namespace, argv, undefined, undefined, undefined, undefined, undefi
6867
if (!fs.existsSync(testCacheDir)) {
6968
fs.mkdirSync(testCacheDir)
7069
}
71-
configManager.load()
7270
})
7371

7472
describe('fetchPlatform', () => {

0 commit comments

Comments
 (0)