github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/modules/k8s/cluster_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 // GetClusterRole returns a Kubernetes ClusterRole resource with the given name. This will fail the test if there is an error. 13 func GetClusterRole(t testing.TestingT, options *KubectlOptions, roleName string) *rbacv1.ClusterRole { 14 role, err := GetClusterRoleE(t, options, roleName) 15 require.NoError(t, err) 16 return role 17 } 18 19 // GetClusterRoleE returns a Kubernetes ClusterRole resource with the given name. 20 func GetClusterRoleE(t testing.TestingT, options *KubectlOptions, roleName string) (*rbacv1.ClusterRole, error) { 21 clientset, err := GetKubernetesClientFromOptionsE(t, options) 22 if err != nil { 23 return nil, err 24 } 25 return clientset.RbacV1().ClusterRoles().Get(context.Background(), roleName, metav1.GetOptions{}) 26 }