Skip to content

Fix unbound variable in upstream-sync.sh when SKIP_PRS is empty#709

Open
jzding wants to merge 1 commit into
openshift:mainfrom
jzding:fix-upstream-sync-ocp
Open

Fix unbound variable in upstream-sync.sh when SKIP_PRS is empty#709
jzding wants to merge 1 commit into
openshift:mainfrom
jzding:fix-upstream-sync-ocp

Conversation

@jzding

@jzding jzding commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix upstream-sync.sh crashing with unbound variable error when SKIP_PRS and SKIP_COMMITS env vars are not set.

Problem

Under set -u, IFS=',' read -ra skip_pr_list <<< "" creates an array that fails when iterated with "${arr[@]}":

./hack/upstream-sync.sh: line 278: skip_pr_list[@]: unbound variable

Fix

  • Initialize arrays empty =()
  • Only populate via read -ra when the env var is non-empty
  • Guard loop iteration with ${#arr[@]} -gt 0 check

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved skip handling during upstream syncs so empty skip settings are ignored safely.
    • Manual skip rules for pull requests and commit IDs now apply more consistently, reducing unexpected behavior when no values are provided.

Under set -u, empty SKIP_PRS/SKIP_COMMITS caused "unbound variable"
error when iterating the arrays. Initialize arrays empty and guard
iteration with length checks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Jack Ding <jackding@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Walkthrough

In hack/upstream-sync.sh, the filter_skipped function is updated to declare skip_pr_list and skip_commit_list as bash arrays populated only when their corresponding env vars are non-empty, and iteration over each list is now guarded by an array-length check.

Changes

filter_skipped empty-list guards

Layer / File(s) Summary
Array initialization and iteration guards
hack/upstream-sync.sh
skip_pr_list and skip_commit_list are now declared as bash arrays and populated conditionally from SKIP_PRS/SKIP_COMMITS only when non-empty; per-PR skip loops are guarded by array-length checks before iterating.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 14 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (14 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix in upstream-sync.sh, though it mentions only SKIP_PRS while the change also covers SKIP_COMMITS.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed The PR only updates hack/upstream-sync.sh; no Ginkgo test titles were added or modified, so naming stability is unaffected.
Test Structure And Quality ✅ Passed PR only changes hack/upstream-sync.sh; no Ginkgo test files were added or modified, so this test-structure check is not applicable.
Microshift Test Compatibility ✅ Passed Only hack/upstream-sync.sh changed; no new/modified Ginkgo e2e tests, so MicroShift compatibility isn’t applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed Only hack/upstream-sync.sh changed; no new Ginkgo e2e tests were added, so SNO compatibility is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed Only hack/upstream-sync.sh was changed; no deployment manifests, operator code, or controllers were modified, so topology-aware scheduling isn’t implicated.
Ote Binary Stdout Contract ✅ Passed The PR only edits hack/upstream-sync.sh skip-list logic; it adds no main/TestMain/BeforeSuite stdout writes or logger redirection changes.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed Only hack/upstream-sync.sh changed; no Ginkgo e2e tests or network-sensitive test code were added, so this check is not applicable.
No-Weak-Crypto ✅ Passed hack/upstream-sync.sh only changes bash array handling/skip logic; no weak crypto, custom crypto, or secret/token comparisons appear in the diff.
Container-Privileges ✅ Passed The PR only changes hack/upstream-sync.sh; no container/K8s manifest fields like privileged or hostNetwork were modified.
No-Sensitive-Data-In-Logs ✅ Passed The patch only changes skip-list initialization/guards in hack/upstream-sync.sh; it adds no new logging or secret-bearing output.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@openshift-ci

openshift-ci Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jzding

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@hack/upstream-sync.sh`:
- Around line 281-287: Add a regression test covering the unset/empty skip-list
path in filter_skipped, since the current shell logic in upstream-sync.sh now
relies on SKIP_PRS and SKIP_COMMITS being safely handled under set -u. Update
the existing test suite around filter_skipped to invoke it with both variables
unset and explicitly empty, and assert it does not crash or misbehave. Use the
filter_skipped and skip_pr_list/skip_commit_list flow as the reference points so
the coverage stays aligned if the shell code shifts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3ee537c8-17d8-4ebc-81a7-eacd6242306b

📥 Commits

Reviewing files that changed from the base of the PR and between 8324a72 and 6b0f464.

📒 Files selected for processing (1)
  • hack/upstream-sync.sh

Comment thread hack/upstream-sync.sh
@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 29, 2026
@openshift-ci

openshift-ci Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@jzding: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant