From eed642a095fc7a83074c51d461b45149521388b3 Mon Sep 17 00:00:00 2001 From: donggyu Date: Thu, 26 Oct 2023 19:12:22 +0900 Subject: [PATCH 1/2] trivial. handling 2xx http status code --- pkg/api-client/api-client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/api-client/api-client.go b/pkg/api-client/api-client.go index 47f1ef05..dd8549e5 100644 --- a/pkg/api-client/api-client.go +++ b/pkg/api-client/api-client.go @@ -140,7 +140,7 @@ func (c *ApiClientImpl) callWithBody(prefix string, method string, path string, res.Body.Close() }() - if res.StatusCode != 200 { + if res.StatusCode%100 != 2 { var restError httpErrors.RestError if err := json.Unmarshal(body, &restError); err != nil { return nil, fmt.Errorf("Invalid http status. failed to unmarshal body : %s", err) From bbde647b96e5e2ea9344ac6aaf08596a71f8ad40 Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Fri, 3 Nov 2023 18:34:47 +0900 Subject: [PATCH 2/2] app-serving: create ns only if it's not given by user --- internal/delivery/http/app-serve-app.go | 41 ++++++++++++++----------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/internal/delivery/http/app-serve-app.go b/internal/delivery/http/app-serve-app.go index 9705d218..7b3df3e5 100644 --- a/internal/delivery/http/app-serve-app.go +++ b/internal/delivery/http/app-serve-app.go @@ -151,24 +151,29 @@ func (h *AppServeAppHandler) CreateAppServeApp(w http.ResponseWriter, r *http.Re return } - // Check if the namespace is already used in the target cluster - ns := "" - nsExist := true - for nsExist { - // Generate unique namespace based on name and random number - src := rand.NewSource(time.Now().UnixNano()) - r1 := rand.New(src) - ns = fmt.Sprintf("%s-%s", app.Name, strconv.Itoa(r1.Intn(10000))) - - nsExist, err = h.usecase.IsAppServeAppNamespaceExist(app.TargetClusterId, ns) - if err != nil { - ErrorJSON(w, r, httpErrors.NewInternalServerError(err, "", "")) - return - } - } - - log.Infof("Using namespace: %s", ns) - app.Namespace = ns + // Create namespace if it's not given by user + if len(strings.TrimSpace(app.Namespace)) == 0 { + // Check if the new namespace is already used in the target cluster + ns := "" + nsExist := true + for nsExist { + // Generate unique namespace based on name and random number + src := rand.NewSource(time.Now().UnixNano()) + r1 := rand.New(src) + ns = fmt.Sprintf("%s-%s", app.Name, strconv.Itoa(r1.Intn(10000))) + + nsExist, err = h.usecase.IsAppServeAppNamespaceExist(app.TargetClusterId, ns) + if err != nil { + ErrorJSON(w, r, httpErrors.NewInternalServerError(err, "", "")) + return + } + } + + log.Infof("Created new namespace: %s", ns) + app.Namespace = ns + } else { + log.Infof("Using existing namespace: %s", app.Namespace) + } // Validate port param for springboot app if app.AppType == "springboot" {