github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/modules/k8s/role.go (about) 1 package k8s 2 3 import ( 4 "context" 5 6 "github.com/gruntwork-io/terratest/modules/testing" 7 "github.com/stretchr/testify/require" 8 rbacv1 "k8s.io/api/rbac/v1" 9 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 ) 11 12 // GetRole returns a Kubernetes role resource in the provided namespace with the given name. The namespace used 13 // is the one provided in the KubectlOptions. This will fail the test if there is an error. 14 func GetRole(t testing.TestingT, options *KubectlOptions, roleName string) *rbacv1.Role { 15 role, err := GetRoleE(t, options, roleName) 16 require.NoError(t, err) 17 return role 18 } 19 20 // GetRoleE returns a Kubernetes role resource in the provided namespace with the given name. The namespace used 21 // is the one provided in the KubectlOptions. 22 func GetRoleE(t testing.TestingT, options *KubectlOptions, roleName string) (*rbacv1.Role, error) { 23 clientset, err := GetKubernetesClientFromOptionsE(t, options) 24 if err != nil { 25 return nil, err 26 } 27 return clientset.RbacV1().Roles(options.Namespace).Get(context.Background(), roleName, metav1.GetOptions{}) 28 }