Skip to content

Commit 7df8234

Browse files
committed
CR
Signed-off-by: Romy <[email protected]>
1 parent 0697861 commit 7df8234

File tree

7 files changed

+45
-13
lines changed

7 files changed

+45
-13
lines changed

src/cmd/nsfs.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,15 @@ async function init_nc_system(config_root) {
264264
};
265265
}
266266
try {
267-
await config_fs.create_system_config_file(JSON.stringify(updated_system_json));
268-
console.log('created NSFS system data with version: ', pkg.version);
267+
if (system_data) {
268+
await config_fs.update_system_config_file(JSON.stringify(updated_system_json));
269+
console.log('updated NC system data with version: ', pkg.version);
270+
} else {
271+
await config_fs.create_system_config_file(JSON.stringify(updated_system_json));
272+
console.log('created NC system data with version: ', pkg.version);
273+
}
269274
} catch (err) {
270-
const msg = 'failed to create NSFS system data due to - ' + err.message;
275+
const msg = 'failed to create/update NC system data due to - ' + err.message;
271276
const error = new Error(msg);
272277
console.error(msg, err);
273278
throw error;

src/manage_nsfs/manage_nsfs_cli_errors.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,12 @@ ManageCLIError.UpgradeHistoryFailed = Object.freeze({
474474
http_code: 500,
475475
});
476476

477+
ManageCLIError.ConfigDirUpdateBlocked = Object.freeze({
478+
code: 'ConfigDirUpdateBlocked',
479+
message: 'Config directory updates are not allowed on mismatch of the config directory version mentioned in system.json and the config directory version of the source code',
480+
http_code: 500,
481+
});
482+
477483
///////////////////////////////
478484
// ERRORS MAPPING //
479485
///////////////////////////////
@@ -495,7 +501,8 @@ ManageCLIError.RPC_ERROR_TO_MANAGE = Object.freeze({
495501
INVALID_SCHEMA: ManageCLIError.InvalidSchema,
496502
NO_SUCH_USER: ManageCLIError.InvalidAccountDistinguishedName,
497503
INVALID_MASTER_KEY: ManageCLIError.InvalidMasterKey,
498-
INVALID_BUCKET_NAME: ManageCLIError.InvalidBucketName
504+
INVALID_BUCKET_NAME: ManageCLIError.InvalidBucketName,
505+
CONFIG_DIR_VERSION_MISMATCH: ManageCLIError.ConfigDirUpdateBlocked
499506
});
500507

501508
const NSFS_CLI_ERROR_EVENT_MAP = {

src/manage_nsfs/manage_nsfs_constants.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const VALID_OPTIONS_DIAGNOSE = {
7878
};
7979

8080
const VALID_OPTIONS_UPGRADE = {
81-
'start': new Set([ 'force', 'expected_version', 'custom_upgrade_scripts_dir', ...CLI_MUTUAL_OPTIONS]),
81+
'start': new Set([ 'skip_verification', 'expected_version', 'custom_upgrade_scripts_dir', ...CLI_MUTUAL_OPTIONS]),
8282
'status': new Set([ ...CLI_MUTUAL_OPTIONS]),
8383
'history': new Set([...CLI_MUTUAL_OPTIONS])
8484
};
@@ -132,7 +132,8 @@ const OPTION_TYPE = {
132132
debug: 'number',
133133
// upgrade options
134134
expected_version: 'string',
135-
custom_upgrade_scripts_dir: 'string'
135+
custom_upgrade_scripts_dir: 'string',
136+
skip_verification: 'boolean'
136137
};
137138

138139
const BOOLEAN_STRING_VALUES = ['true', 'false'];

src/manage_nsfs/upgrade.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ async function manage_upgrade_operations(action, user_input, config_fs) {
3939
*/
4040
async function exec_config_dir_upgrade(user_input, config_fs) {
4141
try {
42-
const force = user_input.force;
42+
const skip_verification = user_input.skip_verification;
4343
const expected_version = user_input.expected_version;
4444
const custom_upgrade_scripts_dir = user_input.custom_upgrade_scripts_dir;
4545

46-
const upgrade_res = await upgrade_config_dir(config_fs, { custom_upgrade_scripts_dir, expected_version, force });
46+
const upgrade_res = await upgrade_config_dir(config_fs, { custom_upgrade_scripts_dir, expected_version, skip_verification });
4747
if (!upgrade_res) throw new Error('Upgrade config directory failed', { cause: upgrade_res });
4848
write_stdout_response(ManageCLIResponse.UpgradeSuccessful, upgrade_res);
4949
} catch (err) {

src/sdk/config_fs.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const native_fs_utils = require('../util/native_fs_utils');
1414
const { RpcError } = require('../rpc');
1515
const nc_mkm = require('../manage_nsfs/nc_master_key_manager').get_instance();
1616
const nsfs_schema_utils = require('../manage_nsfs/nsfs_schema_utils');
17+
const { version_compare } = require('../upgrade/upgrade_utils');
1718

1819
/** @typedef {import('fs').Dirent} Dirent */
1920

@@ -57,6 +58,15 @@ const SYMLINK_SUFFIX = '.symlink';
5758
// need to find a better way for atomic unlinking of symbolic links
5859
// handle atomicity for symlinks
5960

61+
62+
/**
63+
* config_dir_version is a semver that describes the config directory's version.
64+
* config_dir_version is planned to be upgraded when a change that can not be solved only by backward compatibility
65+
* and must require a use of an upgrade script.
66+
* The config directory upgrade script will handle config directory changes of the structure or content of the config files.
67+
* The upgrade script will run via `noobaa-cli upgrade run command`
68+
*/
69+
6070
class ConfigFS {
6171

6272
/**
@@ -987,8 +997,16 @@ class ConfigFS {
987997
async _throw_if_config_dir_locked() {
988998
const system_data = await this.get_system_config_file({silent_if_missing: true});
989999
if (!system_data) return;
990-
if (this.config_dir_version !== system_data.config_directory.config_dir_version) {
991-
throw new RpcError('BAD_REQUEST');
1000+
const running_code_config_dir_version = this.config_dir_version;
1001+
const system_config_dir_version = system_data.config_directory.config_dir_version;
1002+
const ver_comparison = version_compare(running_code_config_dir_version, system_config_dir_version);
1003+
if (ver_comparison > 0) {
1004+
throw new RpcError('CONFIG_DIR_VERSION_MISMATCH', `running code config_dir_version=${running_code_config_dir_version} is higher than the config dir version` +
1005+
`mentioned in system.json =${system_config_dir_version}, any updates to the config directory are blocked until the config dir upgrade`);
1006+
}
1007+
if (ver_comparison < 0) {
1008+
throw new RpcError('CONFIG_DIR_VERSION_MISMATCH', `running code config_dir_version=${running_code_config_dir_version} is lower than the config dir version` +
1009+
`mentioned in system.json =${system_config_dir_version}, any updates to the config directory are blocked until the source code upgrade`);
9921010
}
9931011
}
9941012
}

src/upgrade/nc_upgrade_manager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async function update_rpm_upgrade(config_fs) {
7878
* 4.4. moves the current upgrade from in_progress_upgrade to the upgrade_history.successful_upgrades
7979
* 4.5. is 5.17.0 is a good default for from_version?
8080
* @param {import('../sdk/config_fs').ConfigFS} config_fs
81-
* @param {{custom_upgrade_scripts_dir?: string, expected_version?: string, force?: boolean}} [upgrade_options]
81+
* @param {{custom_upgrade_scripts_dir?: string, expected_version?: string, skip_verification?: boolean}} [upgrade_options]
8282
* @returns {Promise<Object>}
8383
*/
8484
async function upgrade_config_dir(config_fs, upgrade_options = {}) {
@@ -91,11 +91,11 @@ async function upgrade_config_dir(config_fs, upgrade_options = {}) {
9191
const package_from_version = system_data.config_directory.upgrade_package_version;
9292
const package_to_version = pkg.version;
9393
const this_upgrade_versions = { config_dir_from_version, config_dir_to_version, package_from_version, package_to_version };
94-
const { custom_upgrade_scripts_dir, expected_version, force } = upgrade_options;
94+
const { custom_upgrade_scripts_dir, expected_version, skip_verification } = upgrade_options;
9595

9696
if (!should_upgrade(config_dir_from_version, config_dir_to_version)) return { message: 'config_dir_version on system.json and config_fs.config_dir_version match, nothing to upgrade' };
9797

98-
if (!force) await _verify_config_dir_upgrade(system_data, expected_version);
98+
if (!skip_verification) await _verify_config_dir_upgrade(system_data, expected_version);
9999

100100
system_data = await _update_config_dir_upgrade_start(config_fs, system_data, this_upgrade_versions);
101101
const this_upgrade = system_data.config_directory.in_progress_upgrade;

src/upgrade/upgrade_utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ async function load_required_scripts(server_version, container_version, upgrade_
109109

110110
exports.should_upgrade = should_upgrade;
111111
exports.load_required_scripts = load_required_scripts;
112+
exports.version_compare = version_compare;

0 commit comments

Comments
 (0)