Skip to content

rerelease script - #5598

Open
ronnll wants to merge 1 commit into
mainfrom
20260716script
Open

rerelease script#5598
ronnll wants to merge 1 commit into
mainfrom
20260716script

Conversation

@ronnll

@ronnll ronnll commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Add a batch rerelease utility script for creating and monitoring Release CRs from a list of snapshots.

New Features:

  • Provide a bash script to create Release custom resources for snapshots in configurable batches and wait for each batch to complete.
  • Support dry-run mode and logging of per-release outcomes and overall progress for batch rereleases.

@sourcery-ai

sourcery-ai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a bash utility script to batch-create and monitor Release custom resources for a list of snapshots, with support for dry runs, logging, and configurable batch/wait parameters.

Sequence diagram for batch rerelease script creating and monitoring Release CRs

sequenceDiagram
    actor User
    participant batch_rerelease_sh
    participant OpenShift_cluster

    User->>batch_rerelease_sh: ./hack/batch-rerelease.sh --input snapshots.txt
    batch_rerelease_sh->>OpenShift_cluster: oc whoami
    batch_rerelease_sh->>batch_rerelease_sh: mapfile SNAPSHOTS

    loop For each batch
        batch_rerelease_sh->>OpenShift_cluster: oc create -f - (Release CR)
        OpenShift_cluster-->>batch_rerelease_sh: metadata.name
        batch_rerelease_sh->>batch_rerelease_sh: wait_for_releases(names)

        loop wait_for_releases polling
            batch_rerelease_sh->>OpenShift_cluster: oc get release -o json
            OpenShift_cluster-->>batch_rerelease_sh: status.conditions[Released].reason
            alt [reason == Progressing or empty]
                batch_rerelease_sh->>batch_rerelease_sh: sleep 30
            else [reason is Succeeded/Failed]
                batch_rerelease_sh->>batch_rerelease_sh: update SUCCEEDED/FAILED
            end
        end

        batch_rerelease_sh->>batch_rerelease_sh: log batch progress
    end

    batch_rerelease_sh-->>User: Log file rerelease-results.log with summary
Loading

File-Level Changes

Change Details Files
Introduce a batch rerelease bash script that creates Release CRs for snapshots in configurable batches and waits for them to reach terminal states, tracking outcomes and logging progress.
  • Parse CLI options for input file, batch size, max wait, namespace, release plan, dry-run mode, and log file, with sensible defaults and a help output derived from the script header.
  • Validate prerequisites including presence of the input file and active oc login before proceeding.
  • Read snapshot IDs into an array, compute totals, and print a configuration summary; support a dry-run mode that only previews the first few releases and exits.
  • Implement structured logging with timestamps to both stdout and a log file, tracking counters for succeeded, failed, and timed-out releases.
  • Implement wait_for_releases helper that polls Release CRs using oc and jq, waiting up to MAX_WAIT*30s for each batch, updating counters based on Released condition reason and logging per-release results.
  • Loop through snapshots in batches, creating Release CRs via oc create from an inline manifest with generateName, namespace, releasePlan, snapshot, and gracePeriodDays, collecting their names per batch and handling creation failures.
  • After each batch, invoke wait_for_releases on created releases, advance batch indices, and log aggregate batch progress and final summary totals.
hack/batch-rerelease.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 3 issues, and left some high level feedback:

  • Consider explicitly checking for the presence of required CLIs like jq (similar to the oc whoami check) to fail fast with a clear error if dependencies are missing.
  • You might want to make gracePeriodDays a configurable option (with a default) instead of hardcoding 7, so the script can be reused in contexts with different retention requirements.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider explicitly checking for the presence of required CLIs like `jq` (similar to the `oc whoami` check) to fail fast with a clear error if dependencies are missing.
- You might want to make `gracePeriodDays` a configurable option (with a default) instead of hardcoding `7`, so the script can be reused in contexts with different retention requirements.

## Individual Comments

### Comment 1
<location path="hack/batch-rerelease.sh" line_range="34-35" />
<code_context>
+while [[ $# -gt 0 ]]; do
+    case "$1" in
+        --input)        INPUT="$2"; shift 2 ;;
+        --batch-size)   BATCH_SIZE="$2"; shift 2 ;;
+        --max-wait)     MAX_WAIT="$2"; shift 2 ;;
+        --namespace)    NAMESPACE="$2"; shift 2 ;;
+        --release-plan) RELEASE_PLAN="$2"; shift 2 ;;
</code_context>
<issue_to_address>
**issue (bug_risk):** Validate that numeric options (batch-size, max-wait) are integers before using them in arithmetic.

Since these values come directly from user input and are used in arithmetic (e.g., `idx + BATCH_SIZE`, `attempts >= MAX_WAIT`), a non-integer will cause a shell arithmetic error. Please add input validation (for example, `[[ $BATCH_SIZE =~ ^[0-9]+$ ]]` and similarly for `MAX_WAIT`) and exit with a clear error message when the input is invalid.
</issue_to_address>

