Skip to content
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

cmd-cloud-prune: Fixed cloud pruning and backed up builds.json #3863

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

gursewak1997
Copy link
Member

@gursewak1997 gursewak1997 commented Aug 26, 2024

Updated the process to ensure that the build order is preserved while keeping all existing builds from the builds.json file intact. Previously, we were updating the builds on the wrong index after we switched the enumerating of the builds in reversed order which caused us to lose the builds and also switched the ordering.
Additionally, added a step to print the updated builds.json during a dry run, which will be uploaded in non-dry run mode. Also, the previous version of builds.json is now backed up to the S3 bucket as builds.json.bak.

build.setdefault("policy-cleanup", []).append("cloud-uploads")
builds_json_data["builds"][index] = build
build.setdefault("policy-cleanup", []).append("cloud-uploads")
builds[len(builds) - 1 - index] = build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that shouldn't be necessary. build is the original object within builds already.

# Save the updated builds.json to local builds/builds.json
save_builds_json(builds_json_data)
# Ensure the builds are ordered from newest to oldest.
builds.sort(key=lambda x: x['id'], reverse=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be doing any sorting at all here. Why do we need this? How is the array getting unsorted in the first place?

# Ensure the builds are ordered from newest to oldest.
builds.sort(key=lambda x: x['id'], reverse=True)
# Save the updated builds.json to local builds/builds.json
save_builds_json(builds_json_data, BUILDFILES['list'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we lost the conditional on args.dry_run here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to see/print the updated builds.json, we will need to skip on the args.dry_run at couple of places in order to update the builds.json.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, right. But I think it's also weird to have a --dry-run operation actually overwrite builds.json. But OK, I think that's fine.

# Make sure we have the merged json as local builds/builds.json
save_builds_json(remote_builds_json)
# Make sure we have the merged json as local builds/builds.json
save_builds_json(remote_builds_json, BUILDFILES['list'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lost conditional on dry run.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@jlebon
Copy link
Member

jlebon commented Aug 27, 2024

Can you expand on what went wrong that caused some of the build entries to get lost?

src/cmd-cloud-prune Outdated Show resolved Hide resolved
jlebon
jlebon previously approved these changes Aug 27, 2024
# Ensure the builds are ordered from newest to oldest.
builds.sort(key=lambda x: x['id'], reverse=True)
# Save the updated builds.json to local builds/builds.json
save_builds_json(builds_json_data, BUILDFILES['list'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, right. But I think it's also weird to have a --dry-run operation actually overwrite builds.json. But OK, I think that's fine.

with open(BUILDFILES['list'], 'r') as file:
data = json.load(file)
print("This is the updated builds.json\n")
print(json.dumps(data, indent=2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(json.dumps(data, indent=2))
print(json.dumps(data, indent=4))

Comment on lines 237 to 238
print("This is the updated builds.json\n")
print(json.dumps(data, indent=2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like:

Suggested change
print("This is the updated builds.json\n")
print(json.dumps(data, indent=2))
print("---")
print(json.dumps(data, indent=4))
print("---")

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this should work.

Updated the process to ensure that the build order is preserved while keeping all existing builds from the builds.json file intact. Additionally, added a step to print the updated builds.json during a dry run, which will be uploaded in non-dry run mode. Also, the previous version of builds.json is now backed up to the S3 bucket as builds.json.bak.
@jlebon jlebon enabled auto-merge (rebase) August 27, 2024 18:35
@jlebon jlebon merged commit 77118ab into coreos:main Aug 27, 2024
5 checks passed
@gursewak1997 gursewak1997 deleted the fix-pruning branch August 27, 2024 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants