forked from moby/swarmkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspect.go
98 lines (82 loc) · 2.58 KB
/
inspect.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package cluster
import (
"errors"
"fmt"
"os"
"sort"
"text/tabwriter"
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/cmd/swarmctl/common"
"github.com/docker/swarmkit/protobuf/ptypes"
"github.com/spf13/cobra"
)
func printClusterSummary(cluster *api.Cluster) {
w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
defer w.Flush()
common.FprintfIfNotEmpty(w, "ID\t: %s\n", cluster.ID)
common.FprintfIfNotEmpty(w, "Name\t: %s\n", cluster.Spec.Annotations.Name)
fmt.Fprintf(w, "Orchestration settings:\n")
fmt.Fprintf(w, " Task history entries: %d\n", cluster.Spec.Orchestration.TaskHistoryRetentionLimit)
heartbeatPeriod, err := ptypes.Duration(cluster.Spec.Dispatcher.HeartbeatPeriod)
if err == nil {
fmt.Fprintf(w, "Dispatcher settings:\n")
fmt.Fprintf(w, " Dispatcher heartbeat period: %s\n", heartbeatPeriod.String())
}
fmt.Fprintf(w, "Certificate Authority settings:\n")
if cluster.Spec.CAConfig.NodeCertExpiry != nil {
clusterDuration, err := ptypes.Duration(cluster.Spec.CAConfig.NodeCertExpiry)
if err != nil {
fmt.Fprintf(w, " Certificate Validity Duration: [ERROR PARSING DURATION]\n")
} else {
fmt.Fprintf(w, " Certificate Validity Duration: %s\n", clusterDuration.String())
}
}
if len(cluster.Spec.CAConfig.ExternalCAs) > 0 {
fmt.Fprintf(w, " External CAs:\n")
for _, ca := range cluster.Spec.CAConfig.ExternalCAs {
fmt.Fprintf(w, " %s: %s\n", ca.Protocol, ca.URL)
}
}
fmt.Fprintln(w, " Join Tokens:")
fmt.Fprintln(w, " Worker:", cluster.RootCA.JoinTokens.Worker)
fmt.Fprintln(w, " Manager:", cluster.RootCA.JoinTokens.Manager)
if cluster.Spec.TaskDefaults.LogDriver != nil {
fmt.Fprintf(w, "Default Log Driver\t: %s\n", cluster.Spec.TaskDefaults.LogDriver.Name)
var keys []string
if len(cluster.Spec.TaskDefaults.LogDriver.Options) != 0 {
for k := range cluster.Spec.TaskDefaults.LogDriver.Options {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := cluster.Spec.TaskDefaults.LogDriver.Options[k]
if v != "" {
fmt.Fprintf(w, " %s\t: %s\n", k, v)
} else {
fmt.Fprintf(w, " %s\t\n", k)
}
}
}
}
}
var (
inspectCmd = &cobra.Command{
Use: "inspect <cluster name>",
Short: "Inspect a cluster",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("cluster name missing")
}
c, err := common.Dial(cmd)
if err != nil {
return err
}
cluster, err := getCluster(common.Context(cmd), c, args[0])
if err != nil {
return err
}
printClusterSummary(cluster)
return nil
},
}
)