Skip to content

Commit

Permalink
Merge pull request #354 from banzaicloud/handle-GetCluster-409-respon…
Browse files Browse the repository at this point in the history
…se-during-cluster-creation

Handle GetCluster 409 response during cluster creation
  • Loading branch information
akijakya authored Oct 22, 2021
2 parents 22e27da + e786d2a commit 4a30d8c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion internal/cli/command/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"sort"
"strconv"
Expand Down Expand Up @@ -118,7 +119,24 @@ func runCreate(banzaiCli cli.Cli, options createOptions) error {
for {
cluster, _, err := banzaiCli.Client().ClustersApi.GetCluster(context.Background(), orgID, cluster.Id)
if err != nil {
cli.LogAPIError("create cluster", err, out)
openAPIError, ok := err.(pipeline.GenericOpenAPIError)
if !ok {
cli.LogAPIError("create cluster", err, out)
}

var commonError pipeline.CommonError
unmarshalErr := json.Unmarshal(openAPIError.Body(), &commonError)
if unmarshalErr != nil {
cli.LogAPIError("create cluster", err, out)
}

if commonError.Code == http.StatusConflict &&
commonError.Message == "Secret has not been created yet" &&
commonError.Error == "cluster is not ready" {
log.Info("cluster is being created")
} else {
cli.LogAPIError("create cluster", err, out)
}
} else {
format.ClusterShortWrite(banzaiCli, cluster)
if cluster.Status != "CREATING" {
Expand Down

0 comments on commit 4a30d8c

Please sign in to comment.