forked from gruntwork-io/terratest
/
role.go
27 lines (23 loc) · 969 Bytes
/
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
25
26
27
package k8s
import (
"testing"
"github.com/stretchr/testify/require"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// GetRole returns a Kubernetes role resource in the provided namespace with the given name. The namespace used
// is the one provided in the KubectlOptions. This will fail the test if there is an error.
func GetRole(t *testing.T, options *KubectlOptions, roleName string) *rbacv1.Role {
role, err := GetRoleE(t, options, roleName)
require.NoError(t, err)
return role
}
// GetRoleE returns a Kubernetes role resource in the provided namespace with the given name. The namespace used
// is the one provided in the KubectlOptions.
func GetRoleE(t *testing.T, options *KubectlOptions, roleName string) (*rbacv1.Role, error) {
clientset, err := GetKubernetesClientFromOptionsE(t, options)
if err != nil {
return nil, err
}
return clientset.RbacV1().Roles(options.Namespace).Get(roleName, metav1.GetOptions{})
}