Unverified Commit e6389bd0 authored by Sune Keller's avatar Sune Keller 🐳

Print untouched services in separate column

Signed-off-by: Sune Keller's avatarSune Keller <absukl@almbrand.dk>
parent 9ff0eea4
Pipeline #114813469 canceled with stage
in 2 minutes and 42 seconds
......@@ -73,6 +73,24 @@ func main() {
Email: "ablojh@almbrand.dk",
},
},
Commands: []*cli.Command{
&cli.Command{
Hidden: true,
Name: "test-pretty-report",
Action: func(c *cli.Context) error {
printPrettyReport(statusContextType{
mu: &sync.RWMutex{},
Context: context.Background(),
serviceNames: []string{"stack_service-foo", "stack_service-bar", "stack_service-bazookas"},
updating: map[string]struct{}{"stack_service-foo": struct{}{}, "stack_service-bazookas": struct{}{}},
completed: map[string]struct{}{"stack_service-foo": struct{}{}},
untouched: map[string]struct{}{"stack_service-bar": struct{}{}},
failed: map[string]failedStatus{"stack_service-bazookas": failedStatus{Err: "no good", Count: 3}},
})
return nil
},
},
},
Version: version,
Flags: []cli.Flag{
&cli.StringSliceFlag{
......@@ -262,20 +280,6 @@ func main() {
"output": string(output),
}).Fatal("docker stack deploy command failed")
}
// for name, serviceBefore := range servicesBefore {
// service := inspectService(name)
// if service == nil {
// continue
// }
// if serviceBefore.UpdateStatus != nil && serviceBefore.UpdateStatus.State == swarm.UpdateStatePaused && reflect.DeepEqual(service.Spec, serviceBefore.Spec) {
// log.WithFields(logrus.Fields{
// "before": serviceBefore.Spec,
// "now": service.Spec,
// }).Info("Service was paused, no change in spec - not good!")
// failed[name] = "need to check the tasks for this one"
// }
// }
}
// Monitor for end state
......@@ -363,25 +367,29 @@ func printPrettyReport(ctx statusContextType) {
defer w.Flush()
if len(ctx.rolledBack) > 0 || len(ctx.rollbackStarted) > 0 {
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t%s\t%s\t", "Name", "Updating", "Completed", "Failed", "Rolled back", "Rollback started")
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t%s\t%s\t", "----", "----", "----", "----", "----", "----")
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t%s\t%s\t%s\t", "Name", "Updating", "Completed", "Failed", "Untouched", "Rolled back", "Rollback started")
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t%s\t%s\t%s\t", "----", "----", "----", "----", "----", "----", "----")
} else {
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t", "Name", "Updating", "Completed", "Failed")
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t", "----", "----", "----", "----")
}
sortedKeys := []string{}
for k := range ctx.updating {
sortedKeys = append(sortedKeys, k)
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t%s\t", "Name", "Updating", "Completed", "Failed", "Untouched")
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t%s\t", "----", "----", "----", "----", "----")
}
sort.Strings(sortedKeys)
for _, k := range sortedKeys {
sort.Strings(ctx.serviceNames)
for _, k := range ctx.serviceNames {
updating := " "
completed := " "
failed := " "
untouched := " "
rolledBack := " "
rollbackStarted := " "
if _, exists := ctx.updating[k]; exists {
updating = "x"
}
if _, exists := ctx.completed[k]; exists {
completed = "x"
}
if _, exists := ctx.untouched[k]; exists {
untouched = "x"
}
if failedStatus, exists := ctx.failed[k]; exists {
failed = fmt.Sprintf("%d", failedStatus.Count)
}
......@@ -392,10 +400,9 @@ func printPrettyReport(ctx statusContextType) {
if _, exists := ctx.rollbackStarted[k]; exists {
rollbackStarted = "x"
}
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t%s\t%s\t", k, "x", completed, failed, rolledBack, rollbackStarted)
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t%s\t%s\t%s\t", k, updating, completed, failed, untouched, rolledBack, rollbackStarted)
} else {
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t", k, "x", completed, failed)
fmt.Fprintf(w, "\n %s\t%s\t%s\t%s\t%s\t", k, updating, completed, failed, untouched)
}
}
fmt.Fprintln(w)
......@@ -422,64 +429,6 @@ func check(ctx statusContextType) bool {
for _, name := range ctx.serviceNames {
// Inspect service to get UpdateStatus
service := mustInspectService(name)
// updateStatus := service.UpdateStatus
// if updateStatus != nil {
// message := updateStatus.Message
// ctx.updating[name] = struct{}{}
// switch updateStatus.State {
// case swarm.UpdateStateUpdating:
// if _, exists := ctx.updating[name]; !exists {
// ctx.updating[name] = struct{}{}
// log.WithFields(logrus.Fields{
// "service": name,
// }).Info("Service update started")
// }
// case swarm.UpdateStateCompleted:
// if _, exists := ctx.completed[name]; !exists {
// ctx.completed[name] = struct{}{}
// log.WithFields(logrus.Fields{
// "service": name,
// }).Info("Service update completed")
// }
// case swarm.UpdateStatePaused:
// if _, exists := ctx.failed[name]; !exists {
// ctx.failed[name] = message
// log.WithFields(logrus.Fields{
// "service": name,
// "message": message,
// }).Warn("Service update paused")
// }
// case swarm.UpdateStateRollbackStarted:
// if _, exists := ctx.rollbackStarted[name]; !exists {
// ctx.rollbackStarted[name] = message
// log.WithFields(logrus.Fields{
// "service": name,
// "message": message,
// }).Warn("Service rollback started")
// }
// case swarm.UpdateStateRollbackPaused:
// if _, exists := ctx.failed[name]; !exists {
// ctx.failed[name] = message
// log.WithFields(logrus.Fields{
// "service": name,
// "message": message,
// }).Warn("Service rollback paused")
// }
// case swarm.UpdateStateRollbackCompleted:
// if _, exists := ctx.rolledBack[name]; !exists {
// ctx.rolledBack[name] = message
// log.WithFields(logrus.Fields{
// "service": name,
// "message": message,
// }).Warn("Service rollback completed")
// }
// default:
// log.WithFields(logrus.Fields{
// "service": name,
// "state": updateStatus.State,
// }).Warn("Unexpected state")
// }
// } else {
if _, exists := ctx.updating[name]; !exists {
ctx.updating[name] = struct{}{}
log.WithFields(logrus.Fields{
......@@ -525,6 +474,7 @@ func check(ctx statusContextType) bool {
// Service specs identical; count _all_ tasks as there may be existing tasks that satisfy the desired state
if _, exists := ctx.untouched[name]; !exists {
ctx.untouched[name] = struct{}{}
delete(ctx.updating, name)
log.WithFields(logrus.Fields{
"service": name,
}).Info("Task template for service identical; will count all running tasks as valid")
......@@ -591,7 +541,7 @@ func check(ctx statusContextType) bool {
}
}
}
// }
// Count how many services have crossed the threshold for failed tasks and are thus considered failed entirely.
// Services that turned out to be fine will already have been removed from the "failed" map at this point
failedAboveThreshold := 0
......@@ -600,7 +550,7 @@ func check(ctx statusContextType) bool {
failedAboveThreshold++
}
}
if len(ctx.updating) == len(ctx.completed)+len(ctx.rolledBack)+failedAboveThreshold {
if len(ctx.updating)+len(ctx.untouched) == len(ctx.completed)+len(ctx.rolledBack)+failedAboveThreshold {
return true
}
return false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment