refactor: make IsChaos an actual bool

This commit is contained in:
2024-07-09 11:34:01 +02:00
parent 00d60f7114
commit b82ac3bd63
4 changed files with 18 additions and 13 deletions

View File

@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"os/signal"
"strconv"
"strings"
"time"
@ -101,7 +102,7 @@ func GetDeployedServicesByName(ctx context.Context, cl *dockerClient.Client, sta
type DeployMeta struct {
IsDeployed bool // whether the app is deployed or not
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
}
@ -110,7 +111,7 @@ func IsDeployed(ctx context.Context, cl *dockerClient.Client, stackName string)
deployMeta := DeployMeta{
IsDeployed: false,
Version: "unknown",
IsChaos: "false", // NOTE(d1): match string type used on label
IsChaos: false,
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)
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)