-
Notifications
You must be signed in to change notification settings - Fork 82
[NC | DBS3] Add support for reserved bucket tags #8967
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
base: master
Are you sure you want to change the base?
[NC | DBS3] Add support for reserved bucket tags #8967
Conversation
6126797
to
779c0bf
Compare
@@ -256,25 +265,14 @@ async function update_bucket(data) { | |||
*/ | |||
async function delete_bucket(data, force) { | |||
try { | |||
const temp_dir_name = native_fs_utils.get_bucket_tmpdir_name(data._id); | |||
const bucket_empty = await _is_bucket_empty(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a bit confusing, suggesting to change it to:
const bucket_empty = await _is_bucket_empty(data); | |
const is_bucket_empty = await empty_bucket(data); |
From what I understand the operation is to empty the bucket and return true
when it ends.
src/sdk/bucketspace_fs.js
Outdated
try { | ||
const { name, tagging } = params; | ||
dbg.log0('BucketSpaceFS.put_bucket_tagging: Bucket name, tagging', name, tagging); | ||
const bucket = await this.config_fs.get_bucket_by_name(name); | ||
bucket.tag = tagging; | ||
const { ns } = await object_sdk.read_bucket_full_info(name); | ||
const is_bucket_empty = await BucketSpaceFS.#_is_bucket_empty(name, null, ns, object_sdk); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you pass null
as the params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I wanted to not provide and params in this case.
undefined
vs null
- this is quite opinionated. I prefer using null
over undefined
when I intentionally want to have a zero value. It helps me tell when the zero value was intentional and when the zero value is system generated.
I am aware that Guy disagrees with this opinion as null
is an object.
|
||
let list; | ||
try { | ||
if (ns._is_versioning_disabled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
versioning
is a property of the bucket, I think you can check if the bucket versioning is disabled in a simpler way.
noobaa-core/src/server/system_services/schemas/nsfs_bucket_schema.js
Lines 48 to 49 in 779c0bf
versioning: { | |
$ref: 'common_api#/definitions/versioning', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to keep the check consistent with the rest of bucketspace_fs
.
list = await ns.list_objects({ ...params, bucket: name, limit: 1 }, object_sdk); | ||
} else { | ||
list = await ns.list_object_versions({ ...params, bucket: name, limit: 1 }, object_sdk); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code used more than once?
We can move it to a function and reuse it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is I think but don't think its worth moving these lines into a new function. This code is concise enough, wdyt?
@tangledbytes some general comments / questions:
|
5cf067e
to
d52195c
Compare
} | ||
* } | ||
*/ | ||
config.NSFS_GLACIER_RESERVED_BUCKET_TAGS = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this structure is an overkill. Isn't a simple array of reserved tag names sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to keep it simple but at the same time I didn't want to write hard-coded things.
This structure just made sure that I don't have to hard-code few things like -
- Validation for the tags - Different reserved tags will have different validation requirements.
- Default values - Different tags would have different values, some might not even have one.
- Immutability - Different tags would want to behave differently. Some tags might want to allow mutability, some might not and some might want to do conditionally.
Do you have a suggestion for a simpler structure but make sure that we don't have some specific code (because this generic code ain't too complicated)?
* | ||
* @returns {Promise<boolean>} | ||
*/ | ||
static async #_is_bucket_empty(name, params, ns, object_sdk) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO restricting visibility to private is something that should be used only for libraries and well defined API's between separate softwares, not as an internal encapsulation, which will just pollute our code with useless considerations of who should be able to see this function/variable.
continue; | ||
} | ||
if (!tag_info.immutable || (tag_info.immutable === 'if-data' && is_bucket_empty)) { | ||
let validator = ajv.getSchema(tag_info.schema.$id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using AJV for reserving tags is so much more complex that we should... I expected a much simpler implementation.
d52195c
to
0c76f7d
Compare
Signed-off-by: Utkarsh Srivastava <[email protected]> fix put_bucket_tagging test - pass dummy objectsdk Signed-off-by: Utkarsh Srivastava <[email protected]> add support for events, race safe tag manipulation and --merge_tag flag Signed-off-by: Utkarsh Srivastava <[email protected]> fix lint issues Signed-off-by: Utkarsh Srivastava <[email protected]> clarify the reserved tags config comment Signed-off-by: Utkarsh Srivastava <[email protected]> add docs for the CLI changes Signed-off-by: Utkarsh Srivastava <[email protected]> address PR comments Signed-off-by: Utkarsh Srivastava <[email protected]> add account name to the bucket create event Signed-off-by: Utkarsh Srivastava <[email protected]>
0c76f7d
to
4c43788
Compare
Explain the Changes
This PR adds the concept of "reserved" bucket tags which are bucket tags which can be set via noobaa cli or via
put-bucket-tagging
but they can come with further restrictions like a schema, immutability, etc.DBS3 Example:
Usage Example:
Issues: Fixed #xxx / Gap #xxx
Testing Instructions: