Skip to content

ROX-29771: Prefactor roxctl_verification.sh#17294

Merged
vikin91 merged 2 commits intomasterfrom
piotr/refactor-roxctl-verification
Oct 16, 2025
Merged

ROX-29771: Prefactor roxctl_verification.sh#17294
vikin91 merged 2 commits intomasterfrom
piotr/refactor-roxctl-verification

Conversation

@vikin91
Copy link
Contributor

@vikin91 vikin91 commented Oct 15, 2025

Description

Refactored tests/yamls/roxctl_verification.sh to decouple roxctl verification tests from YAML file contents, preventing brittle test failures when YAML files are modified for other purposes.

Problem:
The original test used a wildcard (*.yaml) to test all YAML files and blindly expected exactly 2 specific alerts from every file. This created tight coupling between the roxctl test and the YAML file contents:

  • When YAML files were edited for other tests (e.g., TestPods, container_instances_test), the roxctl verification test would break unexpectedly
  • There was no clear documentation of which files should trigger which policies
  • Error messages were vague ("Did not find 2 alerts") without indicating what was expected

Solution:

  • Replace wildcard file selection with an explicit associative array mapping each file to its expected policy violations
  • Each file now has documented expectations that can be updated independently when the file changes
  • Enhanced error reporting shows both expected and actual policy names, making it immediately clear what needs to be updated
  • When someone modifies a YAML file for their test, they can easily see and update the corresponding expectation in the TEST_CASES array

Additional Improvements:

  • Updated to use --output json instead of deprecated --json flag
  • Fixed jq path for new roxctl JSON output format (.results[].violatedPolicies[].name)
  • Added bash version check (requires 4.0+ for associative arrays)
  • Changed shebang to #!/usr/bin/env bash for portability
  • Added set -euo pipefail for safer script execution
  • Added ROX_PASSWORD environment variable support for authentication
  • Added --insecure-skip-tls-verify fallback when CA is not provided

Why This Matters:
This refactoring prevents the common scenario where:

  1. Developer updates multi-container-pod.yaml for a pod lifecycle test
  2. Roxctl verification test mysteriously fails in CI
  3. Developer has to debug why changing a YAML file broke an unrelated test

Now, the test expectations are explicit and maintainable. When a YAML file changes, the developer can immediately see and update the corresponding entry in TEST_CASES.

AI Assistance:
The core refactoring logic and test structure were generated with AI assistance. Manual corrections included: fixing bash array iteration issues, updating to the correct jq path for the new roxctl output format, adding --insecure-skip-tls-verify support, and validating all test expectations against a live Central instance.

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

Local Validation:

  1. Deployed Central locally on localhost:8443
  2. Ran the refactored script: API_ENDPOINT="localhost:8443" ROX_PASSWORD="..." ./tests/yamls/roxctl_verification.sh
  3. Verified all 15 YAML files are tested successfully with correct policy expectations
  4. All files currently expect 2 alerts: "Latest tag" + "No CPU request or memory limit specified"
  5. Confirmed no deprecation warnings from roxctl (using --output json)
  6. Validated bash version check: fails gracefully with bash 3.2, succeeds with bash 4.0+
  7. Ran make shell-style to verify no style violations
  8. Tested that error messages clearly show both expected and found policies when expectations don't match
  9. Verified shebang portability: works with both /bin/bash and Homebrew bash on macOS

Decoupling Validation:

  • Modified a test YAML file's image tag as a simulation
  • Observed clear error message indicating which policy expectations failed
  • Updated the corresponding TEST_CASES entry
  • Test passed immediately after update
  • This demonstrates the improved maintainability vs. the old wildcard approach

CI Validation:

  • Awaiting CI results to confirm compatibility with CI environment
  • The refactored script maintains the same test coverage as the original

@vikin91
Copy link
Contributor Author

vikin91 commented Oct 15, 2025

This change is part of the following stack:

Change managed by git-spice.

@rhacs-bot
Copy link
Contributor

rhacs-bot commented Oct 15, 2025

Images are ready for the commit at 5d4848e.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.10.x-29-g5d4848edfe.

@vikin91
Copy link
Contributor Author

vikin91 commented Oct 15, 2025

/test gke-nongroovy-e2e-tests

@vikin91 vikin91 added auto-retest PRs with this label will be automatically retested if prow checks fails ai-review ai-assisted labels Oct 15, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


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.

@rhacs-bot
Copy link
Contributor

/retest

@codecov
Copy link

codecov bot commented Oct 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.86%. Comparing base (723fd6b) to head (5d4848e).
⚠️ Report is 24 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #17294      +/-   ##
==========================================
- Coverage   48.86%   48.86%   -0.01%     
==========================================
  Files        2720     2720              
  Lines      203364   203364              
==========================================
- Hits        99381    99374       -7     
- Misses      96161    96166       +5     
- Partials     7822     7824       +2     
Flag Coverage Δ
go-unit-tests 48.86% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vikin91 vikin91 merged commit 2c41166 into master Oct 16, 2025
161 checks passed
@vikin91 vikin91 deleted the piotr/refactor-roxctl-verification branch October 16, 2025 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted ai-review auto-retest PRs with this label will be automatically retested if prow checks fails

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants