Skip to content

Commit

Permalink
set limit as zero
Browse files Browse the repository at this point in the history
  • Loading branch information
SivaanandM committed Oct 21, 2023
1 parent c1b2605 commit 18affeb
Showing 1 changed file with 12 additions and 45 deletions.
57 changes: 12 additions & 45 deletions client/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,33 +102,10 @@ func (h *V1Client) SearchClusterSummaries(clusterContext string, filter *models.
return resp.Payload.Items, nil
}

func (h *V1Client) listClusters(clusterContext string) ([]*models.V1SpectroCluster, string, error) {
func (h *V1Client) listClusters(clusterContext string) ([]*models.V1SpectroCluster, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, "", err
}

var params *clusterC.V1SpectroClustersListParams
switch clusterContext {
case "project":
params = clusterC.NewV1SpectroClustersListParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1SpectroClustersListParams()
}

resp, err := client.V1SpectroClustersList(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {
return nil, "", nil
} else if err != nil {
return nil, "", err
}
return resp.Payload.Items, resp.Payload.Listmeta.Continue, nil
}

func (h *V1Client) listClustersWithPagination(clusterContext string, ContinueToken string) ([]*models.V1SpectroCluster, string, error) {
client, err := h.GetClusterClient()
if err != nil {
return nil, "", err
return nil, err
}

var params *clusterC.V1SpectroClustersListParams
Expand All @@ -138,29 +115,29 @@ func (h *V1Client) listClustersWithPagination(clusterContext string, ContinueTok
case "tenant":
params = clusterC.NewV1SpectroClustersListParams()
}
params.Continue = &ContinueToken
var limit int64 = 0
params.Limit = &limit
resp, err := client.V1SpectroClustersList(params)

if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {
return nil, "", nil
return nil, nil
} else if err != nil {
return nil, "", err
return nil, err
}
return resp.Payload.Items, resp.Payload.Listmeta.Continue, nil
return resp.Payload.Items, nil
}

func (h *V1Client) ListClusters(clusterContext string) ([]*models.V1SpectroCluster, string, error) {
allClusters, continueToken, err := h.listClusters(clusterContext)
func (h *V1Client) ListClusters(clusterContext string) ([]*models.V1SpectroCluster, error) {
allClusters, err := h.listClusters(clusterContext)
if err != nil {
return nil, "", err
return nil, err
}
clusters := make([]*models.V1SpectroCluster, 0)
for _, c := range allClusters {
if c.Status.State != "Deleted" {
clusters = append(clusters, c)
}
}
return clusters, continueToken, nil
return clusters, nil
}

func (h *V1Client) GetClusterWithoutStatus(scope, uid string) (*models.V1SpectroCluster, error) {
Expand Down Expand Up @@ -194,25 +171,15 @@ func (h *V1Client) GetClusterWithoutStatus(scope, uid string) (*models.V1Spectro
}

func (h *V1Client) GetClusterByName(name, clusterContext string) (*models.V1SpectroCluster, error) {
clusters, continueToken, err := h.listClusters(clusterContext)
clusters, err := h.listClusters(clusterContext)
if err != nil {
return nil, err
}
// Finding out in page one with the limit of 50
for _, cluster := range clusters {
if cluster.Metadata.Name == name && cluster.Status.State != "Deleted" {
return cluster, nil
}
}
// Pagination loop till continueToken becomes = ""
for continueToken != "" {
clusters, continueToken, err = h.listClustersWithPagination(clusterContext, continueToken)
for _, cluster := range clusters {
if cluster.Metadata.Name == name && cluster.Status.State != "Deleted" {
return cluster, nil
}
}
}
return nil, nil
}

Expand Down

0 comments on commit 18affeb

Please sign in to comment.