github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/pkg/clients/gitops/space.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  // GetSpaces returns a list of spaces in given namespace.
    13  func (g *GitopsController) GetSpaces(namespace string) (*codereadytoolchainv1alpha1.SpaceList, error) {
    14  	spaceList := &codereadytoolchainv1alpha1.SpaceList{}
    15  
    16  	opts := []client.ListOption{
    17  		client.InNamespace(namespace),
    18  	}
    19  
    20  	err := g.KubeRest().List(context.Background(), spaceList, opts...)
    21  	if err != nil && !k8sErrors.IsNotFound(err) {
    22  		return nil, fmt.Errorf("error occurred while trying to list spaces in %s namespace: %w", namespace, err)
    23  	}
    24  
    25  	return spaceList, nil
    26  }