Skip to content

pulp-cleanup: add nightly Jenkins job for stale Pulp resource cleanup - #2644

Open
vamahaja wants to merge 1 commit into
mainfrom
pulp-cleanup
Open

pulp-cleanup: add nightly Jenkins job for stale Pulp resource cleanup#2644
vamahaja wants to merge 1 commit into
mainfrom
pulp-cleanup

Conversation

@vamahaja

@vamahaja vamahaja commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

  • Add a nightly pulp-cleanup-nightly Jenkins job that purges stale ceph project Pulp repositories and distributions using scripts/purge-policy.yaml.
  • Cleanup excludes named policy refs via label-select, deletes remaining resources past the default retention days (distributions before repositories), then runs orphan cleanup.
  • Update pulp_upload.sh so repository version retention uses per BRANCH & keep_minimum from the purge policy, with fallback to the default.

Job config

  • Job: pulp-cleanup-nightly, triggered @midnight.
  • Parameters: CEPH_BUILD_BRANCH (default main), CEPH bool (default true) to enable ceph project cleanup.
  • Pipeline sets up the Pulp client, then runs cleanup.sh when CEPH is true.

Purge policy (scripts/purge-policy.yaml)

  • Project root: ceph
  • Default retention: days: 14, keep_minimum: 3
  • Per-ref overrides for release and special branches
  • Cleanup uses named refs as exclusions; uploads use keep_minimum for repository version retention

@vamahaja
vamahaja marked this pull request as draft July 8, 2026 07:31
@vamahaja
vamahaja force-pushed the pulp-cleanup branch 5 times, most recently from f47e5f6 to 72d89d9 Compare July 8, 2026 09:39
@vamahaja
vamahaja marked this pull request as ready for review July 8, 2026 13:03
@vamahaja
vamahaja requested review from djgalloway and zmc July 8, 2026 13:03
@vamahaja
vamahaja marked this pull request as draft July 8, 2026 13:06
@djgalloway

Copy link
Copy Markdown
Contributor

I think we need something more like chacra's retention map.

Or at least leave this PR as-is but add KEEP_MINIMUM or RETAIN_MINIMUM on top of RETAIN_DAYS.

@vamahaja

Copy link
Copy Markdown
Member Author

I think we need something more like chacra's retention map.

Or at least leave this PR as-is but add KEEP_MINIMUM or RETAIN_MINIMUM on top of RETAIN_DAYS.

Updated logic PTAL.

@vamahaja
vamahaja force-pushed the pulp-cleanup branch 6 times, most recently from c62087e to 9d67a99 Compare July 14, 2026 11:24
@vamahaja
vamahaja force-pushed the pulp-cleanup branch 3 times, most recently from a0b55c6 to a83e10c Compare July 20, 2026 10:49
Add a nightly Jenkins job and cleanup script that prune stale `Ceph` project
Pulp repositories and distributions using `scripts/purge-policy.yaml`.

Also update `pulp_upload.sh` so repository version retention uses
`keep_minimum` from the purge policy for the current `BRANCH`, falling back
to the default when the ref is not listed.

Signed-off-by: Vaibhav Mahajan <vamahaja@redhat.com>
@vamahaja
vamahaja marked this pull request as ready for review July 20, 2026 11:22
Comment thread scripts/purge-policy.yaml

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it makes more sense to have this in pulp-cleanup/config

Comment thread scripts/purge-policy.yaml
default:
days: 14
keep_minimum: 3
ref:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add main please. Give it the same retention as a release branch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

keep_minimum is never read from anywhere in here

readonly PULP_RESOURCES=(distribution repository)

# Default protection time in hours
readonly PROTECTION_TIME=24

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minutes. Do 1440.

Options:
  --content-hrefs TEXT       List of specific Contents to delete if they are
                             orphans
  --protection-time INTEGER  How long in minutes Pulp should hold orphan
                             Content and Artifacts before becoming candidates
                             for cleanup task


pulp "${type}" "${resource}" list \
--limit "${PULP_LIST_LIMIT}" \
--ordering '-pulp_created' \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

-pulp_created fetches the newest N. We want to delete the oldest N.

--limit "${PULP_LIST_LIMIT}" \
--ordering '-pulp_created' \
--label-select project="${project}","${label_select}" \
2>&1 | sed -n '/^\[/,$p'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The job/script will fail silently with this. Make a failed pulp call fatal.

Comment on lines +64 to +71
echo "${pulp_json}" | jq -r --arg days "${days}" '
.[]
| select(
(.pulp_created | split(".")[0] + "Z" | fromdateiso8601)
< (now - ($days | tonumber) * 86400)
)
| .name
'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should filter on pulp_last_updated instead.

Also, we'll have a ceph-tentacle-rocky-10-x86_64 repository forever. We want to clean up all of the distrubutions inside that are older than 14 days but keep a minimum of 10.

So if the repository matches any of the named branches in purge-policy.yaml, we should proceed with cleaning up the distributions inside by following the policy.

If the repository doesn't match a named branch in purge_policy.yaml and its pulp_last_updated is over 14 days ago, delete the repository. If newer than 14 days, we should check inside for distributions and clean up any older than 14 days.

script {
echo "Setting up yq..."
sh """#!/bin/bash -ex
source ./scripts/setup_yq.sh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sourcing the script just defines the function. Just run it directly.

display-name: 'Pulp: Cleanup Nightly'
project-type: pipeline
description: >
Nightly parameterized cleanup of stale Teuthology Pulp resources.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggest Nightly parameterized cleanup of stale ceph builds in Pulp

@@ -0,0 +1,37 @@
- job:
name: pulp-cleanup-nightly
disabled: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this intentional?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The other job definitions are .yml

Comment on lines +162 to +165
mapfile -t policy_refs < <(get_policy_refs "${project}" "${label}")
_label_select=$(
printf "${label}!=%s\n" "${policy_refs[@]}" | paste -sd, -
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If anything goes wrong here, this falls back to "delete everything"

Gate on a yq failure, missing file, etc. Any error.

@djgalloway

Copy link
Copy Markdown
Contributor

Maybe implement a DRY_RUN. "Would delete repository ceph-wip-nbala-test-1-centos-9-default-x86_64"

"Leaving distributions X Y Z in repository ceph-tentacle-rocky-10-x86_64 to satisfy keep_minimum: 10"

Something like those. I'd like to see some dry-run output before we let this loose even though the artifacts in pulp aren't terribly important yet.

Finished with my review for now.

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