Skip to content

feat(remote-config): save reusable solo flags in remoteconfig #1191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
dec37b5
added new data wrapper for the common flags and the common methods fo…
instamenta Jan 21, 2025
072f142
add to middleware, pass the configManager and the argv down to the re…
instamenta Jan 21, 2025
7d03d77
removed some ts-ignore tags, lint fix and added .madgerc file to igno…
instamenta Jan 21, 2025
95dff03
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta Jan 21, 2025
8b961b3
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta Jan 21, 2025
9722eee
removed circular dependencies and madgerc override
jeromy-cannon Jan 21, 2025
c354941
working on prompting the user and overriding the configManager's valu…
instamenta Jan 22, 2025
1e270e1
changed strategy to override values on argv so they have effect durin…
instamenta Jan 22, 2025
82b2f5b
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta Jan 23, 2025
a3cbd49
merge with mian
instamenta Jan 23, 2025
75d3837
Apply suggestions from code review
instamenta Jan 23, 2025
1cd8d22
add logic for handling quiet and force flags
instamenta Jan 23, 2025
966ab43
Merge remote-tracking branch 'origin/01178-save-reusable-solo-flags-i…
instamenta Jan 23, 2025
b4eb113
rename method
instamenta Jan 23, 2025
f3d57c6
remove leftover functions from merge
instamenta Jan 23, 2025
047f11d
remove leftover comment
instamenta Jan 23, 2025
e7daab4
remove unusued compare method
instamenta Jan 23, 2025
0dd6a2c
removed enquirer and inquirer packages from dependencies
instamenta Jan 23, 2025
43b770f
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta Jan 23, 2025
43d615e
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta Jan 24, 2025
0318b1d
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta Jan 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 3 additions & 201 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"license": "Apache2.0",
"dependencies": {
"@hashgraph/sdk": "^2.56.0",
"@inquirer/prompts": "^7.2.3",
"@kubernetes/client-node": "^0.22.3",
"@listr2/prompt-adapter-enquirer": "^2.0.12",
"@peculiar/x509": "^1.12.3",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class DeploymentCommand extends BaseCommand {
});
},
},
ListrRemoteConfig.createRemoteConfigInMultipleClusters(this),
ListrRemoteConfig.createRemoteConfigInMultipleClusters(this, argv),
],
{
concurrent: false,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ export class MirrorNodeCommand extends BaseCommand {
}

/** Removes the mirror node components from remote config. */
public removeMirrorNodeComponents(): SoloListrTask<object> {
public removeMirrorNodeComponents(): SoloListrTask<any> {
return {
title: 'Remove mirror node from remote config',
skip: (): boolean => !this.remoteConfigManager.isLoaded(),
Expand Down
118 changes: 118 additions & 0 deletions src/core/config/remote/common_flags_data_wrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the ""License"");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an ""AS IS"" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {Flags as flags} from '../../../commands/flags.js';
import type {ToObject} from '../../../types/index.js';
import type {RemoteConfigCommonFlagsStruct} from './types.js';
import type {ConfigManager} from '../../config_manager.js';
import type {CommandFlag} from '../../../types/flag_types.js';
import type {AnyObject} from '../../../types/aliases.js';
import {select} from '@inquirer/prompts';

export class CommonFlagsDataWrapper implements ToObject<RemoteConfigCommonFlagsStruct> {
private static readonly COMMON_FLAGS: CommandFlag[] = [
flags.releaseTag,
flags.chartDirectory,
flags.relayReleaseTag,
flags.soloChartVersion,
flags.mirrorNodeVersion,
flags.nodeAliasesUnparsed,
flags.hederaExplorerVersion,
];

private constructor(
private readonly configManager: ConfigManager,
private readonly flags: RemoteConfigCommonFlagsStruct,
) {}

/**
* Updates the flags or populates them inside the remote config
*/
public async handleFlags(argv: AnyObject): Promise<void> {
for (const flag of CommonFlagsDataWrapper.COMMON_FLAGS) {
await this.checkFlag(flag, argv);
}
}

private async checkFlag(flag: CommandFlag, argv: AnyObject): Promise<void> {
const detectFlagMismatch = async () => {
const oldValue = this.flags[flag.constName] as string;
const newValue = this.configManager.getFlag<string>(flag);

// if the old value is not present, override it with the new one
if (!oldValue && newValue) {
this.flags[flag.constName] = newValue;
return;
}

// if its present but there is a mismatch warn user
else if (oldValue && oldValue !== newValue) {
const answer = await select<string>({
message: 'Value in remote config differs with the one you are passing, choose which you want to use',
choices: [
{
name: `[old value] ${oldValue}`,
value: oldValue,
},
{
name: `[new value] ${newValue}`,
value: newValue,
},
],
});

// Override if user chooses new the new value, else override and keep the old one
if (answer === newValue) {
this.flags[flag.constName] = newValue;
} else {
this.configManager.setFlag(flag, oldValue);
argv[flag.constName] = oldValue;
}
}

Check warning on line 84 in src/core/config/remote/common_flags_data_wrapper.ts

View check run for this annotation

Codecov / codecov/patch

src/core/config/remote/common_flags_data_wrapper.ts#L60-L84

Added lines #L60 - L84 were not covered by tests
};

// if the flag is set, inspect the value
if (this.configManager.hasFlag(flag)) {
await detectFlagMismatch();
}

// if the value is not set and exists, override it
else if (this.flags[flag.constName]) {
argv[flag.constName] = this.flags[flag.constName];
this.configManager.setFlag(flag, this.flags[flag.constName]);
}

Check warning on line 96 in src/core/config/remote/common_flags_data_wrapper.ts

View check run for this annotation

Codecov / codecov/patch

src/core/config/remote/common_flags_data_wrapper.ts#L94-L96

Added lines #L94 - L96 were not covered by tests
}

public static async initializeEmpty(configManager: ConfigManager, argv: AnyObject): Promise<CommonFlagsDataWrapper> {
const commonFlagsDataWrapper = new CommonFlagsDataWrapper(configManager, {});
await commonFlagsDataWrapper.handleFlags(argv);
return commonFlagsDataWrapper;
}

public static fromObject(configManager: ConfigManager, data: RemoteConfigCommonFlagsStruct): CommonFlagsDataWrapper {
return new CommonFlagsDataWrapper(configManager, data);
}

public toObject(): RemoteConfigCommonFlagsStruct {
return {
nodeAliasesUnparsed: this.flags.nodeAliasesUnparsed,
releaseTag: this.flags.releaseTag,
relayReleaseTag: this.flags.relayReleaseTag,
hederaExplorerVersion: this.flags.hederaExplorerVersion,
mirrorNodeVersion: this.flags.mirrorNodeVersion,
};
}
}
Loading
Loading