Skip to content

Add operator and bundle build-push script#79

Open
shreyabiradar07 wants to merge 4 commits intokruize:mvp_demofrom
shreyabiradar07:release_script
Open

Add operator and bundle build-push script#79
shreyabiradar07 wants to merge 4 commits intokruize:mvp_demofrom
shreyabiradar07:release_script

Conversation

@shreyabiradar07
Copy link
Copy Markdown
Contributor

@shreyabiradar07 shreyabiradar07 commented Apr 2, 2026

This PR adds a script to build and push operator and bundle images and also verify the bundle image using operator-sdk cmds.

Summary by Sourcery

Add a script to automate building, pushing, and verifying Kruize operator and bundle images based on a shared version.

Enhancements:

  • Introduce a helper script to coordinate operator and bundle image versioning, build, push, and verification using make and operator-sdk.

Build:

  • Add an operator and bundle build-and-push shell script that supports docker/podman and updates version metadata in Makefile and CSV manifests before building images.

Signed-off-by: Shreya Biradar <shbirada@ibm.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 2, 2026

Reviewer's Guide

Adds a new Bash script to automate building, pushing, and validating Kruize operator and bundle images with aligned versioning and basic prerequisites checks.

Sequence diagram for operator_build_and_push.sh interactions with tools

sequenceDiagram
    actor Developer
    participant Script as operator_build_and_push_sh
    participant Make as make
    participant ContainerTool as CONTAINER_TOOL
    participant OperatorSDK as operator_sdk_bin
    participant FS as FileSystem

    Developer->>Script: Run with -o OPERATOR_IMAGE -b BUNDLE_IMAGE
    Script->>Script: Parse args and validate required images
    Script->>Script: Extract OPERATOR_VERSION and BUNDLE_VERSION
    Script->>Script: Compare versions
    Script-->>Developer: Exit on mismatch

    Script->>Script: check_prerequisites
    Script->>ContainerTool: which CONTAINER_TOOL
    ContainerTool-->>Script: Found or error
    Script->>Make: which make
    Make-->>Script: Found or error
    Script->>FS: Check operator-sdk or ./bin/operator-sdk
    alt operator-sdk missing
        Script->>Make: make operator-sdk
        Make-->>FS: Download ./bin/operator-sdk
    end

    Script->>FS: update_makefile_version
    FS-->>Script: Makefile updated with VERSION

    Script->>FS: update_csv_version
    FS-->>Script: CSVs updated with OPERATOR_IMAGE and VERSION

    Script->>Make: make docker-build docker-push
    Note right of Make: IMG=OPERATOR_IMAGE
    Make->>ContainerTool: Build and push operator image
    ContainerTool-->>Make: Operator image pushed
    Make-->>Script: Operator build/push complete

    Script->>ContainerTool: image inspect OPERATOR_IMAGE
    ContainerTool-->>Script: Metadata and size

    Script->>Make: make bundle bundle-build bundle-push
    Note right of Make: VERSION, IMG, BUNDLE_IMG
    Make->>ContainerTool: Build and push bundle image
    ContainerTool-->>Make: Bundle image pushed
    Make-->>Script: Bundle build/push complete

    Script->>OperatorSDK: bundle validate ./bundle
    OperatorSDK-->>Script: Validation result

    Script->>ContainerTool: image inspect BUNDLE_IMAGE
    ContainerTool-->>Script: Metadata and size

    Script-->>Developer: Print success summary and next steps
Loading

File-Level Changes

Change Details Files
Introduce a unified operator/bundle build, push, and verification workflow script.
  • Add CLI parsing for operator (-o) and bundle (-b) image references with usage/help output
  • Derive and validate a shared version from the operator and bundle image tags, enforcing version equality
  • Check for required tools (container runtime, make, operator-sdk) and auto-download operator-sdk via make if missing
  • Update Makefile VERSION line and CSV manifests to match the requested version and operator image before builds
  • Build and push operator image using make docker-build/docker-push with configurable container tool
  • Build and push bundle using make bundle/bundle-build/bundle-push with aligned VERSION/IMG/BUNDLE_IMG vars
  • Verify both operator and bundle images via container-tool image inspect and validate the bundle directory via operator-sdk bundle validate
  • Provide structured logging and a final summary with suggested next deployment and test commands
