2022-12-07 02:53:06 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
)
|
|
|
|
|
2024-10-01 01:15:51 +00:00
|
|
|
// IsRBACEnabled checks if RBAC is enabled in the current Kubernetes cluster by listing cluster roles.
|
|
|
|
// if the cluster roles can be listed, RBAC is enabled.
|
|
|
|
// otherwise, RBAC is not enabled.
|
2022-12-07 02:53:06 +00:00
|
|
|
func (kcl *KubeClient) IsRBACEnabled() (bool, error) {
|
2024-10-01 01:15:51 +00:00
|
|
|
_, err := kcl.cli.RbacV1().ClusterRoles().List(context.TODO(), metav1.ListOptions{})
|
2022-12-07 02:53:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, nil
|
|
|
|
}
|
2024-10-01 01:15:51 +00:00
|
|
|
return true, nil
|
2022-12-07 02:53:06 +00:00
|
|
|
}
|