Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz committed Oct 8, 2024
1 parent 3194a03 commit cea824c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cmd/command/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (p *Plural) handleUp(c *cli.Context) error {

func getCluster(cd *cd.Plural) (id string, name string, err error) {
if cd == nil {
return "", "", fmt.Errorf("please provide a plural client")
return "", "", fmt.Errorf("your CLI is not logged into Plural, try running `plural login` to generate local credentials")
}
clusters, err := cd.ListClusters()
if err != nil {
Expand Down
41 changes: 3 additions & 38 deletions pkg/provider/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func mkAWS(conf config.Config) (provider *AWSProvider, err error) {
provider.project = account
provider.storageClient = client

azones, err := getAvailabilityZones(ctx, provider.Region(), cloudFlag)
azones, err := getAvailabilityZones(ctx, provider.Region())
if err != nil {
return
}
Expand Down Expand Up @@ -158,44 +158,9 @@ func getEC2Client(ctx context.Context, region string) (*ec2.Client, error) {
return ec2.NewFromConfig(cfg), nil
}

// TODO: during Plural init we should ask the user to choose which AZs they want to use (first 3, random, manual, look at how CAPA does that). There should be a minimum limit of 3.
func getAvailabilityZones(ctx context.Context, region string, cloudFlag bool) ([]string, error) {
first3 := "first three"
random := "random"
manual := "manual"
choice := first3
if !cloudFlag {
choice = ""
prompt := &survey.Select{
Message: "Which availability zones you would like to use:",
Options: []string{first3, random, manual},
}
if err := survey.AskOne(prompt, &choice); err != nil {
return nil, err
}
}

switch choice {
case first3:
return fetchAZ(ctx, region, true)
case random:
return fetchAZ(ctx, region, false)
case manual:
text := ""
prompt := &survey.Multiline{
Message: "Enter at least three availability zones ",
}
if err := survey.AskOne(prompt, &text); err != nil {
return nil, err
}
res := strings.Split(text, "\n")
if len(res) < 3 {
return nil, fmt.Errorf("expected at least three availability zones")
}
return res, nil
}
func getAvailabilityZones(ctx context.Context, region string) ([]string, error) {
return fetchAZ(ctx, region, true)

return nil, nil
}

func fetchAZ(context context.Context, region string, sorted bool) ([]string, error) {
Expand Down

0 comments on commit cea824c

Please sign in to comment.