scripts/operator_build_and_push.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

Copy link
Copy Markdown

@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 - I've found 2 issues, and left some high level feedback:

  • The script relies on grep -P in extract_version, which is not available in BSD grep (e.g., on macOS); consider a POSIX-compatible alternative like ${image##*:} or grep -E to improve portability.
  • The usage example and comment mention build-and-push-images.sh while the file is named operator_build_and_push.sh; aligning these names will reduce confusion for users invoking the script.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The script relies on `grep -P` in `extract_version`, which is not available in BSD grep (e.g., on macOS); consider a POSIX-compatible alternative like `${image##*:}` or `grep -E` to improve portability.
- The usage example and comment mention `build-and-push-images.sh` while the file is named `operator_build_and_push.sh`; aligning these names will reduce confusion for users invoking the script.

## Individual Comments

### Comment 1
<location path="scripts/operator_build_and_push.sh" line_range="118-127" />
<code_context>
+    log_info "Updating Makefile version to ${VERSION}..."
+    
+    if [[ -f "Makefile" ]]; then
+        sed -i "s/^VERSION ?= .*/VERSION ?= ${VERSION}/" Makefile
+        log_success "Makefile version updated"
+    else
+        log_error "Makefile not found"
+        exit 1
+    fi
+}
+
+# Update CSV version
+update_csv_version() {
+    log_info "Updating CSV version to ${VERSION}..."
+    
+    # Update bundle CSV file
+    CSV_FILE="bundle/manifests/kruize-operator.clusterserviceversion.yaml"
+    if [[ -f "$CSV_FILE" ]]; then
+        sed -i "s|containerImage: .*|containerImage: ${OPERATOR_IMAGE}|" "$CSV_FILE"
+        sed -i "s/name: kruize-operator\.v.*/name: kruize-operator.v${VERSION}/" "$CSV_FILE"
+        log_success "Bundle CSV updated"
+    else
</code_context>
<issue_to_address>
**issue (bug_risk):** Use a `sed -i` form that is portable across GNU/BSD sed

This form works on GNU sed but fails on BSD sed (e.g., macOS), which requires a backup suffix (even an empty one). Since this script may run on multiple environments, please switch to a portable form like `sed -i '' ...` or add a small `uname`-based branch to select the appropriate `sed -i` invocation.
</issue_to_address>

### Comment 2
<location path="scripts/operator_build_and_push.sh" line_range="8-11" />
<code_context>
+CONTAINER_TOOL="${CONTAINER_TOOL:-docker}"
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Clarify or align `CONTAINER_TOOL` with the hardcoded docker-based make targets

`CONTAINER_TOOL` defaults to `docker` and is used only for image inspection, while build/push still run `make docker-build docker-push`. If someone sets `CONTAINER_TOOL=podman`, they may expect the whole flow to use podman. Please either document that `CONTAINER_TOOL` only affects verification, or adjust the make targets so build/push also respect this setting.

```suggestion
# Default values
OPERATOR_IMAGE=""
BUNDLE_IMAGE=""

# Note: CONTAINER_TOOL is used only for image inspection/verification in this script.
# Build and push still rely on docker-based make targets (e.g., `make docker-build docker-push`),
# regardless of this setting.
CONTAINER_TOOL="${CONTAINER_TOOL:-docker}"
```
</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.

Signed-off-by: Shreya Biradar <shbirada@ibm.com>
Signed-off-by: Shreya Biradar <shbirada@ibm.com>
@shreyabiradar07
Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

Copy link
Copy Markdown

@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 - I've found 1 issue, and left some high level feedback:

  • The update_csv_version function uses sed -i without the macOS/BSD guard you added in update_makefile_version, which will break on Darwin; consider factoring a small helper for portable in-place sed and using it consistently.
  • The OSTYPE check in update_makefile_version compares to "Darwin", but typical values are lowercase like darwin*; using a case pattern match (e.g., case "$OSTYPE" in darwin*)) would make this more robust.
  • Since the script mutates files (Makefile, CSVs) before building, you might want to warn or prompt if there are uncommitted changes in the working tree to avoid accidentally altering a clean branch.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `update_csv_version` function uses `sed -i` without the macOS/BSD guard you added in `update_makefile_version`, which will break on Darwin; consider factoring a small helper for portable in-place `sed` and using it consistently.
