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:
@ -3,7 +3,6 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
appPkg "coopcloud.tech/abra/pkg/app"
|
||||
@ -28,27 +27,10 @@ var pruneFlag = &cli.BoolFlag{
|
||||
// pruneApp runs the equivalent of a "docker system prune" but only filtering
|
||||
// against resources connected with the app deployment. It is not a system wide
|
||||
// prune. Volumes are not pruned to avoid unwated data loss.
|
||||
func pruneApp(c *cli.Context, cl *dockerClient.Client, app appPkg.App) error {
|
||||
func pruneApp(cl *dockerClient.Client, app appPkg.App) error {
|
||||
stackName := app.StackName()
|
||||
ctx := context.Background()
|
||||
|
||||
for {
|
||||
log.Debugf("polling for %s stack, waiting to be undeployed...", stackName)
|
||||
|
||||
services, err := stack.GetStackServices(ctx, cl, stackName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(services) == 0 {
|
||||
log.Debugf("%s undeployed, moving on with pruning logic", stackName)
|
||||
time.Sleep(time.Second) // give runtime more time to tear down related state
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
pruneFilters := filters.NewArgs()
|
||||
stackSearch := fmt.Sprintf("%s*", stackName)
|
||||
pruneFilters.Add("label", stackSearch)
|
||||
@ -109,16 +91,21 @@ Passing "-p/--prune" does not remove those volumes.
|
||||
|
||||
log.Debugf("checking whether %s is already deployed", stackName)
|
||||
|
||||
isDeployed, deployedVersion, err := stack.IsDeployed(context.Background(), cl, stackName)
|
||||
deployMeta, err := stack.IsDeployed(context.Background(), cl, stackName)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if !isDeployed {
|
||||
if !deployMeta.IsDeployed {
|
||||
log.Fatalf("%s is not deployed?", app.Name)
|
||||
}
|
||||
|
||||
if err := internal.DeployOverview(app, deployedVersion, "continue with undeploy?"); err != nil {
|
||||
chaosVersion := deployMeta.IsChaos
|
||||
if deployMeta.IsChaos == "true" {
|
||||
chaosVersion = deployMeta.ChaosVersion
|
||||
}
|
||||
|
||||
if err := internal.DeployOverview(app, deployMeta.Version, chaosVersion, "continue with undeploy?"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@ -131,7 +118,7 @@ Passing "-p/--prune" does not remove those volumes.
|
||||
}
|
||||
|
||||
if prune {
|
||||
if err := pruneApp(c, cl, app); err != nil {
|
||||
if err := pruneApp(cl, app); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user