Skip to content

Commit e25950b

Browse files
committed
fix(bundle): resolve OLM installation and runtime errors
This commit fixes issues that prevented the operator from installing and running correctly via an OLM bundle. Key changes: - Use `clusterPermissions` in CSV to ensure correct cluster-wide RBAC. - Automate RBAC manifests copying and namespace patching in the bundle. - Remove `USER nobody` from Containerfiles to avoid runtime permission errors. Signed-off-by: Yalan Zhang <[email protected]>
1 parent fe04f21 commit e25950b

File tree

7 files changed

+45
-45
lines changed

7 files changed

+45
-45
lines changed

Containerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ RUN cargo build -p operator $(if [ "$build_type" = release ]; then echo --releas
3333
FROM quay.io/fedora/fedora:42
3434
ARG build_type
3535
COPY --from=builder "/build/target/$build_type/operator" /usr/bin
36-
USER nobody

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bundle: manifests
114114
@OPERATOR_IMAGE=$(OPERATOR_IMAGE) \
115115
COMPUTE_PCRS_IMAGE=$(COMPUTE_PCRS_IMAGE) \
116116
REG_SERVER_IMAGE=$(REG_SERVER_IMAGE) \
117-
scripts/generate-bundle-prod.sh -v $(TAG) $(if $(PREVIOUS_CSV),-p $(PREVIOUS_CSV))
117+
scripts/generate-bundle-prod.sh -v $(TAG) -n $(NAMESPACE) $(if $(PREVIOUS_CSV),-p $(PREVIOUS_CSV))
118118

119119
bundle-image: bundle
120120
@echo "Building OLM bundle image..."

README.md

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,15 @@ This operator can be packaged and deployed as an OLM bundle. This workflow suppo
7777

7878
**1. Prerequisites**
7979

80-
* **Setup Cluster:** Ensure your `kubectl` context points to your target cluster. For local development, you can create a `kind` cluster by running:
81-
```bash
82-
# Set RUNTIME=docker if using Docker instead of Podman.
83-
make cluster-up
84-
```
85-
86-
* **Login to Registry:**
87-
```bash
88-
# Login to your remote container registry (e.g., quay.io)
89-
docker login quay.io
90-
```
91-
92-
* **Install OLM:**
93-
```bash
94-
# Install OLM on your target cluster
95-
(cd /tmp && operator-sdk olm install)
96-
```
80+
For local development (kind):
81+
```bash
82+
# Set RUNTIME=docker if using Docker instead of Podman
83+
make cluster-up
84+
# Login to your remote container registry (e.g., quay.io)
85+
docker login quay.io
86+
# Install OLM on your target cluster
87+
(cd /tmp && operator-sdk olm install)
88+
```
9789

9890
**2. Set Environment Variables**
9991

@@ -114,11 +106,6 @@ The `push-all` target builds all operator images, generates the bundle, builds t
114106
make push-all
115107
```
116108

117-
You can optionally validate the generated bundle manifests at any time after the `bundle` has been generated:
118-
```bash
119-
(cd ./bundle && operator-sdk bundle validate .)
120-
```
121-
122109
**4. Deploy the Bundle**
123110

124111
Deploy the bundle to your cluster. We use `trusted-execution-clusters` as an example namespace.
@@ -135,20 +122,21 @@ Once the operator is running, you need to create a `TrustedExecutionCluster` cus
135122
First, you must update the example CR with the correct public address for the Trustee service, which must be accessible from your worker nodes or VMs.
136123

137124
```bash
138-
# Provide an address where your VMs can access the cluster.
139-
# When using a local kind cluster, this is often the kind bridge IP.
140-
$ ip route
141-
...
142-
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
143-
...
144-
$ export TRUSTEE_ADDR=192.168.122.1
145-
146-
# Use yq (or manually edit) to set the address in the CR.
147-
# Note: yq is installed via 'make build-tools'.
148-
$ yq -i '.spec.publicTrusteeAddr = "'$TRUSTEE_ADDR':8080"' config/deploy/trusted_execution_cluster_cr.yaml
149-
150-
# Now, apply the configured CR
151-
$ kubectl apply -f config/deploy/trusted_execution_cluster_cr.yaml
125+
# Determine an address reachable by the VMs (for libvirt, usually the bridge IP)
126+
ip route | grep virbr0
127+
# Example output:
128+
# 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
129+
export TRUSTEE_ADDR=192.168.122.1
130+
131+
# Update the CR with the trustee address (yq is installed via `make build-tools`)
132+
yq -i '.spec.publicTrusteeAddr = "'$TRUSTEE_ADDR':8080"' \
133+
config/deploy/trusted_execution_cluster_cr.yaml
134+
135+
# Apply the configured CRs
136+
kubectl apply -f config/deploy/trusted_execution_cluster_cr.yaml
137+
kubectl apply -f config/deploy/approved_image_cr.yaml
138+
kubectl apply -f kind/kbs-forward.yaml
139+
kubectl apply -f kind/register-forward.yaml
152140
```
153141

154142
#### **Cleaning Up the Bundle Deployment**
@@ -166,7 +154,6 @@ To clean up your environment after running the non-OLM `Quick Start` method, exe
166154
make cluster-cleanup
167155
# Note: You must use the same RUNTIME environment variable for `cluster-down`
168156
# that you used for `cluster-up`. For example:
169-
#
170157
# RUNTIME=docker make cluster-down
171158
make cluster-down
172159
make clean

bundle/static/manifests/trusted-cluster-operator.clusterserviceversion.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ spec:
7272
install:
7373
strategy: deployment
7474
spec:
75-
permissions:
75+
clusterPermissions:
7676
- serviceAccountName: trusted-cluster-operator
7777
# Rules are dynamically generated from config/rbac/role.yaml during the bundle build
7878
rules: []

compute-pcrs/Containerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ FROM quay.io/fedora/fedora:42
3232
ARG build_type
3333
COPY --from=builder "/build/target/$build_type/compute-pcrs" /usr/bin
3434
COPY --from=builder /build/reference-values /reference-values
35-
USER nobody

register-server/Containerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ RUN cargo build -p register-server $(if [ "$build_type" = release ]; then echo -
2929
FROM quay.io/fedora/fedora:42
3030
ARG build_type
3131
COPY --from=builder "/build/target/$build_type/register-server" /usr/bin
32-
USER nobody
3332
EXPOSE 3030
3433
ENTRYPOINT ["/usr/bin/register-server"]

scripts/generate-bundle-prod.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ set -euo pipefail
88

99
BUNDLE_VERSION=""
1010
PREVIOUS_CSV=""
11+
NAMESPACE="trusted-execution-clusters"
1112

12-
while getopts "v:p:" opt; do
13+
while getopts "v:p:n:" opt; do
1314
case $opt in
1415
v) BUNDLE_VERSION="$OPTARG" ;;
1516
p) PREVIOUS_CSV="$OPTARG" ;;
16-
*) echo "Usage: $0 -v <bundle-version> [-p <previous-csv>]"; exit 1 ;;
17+
n) NAMESPACE="$OPTARG" ;;
18+
*) echo "Usage: $0 -v <bundle-version> [-p <previous-csv>] [-n <namespace>]"; exit 1 ;;
1719
esac
1820
done
1921

@@ -39,6 +41,9 @@ mkdir -p "${BUNDLE_MANIFESTS}" "${BUNDLE_METADATA}"
3941
echo "=> Copying CRDs and static assets..."
4042
shopt -s nullglob
4143
cp "${PROJECT_ROOT}/config/crd"/*.yaml "${BUNDLE_MANIFESTS}/"
44+
cp "${PROJECT_ROOT}/config/rbac"/*.yaml "${BUNDLE_MANIFESTS}/"
45+
rm -f "${BUNDLE_MANIFESTS}/kustomization.yaml"
46+
rm -f "${BUNDLE_MANIFESTS}/service_account.yaml"
4247
cp "$CSV_TEMPLATE" "${BUNDLE_MANIFESTS}/"
4348
cp "$ANNOTATIONS_TEMPLATE" "${BUNDLE_METADATA}/"
4449

@@ -59,7 +64,18 @@ for env_var in COMPUTE_PCRS_IMAGE REG_SERVER_IMAGE; do
5964
done
6065

6166
# Patch RBAC rules
62-
yq -i ".spec.install.spec.permissions[0].rules = load(\"${RBAC_ROLE_FILE}\").rules" "$CSV_FILE"
67+
yq -i ".spec.install.spec.clusterPermissions[0].rules = load(\"${RBAC_ROLE_FILE}\").rules" "$CSV_FILE"
68+
69+
echo "=> Patching RBAC binding namespaces..."
70+
for binding_file in role_binding.yaml metrics_auth_role_binding.yaml leader_election_role_binding.yaml; do
71+
file_path="${BUNDLE_MANIFESTS}/${binding_file}"
72+
if [ -f "$file_path" ]; then
73+
echo "--> Patching ${binding_file}..."
74+
yq -i ".subjects[0].namespace = \"${NAMESPACE}\"" "$file_path"
75+
else
76+
echo "WARN: Binding file ${binding_file} not found in bundle, skipping patch."
77+
fi
78+
done
6379

6480
# Set .spec.replaces for automatic upgrades if provided
6581
if [[ -n "$PREVIOUS_CSV" ]]; then

0 commit comments

Comments
 (0)