- The `OSTYPE` check in `update_makefile_version` compares to `"Darwin"`, but typical values are lowercase like `darwin*`; using a case pattern match (e.g., `case "$OSTYPE" in darwin*)`) would make this more robust.
- Since the script mutates files (Makefile, CSVs) before building, you might want to warn or prompt if there are uncommitted changes in the working tree to avoid accidentally altering a clean branch.

## Individual Comments

### Comment 1
<location path="scripts/operator_build_and_push.sh" line_range="143-145" />
<code_context>
+    log_info "Updating CSV version to ${VERSION}..."
+    
+    # Update bundle CSV file
+    CSV_FILE="bundle/manifests/kruize-operator.clusterserviceversion.yaml"
+    if [[ -f "$CSV_FILE" ]]; then
+        sed -i "s|containerImage: .*|containerImage: ${OPERATOR_IMAGE}|" "$CSV_FILE"
+        sed -i "s/name: kruize-operator\.v.*/name: kruize-operator.v${VERSION}/" "$CSV_FILE"
+        log_success "Bundle CSV updated"
</code_context>
<issue_to_address>
**issue (bug_risk):** Make the sed -i usage in CSV updates macOS-compatible as done in update_makefile_version.

Here `sed -i` (and in the `BASE_CSV_FILE` update) will fail on macOS’s BSD sed because it requires a backup suffix. Please reuse the existing Darwin/other `sed -i` handling from `update_makefile_version`, or factor out a small helper, so these CSV updates work consistently on both Linux and macOS.
</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.

Signed-off-by: Shreya Biradar <shbirada@ibm.com>
@shreyabiradar07
Copy link
Copy Markdown
Contributor Author

Example Script output:

Files to be committed after the script completes:
Makefile, bundle/manifests/kruize-operator.clusterserviceversion.yaml, config/manager/kustomization.yaml, config/manifests/bases/kruize-operator.clusterserviceversion.yaml

$ ./scripts/operator_build_and_push.sh -o quay.io/shbirada/kruize-operator:0.0.5 -b quay.io/shbirada/kruize-operator-bundle:0.0.5

[INFO] ==========================================
[INFO] Kruize Operator Build & Push Script
[INFO] ==========================================
[INFO] Version: 0.0.5
[INFO] Operator Image: quay.io/shbirada/kruize-operator:0.0.5
[INFO] Bundle Image: quay.io/shbirada/kruize-operator-bundle:0.0.5
[INFO] Container Tool: docker
[INFO] ==========================================

[INFO] Checking prerequisites...
[SUCCESS] Prerequisites check passed

[INFO] ==========================================
[INFO] Updating Version Files
[INFO] ==========================================
[INFO] Updating Makefile version to 0.0.5...
[SUCCESS] Makefile version updated
[INFO] Updating CSV version to 0.0.5...
[SUCCESS] Bundle CSV updated
[SUCCESS] Base CSV updated

