Skip to content

Commit

Permalink
feat: add secret not created yet error response
Browse files Browse the repository at this point in the history
In case of a PKE cluster on AWS during creation time.
  • Loading branch information
akijakya committed Oct 21, 2021
1 parent 8801be3 commit 4d3abac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/api/BUILD.plz
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
deps = [
"//.gen/pipeline/pipeline",
"//internal/anchore",
"//internal/cluster",
"//internal/cluster/auth",
"//internal/cluster/clusteradapter",
"//internal/cluster/distribution/eks/eksprovider/driver",
Expand Down
28 changes: 24 additions & 4 deletions src/api/cluster_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/banzaicloud/pipeline/internal/cluster"
"github.com/banzaicloud/pipeline/internal/cluster/oidc"
"github.com/banzaicloud/pipeline/internal/cluster/resourcesummary"
ginutils "github.com/banzaicloud/pipeline/internal/platform/gin/utils"
pkgCluster "github.com/banzaicloud/pipeline/pkg/cluster"
"github.com/banzaicloud/pipeline/pkg/common"
"github.com/banzaicloud/pipeline/pkg/k8sclient"
)
Expand Down Expand Up @@ -58,13 +60,31 @@ func (a *ClusterAPI) GetCluster(c *gin.Context) {

secret, err := commonCluster.GetSecretWithValidation()
if err != nil {
errorHandler.Handle(err)

ginutils.ReplyWithErrorResponse(c, &common.ErrorResponse{
errorResponse := &common.ErrorResponse{
Code: http.StatusInternalServerError,
Message: "Error getting secret",
Error: err.Error(),
})
}

if clusterStatus.Distribution == pkgCluster.PKE &&
clusterStatus.Cloud == pkgCluster.Amazon &&
clusterStatus.Status == pkgCluster.Creating {
err = cluster.NotReadyError{
OrganizationID: commonCluster.GetOrganizationId(),
ID: commonCluster.GetID(),
Name: commonCluster.GetName(),
}

errorResponse = &common.ErrorResponse{
Code: http.StatusConflict,
Message: "Secret has not been created yet",
Error: err.Error(),
}
}

errorHandler.Handle(err)

ginutils.ReplyWithErrorResponse(c, errorResponse)
return
}

Expand Down

0 comments on commit 4d3abac

Please sign in to comment.