From ebb86391af9ed64a3d4c9db10003eeef32eb6df4 Mon Sep 17 00:00:00 2001 From: moritz Date: Tue, 31 Jan 2023 15:06:35 +0000 Subject: [PATCH] add a label to signal that a deploy is a chaos deploy (!265) Resolves https://git.coopcloud.tech/coop-cloud/organising/issues/390 by adding the following label `coop-cloud.${STACK_NAME}.chaos=true` (according to the version label). This is required for the auto updater https://git.coopcloud.tech/coop-cloud/organising/issues/236#issuecomment-15390 Co-authored-by: Moritz Reviewed-on: https://git.coopcloud.tech/coop-cloud/abra/pulls/265 --- cli/app/rollback.go | 1 + cli/app/upgrade.go | 1 + cli/internal/deploy.go | 1 + pkg/config/app.go | 13 +++++++++++++ 4 files changed, 16 insertions(+) diff --git a/cli/app/rollback.go b/cli/app/rollback.go index cadd4d47..941b2fcd 100644 --- a/cli/app/rollback.go +++ b/cli/app/rollback.go @@ -180,6 +180,7 @@ recipes. } config.ExposeAllEnv(stackName, compose, app.Env) config.SetRecipeLabel(compose, stackName, app.Recipe) + config.SetChaosLabel(compose, stackName, internal.Chaos) if !internal.Force { if err := internal.NewVersionOverview(app, deployedVersion, chosenDowngrade, ""); err != nil { diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index 5037a490..a2138f27 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -191,6 +191,7 @@ recipes. } config.ExposeAllEnv(stackName, compose, app.Env) config.SetRecipeLabel(compose, stackName, app.Recipe) + config.SetChaosLabel(compose, stackName, internal.Chaos) if err := internal.NewVersionOverview(app, deployedVersion, chosenUpgrade, releaseNotes); err != nil { logrus.Fatal(err) diff --git a/cli/internal/deploy.go b/cli/internal/deploy.go index 68a007e5..3ae9d8e0 100644 --- a/cli/internal/deploy.go +++ b/cli/internal/deploy.go @@ -136,6 +136,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) if err := DeployOverview(app, version, "continue with deployment?"); err != nil { logrus.Fatal(err) diff --git a/pkg/config/app.go b/pkg/config/app.go index bb06e10d..64de339d 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" "path" + "strconv" "strings" "github.com/schollz/progressbar/v3" @@ -476,3 +477,15 @@ func SetRecipeLabel(compose *composetypes.Config, stackName string, recipe strin } } } + +// SetChaosLabel adds the label 'coop-cloud.${STACK_NAME}.chaos=true/false' to the app container +// to signal if the app is deployed in chaos mode +func SetChaosLabel(compose *composetypes.Config, stackName string, chaos bool) { + for _, service := range compose.Services { + if service.Name == "app" { + logrus.Debugf("set label 'coop-cloud.%s.chaos' to %s for %s", stackName, chaos, stackName) + labelKey := fmt.Sprintf("coop-cloud.%s.chaos", stackName) + service.Deploy.Labels[labelKey] = strconv.FormatBool(chaos) + } + } +}