From 611430aab217feb12496a63acfe61c64c3099dfb Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 1 Mar 2023 12:16:17 +0100 Subject: [PATCH 1/8] Set chaos version label for each deployed or upgraded app --- cli/app/rollback.go | 1 + cli/app/upgrade.go | 1 + cli/internal/deploy.go | 1 + pkg/config/app.go | 11 +++++++++++ 4 files changed, 14 insertions(+) diff --git a/cli/app/rollback.go b/cli/app/rollback.go index a13acbc8..c99f3ebe 100644 --- a/cli/app/rollback.go +++ b/cli/app/rollback.go @@ -183,6 +183,7 @@ recipes. config.ExposeAllEnv(stackName, compose, app.Env) config.SetRecipeLabel(compose, stackName, app.Recipe) config.SetChaosLabel(compose, stackName, internal.Chaos) + config.SetChaosVersionLabel(compose, app.StackName(), chosenDowngrade) config.SetUpdateLabel(compose, stackName, app.Env) if !internal.Force { diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index 2784d9f4..9780fa91 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -194,6 +194,7 @@ recipes. config.ExposeAllEnv(stackName, compose, app.Env) config.SetRecipeLabel(compose, stackName, app.Recipe) config.SetChaosLabel(compose, stackName, internal.Chaos) + config.SetChaosVersionLabel(compose, app.StackName(), chosenUpgrade) config.SetUpdateLabel(compose, stackName, app.Env) if err := internal.NewVersionOverview(app, deployedVersion, chosenUpgrade, releaseNotes); err != nil { diff --git a/cli/internal/deploy.go b/cli/internal/deploy.go index da4b26cb..44775d3d 100644 --- a/cli/internal/deploy.go +++ b/cli/internal/deploy.go @@ -139,6 +139,7 @@ func DeployAction(c *cli.Context) error { config.ExposeAllEnv(app.StackName(), compose, app.Env) config.SetRecipeLabel(compose, app.StackName(), app.Recipe) config.SetChaosLabel(compose, app.StackName(), Chaos) + config.SetChaosVersionLabel(compose, app.StackName(), version) config.SetUpdateLabel(compose, app.StackName(), app.Env) if err := DeployOverview(app, version, "continue with deployment?"); err != nil { diff --git a/pkg/config/app.go b/pkg/config/app.go index 6631503d..f7c528f5 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -499,6 +499,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 // auto update process for this app. The default if this variable is not set is to disable // the auto update process. -- 2.47.2 From 3753357ef8acb6cef01a5840946139f9fa28714c Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 1 Mar 2023 12:17:23 +0100 Subject: [PATCH 2/8] feat(list): show chaos status and chaos version --- cli/app/list.go | 30 +++++++++++++++++++++--------- pkg/config/app.go | 13 ++++++++++++- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/cli/app/list.go b/cli/app/list.go index 6f0eec22..9290c543 100644 --- a/cli/app/list.go +++ b/cli/app/list.go @@ -39,13 +39,15 @@ var listAppServerFlag = &cli.StringFlag{ } type appStatus struct { - Server string `json:"server"` - Recipe string `json:"recipe"` - AppName string `json:"appName"` - Domain string `json:"domain"` - Status string `json:"status"` - Version string `json:"version"` - Upgrade string `json:"upgrade"` + Server string `json:"server"` + Recipe string `json:"recipe"` + AppName string `json:"appName"` + Domain string `json:"domain"` + Status string `json:"status"` + Chaos string `json:"chaos"` + ChaosVersion string `json:"chaosVersion"` + Version string `json:"version"` + Upgrade string `json:"upgrade"` } type serverStatus struct { @@ -138,12 +140,20 @@ can take some time. if status { status := "unknown" version := "unknown" + chaos := "unknown" + chaosVersion := "unknown" if statusMeta, ok := statuses[app.StackName()]; ok { if currentVersion, exists := statusMeta["version"]; exists { if currentVersion != "" { version = currentVersion } } + if chaosDeploy, exists := statusMeta["chaos"]; exists { + chaos = chaosDeploy + } + if chaosDeployVersion, exists := statusMeta["chaosVersion"]; exists { + chaosVersion = chaosDeployVersion + } if statusMeta["status"] != "" { status = statusMeta["status"] } @@ -153,6 +163,8 @@ can take some time. } appStats.Status = status + appStats.Chaos = chaos + appStats.ChaosVersion = chaosVersion appStats.Version = version var newUpdates []string @@ -223,7 +235,7 @@ can take some time. tableCol := []string{"recipe", "domain"} if status { - tableCol = append(tableCol, []string{"status", "version", "upgrade"}...) + tableCol = append(tableCol, []string{"status", "chaos", "chaos version", "version", "upgrade"}...) } table := formatter.CreateTable(tableCol) @@ -231,7 +243,7 @@ can take some time. for _, appStat := range serverStat.Apps { tableRow := []string{appStat.Recipe, appStat.Domain} if status { - tableRow = append(tableRow, []string{appStat.Status, appStat.Version, appStat.Upgrade}...) + tableRow = append(tableRow, []string{appStat.Status, appStat.Chaos, appStat.ChaosVersion, appStat.Version, appStat.Upgrade}...) } table.Append(tableRow) } diff --git a/pkg/config/app.go b/pkg/config/app.go index f7c528f5..816bfe7f 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -403,7 +403,18 @@ func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]str 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.version", name) if version, ok := service.Spec.Labels[labelKey]; ok { result["version"] = version } else { -- 2.47.2 From d120299929c953908d1b8eb2b86328f8e93aa556 Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 1 Mar 2023 12:26:28 +0100 Subject: [PATCH 3/8] feat(list): show autoupdate state --- cli/app/list.go | 10 ++++++++-- pkg/config/app.go | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cli/app/list.go b/cli/app/list.go index 9290c543..55c89fbb 100644 --- a/cli/app/list.go +++ b/cli/app/list.go @@ -46,6 +46,7 @@ type appStatus struct { Status string `json:"status"` Chaos string `json:"chaos"` ChaosVersion string `json:"chaosVersion"` + AutoUpdate string `json:"autoUpdate"` Version string `json:"version"` Upgrade string `json:"upgrade"` } @@ -142,6 +143,7 @@ can take some time. version := "unknown" chaos := "unknown" chaosVersion := "unknown" + autoUpdate := "unknown" if statusMeta, ok := statuses[app.StackName()]; ok { if currentVersion, exists := statusMeta["version"]; exists { if currentVersion != "" { @@ -154,6 +156,9 @@ can take some time. if chaosDeployVersion, exists := statusMeta["chaosVersion"]; exists { chaosVersion = chaosDeployVersion } + if autoUpdateState, exists := statusMeta["autoUpdate"]; exists { + autoUpdate = autoUpdateState + } if statusMeta["status"] != "" { status = statusMeta["status"] } @@ -166,6 +171,7 @@ can take some time. appStats.Chaos = chaos appStats.ChaosVersion = chaosVersion appStats.Version = version + appStats.AutoUpdate = autoUpdate var newUpdates []string if version != "unknown" { @@ -235,7 +241,7 @@ can take some time. tableCol := []string{"recipe", "domain"} if status { - tableCol = append(tableCol, []string{"status", "chaos", "chaos version", "version", "upgrade"}...) + tableCol = append(tableCol, []string{"status", "chaos", "chaos version", "version", "upgrade", "autoupdate"}...) } table := formatter.CreateTable(tableCol) @@ -243,7 +249,7 @@ can take some time. for _, appStat := range serverStat.Apps { tableRow := []string{appStat.Recipe, appStat.Domain} if status { - tableRow = append(tableRow, []string{appStat.Status, appStat.Chaos, appStat.ChaosVersion, appStat.Version, appStat.Upgrade}...) + tableRow = append(tableRow, []string{appStat.Status, appStat.Chaos, appStat.ChaosVersion, appStat.Version, appStat.Upgrade, appStat.AutoUpdate}...) } table.Append(tableRow) } diff --git a/pkg/config/app.go b/pkg/config/app.go index 816bfe7f..853d60a2 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -414,6 +414,13 @@ func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]str 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 { result["version"] = version -- 2.47.2 From 5428ebf43bddc4a3726008ce786a3748fb726407 Mon Sep 17 00:00:00 2001 From: Moritz Date: Tue, 7 Mar 2023 12:23:40 +0100 Subject: [PATCH 4/8] review: avoid stackName recalculation --- cli/app/rollback.go | 4 ++-- cli/app/upgrade.go | 4 ++-- cli/internal/deploy.go | 17 +++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cli/app/rollback.go b/cli/app/rollback.go index c99f3ebe..5b986cbf 100644 --- a/cli/app/rollback.go +++ b/cli/app/rollback.go @@ -183,7 +183,7 @@ recipes. config.ExposeAllEnv(stackName, compose, app.Env) config.SetRecipeLabel(compose, stackName, app.Recipe) config.SetChaosLabel(compose, stackName, internal.Chaos) - config.SetChaosVersionLabel(compose, app.StackName(), chosenDowngrade) + config.SetChaosVersionLabel(compose, stackName, chosenDowngrade) config.SetUpdateLabel(compose, stackName, app.Env) if !internal.Force { @@ -192,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) } diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index 9780fa91..df903d40 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -194,14 +194,14 @@ recipes. config.ExposeAllEnv(stackName, compose, app.Env) config.SetRecipeLabel(compose, stackName, app.Recipe) config.SetChaosLabel(compose, stackName, internal.Chaos) - config.SetChaosVersionLabel(compose, app.StackName(), chosenUpgrade) + config.SetChaosVersionLabel(compose, stackName, chosenUpgrade) config.SetUpdateLabel(compose, stackName, app.Env) if err := internal.NewVersionOverview(app, deployedVersion, chosenUpgrade, releaseNotes); err != nil { 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) } diff --git a/cli/internal/deploy.go b/cli/internal/deploy.go index 44775d3d..34794606 100644 --- a/cli/internal/deploy.go +++ b/cli/internal/deploy.go @@ -25,6 +25,7 @@ import ( // DeployAction is the main command-line action for this package func DeployAction(c *cli.Context) error { app := ValidateApp(c) + stackName := app.StackName() conf := runtime.New() cl, err := client.New(app.Server) @@ -47,9 +48,9 @@ func DeployAction(c *cli.Context) error { 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 { logrus.Fatal(err) } @@ -128,7 +129,7 @@ func DeployAction(c *cli.Context) error { } deployOpts := stack.Deploy{ Composefiles: composeFiles, - Namespace: app.StackName(), + Namespace: stackName, Prune: false, ResolveImage: stack.ResolveImageAlways, } @@ -136,11 +137,11 @@ func DeployAction(c *cli.Context) error { if err != nil { logrus.Fatal(err) } - config.ExposeAllEnv(app.StackName(), compose, app.Env) - config.SetRecipeLabel(compose, app.StackName(), app.Recipe) - config.SetChaosLabel(compose, app.StackName(), Chaos) - config.SetChaosVersionLabel(compose, app.StackName(), version) - config.SetUpdateLabel(compose, app.StackName(), app.Env) + config.ExposeAllEnv(stackName, compose, app.Env) + config.SetRecipeLabel(compose, stackName, app.Recipe) + config.SetChaosLabel(compose, stackName, Chaos) + config.SetChaosVersionLabel(compose, stackName, version) + config.SetUpdateLabel(compose, stackName, app.Env) if err := DeployOverview(app, version, "continue with deployment?"); err != nil { logrus.Fatal(err) -- 2.47.2 From e9879e2226e175b5d096d5cb45903744afcfdd6e Mon Sep 17 00:00:00 2001 From: Moritz Date: Tue, 7 Mar 2023 12:27:02 +0100 Subject: [PATCH 5/8] review: label convention chaos_version -> chaos-version --- pkg/config/app.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/config/app.go b/pkg/config/app.go index 853d60a2..4921d8ee 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -409,7 +409,7 @@ func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]str result["chaos"] = chaos } - labelKey = fmt.Sprintf("coop-cloud.%s.chaos_version", name) + labelKey = fmt.Sprintf("coop-cloud.%s.chaos-version", name) if chaosVersion, ok := service.Spec.Labels[labelKey]; ok { result["chaosVersion"] = chaosVersion } @@ -517,12 +517,12 @@ 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 +// 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) + 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 } } -- 2.47.2 From cb33edaac31d2ad8b9919e8d4f8531ea1be06361 Mon Sep 17 00:00:00 2001 From: Moritz Date: Tue, 7 Mar 2023 12:31:44 +0100 Subject: [PATCH 6/8] review: change label autoupdate -> auto-update --- cli/updater/updater.go | 2 +- pkg/config/app.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/updater/updater.go b/cli/updater/updater.go index ef297cde..7a48273e 100644 --- a/cli/updater/updater.go +++ b/cli/updater/updater.go @@ -403,7 +403,7 @@ func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string, conf *run return nil } - updatesEnabled, err := getBoolLabel(cl, stackName, "autoupdate") + updatesEnabled, err := getBoolLabel(cl, stackName, "auto-update") if err != nil { return err } diff --git a/pkg/config/app.go b/pkg/config/app.go index 4921d8ee..8b8ba218 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -414,7 +414,7 @@ func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]str result["chaosVersion"] = chaosVersion } - labelKey = fmt.Sprintf("coop-cloud.%s.autoupdate", name) + labelKey = fmt.Sprintf("coop-cloud.%s.auto-update", name) if autoUpdate, ok := service.Spec.Labels[labelKey]; ok { result["autoUpdate"] = autoUpdate } else { @@ -538,8 +538,8 @@ func SetUpdateLabel(compose *composetypes.Config, stackName string, appEnv AppEn if !exists { enable_auto_update = "false" } - logrus.Debugf("set label 'coop-cloud.%s.autoupdate' to %s for %s", stackName, enable_auto_update, stackName) - labelKey := fmt.Sprintf("coop-cloud.%s.autoupdate", stackName) + logrus.Debugf("set label 'coop-cloud.%s.auto-update' to %s for %s", stackName, enable_auto_update, stackName) + labelKey := fmt.Sprintf("coop-cloud.%s.auto-update", stackName) service.Deploy.Labels[labelKey] = enable_auto_update } } -- 2.47.2 From d5979436c189ebd171b6a51ecaa3e446b70cbb80 Mon Sep 17 00:00:00 2001 From: Moritz Date: Tue, 7 Mar 2023 12:49:59 +0100 Subject: [PATCH 7/8] review: merge chaos + chaos_version column --- cli/app/list.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/app/list.go b/cli/app/list.go index 55c89fbb..e3abe77b 100644 --- a/cli/app/list.go +++ b/cli/app/list.go @@ -241,7 +241,7 @@ can take some time. tableCol := []string{"recipe", "domain"} if status { - tableCol = append(tableCol, []string{"status", "chaos", "chaos version", "version", "upgrade", "autoupdate"}...) + tableCol = append(tableCol, []string{"status", "chaos", "version", "upgrade", "autoupdate"}...) } table := formatter.CreateTable(tableCol) @@ -249,7 +249,13 @@ can take some time. for _, appStat := range serverStat.Apps { tableRow := []string{appStat.Recipe, appStat.Domain} if status { - tableRow = append(tableRow, []string{appStat.Status, appStat.Chaos, appStat.ChaosVersion, appStat.Version, appStat.Upgrade, appStat.AutoUpdate}...) + 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) } -- 2.47.2 From edff63b446535bc027f76837210287782fcb4b22 Mon Sep 17 00:00:00 2001 From: Moritz Date: Tue, 7 Mar 2023 13:10:57 +0100 Subject: [PATCH 8/8] Revert "review: change label autoupdate -> auto-update" This reverts commit 74baa76f5ee5e5dd7b71b1f14be97cc40dfc611b. --- cli/updater/updater.go | 2 +- pkg/config/app.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/updater/updater.go b/cli/updater/updater.go index 7a48273e..ef297cde 100644 --- a/cli/updater/updater.go +++ b/cli/updater/updater.go @@ -403,7 +403,7 @@ func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string, conf *run return nil } - updatesEnabled, err := getBoolLabel(cl, stackName, "auto-update") + updatesEnabled, err := getBoolLabel(cl, stackName, "autoupdate") if err != nil { return err } diff --git a/pkg/config/app.go b/pkg/config/app.go index 8b8ba218..4921d8ee 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -414,7 +414,7 @@ func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]str result["chaosVersion"] = chaosVersion } - labelKey = fmt.Sprintf("coop-cloud.%s.auto-update", name) + labelKey = fmt.Sprintf("coop-cloud.%s.autoupdate", name) if autoUpdate, ok := service.Spec.Labels[labelKey]; ok { result["autoUpdate"] = autoUpdate } else { @@ -538,8 +538,8 @@ func SetUpdateLabel(compose *composetypes.Config, stackName string, appEnv AppEn if !exists { enable_auto_update = "false" } - logrus.Debugf("set label 'coop-cloud.%s.auto-update' to %s for %s", stackName, enable_auto_update, stackName) - labelKey := fmt.Sprintf("coop-cloud.%s.auto-update", stackName) + logrus.Debugf("set label 'coop-cloud.%s.autoupdate' to %s for %s", stackName, enable_auto_update, stackName) + labelKey := fmt.Sprintf("coop-cloud.%s.autoupdate", stackName) service.Deploy.Labels[labelKey] = enable_auto_update } } -- 2.47.2