Skip to content

Instantly share code, notes, and snippets.

@frobware
Created September 16, 2025 09:10
Show Gist options
  • Save frobware/50f13a71739db7313879204c2cf9ccaf to your computer and use it in GitHub Desktop.
Save frobware/50f13a71739db7313879204c2cf9ccaf to your computer and use it in GitHub Desktop.
Not desperation - pragmatism.
#!/bin/bash
# Generate Containerfile.bundle.openshift with current VERSION
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
repo_root="$(cd "$script_dir/../.." && pwd)"
version_file="${repo_root}/VERSION"
output_file="${repo_root}/Containerfile.bundle.openshift"
if [ ! -f "$version_file" ]; then
echo "Error: VERSION file not found at $version_file"
exit 1
fi
version=$(cat "$version_file" | tr -d '\n')
echo "Generating $output_file with VERSION=$version"
cat > "$output_file" << 'EOF'
# THIS FILE IS AUTOGENERATED. EDITS WILL BE LOST.
# Generated by: hack/openshift/generate-bundle-containerfile.sh
# Source: VERSION file
#
# Red Hat rebranding tool for bpfman-operator OpenShift bundle
#
# This Containerfile takes upstream bpfman-operator bundles and
# transforms them for Red Hat distribution by:
# - Updating ClusterServiceVersion (CSV) with Red Hat branding and image references
# - Adding architecture labels and OpenShift feature annotations
# - Updating ConfigMap with Red Hat image pullspecs
#
# To test the Python tools locally without container build:
# make -C hack/openshift transform-bundle transform-configmap
#
# To build locally within a container:
# make -C hack/openshift container-transform-bundle
#
ARG PYTHON_BUILDER_IMAGE_REF=registry.access.redhat.com/ubi9/python-312
FROM ${PYTHON_BUILDER_IMAGE_REF} AS builder
WORKDIR /usr/src/bundle-transform
RUN pip3 install ruamel.yaml
USER root
RUN dnf install -y diffutils
USER default
COPY --chown=default hack/openshift/ ./hack/openshift/
COPY --chown=default bundle/manifests /manifests/
COPY --chown=default bundle/metadata /metadata/
COPY --chown=default bundle/tests/scorecard /tests/scorecard/
COPY --chown=default VERSION /VERSION
RUN cp /manifests/bpfman-operator.clusterserviceversion.yaml /tmp/bpfman-operator.clusterserviceversion.yaml.orig
RUN cp /manifests/bpfman-config_v1_configmap.yaml /tmp/bpfman-config_v1_configmap.yaml.orig
RUN hack/openshift/update-bundle.py \
--csv-file /manifests/bpfman-operator.clusterserviceversion.yaml \
--image-pullspec "$(cat hack/openshift/konflux/images/bpfman-operator.txt)"
RUN hack/openshift/update-configmap.py \
--configmap-file /manifests/bpfman-config_v1_configmap.yaml \
--agent-pullspec "$(cat hack/openshift/konflux/images/bpfman-agent.txt)" \
--bpfman-pullspec "$(cat hack/openshift/konflux/images/bpfman.txt)"
RUN echo "=== CSV transformation changes ===" && \
diff -u /tmp/bpfman-operator.clusterserviceversion.yaml.orig /manifests/bpfman-operator.clusterserviceversion.yaml || true
RUN echo "=== ConfigMap transformation changes ===" && \
diff -u /tmp/bpfman-config_v1_configmap.yaml.orig /manifests/bpfman-config_v1_configmap.yaml || true
FROM scratch
# Core bundle labels.
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=bpfman-operator
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.26.0
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3
# Labels for testing.
LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1
LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/
EOF
# Now append the labels with the actual VERSION value
cat >> "$output_file" << EOF
LABEL name="bpfman-operator" \\
com.redhat.component="bpfman-operator" \\
io.k8s.display-name="Bpfman Operator" \\
description="The bpfman-operator manage bpfman ebpf programs on every node." \\
distribution-scope=public \\
io.k8s.description="The bpfman-operator manage bpfman programs on every node. ." \\
io.openshift.tags="bpfman-operator" \\
version="$version" \\
release="$version" \\
url="https://github.com/openshift/bpfman-operator" \\
vendor="Red Hat, Inc." \\
summary="Bpfman Operator"
# Copy files to locations specified by labels.
COPY --from=builder /manifests /manifests/
COPY --from=builder /metadata /metadata/
COPY --from=builder /tests/scorecard /tests/scorecard/
EOF
echo "Generated $output_file successfully"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment