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

app-serving: add validation & etc #54

Merged
merged 3 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions internal/delivery/http/app-serve-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ var (
"ROLLBACKING": "ROLLBACKING",
"ROLLBACK_SUCCESS": "DONE",
"ROLLBACK_FAILED": "FAILED",
"DELETING": "DELETING",
"DELETE_FAILED": "FAILED",
}
StatusName = map[string]string{
"BUILDING": "BUILD",
Expand Down Expand Up @@ -74,6 +76,8 @@ var (
"ROLLBACKING": "ROLLBACK",
"ROLLBACK_SUCCESS": "ROLLBACK",
"ROLLBACK_FAILED": "ROLLBACK",
"DELETING": "DELETE",
"DELETE_FAILED": "DELETE",
}
StatusStages = map[string][]string{
"PREPARING": {},
Expand Down Expand Up @@ -104,6 +108,8 @@ var (
"ROLLBACKING": {"ROLLBACKING"},
"ROLLBACK_SUCCESS": {"ROLLBACK_SUCCESS"},
"ROLLBACK_FAILED": {"ROLLBACK_FAILED"},
"DELETING": {"DELETING"},
"DELETE_FAILED": {"DELETE_FAILED"},
}
)

Expand Down Expand Up @@ -283,14 +289,18 @@ func (h *AppServeAppHandler) GetAppServeApp(w http.ResponseWriter, r *http.Reque
return
}

newTask := make([]domain.AppServeAppTask, 0)
for _, t := range app.AppServeAppTasks {
if strings.Contains(t.Status, "SUCCESS") {
t.AvailableRollback = true
// For very first task, rollback should be disabled.
if len(app.AppServeAppTasks) > 1 {
newTasks := make([]domain.AppServeAppTask, 0)
for _, t := range app.AppServeAppTasks {
if strings.Contains(t.Status, "SUCCESS") && t.Status != "BLUEGREEN_ABORT_SUCCESS" &&
t.Status != "ROLLBACK_SUCCESS" {
t.AvailableRollback = true
}
newTasks = append(newTasks, t)
}
newTask = append(newTask, t)
app.AppServeAppTasks = newTasks
}
app.AppServeAppTasks = newTask

var out domain.GetAppServeAppResponse
out.AppServeApp = *app
Expand Down
26 changes: 17 additions & 9 deletions internal/usecase/app-serve-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ func (u *AppServeAppUsecase) DeleteAppServeApp(appId string) (res string, err er
}

if app == nil {
return "", httpErrors.NewNoContentError(fmt.Errorf("the appId don't exists"), "", "")
return "", httpErrors.NewNoContentError(fmt.Errorf("the appId doesn't exist"), "", "")
}
// Validate app status
if app.Status == "WAIT_FOR_PROMOTE" || app.Status == "BLUEGREEN_FAILED" {
return "", fmt.Errorf("the app is in blue-green related state. Promote or abort first before deleting")
// TODO: Add common helper function for this kind of status validation
if app.Status == "BUILDING" || app.Status == "DEPLOYING" || app.Status == "BLUEGREEN_DEPLOYING" ||
app.Status == "BLUEGREEN_PROMOTING" || app.Status == "BLUEGREEN_ABORTING" {
return "작업 진행 중에는 앱을 삭제할 수 없습니다", fmt.Errorf("Can't delete app while the task is in progress.")
}

/********************
Expand Down Expand Up @@ -284,6 +286,17 @@ func (u *AppServeAppUsecase) UpdateAppServeApp(app *domain.AppServeApp, appTask
return "", errors.New("invalid parameters. appTask is nil")
}

app_, err := u.repo.GetAppServeAppById(app.ID)
if err != nil {
return "", fmt.Errorf("error while getting ASA Info from DB. Err: %s", err)
}

// Block update if the app's current status is one of those.
if app_.Status == "BLUEGREEN_WAIT" || app_.Status == "BLUEGREEN_PROMOTING" || app_.Status == "BLUEGREEN_ABORTING" ||
app_.Status == "CANARY_WAIT" || app_.Status == "CANARY_PROMOTING" || app_.Status == "CANARY_ABORTING" {
return "승인대기 또는 프로모트 작업 중에는 업그레이드를 수행할 수 없습니다", fmt.Errorf("Update not possible. The app is waiting for promote or in the middle of promote process.")
}

log.Info("Starting normal update process..")

// TODO: for more strict validation, check if immutable fields are provided by user
Expand All @@ -295,11 +308,6 @@ func (u *AppServeAppUsecase) UpdateAppServeApp(app *domain.AppServeApp, appTask
"\n\t- rolling-update\n\t- blue-green\n\t- canary")
}

//app, err := u.repo.GetAppServeAppById(appTask.AppServeAppId)
//if err != nil {
// return "", fmt.Errorf("error while getting ASA Info from DB. Error: %v", err)
//}

if app.Type != "deploy" {
// Construct imageUrl
imageUrl := viper.GetString("image-registry-url") + "/" + app.Name + "-" + app.TargetClusterId + ":" + appTask.Version
Expand Down Expand Up @@ -381,7 +389,7 @@ func (u *AppServeAppUsecase) PromoteAppServeApp(appId string) (ret string, err e
}

if app.Status != "BLUEGREEN_WAIT" && app.Status != "BLUEGREEN_PROMOTE_FAILED" {
return "", fmt.Errorf("the app is not in 'WAIT_FOR_PROMOTE' state. Exiting")
return "", fmt.Errorf("The app is not in blue-green related state. Exiting..")
}

// Get the latest task ID so that the task status can be modified inside workflow once the promotion is done.
Expand Down