mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-08-23 22:26:49 +00:00
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package cache
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
rbacv1 "k8s.io/api/rbac/v1"
|
|
)
|
|
|
|
const (
|
|
byClusterRole = "byClusterRole"
|
|
byRole = "byRole"
|
|
)
|
|
|
|
func crbIndexByClusterRole(obj interface{}) ([]string, error) {
|
|
crb, ok := obj.(*rbacv1.ClusterRoleBinding)
|
|
if !ok {
|
|
return []string{}, fmt.Errorf("obj is supposed to be a ClusterRoleBinding, but is %T", obj)
|
|
}
|
|
|
|
return []string{crb.RoleRef.Name}, nil
|
|
}
|
|
|
|
func rbIndexByClusterRole(obj interface{}) ([]string, error) {
|
|
rb, ok := obj.(*rbacv1.RoleBinding)
|
|
if !ok {
|
|
return []string{}, fmt.Errorf("obj is supposed to be a RoleBinding, but is %T", obj)
|
|
}
|
|
|
|
if rb.RoleRef.Kind == "ClusterRole" {
|
|
return []string{rb.RoleRef.Name}, nil
|
|
}
|
|
return []string{}, nil
|
|
}
|
|
|
|
func rbIndexByRole(obj interface{}) ([]string, error) {
|
|
rb, ok := obj.(*rbacv1.RoleBinding)
|
|
if !ok {
|
|
return []string{}, fmt.Errorf("obj is supposed to be a RoleBinding, but is %T", obj)
|
|
}
|
|
|
|
if rb.RoleRef.Kind == "Role" {
|
|
return []string{fmt.Sprintf("%s/%s", rb.Namespace, rb.RoleRef.Name)}, nil
|
|
}
|
|
|
|
return []string{}, nil
|
|
}
|