Skip to content

Commit

Permalink
CLOUDP-273727 "atlas deployments search index describe" fails with un…
Browse files Browse the repository at this point in the history
…clear error message when local deployment is paused (#3284)
  • Loading branch information
fmenezes authored Sep 25, 2024
1 parent 4605aaa commit ba0ed40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions internal/cli/deployments/options/deployment_opts_pre_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package options
import (
"context"
"errors"
"fmt"
"runtime"
"slices"

Expand All @@ -26,6 +27,8 @@ import (
atlasv2 "go.mongodb.org/atlas-sdk/v20240805001/admin"
)

var errDeploymentUnexpectedState = errors.New("deployment is in unexpected state")

func (opts *DeploymentOpts) listDeployments(ctx context.Context, projectID string) ([]Deployment, error) {
var atlasDeployments, localDeployments []Deployment
var atlasErr, localErr error
Expand Down Expand Up @@ -72,9 +75,20 @@ func (opts *DeploymentOpts) SelectDeployments(ctx context.Context, projectID str
}

deployments = opts.filterDeploymentByName(deployments...)
deployments = opts.filterDeploymentByState(deployments, states...)
if opts.DeploymentName == "" {
deployments = opts.filterDeploymentByState(deployments, states...)
}

d, err := opts.Select(deployments)
if err != nil {
return Deployment{}, err
}

if len(states) > 0 && !slices.Contains(states, d.StateName) {
return Deployment{}, fmt.Errorf("%w: %s", errDeploymentUnexpectedState, d.StateName)
}

return opts.Select(deployments)
return d, nil
}

func isUnauthenticatedErr(err error) bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/deployments/search/indexes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ListOpts struct {
}

func (opts *ListOpts) Run(ctx context.Context) error {
if _, err := opts.SelectDeployments(ctx, opts.ConfigProjectID()); err != nil {
if _, err := opts.SelectDeployments(ctx, opts.ConfigProjectID(), options.IdleState); err != nil {
return err
}

Expand Down

0 comments on commit ba0ed40

Please sign in to comment.