forked from toolshed/abra
fix!: chaos consistency (deploy/undeploy/rollback/upgrade)
See coop-cloud/organising#559 --chaos for rollback/upgrade goes away.
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
stdlibErr "errors"
|
||||
@ -35,7 +36,7 @@ const (
|
||||
)
|
||||
|
||||
// Timeout to wait until docker services converge, default is 50s (random choice)
|
||||
var WaitTimeout int = 50
|
||||
var WaitTimeout = 50
|
||||
|
||||
type StackStatus struct {
|
||||
Services []swarm.Service
|
||||
@ -96,35 +97,64 @@ func GetDeployedServicesByName(ctx context.Context, cl *dockerClient.Client, sta
|
||||
return StackStatus{services, nil}
|
||||
}
|
||||
|
||||
// IsDeployed chekcks whether an appp is deployed or not.
|
||||
func IsDeployed(ctx context.Context, cl *dockerClient.Client, stackName string) (bool, string, error) {
|
||||
version := "unknown"
|
||||
isDeployed := false
|
||||
// DeployMeta is runtime metadata about an app deployment.
|
||||
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
|
||||
ChaosVersion string // the --chaos deployment version
|
||||
}
|
||||
|
||||
// IsDeployed gathers metadata about an app deployment.
|
||||
func IsDeployed(ctx context.Context, cl *dockerClient.Client, stackName string) (DeployMeta, error) {
|
||||
deployMeta := DeployMeta{
|
||||
IsDeployed: false,
|
||||
Version: "unknown",
|
||||
IsChaos: "false", // NOTE(d1): match string type used on label
|
||||
ChaosVersion: "false", // NOTE(d1): match string type used on label
|
||||
}
|
||||
|
||||
filter := filters.NewArgs()
|
||||
filter.Add("label", fmt.Sprintf("%s=%s", convert.LabelNamespace, stackName))
|
||||
|
||||
services, err := cl.ServiceList(ctx, types.ServiceListOptions{Filters: filter})
|
||||
if err != nil {
|
||||
return false, version, err
|
||||
return deployMeta, err
|
||||
}
|
||||
|
||||
if len(services) > 0 {
|
||||
deployMeta.IsDeployed = true
|
||||
|
||||
for _, service := range services {
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.version", stackName)
|
||||
if deployedVersion, ok := service.Spec.Labels[labelKey]; ok {
|
||||
version = deployedVersion
|
||||
break
|
||||
splitter := fmt.Sprintf("%s_", stackName)
|
||||
serviceName := strings.Split(service.Spec.Name, splitter)[1]
|
||||
|
||||
if serviceName == "app" {
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.version", stackName)
|
||||
if deployedVersion, ok := service.Spec.Labels[labelKey]; ok {
|
||||
deployMeta.Version = deployedVersion
|
||||
}
|
||||
|
||||
labelKey = fmt.Sprintf("coop-cloud.%s.chaos", stackName)
|
||||
if isChaos, ok := service.Spec.Labels[labelKey]; ok {
|
||||
deployMeta.IsChaos = isChaos
|
||||
}
|
||||
|
||||
labelKey = fmt.Sprintf("coop-cloud.%s.chaos-version", stackName)
|
||||
if chaosVersion, ok := service.Spec.Labels[labelKey]; ok {
|
||||
deployMeta.ChaosVersion = chaosVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("%s has been detected as deployed with version %s", stackName, version)
|
||||
log.Debugf("%s has been detected as deployed: %v", stackName, deployMeta)
|
||||
|
||||
return true, version, nil
|
||||
return deployMeta, nil
|
||||
}
|
||||
|
||||
log.Debugf("%s has been detected as not deployed", stackName)
|
||||
return isDeployed, version, nil
|
||||
|
||||
return deployMeta, nil
|
||||
}
|
||||
|
||||
// pruneServices removes services that are no longer referenced in the source
|
||||
|
Reference in New Issue
Block a user