From 961248031a4e8f792e0af9f5eee46d44370999fa Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Tue, 7 May 2024 10:54:37 +0900 Subject: [PATCH 1/2] app-serving: remove omitempty tag --- internal/model/app-serve-app.go | 62 ++++++++++++++++----------------- pkg/domain/app-serve-app.go | 62 ++++++++++++++++----------------- 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/internal/model/app-serve-app.go b/internal/model/app-serve-app.go index 0a5e9f77..4d86c603 100644 --- a/internal/model/app-serve-app.go +++ b/internal/model/app-serve-app.go @@ -7,43 +7,43 @@ import ( ) type AppServeApp struct { - ID string `gorm:"primarykey" json:"id,omitempty"` - Name string `gorm:"index" json:"name,omitempty"` // application name - Namespace string `json:"namespace,omitempty"` // application namespace - OrganizationId string `json:"organizationId,omitempty"` // contractId is a contract ID which this app belongs to - ProjectId string `json:"projectId,omitempty"` // project ID which this app belongs to - Type string `json:"type,omitempty"` // type (build/deploy/all) - AppType string `json:"appType,omitempty"` // appType (spring/springboot) - EndpointUrl string `json:"endpointUrl,omitempty"` // endpoint URL of deployed app - PreviewEndpointUrl string `json:"previewEndpointUrl,omitempty"` // preview svc endpoint URL in B/G deployment - TargetClusterId string `json:"targetClusterId,omitempty"` // target cluster to which the app is deployed - TargetClusterName string `gorm:"-:all" json:"targetClusterName,omitempty"` // target cluster name - Status string `gorm:"index" json:"status,omitempty"` // status is status of deployed app - GrafanaUrl string `json:"grafanaUrl,omitempty"` // grafana dashboard URL for deployed app - Description string `json:"description,omitempty"` // description for application + ID string `gorm:"primarykey" json:"id"` + Name string `gorm:"index" json:"name"` // application name + Namespace string `json:"namespace"` // application namespace + OrganizationId string `json:"organizationId"` // contractId is a contract ID which this app belongs to + ProjectId string `json:"projectId"` // project ID which this app belongs to + Type string `json:"type"` // type (build/deploy/all) + AppType string `json:"appType"` // appType (spring/springboot) + EndpointUrl string `json:"endpointUrl"` // endpoint URL of deployed app + PreviewEndpointUrl string `json:"previewEndpointUrl"` // preview svc endpoint URL in B/G deployment + TargetClusterId string `json:"targetClusterId"` // target cluster to which the app is deployed + TargetClusterName string `gorm:"-:all" json:"targetClusterName"` // target cluster name + Status string `gorm:"index" json:"status"` // status is status of deployed app + GrafanaUrl string `json:"grafanaUrl"` // grafana dashboard URL for deployed app + Description string `json:"description"` // description for application CreatedAt time.Time `gorm:"autoCreateTime:false" json:"createdAt" ` UpdatedAt *time.Time `gorm:"autoUpdateTime:false" json:"updatedAt"` DeletedAt *time.Time `json:"deletedAt"` } type AppServeAppTask struct { - ID string `gorm:"primarykey" json:"id,omitempty"` - AppServeAppId string `gorm:"not null" json:"appServeAppId,omitempty"` // ID for appServeApp that this task belongs to - Version string `json:"version,omitempty"` // application version - Status string `json:"status,omitempty"` // status is app status - Output string `json:"output,omitempty"` // output for task result - ArtifactUrl string `json:"artifactUrl,omitempty"` // URL of java app artifact (Eg, Jar) - ImageUrl string `json:"imageUrl,omitempty"` // URL of built image for app - ExecutablePath string `json:"executablePath,omitempty"` // Executable path of app image - Profile string `json:"profile,omitempty"` // java app profile - AppConfig string `json:"appConfig,omitempty"` // java app config - AppSecret string `json:"appSecret,omitempty"` // java app secret - ExtraEnv string `json:"extraEnv,omitempty"` // env variable list for java app - Port string `json:"port,omitempty"` // java app port - ResourceSpec string `json:"resourceSpec,omitempty"` // resource spec of app pod - HelmRevision int32 `gorm:"default:0" json:"helmRevision,omitempty"` // revision of deployed helm release - Strategy string `json:"strategy,omitempty"` // deployment strategy (eg, rolling-update) - RollbackVersion string `json:"rollbackVersion,omitempty"` // rollback target version + ID string `gorm:"primarykey" json:"id"` + AppServeAppId string `gorm:"not null" json:"appServeAppId"` // ID for appServeApp that this task belongs to + Version string `json:"version"` // application version + Status string `json:"status"` // status is app status + Output string `json:"output"` // output for task result + ArtifactUrl string `json:"artifactUrl"` // URL of java app artifact (Eg, Jar) + ImageUrl string `json:"imageUrl"` // URL of built image for app + ExecutablePath string `json:"executablePath"` // Executable path of app image + Profile string `json:"profile"` // java app profile + AppConfig string `json:"appConfig"` // java app config + AppSecret string `json:"appSecret"` // java app secret + ExtraEnv string `json:"extraEnv"` // env variable list for java app + Port string `json:"port"` // java app port + ResourceSpec string `json:"resourceSpec"` // resource spec of app pod + HelmRevision int32 `gorm:"default:0" json:"helmRevision"` // revision of deployed helm release + Strategy string `json:"strategy"` // deployment strategy (eg, rolling-update) + RollbackVersion string `json:"rollbackVersion"` // rollback target version PvEnabled bool `json:"pvEnabled"` PvStorageClass string `json:"pvStorageClass"` PvAccessMode string `json:"pvAccessMode"` diff --git a/pkg/domain/app-serve-app.go b/pkg/domain/app-serve-app.go index b12c192b..757b877a 100644 --- a/pkg/domain/app-serve-app.go +++ b/pkg/domain/app-serve-app.go @@ -3,43 +3,43 @@ package domain import "time" type AppServeAppResponse struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` // application name - Namespace string `json:"namespace,omitempty"` // application namespace - OrganizationId string `json:"organizationId,omitempty"` // contractId is a contract ID which this app belongs to - ProjectId string `json:"projectId,omitempty"` // project ID which this app belongs to - Type string `json:"type,omitempty"` // type (build/deploy/all) - AppType string `json:"appType,omitempty"` // appType (spring/springboot) - EndpointUrl string `json:"endpointUrl,omitempty"` // endpoint URL of deployed app - PreviewEndpointUrl string `json:"previewEndpointUrl,omitempty"` // preview svc endpoint URL in B/G deployment - TargetClusterId string `json:"targetClusterId,omitempty"` // target cluster to which the app is deployed - TargetClusterName string `json:"targetClusterName,omitempty"` // target cluster name - Status string `json:"status,omitempty"` // status is status of deployed app - GrafanaUrl string `json:"grafanaUrl,omitempty"` // grafana dashboard URL for deployed app - Description string `json:"description,omitempty"` // description for application + ID string `json:"id"` + Name string `json:"name"` // application name + Namespace string `json:"namespace"` // application namespace + OrganizationId string `json:"organizationId"` // contractId is a contract ID which this app belongs to + ProjectId string `json:"projectId"` // project ID which this app belongs to + Type string `json:"type"` // type (build/deploy/all) + AppType string `json:"appType"` // appType (spring/springboot) + EndpointUrl string `json:"endpointUrl"` // endpoint URL of deployed app + PreviewEndpointUrl string `json:"previewEndpointUrl"` // preview svc endpoint URL in B/G deployment + TargetClusterId string `json:"targetClusterId"` // target cluster to which the app is deployed + TargetClusterName string `json:"targetClusterName"` // target cluster name + Status string `json:"status"` // status is status of deployed app + GrafanaUrl string `json:"grafanaUrl"` // grafana dashboard URL for deployed app + Description string `json:"description"` // description for application CreatedAt time.Time `json:"createdAt" ` UpdatedAt *time.Time `json:"updatedAt"` DeletedAt *time.Time `json:"deletedAt"` } type AppServeAppTaskResponse struct { - ID string `json:"id,omitempty"` - AppServeAppId string `json:"appServeAppId,omitempty"` // ID for appServeApp that this task belongs to - Version string `json:"version,omitempty"` // application version - Status string `json:"status,omitempty"` // status is app status - Output string `json:"output,omitempty"` // output for task result - ArtifactUrl string `json:"artifactUrl,omitempty"` // URL of java app artifact (Eg, Jar) - ImageUrl string `json:"imageUrl,omitempty"` // URL of built image for app - ExecutablePath string `json:"executablePath,omitempty"` // Executable path of app image - Profile string `json:"profile,omitempty"` // java app profile - AppConfig string `json:"appConfig,omitempty"` // java app config - AppSecret string `json:"appSecret,omitempty"` // java app secret - ExtraEnv string `json:"extraEnv,omitempty"` // env variable list for java app - Port string `json:"port,omitempty"` // java app port - ResourceSpec string `json:"resourceSpec,omitempty"` // resource spec of app pod - HelmRevision int32 `json:"helmRevision,omitempty"` // revision of deployed helm release - Strategy string `json:"strategy,omitempty"` // deployment strategy (eg, rolling-update) - RollbackVersion string `json:"rollbackVersion,omitempty"` // rollback target version + ID string `json:"id"` + AppServeAppId string `json:"appServeAppId"` // ID for appServeApp that this task belongs to + Version string `json:"version"` // application version + Status string `json:"status"` // status is app status + Output string `json:"output"` // output for task result + ArtifactUrl string `json:"artifactUrl"` // URL of java app artifact (Eg, Jar) + ImageUrl string `json:"imageUrl"` // URL of built image for app + ExecutablePath string `json:"executablePath"` // Executable path of app image + Profile string `json:"profile"` // java app profile + AppConfig string `json:"appConfig"` // java app config + AppSecret string `json:"appSecret"` // java app secret + ExtraEnv string `json:"extraEnv"` // env variable list for java app + Port string `json:"port"` // java app port + ResourceSpec string `json:"resourceSpec"` // resource spec of app pod + HelmRevision int32 `json:"helmRevision"` // revision of deployed helm release + Strategy string `json:"strategy"` // deployment strategy (eg, rolling-update) + RollbackVersion string `json:"rollbackVersion"` // rollback target version PvEnabled bool `json:"pvEnabled"` PvStorageClass string `json:"pvStorageClass"` PvAccessMode string `json:"pvAccessMode"` From 8326bacdbbeebbbe3619c5a039653754c2cd0e61 Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Tue, 7 May 2024 11:44:01 +0900 Subject: [PATCH 2/2] bugfix: disable rollback of latest task --- internal/delivery/http/app-serve-app.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/delivery/http/app-serve-app.go b/internal/delivery/http/app-serve-app.go index 70a383ac..5a76487e 100644 --- a/internal/delivery/http/app-serve-app.go +++ b/internal/delivery/http/app-serve-app.go @@ -574,8 +574,16 @@ func (h *AppServeAppHandler) GetAppServeAppTaskDetail(w http.ResponseWriter, r * return } - // TODO: this should be false for latest task - if strings.Contains(task.Status, "SUCCESS") && task.Status != "ABORT_SUCCESS" && + // Workaround: Compare task ID with latest task ID + // Mark latest task with additional flag later + latestTask, err := h.usecase.GetAppServeAppLatestTask(r.Context(), appId) + if err != nil { + ErrorJSON(w, r, httpErrors.NewInternalServerError(err, "", "")) + return + } + if taskId == latestTask.ID { + task.AvailableRollback = false + } else if strings.Contains(task.Status, "SUCCESS") && task.Status != "ABORT_SUCCESS" && task.Status != "ROLLBACK_SUCCESS" { task.AvailableRollback = true }