github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/pkg/clients/gitops/space_requests.go (about)

     1  package gitops
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	codereadytoolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
     8  	k8sErrors "k8s.io/apimachinery/pkg/api/errors"
     9  	"sigs.k8s.io/controller-runtime/pkg/client"
    10  )
    11  
    12  // GetSpaceRequests returns a list of spaceRequests in given namespace.
    13  func (g *GitopsController) GetSpaceRequests(namespace string) (*codereadytoolchainv1alpha1.SpaceRequestList, error) {
    14  	spaceRequestList := &codereadytoolchainv1alpha1.SpaceRequestList{}
    15  
    16  	opts := []client.ListOption{
    17  		client.InNamespace(namespace),
    18  	}
    19  
    20  	err := g.KubeRest().List(context.Background(), spaceRequestList, opts...)
    21  	if err != nil && !k8sErrors.IsNotFound(err) {
    22  		return nil, fmt.Errorf("error occurred while trying to list spaceRequests in %s namespace: %v", namespace, err)
    23  	}
    24  
    25  	return spaceRequestList, nil
    26  }