generated from cybozu-go/neco-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.go
59 lines (49 loc) · 1.1 KB
/
dump.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
package cmd
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(dumpCmd)
}
var dumpCmd = &cobra.Command{
Use: "dump",
Short: "dump endpoint status",
Long: `Dump endpoint status`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runDump(context.Background(), cmd.OutOrStdout(), args[0])
},
}
func runDump(ctx context.Context, w io.Writer, name string) error {
clientset, dynamicClient, _, err := createClients(ctx, name)
if err != nil {
return err
}
endpointID, err := getPodEndpointID(ctx, dynamicClient, rootOptions.namespace, name)
if err != nil {
return err
}
proxyEndpoint, err := getProxyEndpoint(ctx, clientset, rootOptions.namespace, name)
if err != nil {
return err
}
resp, err := http.Get(proxyEndpoint + fmt.Sprintf("/v1/endpoint/%d", endpointID))
if err != nil {
return err
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
var buf bytes.Buffer
json.Indent(&buf, data, "", " ")
buf.WriteTo(w)
return nil
}