Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/gpctl/cmd/workspaces-describe.go
2498 views
1
// Copyright (c) 2020 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
"strings"
10
11
"github.com/spf13/cobra"
12
13
"github.com/gitpod-io/gitpod/common-go/log"
14
"github.com/gitpod-io/gitpod/ws-manager/api"
15
)
16
17
// workspacesDescribeCmd represents the describe command
18
var workspacesDescribeCmd = &cobra.Command{
19
Use: "describe <instanceID | URL>",
20
Short: "describes a workspace",
21
Args: cobra.ExactArgs(1),
22
Run: func(cmd *cobra.Command, args []string) {
23
ctx, cancel := context.WithCancel(context.Background())
24
defer cancel()
25
26
conn, client, err := getWorkspacesClient(ctx)
27
if err != nil {
28
log.WithError(err).Fatal("cannot connect")
29
}
30
defer conn.Close()
31
32
instanceID := args[0]
33
var status *api.WorkspaceStatus
34
if strings.ContainsAny(instanceID, ".") || strings.HasPrefix(instanceID, "http://") || strings.HasPrefix(instanceID, "https://") {
35
status, err = getStatusByURL(ctx, client, instanceID)
36
if err != nil {
37
log.Fatal(err)
38
}
39
} else {
40
resp, err := client.DescribeWorkspace(ctx, &api.DescribeWorkspaceRequest{
41
Id: instanceID,
42
})
43
if err != nil {
44
log.WithError(err).Fatal("error during RPC call")
45
}
46
status = resp.Status
47
}
48
49
tpl := `Owner: {{ .Metadata.Owner }}
50
Workspace: {{ .Metadata.MetaId }}
51
Instance: {{ .Id }}
52
Phase: {{.Phase}}
53
Conditions:
54
{{- if not (eq .Conditions.Failed "") }} Failed: {{ .Conditions.Failed }}{{ end }}
55
{{- if not (eq .Conditions.Timeout "") }} Timeout: {{ .Conditions.Timeout }}{{ end }}
56
PullingImages: {{ .Conditions.PullingImages }}
57
Deployed: {{ .Conditions.Deployed }}
58
FinalBackupComplete: {{ .Conditions.FinalBackupComplete }}
59
Spec:
60
Image: {{ .Spec.WorkspaceImage }}
61
URL: {{ .Spec.Url }}
62
`
63
err = getOutputFormat(tpl, "{.id}").Print(status)
64
if err != nil {
65
log.Fatal(err)
66
}
67
},
68
}
69
70
func init() {
71
workspacesCmd.AddCommand(workspacesDescribeCmd)
72
}
73
74