Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/gpctl/cmd/clusters-list.go
2498 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"context"
9
"io"
10
11
"github.com/spf13/cobra"
12
13
"github.com/gitpod-io/gitpod/common-go/log"
14
"github.com/gitpod-io/gitpod/ws-manager-bridge/api"
15
)
16
17
// clustersListCmd represents the clustersListCmd command
18
var clustersListCmd = &cobra.Command{
19
Use: "list",
20
Short: "Lists all clusters",
21
Run: func(cmd *cobra.Command, args []string) {
22
ctx, cancel := context.WithCancel(context.Background())
23
defer cancel()
24
25
conn, client, err := getClustersClient(ctx)
26
if err != nil {
27
log.WithError(err).Fatal("cannot connect")
28
}
29
defer conn.Close()
30
31
resp, err := client.List(ctx, &api.ListRequest{})
32
if err != nil && err != io.EOF {
33
log.Fatal(err)
34
}
35
36
tpl := `NAME URL STATIC STATE SCORE GOVERNED REGION ADMISSION CONSTRAINTS
37
{{- range .Status }}
38
{{ .Name }} {{ .Url }} {{ .Static }} {{ .State }} {{ .Score }} {{ .Governed }} {{ .Region }} {{ .AdmissionConstraint -}}
39
{{ end }}
40
`
41
err = getOutputFormat(tpl, "{..name}").Print(resp)
42
if err != nil {
43
log.Fatal(err)
44
}
45
},
46
}
47
48
func init() {
49
clustersCmd.AddCommand(clustersListCmd)
50
}
51
52