Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20231107 develop to release #198

Merged
merged 10 commits into from
Nov 8, 2023
41 changes: 23 additions & 18 deletions internal/delivery/http/app-serve-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api-client/api-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading