Skip to content

Commit 90e5fcc

Browse files
committed
operator: Include ClusterRole permission for redpanda controller
In the redpanda package the kubebuilder comment does not have all possible variants of ClusterRole permissions neccessery to handle creation of all Redpanda helm chart resources. When rpk bundle ClusterRole was included to the Redpanda helm chart deployment, then the integration test suite failed with flux reporting the following: ``` creation of clusterroles.rbac.authorization.k8s.io "rp-9gd31r-rpk-bundle" is forbidden: user "system:serviceaccount:testenv-g5jfk:testenv-pzy3ce" (groups=["system:serviceaccounts" "system:serviceaccounts:testenv-g5jfk" "system:authenticated"]) is attempting to grant RBAC permissions not currently held: {APIGroups:[""], Resources:["endpoints"], Verbs:["get" "list"]} {APIGroups:[""], Resources:["events"], Verbs:["get" "list"]} {APIGroups:[""], Resources:["limitranges"], Verbs:["get" "list"]} {APIGroups:[""], Resources:["persistentvolumeclaims"], Verbs:["get" "list"]} {APIGroups:[""], Resources:["pods"], Verbs:["get" "list"]} {APIGroups:[""], Resources:["pods/log"], Verbs:["get" "list"]} {APIGroups:[""], Resources:["replicationcontrollers"], Verbs:["get" "list"]} {APIGroups:[""], Resources:["resourcequotas"], Verbs:["get" "list"]} {APIGroups:[""], Resources:["serviceaccounts"], Verbs:["get" "list"]} {APIGroups:[""], Resources:["services"], Verbs:["get" "list"]} ``` The setup of integration test suite included only permissions defined in redpanda package. Kustomize and Operator helm chart includes those missing permissions.
1 parent 9f01ceb commit 90e5fcc

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

operator/config/rbac/bases/operator/role.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ rules:
1616
- patch
1717
- update
1818
- watch
19+
- apiGroups:
20+
- ""
21+
resources:
22+
- endpoints
23+
- limitranges
24+
- pods/log
25+
- replicationcontrollers
26+
- resourcequotas
27+
verbs:
28+
- get
29+
- list
1930
- apiGroups:
2031
- ""
2132
resources:

operator/config/rbac/v2-manager-role/role.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ rules:
1414
- get
1515
- list
1616
- watch
17+
- apiGroups:
18+
- ""
19+
resources:
20+
- endpoints
21+
- events
22+
- limitranges
23+
- persistentvolumeclaims
24+
- pods
25+
- pods/log
26+
- replicationcontrollers
27+
- resourcequotas
28+
- serviceaccounts
29+
- services
30+
verbs:
31+
- get
32+
- list
1733
- apiGroups:
1834
- ""
1935
resources:

operator/internal/controller/redpanda/redpanda_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ type RedpandaReconciler struct {
140140
// The leases is used by controller-runtime in sidecar. Operator main reconciliation needs to have leases permissions in order to create role that have the same permissions.
141141
// +kubebuilder:rbac:groups=coordination.k8s.io,namespace=default,resources=leases,verbs=get;list;watch;create;update;patch;delete
142142

143+
// rpk bundle additional rbac permissions
144+
// When Redpanda chart values has set `rbac.enabled = true`, then operator needs to have elevated permissions to create ClusterRole
145+
// +kubebuilder:rbac:groups=core,resources=endpoints;events;limitranges;persistentvolumeclaims;pods;pods/log;replicationcontrollers;resourcequotas;serviceaccounts;services,verbs=get;list
146+
143147
// SetupWithManager sets up the controller with the Manager.
144148
func (r *RedpandaReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
145149
if err := registerHelmReferencedIndex(ctx, mgr, "statefulset", &appsv1.StatefulSet{}); err != nil {

operator/internal/controller/redpanda/redpanda_controller_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ func (s *RedpandaControllerSuite) TestStableUIDAndGeneration() {
731731
flipped := s.snapshotCluster(filter)
732732
s.compareSnapshot(fresh, flipped, isStable)
733733

734-
s.T().Logf("toggling useFlux: %t -> %t", useFlux, !useFlux)
734+
s.T().Logf("toggling useFlux: %t -> %t", !useFlux, useFlux)
735735
rp.Spec.ChartRef.UseFlux = ptr.To(useFlux)
736736
s.applyAndWait(rp)
737737

@@ -743,9 +743,15 @@ func (s *RedpandaControllerSuite) TestStableUIDAndGeneration() {
743743
// HelmRelease and HelmChart are checked explicitly here, but any test that would left behind mentioned resource
744744
// will prevent from namespace deletion. In other words if test suite can not delete namespace, then with high
745745
// probability resource with finalizer prevents from namespace deletion.
746-
var hr v2beta2.HelmRelease
747-
err := s.client.Get(s.ctx, types.NamespacedName{Name: rp.GetHelmReleaseName(), Namespace: rp.Namespace}, &hr)
748-
s.True(apierrors.IsNotFound(err))
746+
747+
// In the flux base deployment the HelmRelease will be deleted after Redpanda is fully removed from
748+
// Kubernetes API server. The ownerReference tight together Redpanda with HelmRelease, but there is
749+
// delay between HelmRelease and Redpadna custom resource deletion.
750+
s.EventuallyWithT(func(t *assert.CollectT) {
751+
var hr v2beta2.HelmRelease
752+
err := s.client.Get(s.ctx, types.NamespacedName{Name: rp.GetHelmReleaseName(), Namespace: rp.Namespace}, &hr)
753+
assert.True(t, apierrors.IsNotFound(err))
754+
}, time.Minute, time.Second, "HelmRelease not GC'd")
749755

750756
var hc sourcecontrollerv1beta2.HelmChart
751757
err = s.client.Get(s.ctx, types.NamespacedName{Name: rp.Namespace + "-" + rp.Name, Namespace: rp.Namespace}, &hc)
@@ -958,7 +964,7 @@ func (s *RedpandaControllerSuite) minimalRP(useFlux bool) *redpandav1alpha2.Redp
958964
},
959965
},
960966
RBAC: &redpandav1alpha2.RBAC{
961-
Enabled: ptr.To(false),
967+
Enabled: ptr.To(true),
962968
},
963969
},
964970
},

operator/internal/controller/redpanda/role.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ rules:
1414
- get
1515
- list
1616
- watch
17+
- apiGroups:
18+
- ""
19+
resources:
20+
- endpoints
21+
- events
22+
- limitranges
23+
- persistentvolumeclaims
24+
- pods
25+
- pods/log
26+
- replicationcontrollers
27+
- resourcequotas
28+
- serviceaccounts
29+
- services
30+
verbs:
31+
- get
32+
- list
1733
- apiGroups:
1834
- ""
1935
resources:

0 commit comments

Comments
 (0)