Merge pull request 'app ls --status shows more detailles about the deployment state' (!280) from detailed_app_list into main
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: coop-cloud/abra#280
This commit is contained in:
moritz 2023-03-07 12:31:38 +00:00
commit 0ce8b3a5c2
5 changed files with 76 additions and 19 deletions

View File

@ -39,13 +39,16 @@ var listAppServerFlag = &cli.StringFlag{
} }
type appStatus struct { type appStatus struct {
Server string `json:"server"` Server string `json:"server"`
Recipe string `json:"recipe"` Recipe string `json:"recipe"`
AppName string `json:"appName"` AppName string `json:"appName"`
Domain string `json:"domain"` Domain string `json:"domain"`
Status string `json:"status"` Status string `json:"status"`
Version string `json:"version"` Chaos string `json:"chaos"`
Upgrade string `json:"upgrade"` ChaosVersion string `json:"chaosVersion"`
AutoUpdate string `json:"autoUpdate"`
Version string `json:"version"`
Upgrade string `json:"upgrade"`
} }
type serverStatus struct { type serverStatus struct {
@ -138,12 +141,24 @@ can take some time.
if status { if status {
status := "unknown" status := "unknown"
version := "unknown" version := "unknown"
chaos := "unknown"
chaosVersion := "unknown"
autoUpdate := "unknown"
if statusMeta, ok := statuses[app.StackName()]; ok { if statusMeta, ok := statuses[app.StackName()]; ok {
if currentVersion, exists := statusMeta["version"]; exists { if currentVersion, exists := statusMeta["version"]; exists {
if currentVersion != "" { if currentVersion != "" {
version = currentVersion version = currentVersion
} }
} }
if chaosDeploy, exists := statusMeta["chaos"]; exists {
chaos = chaosDeploy
}
if chaosDeployVersion, exists := statusMeta["chaosVersion"]; exists {
chaosVersion = chaosDeployVersion
}
if autoUpdateState, exists := statusMeta["autoUpdate"]; exists {
autoUpdate = autoUpdateState
}
if statusMeta["status"] != "" { if statusMeta["status"] != "" {
status = statusMeta["status"] status = statusMeta["status"]
} }
@ -153,7 +168,10 @@ can take some time.
} }
appStats.Status = status appStats.Status = status
appStats.Chaos = chaos
appStats.ChaosVersion = chaosVersion
appStats.Version = version appStats.Version = version
appStats.AutoUpdate = autoUpdate
var newUpdates []string var newUpdates []string
if version != "unknown" { if version != "unknown" {
@ -223,7 +241,7 @@ can take some time.
tableCol := []string{"recipe", "domain"} tableCol := []string{"recipe", "domain"}
if status { if status {
tableCol = append(tableCol, []string{"status", "version", "upgrade"}...) tableCol = append(tableCol, []string{"status", "chaos", "version", "upgrade", "autoupdate"}...)
} }
table := formatter.CreateTable(tableCol) table := formatter.CreateTable(tableCol)
@ -231,7 +249,13 @@ can take some time.
for _, appStat := range serverStat.Apps { for _, appStat := range serverStat.Apps {
tableRow := []string{appStat.Recipe, appStat.Domain} tableRow := []string{appStat.Recipe, appStat.Domain}
if status { if status {
tableRow = append(tableRow, []string{appStat.Status, appStat.Version, appStat.Upgrade}...) chaosStatus := "unknown"
if appStat.ChaosVersion != "unknown" {
chaosStatus = appStat.Chaos + appStat.ChaosVersion
} else {
chaosStatus = appStat.Chaos
}
tableRow = append(tableRow, []string{appStat.Status, chaosStatus, appStat.Version, appStat.Upgrade, appStat.AutoUpdate}...)
} }
table.Append(tableRow) table.Append(tableRow)
} }

View File

@ -183,6 +183,7 @@ recipes.
config.ExposeAllEnv(stackName, compose, app.Env) config.ExposeAllEnv(stackName, compose, app.Env)
config.SetRecipeLabel(compose, stackName, app.Recipe) config.SetRecipeLabel(compose, stackName, app.Recipe)
config.SetChaosLabel(compose, stackName, internal.Chaos) config.SetChaosLabel(compose, stackName, internal.Chaos)
config.SetChaosVersionLabel(compose, stackName, chosenDowngrade)
config.SetUpdateLabel(compose, stackName, app.Env) config.SetUpdateLabel(compose, stackName, app.Env)
if !internal.Force { if !internal.Force {
@ -191,7 +192,7 @@ recipes.
} }
} }
if err := stack.RunDeploy(cl, deployOpts, compose, app.StackName(), internal.DontWaitConverge); err != nil { if err := stack.RunDeploy(cl, deployOpts, compose, stackName, internal.DontWaitConverge); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }

View File

@ -194,13 +194,14 @@ recipes.
config.ExposeAllEnv(stackName, compose, app.Env) config.ExposeAllEnv(stackName, compose, app.Env)
config.SetRecipeLabel(compose, stackName, app.Recipe) config.SetRecipeLabel(compose, stackName, app.Recipe)
config.SetChaosLabel(compose, stackName, internal.Chaos) config.SetChaosLabel(compose, stackName, internal.Chaos)
config.SetChaosVersionLabel(compose, stackName, chosenUpgrade)
config.SetUpdateLabel(compose, stackName, app.Env) config.SetUpdateLabel(compose, stackName, app.Env)
if err := internal.NewVersionOverview(app, deployedVersion, chosenUpgrade, releaseNotes); err != nil { if err := internal.NewVersionOverview(app, deployedVersion, chosenUpgrade, releaseNotes); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
if err := stack.RunDeploy(cl, deployOpts, compose, app.StackName(), internal.DontWaitConverge); err != nil { if err := stack.RunDeploy(cl, deployOpts, compose, stackName, internal.DontWaitConverge); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }

View File

@ -25,6 +25,7 @@ import (
// DeployAction is the main command-line action for this package // DeployAction is the main command-line action for this package
func DeployAction(c *cli.Context) error { func DeployAction(c *cli.Context) error {
app := ValidateApp(c) app := ValidateApp(c)
stackName := app.StackName()
conf := runtime.New() conf := runtime.New()
cl, err := client.New(app.Server) cl, err := client.New(app.Server)
@ -47,9 +48,9 @@ func DeployAction(c *cli.Context) error {
logrus.Fatal(err) logrus.Fatal(err)
} }
logrus.Debugf("checking whether %s is already deployed", app.StackName()) logrus.Debugf("checking whether %s is already deployed", stackName)
isDeployed, deployedVersion, err := stack.IsDeployed(context.Background(), cl, app.StackName()) isDeployed, deployedVersion, err := stack.IsDeployed(context.Background(), cl, stackName)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
@ -128,7 +129,7 @@ func DeployAction(c *cli.Context) error {
} }
deployOpts := stack.Deploy{ deployOpts := stack.Deploy{
Composefiles: composeFiles, Composefiles: composeFiles,
Namespace: app.StackName(), Namespace: stackName,
Prune: false, Prune: false,
ResolveImage: stack.ResolveImageAlways, ResolveImage: stack.ResolveImageAlways,
} }
@ -136,10 +137,11 @@ func DeployAction(c *cli.Context) error {
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
config.ExposeAllEnv(app.StackName(), compose, app.Env) config.ExposeAllEnv(stackName, compose, app.Env)
config.SetRecipeLabel(compose, app.StackName(), app.Recipe) config.SetRecipeLabel(compose, stackName, app.Recipe)
config.SetChaosLabel(compose, app.StackName(), Chaos) config.SetChaosLabel(compose, stackName, Chaos)
config.SetUpdateLabel(compose, app.StackName(), app.Env) config.SetChaosVersionLabel(compose, stackName, version)
config.SetUpdateLabel(compose, stackName, app.Env)
if err := DeployOverview(app, version, "continue with deployment?"); err != nil { if err := DeployOverview(app, version, "continue with deployment?"); err != nil {
logrus.Fatal(err) logrus.Fatal(err)

View File

@ -403,7 +403,25 @@ func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]str
result["status"] = "deployed" result["status"] = "deployed"
} }
labelKey := fmt.Sprintf("coop-cloud.%s.version", name) labelKey := fmt.Sprintf("coop-cloud.%s.chaos", name)
chaos, ok := service.Spec.Labels[labelKey]
if ok {
result["chaos"] = chaos
}
labelKey = fmt.Sprintf("coop-cloud.%s.chaos-version", name)
if chaosVersion, ok := service.Spec.Labels[labelKey]; ok {
result["chaosVersion"] = chaosVersion
}
labelKey = fmt.Sprintf("coop-cloud.%s.autoupdate", name)
if autoUpdate, ok := service.Spec.Labels[labelKey]; ok {
result["autoUpdate"] = autoUpdate
} else {
result["autoUpdate"] = "false"
}
labelKey = fmt.Sprintf("coop-cloud.%s.version", name)
if version, ok := service.Spec.Labels[labelKey]; ok { if version, ok := service.Spec.Labels[labelKey]; ok {
result["version"] = version result["version"] = version
} else { } else {
@ -499,6 +517,17 @@ func SetChaosLabel(compose *composetypes.Config, stackName string, chaos bool) {
} }
} }
// SetChaosVersionLabel adds the label 'coop-cloud.${STACK_NAME}.chaos-version=$(GIT_COMMIT)' to the app container
func SetChaosVersionLabel(compose *composetypes.Config, stackName string, chaosVersion string) {
for _, service := range compose.Services {
if service.Name == "app" {
logrus.Debugf("set label 'coop-cloud.%s.chaos-version' to %v for %s", stackName, chaosVersion, stackName)
labelKey := fmt.Sprintf("coop-cloud.%s.chaos-version", stackName)
service.Deploy.Labels[labelKey] = chaosVersion
}
}
}
// SetUpdateLabel adds env ENABLE_AUTO_UPDATE as label to enable/disable the // SetUpdateLabel adds env ENABLE_AUTO_UPDATE as label to enable/disable the
// auto update process for this app. The default if this variable is not set is to disable // auto update process for this app. The default if this variable is not set is to disable
// the auto update process. // the auto update process.