-
Notifications
You must be signed in to change notification settings - Fork 174
chore(operator): eradicate Python step 1 #18754
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
Closed
porridge
wants to merge
21
commits into
master
from
konflux/porridge/bundle-helpers-rewrite-fixorder
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c918e4c
chore(operator): wrapper for bundle helpers
porridge c7311ef
chore(operator): Go implemetation of fix-spec-descriptor-order
porridge 70be9c3
fixes
porridge 5df5a87
merge
porridge 1c09d58
tidy
porridge 56f040c
move the tidy
porridge 4437f97
go mod tidy
porridge d033313
fix deps, checkout
porridge 7848d77
cleanup e2e
porridge 75f64a3
fix normalizer path
porridge 71806a3
fix comparison
porridge cacbec6
improve comparison, fix summary
porridge 36d1c8f
keep linter happy
porridge 0be9b32
lint
porridge 60adc1a
lint
porridge a525713
try multiple modes
porridge b016252
pass related images mode
porridge b1417b7
do not fail fast, set related image vars
porridge 7568bb5
matrix artifacts
porridge 4d52f0e
set -e and git diff at end
porridge 7a223d5
branding
porridge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,248 @@ | ||
| name: Test Bundle Helpers | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - '*' | ||
| branches: | ||
| - master | ||
| - release-* | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
|
|
||
| env: | ||
| ROX_PRODUCT_BRANDING: RHACS_BRANDING | ||
| RELATED_IMAGE_MAIN: foo | ||
| RELATED_IMAGE_SCANNER: foo | ||
| RELATED_IMAGE_SCANNER_SLIM: foo | ||
| RELATED_IMAGE_SCANNER_DB: foo | ||
| RELATED_IMAGE_SCANNER_DB_SLIM: foo | ||
| RELATED_IMAGE_COLLECTOR: foo | ||
| RELATED_IMAGE_ROXCTL: foo | ||
| RELATED_IMAGE_CENTRAL_DB: foo | ||
| RELATED_IMAGE_SCANNER_V4_DB: foo | ||
| RELATED_IMAGE_SCANNER_V4: foo | ||
|
|
||
| jobs: | ||
| test-python-implementation: | ||
| strategy: | ||
| matrix: | ||
| related_img_mode: | ||
| - konflux | ||
| - omit | ||
| - downstream | ||
| name: Test Python Implementation | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: operator | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Install Python dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -r bundle_helpers/requirements.txt | ||
|
|
||
| - name: Run Python unit tests | ||
| run: make test-bundle-helpers | ||
|
|
||
| - name: Generate bundle with Python | ||
| env: | ||
| USE_GO_BUNDLE_HELPER: false | ||
| RELATED_IMAGES_MODE: ${{ matrix.related_img_mode }} | ||
| run: | | ||
| set -euo pipefail | ||
| go mod tidy | ||
| make bundle bundle-post-process | ||
| mkdir -p /tmp/artifacts | ||
| cp -r bundle /tmp/artifacts/bundle-python | ||
| if [ -d build/bundle ]; then | ||
| cp -r build/bundle /tmp/artifacts/build-bundle-python | ||
| fi | ||
| git diff || true | ||
|
|
||
| - name: Upload Python bundle artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: bundle-python-${{ matrix.related_img_mode }} | ||
| path: /tmp/artifacts/ | ||
| retention-days: 1 | ||
|
|
||
| test-go-implementation: | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| related_img_mode: | ||
| - konflux | ||
| - omit | ||
| - downstream | ||
| name: Test Go Implementation | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: operator | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
||
| - name: Run Go unit tests | ||
| run: | | ||
| cd bundle_helpers | ||
| go test ./... | ||
|
|
||
| # For python fallback | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| # For python fallback | ||
| - name: Install Python dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -r bundle_helpers/requirements.txt | ||
|
|
||
| - name: Generate bundle with Go | ||
| env: | ||
| USE_GO_BUNDLE_HELPER: true | ||
| RELATED_IMAGES_MODE: ${{ matrix.related_img_mode }} | ||
| run: | | ||
| set -euo pipefail | ||
| go mod tidy | ||
| make bundle bundle-post-process | ||
| mkdir -p /tmp/artifacts | ||
| cp -r bundle /tmp/artifacts/bundle-go | ||
| if [ -d build/bundle ]; then | ||
| cp -r build/bundle /tmp/artifacts/build-bundle-go | ||
| fi | ||
| git diff || true | ||
|
|
||
| - name: Upload Go bundle artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: bundle-go-${{ matrix.related_img_mode }} | ||
| path: /tmp/artifacts/ | ||
| retention-days: 1 | ||
|
|
||
| compare-implementations: | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| related_img_mode: | ||
| - konflux | ||
| - omit | ||
| - downstream | ||
| name: Compare Python and Go Outputs | ||
| runs-on: ubuntu-latest | ||
| needs: [test-python-implementation, test-go-implementation] | ||
| # Only run comparison if Go implementation exists | ||
| if: always() && needs.test-go-implementation.result == 'success' | ||
|
|
||
| steps: | ||
| - name: Download Python bundle | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: bundle-python-${{ matrix.related_img_mode }} | ||
| path: /tmp/python | ||
|
|
||
| - name: Download Go bundle | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: bundle-go-${{ matrix.related_img_mode }} | ||
| path: /tmp/go | ||
| continue-on-error: true | ||
|
|
||
| - name: Install comparison tools | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y diffutils | ||
|
|
||
| - name: Compare bundle outputs | ||
| run: | | ||
| echo "=== Comparing Python and Go bundle outputs ===" | ||
|
|
||
| if diff -ruN /tmp/python/bundle-python /tmp/go/bundle-go; then | ||
| echo "✓ SUCCESS: Bundle outputs are identical" | ||
| else | ||
| echo "✗ FAILURE: Bundle outputs differ" | ||
| exit 1 | ||
| fi | ||
| echo "" | ||
| echo "=== Pruning createdAt lines..." | ||
| sed -i '/^ createdAt:/d' /tmp/*/build-bundle-*/manifests/rhacs-operator.clusterserviceversion.yaml | ||
|
|
||
| echo "" | ||
| echo "=== Comparing build/bundle outputs ===" | ||
| if diff -ruN /tmp/python/build-bundle-python /tmp/go/build-bundle-go; then | ||
| echo "✓ SUCCESS: Build bundle outputs are identical" | ||
| else | ||
| echo "✗ FAILURE: Build bundle outputs differ" | ||
| exit 1 | ||
| fi | ||
| echo "" | ||
| echo "=== Listing contents" | ||
| find /tmp/python /tmp/go -ls | ||
| find /tmp/python /tmp/go -type f -print0 | xargs -0 md5sum | sort | ||
|
|
||
| status-check: | ||
| strategy: | ||
| matrix: | ||
| related_img_mode: | ||
| - konflux | ||
| - omit | ||
| - downstream | ||
| name: Bundle Helper Tests Status | ||
| runs-on: ubuntu-latest | ||
| needs: [test-python-implementation, test-go-implementation, compare-implementations] | ||
| if: always() | ||
|
|
||
| steps: | ||
| - name: Check test results | ||
| run: | | ||
| python_result="${{ needs.test-python-implementation.result }}" | ||
| go_result="${{ needs.test-go-implementation.result }}" | ||
| compare_result="${{ needs.compare-implementations.result }}" | ||
|
|
||
| echo "Python tests: $python_result" | ||
| echo "Go tests: $go_result" | ||
| echo "Comparison: $compare_result" | ||
|
|
||
| if [ "$python_result" != "success" ]; then | ||
| echo "✗ Python tests failed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ "$go_result" != "success" ]; then | ||
| echo "✗ Go tests failed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ "$compare_result" != "success" ]; then | ||
| echo "✗ Go/Python comparison failed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "✓ All required tests passed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
|
|
||
| "github.com/stackrox/rox/operator/bundle_helpers/pkg/descriptor" | ||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| // FixSpecDescriptorOrder fixes the ordering of specDescriptors in a CSV file. | ||
| // It reads from stdin and writes to stdout, matching the Python script behavior. | ||
| func FixSpecDescriptorOrder(args []string) error { | ||
| if len(args) > 0 && (args[0] == "-h" || args[0] == "--help") { | ||
| fmt.Println("Usage: bundle-helper fix-spec-descriptor-order < input.yaml > output.yaml") | ||
| fmt.Println() | ||
| fmt.Println("Fixes the ordering of specDescriptors in a ClusterServiceVersion YAML file.") | ||
| fmt.Println("Ensures parent descriptors appear before their children.") | ||
| return nil | ||
| } | ||
|
|
||
| // Read CSV from stdin | ||
| data, err := io.ReadAll(os.Stdin) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to read stdin: %w", err) | ||
| } | ||
|
|
||
| // Parse YAML into a map (like Python's yaml.safe_load) | ||
| var csvDoc map[string]interface{} | ||
| if err := yaml.Unmarshal(data, &csvDoc); err != nil { | ||
| return fmt.Errorf("failed to parse YAML: %w", err) | ||
| } | ||
|
|
||
| // Process descriptors | ||
| if err := descriptor.FixCSVDescriptorsMap(csvDoc); err != nil { | ||
| return fmt.Errorf("failed to fix descriptors: %w", err) | ||
| } | ||
|
|
||
| // Encode to YAML using Go's yaml.v3 | ||
| var buf bytes.Buffer | ||
| encoder := yaml.NewEncoder(&buf) | ||
| encoder.SetIndent(2) | ||
| if err := encoder.Encode(csvDoc); err != nil { | ||
| return fmt.Errorf("failed to encode YAML: %w", err) | ||
| } | ||
| if err := encoder.Close(); err != nil { | ||
| return fmt.Errorf("failed to close encoder: %w", err) | ||
| } | ||
|
|
||
| // Normalize through Python to match PyYAML's exact formatting | ||
| // This is the "escape hatch" mentioned in the migration plan | ||
| return normalizeYAMLOutput(buf.Bytes(), os.Stdout) | ||
| } | ||
|
|
||
| // normalizeYAMLOutput pipes YAML through the Python normalizer to match PyYAML formatting. | ||
| // This handles formatting quirks (quote styles, line wrapping, etc.) while keeping | ||
| // all business logic in Go. | ||
| func normalizeYAMLOutput(goYAML []byte, w io.Writer) error { | ||
| wd, _ := os.Getwd() | ||
| normalizerPath := filepath.Join(wd, "bundle_helpers", "yaml-normalizer.py") | ||
|
|
||
| // Run the normalizer | ||
| cmd := exec.Command(normalizerPath) | ||
| cmd.Stdin = bytes.NewReader(goYAML) | ||
| cmd.Stdout = w | ||
| cmd.Stderr = os.Stderr | ||
|
|
||
| if err := cmd.Run(); err != nil { | ||
| return fmt.Errorf("failed to normalize YAML: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package cmd | ||
|
|
||
| // PatchCSV patches a ClusterServiceVersion YAML file with version and image information. | ||
| // This is a placeholder implementation - to be implemented in future phases. | ||
| func PatchCSV(args []string) error { | ||
| panic("not yet implemented") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.