From 233337f9e43345687cf7ab120a21fa9011783451 Mon Sep 17 00:00:00 2001 From: Florian Imdahl Date: Sat, 18 Dec 2021 16:12:19 +0100 Subject: [PATCH 1/6] feat: Extend workspace timeout --- components/gitpod-cli/cmd/timeout-extend.go | 44 +++++++++++++++++++++ components/gitpod-cli/go.mod | 3 +- components/gitpod-cli/go.sum | 1 + 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 components/gitpod-cli/cmd/timeout-extend.go diff --git a/components/gitpod-cli/cmd/timeout-extend.go b/components/gitpod-cli/cmd/timeout-extend.go new file mode 100644 index 00000000000000..aa0a30f3c7344d --- /dev/null +++ b/components/gitpod-cli/cmd/timeout-extend.go @@ -0,0 +1,44 @@ +// Copyright (c) 2021 Gitpod GmbH. All rights reserved. +// Licensed under the GNU Affero General Public License (AGPL). +// See License-AGPL.txt in the project root for license information. + +package cmd + +import ( + "context" + "time" + + gitpod "github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod" + "github.com/spf13/cobra" +) + +// timeoutExtendCmd represents the timeoutExtendCmd command +var timeoutExtendCmd = &cobra.Command{ + Use: "timeout-extend", + Short: "Boost the timeout of this workspace", + Args: cobra.NoArgs, + Run: func(cmd *cobra.Command, args []string) { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + wsInfo, err := gitpod.GetWSInfo(ctx) + if err != nil { + fail(err.Error()) + } + client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{ + "function:setWorkspaceTimeout", + "180m", + "resource:workspace::" + wsInfo.WorkspaceId + "::get/update", + }) + if err != nil { + fail(err.Error()) + } + err = client.StopWorkspace(ctx, wsInfo.WorkspaceId) + if err != nil { + fail(err.Error()) + } + }, +} + +func init() { + rootCmd.AddCommand(timeoutExtendCmd) +} diff --git a/components/gitpod-cli/go.mod b/components/gitpod-cli/go.mod index d2369443c0b156..d184bf6fed0ae5 100644 --- a/components/gitpod-cli/go.mod +++ b/components/gitpod-cli/go.mod @@ -22,6 +22,8 @@ require ( gopkg.in/yaml.v2 v2.4.0 ) +require github.com/sourcegraph/jsonrpc2 v0.0.0-20200429184054-15c2290dcb37 + require ( github.com/alecthomas/gometalinter v2.0.11+incompatible // indirect github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect @@ -39,7 +41,6 @@ require ( github.com/mattn/go-colorable v0.0.9 // indirect github.com/mattn/go-isatty v0.0.4 // indirect github.com/pelletier/go-toml v1.2.0 // indirect - github.com/sourcegraph/jsonrpc2 v0.0.0-20200429184054-15c2290dcb37 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9 // indirect golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect diff --git a/components/gitpod-cli/go.sum b/components/gitpod-cli/go.sum index dd46008e6516aa..4d82c36658537f 100644 --- a/components/gitpod-cli/go.sum +++ b/components/gitpod-cli/go.sum @@ -169,6 +169,7 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0 h1:ajue7SzQMywqRjg2fK7dcpc0QhFGpTR2plWfV4EZWR4= github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0/go.mod h1:r1hZAcvfFXuYmcKyCJI9wlyOPIZUJl6FCB8Cpca/NLE= From f1ad17a8cd127316f54c5dca1b1fbdcbcdecd038 Mon Sep 17 00:00:00 2001 From: Florian Imdahl Date: Wed, 22 Dec 2021 19:48:50 +0100 Subject: [PATCH 2/6] use client.SetWorkspaceTimeout --- components/gitpod-cli/cmd/timeout-extend.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/gitpod-cli/cmd/timeout-extend.go b/components/gitpod-cli/cmd/timeout-extend.go index aa0a30f3c7344d..8b495303a2e2ff 100644 --- a/components/gitpod-cli/cmd/timeout-extend.go +++ b/components/gitpod-cli/cmd/timeout-extend.go @@ -9,6 +9,7 @@ import ( "time" gitpod "github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod" + serverapi "github.com/gitpod-io/gitpod/gitpod-protocol" "github.com/spf13/cobra" ) @@ -26,13 +27,12 @@ var timeoutExtendCmd = &cobra.Command{ } client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{ "function:setWorkspaceTimeout", - "180m", "resource:workspace::" + wsInfo.WorkspaceId + "::get/update", }) if err != nil { fail(err.Error()) } - err = client.StopWorkspace(ctx, wsInfo.WorkspaceId) + _, err = client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, *serverapi.WorkspaceTimeoutDuration180m) if err != nil { fail(err.Error()) } From 5727950d57a4de2e06fa12c83bb3d10a0c11e5bf Mon Sep 17 00:00:00 2001 From: Florian Imdahl Date: Wed, 22 Dec 2021 19:50:42 +0100 Subject: [PATCH 3/6] wording --- components/gitpod-cli/cmd/timeout-extend.go | 2 +- components/gitpod-protocol/src/gitpod-service.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/gitpod-cli/cmd/timeout-extend.go b/components/gitpod-cli/cmd/timeout-extend.go index 8b495303a2e2ff..644b8e21b11c7b 100644 --- a/components/gitpod-cli/cmd/timeout-extend.go +++ b/components/gitpod-cli/cmd/timeout-extend.go @@ -16,7 +16,7 @@ import ( // timeoutExtendCmd represents the timeoutExtendCmd command var timeoutExtendCmd = &cobra.Command{ Use: "timeout-extend", - Short: "Boost the timeout of this workspace", + Short: "Extend the timeout of this workspace", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) diff --git a/components/gitpod-protocol/src/gitpod-service.ts b/components/gitpod-protocol/src/gitpod-service.ts index a4ad550efb49a9..a0ed85fe3b20c2 100644 --- a/components/gitpod-protocol/src/gitpod-service.ts +++ b/components/gitpod-protocol/src/gitpod-service.ts @@ -634,4 +634,4 @@ export function createGitpodService(gitpodServer, { onReconnect }); -} \ No newline at end of file +} From 60b24b5f31bfa3dfdf2e966b72e7ee5a9bc156cd Mon Sep 17 00:00:00 2001 From: Florian Imdahl Date: Wed, 22 Dec 2021 19:57:41 +0100 Subject: [PATCH 4/6] wording --- components/gitpod-cli/cmd/timeout-extend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/gitpod-cli/cmd/timeout-extend.go b/components/gitpod-cli/cmd/timeout-extend.go index 644b8e21b11c7b..ad8861c574474e 100644 --- a/components/gitpod-cli/cmd/timeout-extend.go +++ b/components/gitpod-cli/cmd/timeout-extend.go @@ -16,7 +16,7 @@ import ( // timeoutExtendCmd represents the timeoutExtendCmd command var timeoutExtendCmd = &cobra.Command{ Use: "timeout-extend", - Short: "Extend the timeout of this workspace", + Short: "Extend the timeout of the current workspace to 180 minutes", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) From b5ba81f23c4558e15cc132069c15a7e62821f503 Mon Sep 17 00:00:00 2001 From: Florian Imdahl Date: Wed, 5 Jan 2022 20:24:41 +0100 Subject: [PATCH 5/6] revert unnecessary changes --- components/gitpod-protocol/src/gitpod-service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/gitpod-protocol/src/gitpod-service.ts b/components/gitpod-protocol/src/gitpod-service.ts index a0ed85fe3b20c2..a4ad550efb49a9 100644 --- a/components/gitpod-protocol/src/gitpod-service.ts +++ b/components/gitpod-protocol/src/gitpod-service.ts @@ -634,4 +634,4 @@ export function createGitpodService(gitpodServer, { onReconnect }); -} +} \ No newline at end of file From b320675e4509623700435669e6b55de3d94b1724 Mon Sep 17 00:00:00 2001 From: Florian Imdahl Date: Wed, 5 Jan 2022 20:25:45 +0100 Subject: [PATCH 6/6] remove pointer --- components/gitpod-cli/cmd/timeout-extend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/gitpod-cli/cmd/timeout-extend.go b/components/gitpod-cli/cmd/timeout-extend.go index ad8861c574474e..b84fbe98f7d605 100644 --- a/components/gitpod-cli/cmd/timeout-extend.go +++ b/components/gitpod-cli/cmd/timeout-extend.go @@ -32,7 +32,7 @@ var timeoutExtendCmd = &cobra.Command{ if err != nil { fail(err.Error()) } - _, err = client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, *serverapi.WorkspaceTimeoutDuration180m) + _, err = client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, serverapi.WorkspaceTimeoutDuration180m) if err != nil { fail(err.Error()) }