[INFO] ==========================================
[INFO] Building and Pushing Operator Image
[INFO] ==========================================
[INFO] Building and pushing operator image: quay.io/shbirada/kruize-operator:0.0.5
[INFO] Running: make docker-build docker-push IMG=quay.io/shbirada/kruize-operator:0.0.5 CONTAINER_TOOL=docker
docker build -t quay.io/shbirada/kruize-operator:0.0.5 .
[+] Building 2.5s (20/20) FINISHED                                                                                                                                                                   docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                                           0.1s
 => => transferring dockerfile: 1.38kB                                                                                                                                                                         0.0s
 => [internal] load metadata for registry.access.redhat.com/ubi10/ubi-minimal:10.1-1774545417                                                                                                                  1.5s
 => [internal] load metadata for registry.access.redhat.com/ubi10/go-toolset:1.25                                                                                                                              1.4s
 => [internal] load .dockerignore                                                                                                                                                                              0.1s
 => => transferring context: 2B                                                                                                                                                                                0.0s
 => [internal] load build context                                                                                                                                                                              0.1s
 => => transferring context: 155.62kB                                                                                                                                                                          0.0s
 => [builder  1/11] FROM registry.access.redhat.com/ubi10/go-toolset:1.25@sha256:41a87e42d29be03c3d7cd80fa4fabce891e0e6682a90093c156d5cedc3315be2                                                              0.0s
 => [stage-1 1/3] FROM registry.access.redhat.com/ubi10/ubi-minimal:10.1-1774545417@sha256:7bd3d2e7f5c507aebd1575d0f2fab9fe3e882e25fee54fa07f7970aa8bbc5fab                                                    0.0s
 => CACHED [stage-1 2/3] WORKDIR /app                                                                                                                                                                          0.0s
 => CACHED [builder  2/11] WORKDIR /workspace                                                                                                                                                                  0.0s
 => CACHED [builder  3/11] COPY go.mod go.mod                                                                                                                                                                  0.0s
 => CACHED [builder  4/11] COPY go.sum go.sum                                                                                                                                                                  0.0s
 => CACHED [builder  5/11] RUN go mod download                                                                                                                                                                 0.0s
 => CACHED [builder  6/11] COPY cmd/main.go cmd/main.go                                                                                                                                                        0.0s
 => CACHED [builder  7/11] COPY api/ api/                                                                                                                                                                      0.0s
 => CACHED [builder  8/11] COPY internal/controller/ internal/controller/                                                                                                                                      0.0s
 => CACHED [builder  9/11] COPY internal/utils/ internal/utils/                                                                                                                                                0.0s
 => CACHED [builder 10/11] COPY internal/constants/ internal/constants/                                                                                                                                        0.0s
 => CACHED [builder 11/11] RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /tmp/manager cmd/main.go                                                                                                   0.0s
 => CACHED [stage-1 3/3] COPY --from=builder /tmp/manager .                                                                                                                                                    0.0s
 => exporting to image                                                                                                                                                                                         0.3s
 => => exporting layers                                                                                                                                                                                        0.0s
 => => writing image sha256:eaf85e28f9c0f4b54b3cd17b55c3f48e5efba14a9d8ad7033cc2ee017f99765d                                                                                                                   0.2s
 => => naming to quay.io/shbirada/kruize-operator:0.0.5                                                                                                                                                        0.0s
docker push quay.io/shbirada/kruize-operator:0.0.5
The push refers to repository [quay.io/shbirada/kruize-operator]
98068ce36aec: Layer already exists 
71dcd5b9b412: Layer already exists 
3a66063ddcd3: Layer already exists 
0.0.5: digest: sha256:616c8b7157abed83f4a00c0b2a931a0c2501a365c074e742039dd869d02b4030 size: 947
[SUCCESS] Operator image built and pushed: quay.io/shbirada/kruize-operator:0.0.5
[INFO] Verifying operator image...
[SUCCESS] Operator image verified
  Size: 165213827 bytes

