Skip to content

Commit 6175a34

Browse files
committed
refactor: support multi-namespace operator deployments
Restructure RBAC to allow installing the operator in multiple namespaces simultaneously without conflicts. - Move RBAC to standard Kustomize base/overlays structure - Base resources in config/rbac/base/ - Platform overlays in config/rbac/overlays/{kind,openshift} - Add namespace prefix to cluster-scoped bindings to prevent conflicts - ClusterRoleBindings: {namespace}-manager-rolebinding, {namespace}-metrics-auth-rolebinding - OpenShift SCC: {namespace}-trusted-cluster-scc - Add PLATFORM variable (kind/openshift) to Makefile - Consolidate kubebuilder RBAC markers in api/v1alpha1/crds.go This enables running multiple operator instances (e.g., in "demo" and "production" namespaces) without resource conflicts. Signed-off-by: Yalan Zhang <yalzhang@redhat.com>
1 parent 14dc956 commit 6175a34

22 files changed

+113
-19
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trusted-cluster-gen
1010
/bin
1111
/config/crd
1212
/config/deploy
13-
/config/rbac/role.yaml
13+
/config/rbac/base/role.yaml
1414
/lib/src/kopium
1515
/target
1616
bundle/manifests/

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.PHONY: all build build-tools crds-rs generate manifests cluster-up cluster-down image push install-trustee install clean fmt-check clippy lint test test-release release-tarball
77

88
NAMESPACE ?= trusted-execution-clusters
9+
PLATFORM ?= kind
910

1011
KUBECTL=kubectl
1112

@@ -41,10 +42,12 @@ reg-server: crds-rs
4142
cargo build -p register-server
4243

4344
CRD_YAML_PATH = config/crd
45+
RBAC_YAML_PATH = config/rbac/base
4446
API_PATH = api/v1alpha1
4547
generate: $(CONTROLLER_GEN)
4648
$(CONTROLLER_GEN) rbac:roleName=trusted-cluster-operator-role crd webhook paths="./..." \
47-
output:crd:artifacts:config=$(CRD_YAML_PATH)
49+
output:crd:artifacts:config=$(CRD_YAML_PATH) \
50+
output:rbac:artifacts:config=$(RBAC_YAML_PATH)
4851

4952
RS_LIB_PATH = lib/src
5053
CRD_RS_PATH = $(RS_LIB_PATH)/kopium
@@ -132,10 +135,15 @@ endif
132135
scripts/clean-cluster-kind.sh $(OPERATOR_IMAGE) $(COMPUTE_PCRS_IMAGE) $(REG_SERVER_IMAGE)
133136
$(YQ) '.spec.publicTrusteeAddr = "$(TRUSTEE_ADDR):8080"' \
134137
-i $(DEPLOY_PATH)/trusted_execution_cluster_cr.yaml
135-
$(YQ) '.namespace = "$(NAMESPACE)"' -i config/rbac/kustomization.yaml
138+
$(YQ) '.namespace = "$(NAMESPACE)"' -i config/rbac/base/kustomization.yaml
139+
$(YQ) '.patches[0].patch = "- op: replace\n path: /metadata/name\n value: $(NAMESPACE)-manager-rolebinding"' -i config/rbac/base/kustomization.yaml
140+
$(YQ) '.patches[1].patch = "- op: replace\n path: /metadata/name\n value: $(NAMESPACE)-metrics-auth-rolebinding"' -i config/rbac/base/kustomization.yaml
141+
@if [ "$(PLATFORM)" = "openshift" ]; then \
142+
$(YQ) '.patches[0].patch = "- op: replace\n path: /metadata/name\n value: $(NAMESPACE)-trusted-cluster-scc\n- op: replace\n path: /users/0\n value: system:serviceaccount:$(NAMESPACE):trusted-cluster-operator"' -i config/rbac/overlays/openshift/kustomization.yaml; \
143+
fi
136144
$(KUBECTL) apply -f $(DEPLOY_PATH)/operator.yaml
137145
$(KUBECTL) apply -f config/crd
138-
$(KUBECTL) apply -k config/rbac
146+
$(KUBECTL) apply -k config/rbac/overlays/$(PLATFORM)
139147
$(KUBECTL) apply -f $(DEPLOY_PATH)/trusted_execution_cluster_cr.yaml
140148
$(KUBECTL) apply -f $(DEPLOY_PATH)/approved_image_cr.yaml
141149
$(KUBECTL) apply -f kind/register-forward.yaml
@@ -147,7 +155,7 @@ install-kubevirt:
147155
clean:
148156
cargo clean
149157
rm -rf bin manifests $(CRD_YAML_PATH) $(CRD_RS_PATH)
150-
rm -f trusted-cluster-gen config/rbac/role.yaml .crates.toml .crates2.json
158+
rm -f trusted-cluster-gen config/rbac/base/role.yaml .crates.toml .crates2.json
151159

152160
fmt-check:
153161
cargo fmt -- --check

api/v1alpha1/crds.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@ var (
2525
AddToScheme = SchemeBuilder.AddToScheme
2626
)
2727

28-
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;create;patch;update
29-
// +kubebuilder:rbac:groups="",resources=services,verbs=create
30-
// +kubebuilder:rbac:groups="",resources=secrets,verbs=create
31-
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;create;update
32-
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=create;delete;list;watch
33-
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters,verbs=list;watch
34-
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters/status,verbs=patch
35-
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=machines,verbs=create;list;delete;watch;patch
36-
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=approvedimages,verbs=get;list;watch;patch
37-
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=approvedimages/status,verbs=patch
28+
// +kubebuilder:rbac:groups="",resources=configmaps;services;secrets,verbs=create;get;list;watch
29+
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=create;delete;get;list;patch;update;watch
30+
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=create;delete;get;list;patch;update;watch
31+
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters;machines;approvedimages,verbs=create;delete;get;list;patch;update;watch
32+
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters/finalizers,verbs=update
33+
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=machines/finalizers,verbs=update
34+
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters/status;machines/status;approvedimages/status,verbs=get;patch;update
3835

3936
// TrustedExecutionClusterSpec defines the desired state of TrustedExecutionCluster
4037
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.publicTrusteeAddr) || has(self.publicTrusteeAddr)", message="Value is required once set"
File renamed without changes.
File renamed without changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
# SPDX-License-Identifier: CC0-1.0
44

55
namespace: trusted-execution-clusters
6+
patches:
7+
- target:
8+
kind: ClusterRoleBinding
9+
name: manager-rolebinding
10+
patch: |-
11+
- op: replace
12+
path: /metadata/name
13+
value: NAMESPACE-manager-rolebinding
14+
- target:
15+
kind: ClusterRoleBinding
16+
name: metrics-auth-rolebinding
17+
patch: |-
18+
- op: replace
19+
path: /metadata/name
20+
value: NAMESPACE-metrics-auth-rolebinding
621
resources:
722
# All RBAC will be applied under this service account in
823
# the deployment namespace. You may comment out this resource
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)