0
0
forked from toolshed/abra

refactor: make IsChaos an actual bool

This commit is contained in:
decentral1se 2024-07-09 11:34:01 +02:00
parent 00d60f7114
commit b82ac3bd63
Signed by untrusted user: decentral1se
GPG Key ID: 03789458B3D0C410
4 changed files with 18 additions and 13 deletions

View File

@ -129,7 +129,7 @@ EXAMPLE:
} }
if deployMeta.Version != "unknown" && specificVersion == "" { if deployMeta.Version != "unknown" && specificVersion == "" {
if deployMeta.IsChaos == "true" { if deployMeta.IsChaos {
log.Warn("attempting to rollback a chaos deployment") log.Warn("attempting to rollback a chaos deployment")
} }
@ -162,7 +162,7 @@ EXAMPLE:
log.Debugf("choosing %s as version to downgrade to (--force/--no-input)", chosenDowngrade) log.Debugf("choosing %s as version to downgrade to (--force/--no-input)", chosenDowngrade)
} else { } else {
msg := fmt.Sprintf("please select a downgrade (version: %s):", deployMeta.Version) msg := fmt.Sprintf("please select a downgrade (version: %s):", deployMeta.Version)
if deployMeta.IsChaos == "true" { if deployMeta.IsChaos {
msg = fmt.Sprintf("please select a downgrade (version: %s, chaosVersion: %s):", deployMeta.Version, deployMeta.ChaosVersion) msg = fmt.Sprintf("please select a downgrade (version: %s, chaosVersion: %s):", deployMeta.Version, deployMeta.ChaosVersion)
} }
@ -214,8 +214,8 @@ EXAMPLE:
appPkg.SetChaosVersionLabel(compose, stackName, chosenDowngrade) appPkg.SetChaosVersionLabel(compose, stackName, chosenDowngrade)
appPkg.SetUpdateLabel(compose, stackName, app.Env) appPkg.SetUpdateLabel(compose, stackName, app.Env)
chaosVersion := deployMeta.IsChaos chaosVersion := "false"
if deployMeta.IsChaos == "true" { if deployMeta.IsChaos {
chaosVersion = deployMeta.ChaosVersion chaosVersion = deployMeta.ChaosVersion
} }

View File

@ -99,8 +99,8 @@ Passing "-p/--prune" does not remove those volumes.`,
log.Fatalf("%s is not deployed?", app.Name) log.Fatalf("%s is not deployed?", app.Name)
} }
chaosVersion := deployMeta.IsChaos chaosVersion := "false"
if deployMeta.IsChaos == "true" { if deployMeta.IsChaos {
chaosVersion = deployMeta.ChaosVersion chaosVersion = deployMeta.ChaosVersion
} }

View File

@ -132,7 +132,7 @@ EXAMPLE:
} }
if deployMeta.Version != "unknown" && specificVersion == "" { if deployMeta.Version != "unknown" && specificVersion == "" {
if deployMeta.IsChaos == "true" { if deployMeta.IsChaos {
log.Warn("attempting to upgrade a chaos deployment") log.Warn("attempting to upgrade a chaos deployment")
} }
@ -159,7 +159,7 @@ EXAMPLE:
log.Debugf("choosing %s as version to upgrade to", chosenUpgrade) log.Debugf("choosing %s as version to upgrade to", chosenUpgrade)
} else { } else {
msg := fmt.Sprintf("please select an upgrade (version: %s):", deployMeta.Version) msg := fmt.Sprintf("please select an upgrade (version: %s):", deployMeta.Version)
if deployMeta.IsChaos == "true" { if deployMeta.IsChaos {
msg = fmt.Sprintf("please select an upgrade (version: %s, chaosVersion: %s):", deployMeta.Version, deployMeta.ChaosVersion) msg = fmt.Sprintf("please select an upgrade (version: %s, chaosVersion: %s):", deployMeta.Version, deployMeta.ChaosVersion)
} }
@ -259,8 +259,8 @@ EXAMPLE:
return nil return nil
} }
chaosVersion := deployMeta.IsChaos chaosVersion := "false"
if deployMeta.IsChaos == "true" { if deployMeta.IsChaos {
chaosVersion = deployMeta.ChaosVersion chaosVersion = deployMeta.ChaosVersion
} }

View File

@ -7,6 +7,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/signal" "os/signal"
"strconv"
"strings" "strings"
"time" "time"
@ -101,7 +102,7 @@ func GetDeployedServicesByName(ctx context.Context, cl *dockerClient.Client, sta
type DeployMeta struct { type DeployMeta struct {
IsDeployed bool // whether the app is deployed or not IsDeployed bool // whether the app is deployed or not
Version string // the deployed version Version string // the deployed version
IsChaos string // whether or not the deployment is --chaos IsChaos bool // whether or not the deployment is --chaos
ChaosVersion string // the --chaos deployment version ChaosVersion string // the --chaos deployment version
} }
@ -110,7 +111,7 @@ func IsDeployed(ctx context.Context, cl *dockerClient.Client, stackName string)
deployMeta := DeployMeta{ deployMeta := DeployMeta{
IsDeployed: false, IsDeployed: false,
Version: "unknown", Version: "unknown",
IsChaos: "false", // NOTE(d1): match string type used on label IsChaos: false,
ChaosVersion: "false", // NOTE(d1): match string type used on label ChaosVersion: "false", // NOTE(d1): match string type used on label
} }
@ -137,7 +138,11 @@ func IsDeployed(ctx context.Context, cl *dockerClient.Client, stackName string)
labelKey = fmt.Sprintf("coop-cloud.%s.chaos", stackName) labelKey = fmt.Sprintf("coop-cloud.%s.chaos", stackName)
if isChaos, ok := service.Spec.Labels[labelKey]; ok { if isChaos, ok := service.Spec.Labels[labelKey]; ok {
deployMeta.IsChaos = isChaos boolVal, err := strconv.ParseBool(isChaos)
if err != nil {
return deployMeta, fmt.Errorf("unable to parse '%s' value as bool: %s", labelKey, err)
}
deployMeta.IsChaos = boolVal
} }
labelKey = fmt.Sprintf("coop-cloud.%s.chaos-version", stackName) labelKey = fmt.Sprintf("coop-cloud.%s.chaos-version", stackName)