-
Notifications
You must be signed in to change notification settings - Fork 9
/
types.go
45 lines (36 loc) · 1014 Bytes
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package runtime
import (
"fmt"
"strings"
)
func (d *Diagnostics) Failed() bool {
return d.Terminated && d.ExitCode > 0
}
func (cw *ContainerWaitStatus) WaitStatus() string {
var inits []string
for _, init := range cw.Initializers {
inits = append(inits, fmt.Sprintf("%s: %s", init.Name, init.StatusLabel))
}
joinedInits := strings.Join(inits, "; ")
switch len(cw.Containers) {
case 0:
return joinedInits
case 1:
return box(cw.Containers[0].StatusLabel, joinedInits)
default:
var labels []string
for _, ctr := range cw.Containers {
labels = append(labels, fmt.Sprintf("%s: %s", ctr.Name, ctr.StatusLabel))
}
return box(fmt.Sprintf("{%s}", strings.Join(labels, "; ")), joinedInits)
}
}
func box(a, b string) string {
if b == "" {
return a
}
return fmt.Sprintf("%s [%s]", a, b)
}