forked from gruntwork-io/terratest
/
cluster_role.go
24 lines (21 loc) · 893 Bytes
/
cluster_role.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package k8s
import (
"github.com/gruntwork-io/terratest/modules/testing"
"github.com/stretchr/testify/require"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// GetClusterRole returns a Kubernetes ClusterRole resource with the given name. This will fail the test if there is an error.
func GetClusterRole(t testing.TestingT, options *KubectlOptions, roleName string) *rbacv1.ClusterRole {
role, err := GetClusterRoleE(t, options, roleName)
require.NoError(t, err)
return role
}
// GetClusterRoleE returns a Kubernetes ClusterRole resource with the given name.
func GetClusterRoleE(t testing.TestingT, options *KubectlOptions, roleName string) (*rbacv1.ClusterRole, error) {
clientset, err := GetKubernetesClientFromOptionsE(t, options)
if err != nil {
return nil, err
}
return clientset.RbacV1().ClusterRoles().Get(roleName, metav1.GetOptions{})
}