From 4d3abacaa54c5070066ea746888e66c6c663bdb7 Mon Sep 17 00:00:00 2001 From: Andras Jaky Date: Thu, 21 Oct 2021 15:58:01 +0200 Subject: [PATCH] feat: add secret not created yet error response In case of a PKE cluster on AWS during creation time. --- src/api/BUILD.plz | 1 + src/api/cluster_get.go | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/api/BUILD.plz b/src/api/BUILD.plz index 690de1a496..ba36ddced0 100644 --- a/src/api/BUILD.plz +++ b/src/api/BUILD.plz @@ -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", diff --git a/src/api/cluster_get.go b/src/api/cluster_get.go index 53dac5c1a5..63dc88ddab 100644 --- a/src/api/cluster_get.go +++ b/src/api/cluster_get.go @@ -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" ) @@ -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 }