-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
status.go
70 lines (60 loc) · 1.67 KB
/
status.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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package cmd
import (
"os"
"text/tabwriter"
"github.com/spf13/cobra"
"github.com/cilium/cilium/api/v1/health/models"
"github.com/cilium/cilium/pkg/command"
clientPkg "github.com/cilium/cilium/pkg/health/client"
)
var (
probe bool
succinct bool
verbose bool
)
// statusGetCmd represents the status command
var statusGetCmd = &cobra.Command{
Use: "status",
Aliases: []string{"connectivity"},
Short: "Display cilium connectivity to other nodes",
Run: func(cmd *cobra.Command, args []string) {
var sr *models.HealthStatusResponse
if client == nil {
Fatalf("Invalid combination of arguments")
}
if probe {
result, err := client.Connectivity.PutStatusProbe(nil)
if err != nil {
Fatalf("Cannot get status/probe: %s\n", err)
}
sr = result.Payload
} else {
result, err := client.Connectivity.GetStatus(nil)
if err != nil {
Fatalf("Cannot get status: %s\n", err)
}
sr = result.Payload
}
if command.OutputOption() {
if err := command.PrintOutput(sr); err != nil {
os.Exit(1)
}
} else {
w := tabwriter.NewWriter(os.Stdout, 2, 0, 3, ' ', 0)
clientPkg.FormatHealthStatusResponse(w, sr, true, succinct, verbose, 0)
w.Flush()
}
},
}
func init() {
rootCmd.AddCommand(statusGetCmd)
statusGetCmd.Flags().BoolVarP(&probe, "probe", "", false,
"Synchronously probe connectivity status")
statusGetCmd.Flags().BoolVarP(&succinct, "succinct", "", false,
"Print the result succinctly (one node per line)")
statusGetCmd.Flags().BoolVarP(&verbose, "verbose", "", false,
"Print more information in results")
command.AddOutputOption(statusGetCmd)
}