github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/framework/resources.go (about)

     1  package framework
     2  
     3  import (
     4  	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     5  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
     6  	"k8s.io/apimachinery/pkg/runtime/schema"
     7  )
     8  
     9  type ResourceType int
    10  
    11  const (
    12  	Issuers ResourceType = iota
    13  	Certificates
    14  )
    15  
    16  var (
    17  	resourceMap = map[ResourceType]schema.GroupVersionResource{
    18  		Issuers: {
    19  			Group:    "certmanager.k8s.io",
    20  			Version:  "v1alpha1",
    21  			Resource: "issuers",
    22  		},
    23  		Certificates: {
    24  			Group:    "certmanager.k8s.io",
    25  			Version:  "v1alpha1",
    26  			Resource: "certificates",
    27  		},
    28  	}
    29  )
    30  
    31  // GetResource returns the given resource type, identified by its given name
    32  func (f *Framework) GetResource(resourceType ResourceType, name string) (*unstructured.Unstructured, error) {
    33  	return f.DynClient.Resource(resourceMap[resourceType]).Namespace(f.Namespace).Get(name, v1.GetOptions{})
    34  }
    35  
    36  // ListResources returns a list of resources found in the related Framework's namespace,
    37  // for the given resource type
    38  func (f *Framework) ListResources(resourceType ResourceType) (*unstructured.UnstructuredList, error) {
    39  	return f.DynClient.Resource(resourceMap[resourceType]).Namespace(f.Namespace).List(v1.ListOptions{})
    40  }