Skip to content

Commit 713f7ea

Browse files
committed
previewctl install-context --watch
1 parent 3ffe8fd commit 713f7ea

File tree

13 files changed

+975
-113
lines changed

13 files changed

+975
-113
lines changed

dev/preview/previewctl/cmd/get_name.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@ package cmd
66

77
import (
88
"fmt"
9-
109
"github.com/gitpod-io/gitpod/previewctl/pkg/preview"
11-
"github.com/sirupsen/logrus"
10+
1211
"github.com/spf13/cobra"
1312
)
1413

15-
func getNameCmd(logger *logrus.Logger) *cobra.Command {
16-
14+
func getNameCmd() *cobra.Command {
1715
cmd := &cobra.Command{
1816
Use: "get-name",
1917
Short: "Returns the name of the preview for the corresponding branch.",
2018
Run: func(cmd *cobra.Command, args []string) {
21-
p := preview.New(branch, logger)
22-
23-
fmt.Println(p.GetPreviewName())
19+
fmt.Println(preview.GetName(branch))
2420
},
2521
}
2622

dev/preview/previewctl/cmd/install_context.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,39 @@
55
package cmd
66

77
import (
8+
"time"
9+
810
"github.com/gitpod-io/gitpod/previewctl/pkg/preview"
911
"github.com/sirupsen/logrus"
1012
"github.com/spf13/cobra"
1113
)
1214

1315
var (
14-
watch = false
16+
watch = false
17+
timeout = time.Minute * 5
1518
)
1619

1720
func installContextCmd(logger *logrus.Logger) *cobra.Command {
1821

1922
cmd := &cobra.Command{
2023
Use: "install-context",
2124
Short: "Installs the kubectl context of a preview environment.",
22-
Run: func(cmd *cobra.Command, args []string) {
23-
p := preview.New(branch, logger)
25+
RunE: func(cmd *cobra.Command, args []string) error {
26+
p, err := preview.New(branch, logger)
27+
if err != nil {
28+
return err
29+
}
2430

25-
err := p.InstallContext(watch)
31+
err = p.InstallContext(watch, timeout)
2632
if err != nil {
2733
logger.WithFields(logrus.Fields{"err": err}).Fatal("Failed to install context.")
2834
}
35+
36+
return nil
2937
},
3038
}
3139

3240
cmd.Flags().BoolVar(&watch, "watch", false, "If wait is enabled, previewctl will keep trying to install the kube-context every 30 seconds.")
41+
cmd.Flags().DurationVarP(&timeout, "timeout", "t", 10*time.Minute, "Timeout for the watch flag.")
3342
return cmd
3443
}

dev/preview/previewctl/cmd/list_previews.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,22 @@ func listPreviewsCmd(logger *logrus.Logger) *cobra.Command {
1515
cmd := &cobra.Command{
1616
Use: "list",
1717
Short: "List all existing Preview Environments.",
18-
Run: func(cmd *cobra.Command, args []string) {
18+
RunE: func(cmd *cobra.Command, args []string) error {
1919
if branch != "" {
2020
logger.Warn("Branch flag is ignored for 'list' command.")
2121
}
2222

23-
err := preview.ListAllPreviews()
23+
p, err := preview.New(branch, logger)
24+
if err != nil {
25+
return err
26+
}
27+
28+
err = p.ListAllPreviews()
2429
if err != nil {
2530
logger.WithFields(logrus.Fields{"err": err}).Fatal("Failed to list previews.")
2631
}
32+
33+
return nil
2734
},
2835
}
2936

dev/preview/previewctl/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func RootCmd(logger *logrus.Logger) *cobra.Command {
2424

2525
cmd.AddCommand(
2626
installContextCmd(logger),
27-
getNameCmd(logger),
27+
getNameCmd(),
2828
listPreviewsCmd(logger),
2929
SSHPreviewCmd(logger),
3030
)

dev/preview/previewctl/cmd/ssh_vm.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ func SSHPreviewCmd(logger *logrus.Logger) *cobra.Command {
1515
cmd := &cobra.Command{
1616
Use: "ssh",
1717
Short: "SSH into a preview's Virtual Machine.",
18-
Run: func(cmd *cobra.Command, args []string) {
19-
p := preview.New(branch, logger)
18+
RunE: func(cmd *cobra.Command, args []string) error {
2019

21-
err := p.SSHPreview()
20+
err := preview.SSHPreview(branch)
2221
if err != nil {
2322
logger.WithFields(logrus.Fields{"err": err}).Fatal("Failed to SSH preview's VM.")
2423
}
24+
25+
return err
2526
},
2627
}
2728

dev/preview/previewctl/go.mod

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,61 @@ module github.com/gitpod-io/gitpod/previewctl
22

33
go 1.18
44

5-
require github.com/spf13/cobra v1.4.0
5+
require (
6+
github.com/pkg/errors v0.9.1
7+
github.com/spf13/cobra v1.5.0
8+
github.com/stretchr/testify v1.7.0
9+
k8s.io/api v0.24.2
10+
k8s.io/apimachinery v0.24.2
11+
kubevirt.io/api v0.54.0
12+
)
613

714
require (
815
github.com/davecgh/go-spew v1.1.1 // indirect
9-
github.com/go-logr/logr v1.2.0 // indirect
16+
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
17+
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
18+
github.com/fsnotify/fsnotify v1.5.1 // indirect
19+
github.com/go-logr/logr v1.2.3 // indirect
20+
github.com/go-openapi/jsonpointer v0.19.5 // indirect
21+
github.com/go-openapi/jsonreference v0.20.0 // indirect
22+
github.com/go-openapi/swag v0.21.1 // indirect
1023
github.com/gogo/protobuf v1.3.2 // indirect
1124
github.com/golang/protobuf v1.5.2 // indirect
12-
github.com/google/gofuzz v1.1.0 // indirect
13-
github.com/imdario/mergo v0.3.5 // indirect
25+
github.com/google/gnostic v0.6.9 // indirect
26+
github.com/google/go-cmp v0.5.8 // indirect
27+
github.com/google/gofuzz v1.2.0 // indirect
28+
github.com/google/uuid v1.3.0 // indirect
29+
github.com/imdario/mergo v0.3.13 // indirect
30+
github.com/josharian/intern v1.0.0 // indirect
1431
github.com/json-iterator/go v1.1.12 // indirect
32+
github.com/mailru/easyjson v0.7.7 // indirect
1533
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
1634
github.com/modern-go/reflect2 v1.0.2 // indirect
17-
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
18-
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
19-
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
20-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
35+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
36+
github.com/onsi/ginkgo v1.16.5 // indirect
37+
github.com/openshift/custom-resource-status v1.1.2 // indirect
38+
github.com/pborman/uuid v1.2.1 // indirect
39+
github.com/pmezard/go-difflib v1.0.0 // indirect
40+
golang.org/x/net v0.0.0-20220622184535-263ec571b305 // indirect
41+
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect
42+
golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664 // indirect
43+
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
2144
golang.org/x/text v0.3.7 // indirect
22-
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
45+
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
2346
google.golang.org/appengine v1.6.7 // indirect
24-
google.golang.org/protobuf v1.27.1 // indirect
47+
google.golang.org/protobuf v1.28.0 // indirect
2548
gopkg.in/inf.v0 v0.9.1 // indirect
2649
gopkg.in/yaml.v2 v2.4.0 // indirect
27-
k8s.io/apimachinery v0.24.2 // indirect
28-
k8s.io/klog/v2 v2.60.1 // indirect
50+
gopkg.in/yaml.v3 v3.0.1 // indirect
51+
k8s.io/apiextensions-apiserver v0.24.2 // indirect
52+
k8s.io/klog/v2 v2.70.0 // indirect
53+
k8s.io/kube-openapi v0.0.0-20220621154418-c39d0f63fac8 // indirect
2954
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
30-
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
55+
kubevirt.io/containerized-data-importer-api v1.50.0 // indirect
56+
kubevirt.io/controller-lifecycle-operator-sdk/api v0.2.4 // indirect
57+
sigs.k8s.io/json v0.0.0-20220525155127-227cbc7cc124 // indirect
3158
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
32-
sigs.k8s.io/yaml v1.2.0 // indirect
59+
sigs.k8s.io/yaml v1.3.0 // indirect
3360
)
3461

3562
require (

0 commit comments

Comments
 (0)