Skip to content

Commit

Permalink
Merge pull request #196 from openinfradev/tks-issues-932
Browse files Browse the repository at this point in the history
app-serving: create ns only if it's not given by user
  • Loading branch information
robertchoi80 authored Nov 6, 2023
2 parents 5b0bac6 + bbde647 commit 98abc83
Showing 1 changed file with 23 additions and 18 deletions.
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

0 comments on commit 98abc83

Please sign in to comment.