### Comment 2
<location path="hack/batch-rerelease.sh" line_range="117-118" />
<code_context>
+    done
+
+    for name in "${names[@]}"; do
+        local rel_json
+        rel_json=$(oc get release "$name" -n "$NAMESPACE" -o json 2>/dev/null) || true
+        local rel_result
+        rel_result=$(echo "$rel_json" | \
</code_context>
<issue_to_address>
**issue (bug_risk):** Handle missing or failed `oc get release` calls explicitly to avoid misclassifying results as timeouts.

Right now, if `oc get release` fails (deleted Release, API error, etc.), `rel_json` is empty, `jq` yields null/empty, and we count it as `TIMED_OUT`. That mixes API/resource errors with real timeouts. Please treat empty `rel_json` explicitly (e.g., log "release not found" and either skip incrementing or use a separate category) so the metrics remain accurate and easier to interpret.
</issue_to_address>

### Comment 3
<location path="hack/batch-rerelease.sh" line_range="120-101" />
<code_context>
+        local rel_json
+        rel_json=$(oc get release "$name" -n "$NAMESPACE" -o json 2>/dev/null) || true
+        local rel_result
+        rel_result=$(echo "$rel_json" | \
+            jq -r '(.status.conditions // [])[] | select(.type == "Released") | .reason') || true
+        local snapshot
+        snapshot=$(echo "$rel_json" | jq -r '.spec.snapshot') || true
</code_context>
<issue_to_address>
**suggestion:** Guard against multiple `Released` conditions or missing condition, rather than assuming a single reason string.

The jq expression currently returns `.reason` for every `Released` condition, so `rel_result` may contain multiple lines while the `case` logic assumes a single value. Consider constraining this to one well-defined status (e.g., selecting the last matching condition) and also handling the scenario where there is no `Released` condition yet.

Suggested implementation:

```
        local rel_result
        rel_result=$(echo "$rel_json" | \
            jq -r '(.status.conditions // [] | map(select(.type == "Released")) | last | .reason // "")') || true

```

This change:
1. Ensures only a single reason is used by mapping all `Released` conditions and taking the last one.
2. Safely handles the case where there are no `Released` conditions by returning an empty string (which already falls into the `*` branch of the `case` statement).
If you have other logic elsewhere that assumes `rel_result` is non-empty, you may want to add explicit handling for the empty-string case.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread hack/batch-rerelease.sh
Comment on lines +34 to +35
--batch-size) BATCH_SIZE="$2"; shift 2 ;;
--max-wait) MAX_WAIT="$2"; shift 2 ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Validate that numeric options (batch-size, max-wait) are integers before using them in arithmetic.

Since these values come directly from user input and are used in arithmetic (e.g., idx + BATCH_SIZE, attempts >= MAX_WAIT), a non-integer will cause a shell arithmetic error. Please add input validation (for example, [[ $BATCH_SIZE =~ ^[0-9]+$ ]] and similarly for MAX_WAIT) and exit with a clear error message when the input is invalid.

Comment thread hack/batch-rerelease.sh
Comment on lines +117 to +118
local rel_json
rel_json=$(oc get release "$name" -n "$NAMESPACE" -o json 2>/dev/null) || true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Handle missing or failed oc get release calls explicitly to avoid misclassifying results as timeouts.

Right now, if oc get release fails (deleted Release, API error, etc.), rel_json is empty, jq yields null/empty, and we count it as TIMED_OUT. That mixes API/resource errors with real timeouts. Please treat empty rel_json explicitly (e.g., log "release not found" and either skip incrementing or use a separate category) so the metrics remain accurate and easier to interpret.

Comment thread hack/batch-rerelease.sh
for name in "${names[@]}"; do
local rel_reason
rel_reason=$(oc get release "$name" -n "$NAMESPACE" -o json 2>/dev/null | \
jq -r '(.status.conditions // [])[] | select(.type == "Released") | .reason') || true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Guard against multiple Released conditions or missing condition, rather than assuming a single reason string.

The jq expression currently returns .reason for every Released condition, so rel_result may contain multiple lines while the case logic assumes a single value. Consider constraining this to one well-defined status (e.g., selecting the last matching condition) and also handling the scenario where there is no Released condition yet.

Suggested implementation:

        local rel_result
        rel_result=$(echo "$rel_json" | \
            jq -r '(.status.conditions // [] | map(select(.type == "Released")) | last | .reason // "")') || true

This change:

  1. Ensures only a single reason is used by mapping all Released conditions and taking the last one.
  2. Safely handles the case where there are no Released conditions by returning an empty string (which already falls into the * branch of the case statement).
    If you have other logic elsewhere that assumes rel_result is non-empty, you may want to add explicit handling for the empty-string case.

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.

1 participant