Skip to content

Commit 8eefe31

Browse files
committed
Add ClusterRole having AggregatedRule to integration tests
Signed-off-by: Maciej Zimnoch <[email protected]>
1 parent 27659b8 commit 8eefe31

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: aggregation-memcached-subrole
5+
labels:
6+
rbac.example.memcached.com/aggregate-to-aggregation-memcached: "true"
7+
rules:
8+
- apiGroups:
9+
- ""
10+
resources:
11+
- pods
12+
verbs:
13+
- update
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRoleBinding
3+
metadata:
4+
name: aggregation-memcached
5+
roleRef:
6+
apiGroup: rbac.authorization.k8s.io
7+
kind: ClusterRole
8+
name: aggregation-memcached
9+
subjects:
10+
- kind: ServiceAccount
11+
name: controller-manager
12+
namespace: system
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: aggregation-memcached
5+
aggregationRule:
6+
clusterRoleSelectors:
7+
- matchLabels:
8+
rbac.example.memcached.com/aggregate-to-aggregation-memcached: "true"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
- aggregation.clusterrolebinding.yaml
3+
- aggregation-subrole.clusterrole.yaml
4+
- aggregation.clusterrole.yaml
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package manifests
2+
3+
import (
4+
_ "embed"
5+
)
6+
7+
var (
8+
//go:embed "aggregation.clusterrole.yaml"
9+
AggregationClusterRoleString string
10+
11+
//go:embed "aggregation-subrole.clusterole.yaml"
12+
AggregationSubroleClusterRoleString string
13+
14+
//go:embed "aggregation.clusterolebinding.yaml"
15+
AggregationClusterRoleBindingString string
16+
17+
//go:embed "aggregation.kustomization.patch.yaml"
18+
AggregationKustomizationPatchString string
19+
)

hack/generate/samples/internal/go/memcached-with-customization/memcached_with_customization.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"path/filepath"
2222
"strings"
2323

24+
"github.com/operator-framework/operator-sdk/hack/generate/samples/internal/go/memcached-with-customization/manifests"
2425
log "github.com/sirupsen/logrus"
2526
kbutil "sigs.k8s.io/kubebuilder/v4/pkg/plugin/util"
2627

@@ -139,6 +140,9 @@ func (mh *Memcached) Run() {
139140

140141
mh.implementingWebhooks()
141142

143+
log.Infof("implementing the aggregated cluster rule")
144+
mh.implementingAggregatedClusterRules()
145+
142146
mh.uncommentDefaultKustomizationV4()
143147
mh.uncommentManifestsKustomizationv4()
144148

@@ -780,6 +784,40 @@ func (mh *Memcached) customizingMakefile() {
780784
pkg.CheckError("adding metrics documentation", err)
781785
}
782786

787+
func (mh *Memcached) implementingAggregatedClusterRules() {
788+
rbacDirPath := filepath.Join(mh.ctx.Dir, "config", "rbac")
789+
790+
var filePerm os.FileMode = 0600
791+
792+
err := os.WriteFile(
793+
filepath.Join(rbacDirPath, "aggregation.clusterrole.yaml"),
794+
[]byte(manifests.AggregationClusterRoleString),
795+
filePerm,
796+
)
797+
pkg.CheckError("creating aggregation clusterrole", err)
798+
799+
err = os.WriteFile(
800+
filepath.Join(rbacDirPath, "aggregation-subrole.clusterrole.yaml"),
801+
[]byte(manifests.AggregationSubroleClusterRoleString),
802+
filePerm,
803+
)
804+
pkg.CheckError("creating aggregation clusterrole subrole", err)
805+
806+
err = os.WriteFile(
807+
filepath.Join(rbacDirPath, "aggregation.clusterrolebinding.yaml"),
808+
[]byte(manifests.AggregationClusterRoleBindingString),
809+
filePerm,
810+
)
811+
pkg.CheckError("creating aggregation clusterrolebinding", err)
812+
813+
kustomizationPath := filepath.Join(rbacDirPath, "kustomization.yaml")
814+
err = kbutil.InsertCode(kustomizationPath,
815+
`- memcached_viewer_role.yaml`,
816+
manifests.AggregationKustomizationPatchString,
817+
)
818+
pkg.CheckError("adding metrics documentation", err)
819+
}
820+
783821
const metricsFragment = `
784822
785823
package monitoring

0 commit comments

Comments
 (0)