@@ -25,18 +25,36 @@ public RbacGenerator(EntitySerializer serializer)
25
25
26
26
public async Task < int > OnExecuteAsync ( CommandLineApplication app )
27
27
{
28
- var output = _serializer . Serialize ( GenerateManagerRbac ( ) , Format ) ;
28
+ var role = _serializer . Serialize ( GenerateManagerRbac ( ) , Format ) ;
29
+ var roleBinding = _serializer . Serialize ( new V1ClusterRoleBinding
30
+ {
31
+ ApiVersion = $ "{ V1ClusterRoleBinding . KubeGroup } /{ V1ClusterRoleBinding . KubeApiVersion } ",
32
+ Kind = V1ClusterRoleBinding . KubeKind ,
33
+ Metadata = new V1ObjectMeta { Name = "operator-role-binding" } ,
34
+ RoleRef = new V1RoleRef ( V1ClusterRole . KubeGroup , V1ClusterRole . KubeKind , "operator-role" ) ,
35
+ Subjects = new List < V1Subject >
36
+ {
37
+ new V1Subject ( V1ServiceAccount . KubeKind , "default" , namespaceProperty : "system" )
38
+ }
39
+ } , Format ) ;
29
40
30
41
if ( ! string . IsNullOrWhiteSpace ( OutputPath ) )
31
42
{
32
43
Directory . CreateDirectory ( OutputPath ) ;
33
- await using var file = File . Open ( Path . Join ( OutputPath ,
34
- $ "operator.{ Format . ToString ( ) . ToLower ( ) } ") , FileMode . Create ) ;
35
- await file . WriteAsync ( Encoding . UTF8 . GetBytes ( output ) ) ;
44
+ await using var roleFile = File . Open ( Path . Join ( OutputPath ,
45
+ $ "operator-role.{ Format . ToString ( ) . ToLower ( ) } ") , FileMode . Create ) ;
46
+ await roleFile . WriteAsync ( Encoding . UTF8 . GetBytes ( role ) ) ;
47
+ await using var bindingFile = File . Open ( Path . Join ( OutputPath ,
48
+ $ "operator-role-binding.{ Format . ToString ( ) . ToLower ( ) } ") , FileMode . Create ) ;
49
+ await bindingFile . WriteAsync ( Encoding . UTF8 . GetBytes ( roleBinding ) ) ;
36
50
37
51
var kustomize = new KustomizationConfig
38
52
{
39
- Resources = new List < string > { $ "operator.{ Format . ToString ( ) . ToLower ( ) } "} ,
53
+ Resources = new List < string >
54
+ {
55
+ $ "operator-role.{ Format . ToString ( ) . ToLower ( ) } ",
56
+ $ "operator-role-binding.{ Format . ToString ( ) . ToLower ( ) } ",
57
+ } ,
40
58
CommonLabels = new Dictionary < string , string >
41
59
{
42
60
{ "operator-element" , "rbac" } ,
@@ -49,7 +67,8 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app)
49
67
}
50
68
else
51
69
{
52
- await app . Out . WriteLineAsync ( output ) ;
70
+ await app . Out . WriteLineAsync ( role ) ;
71
+ await app . Out . WriteLineAsync ( roleBinding ) ;
53
72
}
54
73
55
74
return ExitCodes . Success ;
0 commit comments