[INFO] ==========================================
[INFO] Building and Pushing Bundle Image
[INFO] ==========================================
[INFO] Building and pushing bundle image: quay.io/shbirada/kruize-operator-bundle:0.0.5
[INFO] Running: make bundle bundle-build bundle-push VERSION=0.0.5 IMG=quay.io/shbirada/kruize-operator:0.0.5 BUNDLE_IMG=quay.io/shbirada/kruize-operator-bundle:0.0.5 CONTAINER_TOOL=docker
/home/shbirada/github/shreyabiradar07/kruize-operator/bin/controller-gen-v0.14.0 rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/usr/local/bin/operator-sdk generate kustomize manifests -q
cd config/manager && /home/shbirada/github/shreyabiradar07/kruize-operator/bin/kustomize-v5.3.0 edit set image controller=quay.io/shbirada/kruize-operator:0.0.5
/home/shbirada/github/shreyabiradar07/kruize-operator/bin/kustomize-v5.3.0 build config/manifests | /usr/local/bin/operator-sdk generate bundle -q --overwrite=false --version 0.0.5  
/usr/local/bin/operator-sdk bundle validate ./bundle
INFO[0000] All validation tests have completed successfully 
docker build -f bundle.Dockerfile -t quay.io/shbirada/kruize-operator-bundle:0.0.5 .
[+] Building 2.4s (9/9) FINISHED                                                                                                                                                                     docker:default
 => [internal] load build definition from bundle.Dockerfile                                                                                                                                                    0.1s
 => => transferring dockerfile: 1.21kB                                                                                                                                                                         0.0s
 => [internal] load metadata for registry.access.redhat.com/ubi10/ubi-minimal:10.1-1774545417                                                                                                                  0.5s
 => [internal] load .dockerignore                                                                                                                                                                              0.1s
 => => transferring context: 2B                                                                                                                                                                                0.0s
 => CACHED [1/4] FROM registry.access.redhat.com/ubi10/ubi-minimal:10.1-1774545417@sha256:7bd3d2e7f5c507aebd1575d0f2fab9fe3e882e25fee54fa07f7970aa8bbc5fab                                                     0.0s
 => [internal] load build context                                                                                                                                                                              0.1s
 => => transferring context: 40.92kB                                                                                                                                                                           0.0s
 => [2/4] COPY bundle/manifests /manifests/                                                                                                                                                                    0.2s
 => [3/4] COPY bundle/metadata /metadata/                                                                                                                                                                      0.4s
 => [4/4] COPY bundle/tests/scorecard /tests/scorecard/                                                                                                                                                        0.3s
 => exporting to image                                                                                                                                                                                         0.3s
 => => exporting layers                                                                                                                                                                                        0.2s
 => => writing image sha256:585a91559a187ad263f278f9e5dffed08705ca809b902eca267aa68c879353d1                                                                                                                   0.0s
 => => naming to quay.io/shbirada/kruize-operator-bundle:0.0.5                                                                                                                                                 0.0s
make docker-push IMG=quay.io/shbirada/kruize-operator-bundle:0.0.5
make[1]: Entering directory '/home/shbirada/github/shreyabiradar07/kruize-operator'
docker push quay.io/shbirada/kruize-operator-bundle:0.0.5
The push refers to repository [quay.io/shbirada/kruize-operator-bundle]
87b9684c7571: Pushed 
565320d80c8d: Layer already exists 
bd39e039395e: Pushed 
3a66063ddcd3: Layer already exists 
0.0.5: digest: sha256:68b2b7682b2327f266171a6c5b463451defaae1fdca54027078b6456fd234df3 size: 1153
make[1]: Leaving directory '/home/shbirada/github/shreyabiradar07/kruize-operator'
[SUCCESS] Bundle image built and pushed: quay.io/shbirada/kruize-operator-bundle:0.0.5
[INFO] Verifying bundle with operator-sdk...
[INFO] Validating bundle directory...
INFO[0000] All validation tests have completed successfully 
[SUCCESS] Bundle validation passed
[SUCCESS] Bundle image verified
  Size: 85740503 bytes

[INFO] ==========================================
[SUCCESS] Build and Push Complete!
[INFO] ==========================================
[INFO] Version: 0.0.5
[INFO] Operator Image: quay.io/shbirada/kruize-operator:0.0.5
[INFO] Bundle Image: quay.io/shbirada/kruize-operator-bundle:0.0.5

[INFO] Next steps:
[INFO]   Deploy: make deploy IMG=quay.io/shbirada/kruize-operator:0.0.5
[INFO]   Test: operator-sdk run bundle quay.io/shbirada/kruize-operator-bundle:0.0.5

@shreyabiradar07 shreyabiradar07 moved this from In Progress to Under Review in Monitoring Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Under Review

Development

Successfully merging this pull request may close these issues.

1 participant