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

[devbin] Generate cleanup policies for GCP artifact registry #13489

Merged
merged 12 commits into from
Aug 29, 2023

Conversation

jigold
Copy link
Contributor

@jigold jigold commented Aug 24, 2023

Fixes #13441

Usage: python3 devbin/generate_gcp_ar_cleanup_policy.py > my_policy_file.txt
Reference: https://cloud.google.com/artifact-registry/docs/repositories/cleanup-policy
Note, we have a maximum of 10 policies available.

image = image.strip()
package = image.split(':')[0]
if package not in third_party_packages:
third_party_packages.append(package)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep only the tags listed there?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that means we need #-of-package policies, which is currently 11.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I grabbed all of the tags if they exist, but I'm concerned because these are tag prefix matches so it's not 100% specific to the package.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think if we can't do something exact we should do nothing at all. Better to not have a false sense of security.



deploy_packages = []
with open('build.yaml', 'r') as f:
Copy link
Contributor

Choose a reason for hiding this comment

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

Also get the images from ci/test/resources/build.yaml

return data


class ConditionalKeepPolicy(CleanupPolicy):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just a KeepPolicy, right? Or, otherwise, the above is a ConditionalDeletePolicy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just used their nomenclature in the docs

DeletePolicy('delete_test_pr', 'tagged', tag_prefixes=['test-pr-'], older_than='3d'),
DeletePolicy('delete_test_deploy', 'tagged', tag_prefixes=['test-deploy-'], older_than='3d'),
DeletePolicy('delete_cache', 'tagged', tag_prefixes=['cache-pr-'], older_than='7d'),
DeletePolicy('delete_cache', 'tagged', tag_prefixes=['cache-'], older_than='30d'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the names required to be unique?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sort above.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm referring to the names of the policies themselves; delete_cache appears twice.

@danking
Copy link
Contributor

danking commented Aug 24, 2023

@daniel-goldstein is it possible to run a script and use that as input to terraform? Or is it easier to bake in a policy file and then verify in CI that the policy file has not changed?

@daniel-goldstein
Copy link
Contributor

In the former, do you mean to run terraform in CI? The latter seems easier to me given our current system. That being said, our current system isn't great since it does not let you have more than 1 concurrent PR that wants to make terraform changes.

@danking
Copy link
Contributor

danking commented Aug 24, 2023

I was thinking either:

  1. terraform apply somehow executes a bash script which is then fed as input to the terraform provider for the cleanup polices.
  2. The cleanup policy is a checked-in file which we verify is up-to-date in CI (much like how pinned-requirements.txt are derived from requirements.txt).

The latter seems better to me since we know the current state of the cleanup policy on any commit by looking at a file rather than executing some code.

@daniel-goldstein
Copy link
Contributor

Ah, I see. 1. is definitely possible, but I agree with you that I prefer 2 because it is checked by our system.

Copy link
Contributor

@danking danking left a comment

Choose a reason for hiding this comment

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

Excellent, my final request is to:

  1. Run this and check in the result (store it in infra/gcp-broad/).
  2. Add a build.yaml step that runs this and diffs against the checked in file. Fail if they differ.
  3. Install the policy in hail-vdc.
  4. Create a bug issue that asks us to import this into terraform once hashicorp/terraform-provider-google-beta@bc4aa51 is publicly released (see also the overarching tracking issue). It's not in 4.79.0 (see what was added since then). Releases appear to happen ~once a week, so we should be able to import into terraform in September.

@jigold
Copy link
Contributor Author

jigold commented Aug 28, 2023

Once you've looked over the policy generated, I'll apply it. Otherwise, this is ready to go.

Copy link
Contributor

@danking danking left a comment

Choose a reason for hiding this comment

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

lgtm

@danking
Copy link
Contributor

danking commented Aug 28, 2023

Once it merges, please apply it

@jigold jigold force-pushed the ar-cleanup-policy branch from 5d1407f to 16c2fb4 Compare August 29, 2023 15:36
@danking danking merged commit 0132c19 into hail-is:main Aug 29, 2023
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.

[infra] Hail should automatically and periodically cleanup unnecessary images
3 participants