@@ -22,6 +22,7 @@ import (
2222 orchestrationv1alpha1 "github.com/vllm-project/aibrix/api/orchestration/v1alpha1"
2323 "github.com/vllm-project/aibrix/pkg/constants"
2424 corev1 "k8s.io/api/core/v1"
25+ rbacv1 "k8s.io/api/rbac/v1"
2526 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627 "k8s.io/apimachinery/pkg/util/intstr"
2728)
@@ -113,3 +114,75 @@ func buildRedisService(kvCache *orchestrationv1alpha1.KVCache) *corev1.Service {
113114
114115 return svc
115116}
117+
118+ // buildServiceAccount creates a new ServiceAccount for Distributed kv cache solution.
119+ func buildServiceAccount (kvCache * orchestrationv1alpha1.KVCache ) * corev1.ServiceAccount {
120+ sa := & corev1.ServiceAccount {
121+ ObjectMeta : metav1.ObjectMeta {
122+ Name : kvCache .Name ,
123+ Namespace : kvCache .Namespace ,
124+ Labels : map [string ]string {
125+ constants .KVCacheLabelKeyIdentifier : kvCache .Name ,
126+ constants .KVCacheLabelKeyRole : constants .KVCacheLabelValueRoleCache ,
127+ },
128+ },
129+ }
130+
131+ return sa
132+ }
133+
134+ // buildRole creates a new Role for a KVCache resource.
135+ func buildRole (kvCache * orchestrationv1alpha1.KVCache ) * rbacv1.Role {
136+ role := & rbacv1.Role {
137+ ObjectMeta : metav1.ObjectMeta {
138+ Name : kvCache .Name ,
139+ Namespace : kvCache .Namespace ,
140+ Labels : map [string ]string {
141+ constants .KVCacheLabelKeyIdentifier : kvCache .Name ,
142+ constants .KVCacheLabelKeyRole : constants .KVCacheLabelValueRoleCache ,
143+ },
144+ },
145+ Rules : []rbacv1.PolicyRule {
146+ {
147+ APIGroups : []string {"" },
148+ Resources : []string {"pods" },
149+ Verbs : []string {"get" , "list" , "watch" },
150+ },
151+ {
152+ APIGroups : []string {"" },
153+ Resources : []string {"pods/exec" },
154+ Verbs : []string {"create" },
155+ },
156+ },
157+ }
158+
159+ return role
160+ }
161+
162+ // buildRoleBinding creates rolebinding for a kvCache object
163+ func buildRoleBinding (kvCache * orchestrationv1alpha1.KVCache ) * rbacv1.RoleBinding {
164+ rb := & rbacv1.RoleBinding {
165+ ObjectMeta : metav1.ObjectMeta {
166+ Name : kvCache .Name ,
167+ Namespace : kvCache .Namespace ,
168+ Labels : map [string ]string {
169+ constants .KVCacheLabelKeyIdentifier : kvCache .Name ,
170+ constants .KVCacheLabelKeyRole : constants .KVCacheLabelValueRoleCache ,
171+ },
172+ },
173+ Subjects : []rbacv1.Subject {
174+ {
175+ Kind : rbacv1 .ServiceAccountKind ,
176+ Name : kvCache .Name ,
177+ Namespace : kvCache .Namespace ,
178+ },
179+ },
180+ RoleRef : rbacv1.RoleRef {
181+ APIGroup : rbacv1 .GroupName ,
182+ Kind : "Role" ,
183+ Name : kvCache .Name ,
184+ },
185+ }
186+
187+ return rb
188+ }
0 commit comments