From fe784f73b2f42c6c25809b564a469b68fd375de9 Mon Sep 17 00:00:00 2001 From: Autofix <61800571+autofix-bot@users.noreply.github.com> Date: Tue, 7 Nov 2023 08:44:45 +0100 Subject: [PATCH 1/8] Autofix: trailing-spaces (#18890) Co-authored-by: Autofix --- .github/ISSUE_TEMPLATE/epic.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/epic.yml b/.github/ISSUE_TEMPLATE/epic.yml index 55187cd90bb133..b33deac72cccca 100644 --- a/.github/ISSUE_TEMPLATE/epic.yml +++ b/.github/ISSUE_TEMPLATE/epic.yml @@ -7,7 +7,7 @@ body: id: press-release attributes: label: Press release (and FAQ's) - description: What would the future feature announcement look like from a customer/user point of view? Think about questions both Gitpodders, and users/customers might ask about this feature. + description: What would the future feature announcement look like from a customer/user point of view? Think about questions both Gitpodders, and users/customers might ask about this feature. validations: required: false - type: textarea @@ -35,14 +35,14 @@ body: id: measurement attributes: label: Measurement - description: What will we measure to know whether we've been successful? + description: What will we measure to know whether we've been successful? validations: required: false - type: textarea id: personas attributes: label: Persona(s) - description: Optionally specifiy which user will be impacted by this change? + description: Optionally specifiy which user will be impacted by this change? placeholder: Developer/Installer/Project Configurer/Customer/Security Reviewer - optionally the ecosystem persona e.g. Python Developers validations: required: false @@ -64,6 +64,6 @@ body: id: complexities attributes: label: Complexities - description: Optionally make explicit any complexities, e.g. dependencies on other teams, technical challenges, unknowns. + description: Optionally make explicit any complexities, e.g. dependencies on other teams, technical challenges, unknowns. validations: required: false From 6c0bb90a743bafdcd8bc2881ecf73648980e49fb Mon Sep 17 00:00:00 2001 From: Nandaja Varma Date: Tue, 7 Nov 2023 09:26:44 +0100 Subject: [PATCH 2/8] Update k3s to gen 106 (#19004) --- dev/preview/infrastructure/modules/gce/variables.tf | 2 +- dev/preview/infrastructure/modules/harvester/variables.tf | 2 +- dev/preview/infrastructure/variables.tf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/preview/infrastructure/modules/gce/variables.tf b/dev/preview/infrastructure/modules/gce/variables.tf index 78b69e686ab93b..6d3691eef1ea84 100644 --- a/dev/preview/infrastructure/modules/gce/variables.tf +++ b/dev/preview/infrastructure/modules/gce/variables.tf @@ -44,7 +44,7 @@ variable "harvester_ingress_ip" { variable "vm_image" { type = string description = "The VM image" - default = "gitpod-k3s-202309220725" + default = "gitpod-k3s-202311030912" } variable "cert_issuer" { diff --git a/dev/preview/infrastructure/modules/harvester/variables.tf b/dev/preview/infrastructure/modules/harvester/variables.tf index 9ded3db0ef544e..c837c42929dbc5 100644 --- a/dev/preview/infrastructure/modules/harvester/variables.tf +++ b/dev/preview/infrastructure/modules/harvester/variables.tf @@ -33,7 +33,7 @@ variable "ssh_key" { variable "vm_image" { type = string description = "The VM image" - default = "gitpod-k3s-202309220725" + default = "gitpod-k3s-202311030912" } variable "harvester_ingress_ip" { diff --git a/dev/preview/infrastructure/variables.tf b/dev/preview/infrastructure/variables.tf index ec6ec17a28a25a..b2ffbee8606ef0 100644 --- a/dev/preview/infrastructure/variables.tf +++ b/dev/preview/infrastructure/variables.tf @@ -35,7 +35,7 @@ variable "vm_type" { variable "vm_image" { type = string description = "The VM image" - default = "gitpod-k3s-202309220725" + default = "gitpod-k3s-202311030912" } variable "cert_issuer" { From ec8766012c41da326da03fc13358d32d2e14ce54 Mon Sep 17 00:00:00 2001 From: Huiwen Date: Tue, 7 Nov 2023 20:03:45 +0800 Subject: [PATCH 3/8] [installer] fix service-waiter bug (#19025) --- install/installer/pkg/common/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/installer/pkg/common/common.go b/install/installer/pkg/common/common.go index e50370696e4ddd..36885387658e2f 100644 --- a/install/installer/pkg/common/common.go +++ b/install/installer/pkg/common/common.go @@ -503,7 +503,7 @@ func ServerComponentWaiterContainer(ctx *RenderContext) *corev1.Container { // PublicApiServerComponentWaiterContainer is the container used to wait for the deployment/public-api-server to be ready // it requires pods list access to the cluster func PublicApiServerComponentWaiterContainer(ctx *RenderContext) *corev1.Container { - image := ctx.ImageName(ctx.Config.Repository, PublicApiComponent, ctx.VersionManifest.Components.Server.Version) + image := ctx.ImageName(ctx.Config.Repository, PublicApiComponent, ctx.VersionManifest.Components.PublicAPIServer.Version) return componentWaiterContainer(ctx, PublicApiComponent, DefaultLabels(PublicApiComponent), image) } From cf78ae016e4731f5f3ae6f9a5d556e14ab177cdf Mon Sep 17 00:00:00 2001 From: Huiwen Date: Tue, 7 Nov 2023 21:31:45 +0800 Subject: [PATCH 4/8] Revert service-waiter for server components on dashboard deployment (#19026) --- install/installer/pkg/components/dashboard/deployment.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/install/installer/pkg/components/dashboard/deployment.go b/install/installer/pkg/components/dashboard/deployment.go index 603f1eb4f2a6c3..e14a76ce1ae465 100644 --- a/install/installer/pkg/components/dashboard/deployment.go +++ b/install/installer/pkg/components/dashboard/deployment.go @@ -48,10 +48,6 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) { DNSPolicy: corev1.DNSClusterFirst, RestartPolicy: corev1.RestartPolicyAlways, TerminationGracePeriodSeconds: pointer.Int64(30), - InitContainers: []corev1.Container{ - *common.PublicApiServerComponentWaiterContainer(ctx), - *common.ServerComponentWaiterContainer(ctx), - }, Containers: []corev1.Container{{ Name: Component, Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.Dashboard.Version), From 8feb81924a9289c16f25139bb63e85d1cdb80ca1 Mon Sep 17 00:00:00 2001 From: Huiwen Date: Tue, 7 Nov 2023 23:28:45 +0800 Subject: [PATCH 5/8] Gitpod VS Code Browser Release `1.84.1` (#19024) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [code] build stable * update stable code --------- Co-authored-by: Filip Troníček --- WORKSPACE.yaml | 4 ++-- install/installer/pkg/components/workspace/ide/constants.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WORKSPACE.yaml b/WORKSPACE.yaml index 5d7337789a6302..d6f66c33a39d60 100644 --- a/WORKSPACE.yaml +++ b/WORKSPACE.yaml @@ -7,8 +7,8 @@ defaultArgs: publishToNPM: true publishToJBMarketplace: true localAppVersion: unknown - codeCommit: 50b5698060d06fa4650f10651a8714fe1d3cffe2 - codeVersion: 1.84.0 + codeCommit: e8edec1d836142a8a82e9c372b8d146d2c53b2fa + codeVersion: 1.84.1 codeQuality: stable noVerifyJBPlugin: false intellijDownloadUrl: "https://download.jetbrains.com/idea/ideaIU-2023.2.3.tar.gz" diff --git a/install/installer/pkg/components/workspace/ide/constants.go b/install/installer/pkg/components/workspace/ide/constants.go index 7e3ab21000ec5e..9b77f35b009e72 100644 --- a/install/installer/pkg/components/workspace/ide/constants.go +++ b/install/installer/pkg/components/workspace/ide/constants.go @@ -6,7 +6,7 @@ package ide const ( CodeIDEImage = "ide/code" - CodeIDEImageStableVersion = "commit-9126e605808f72ca6870fc881ce6583a8a0042bc" // stable version that will be updated manually on demand + CodeIDEImageStableVersion = "commit-0bfb871a1d539936e3ef9959d7db453ab59af352" // stable version that will be updated manually on demand CodeHelperIDEImage = "ide/code-codehelper" CodeWebExtensionImage = "ide/gitpod-code-web" CodeWebExtensionVersion = "commit-49bb715b599dce2356dd02a6ede7ae8cf10d8d12" // gitpod-web extension version comes from https://github.com/gitpod-io/gitpod-code From d7eae216e33cf60a91d86a2692269cbea7babe05 Mon Sep 17 00:00:00 2001 From: Huiwen Date: Wed, 8 Nov 2023 03:28:45 +0800 Subject: [PATCH 6/8] [LocalCLI] add completion for `--class` and `--editor` flags (#19019) * init * 1 * 1 * Remove completion in help * :lipstick: * Address feedback * add completion to workspace up --- .gitpod.yml | 5 +++ components/local-app/BUILD.yaml | 12 ++++++ components/local-app/README.md | 16 +++++++- components/local-app/cmd/root.go | 7 ++++ components/local-app/cmd/workspace-create.go | 43 ++++++++++++++++++++ components/local-app/cmd/workspace-up.go | 3 ++ 6 files changed, 85 insertions(+), 1 deletion(-) diff --git a/.gitpod.yml b/.gitpod.yml index ba4b1eca0975d9..df332fb5930cfa 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -42,6 +42,11 @@ tasks: gp env -u GCP_ADC_FILE fi exit 0 + - name: Install `gitpod` CLI + command: | + leeway run components/local-app:install-cli + leeway run components/local-app:cli-completion + exit 0 # This task takes care of configuring your workspace so it can manage and interact # with preview environments. - name: Preview environment configuration diff --git a/components/local-app/BUILD.yaml b/components/local-app/BUILD.yaml index 4665c0cc20aadb..9eee7881858b21 100644 --- a/components/local-app/BUILD.yaml +++ b/components/local-app/BUILD.yaml @@ -13,3 +13,15 @@ packages: image: - ${imageRepoBase}/local-app:${version} - ${imageRepoBase}/local-app:commit-${__git_commit} + +scripts: + - name: install-cli + description: "Install gitpod-cli as `gitpod` command and add auto-completion. Usage: '. $(leeway run components/local-app:install-cli)'" + script: | + go build -o gitpod ./main/gitpod-cli + sudo mv gitpod /usr/bin/gitpod + sudo chmod +x /usr/bin/gitpod + - name: cli-completion + description: "Add completion of gitpod-cli to bash-completion. Usage: '. $(leeway run components/local-app:cli-completion)'" + script: | + sudo /usr/bin/gitpod completion bash | sudo tee /usr/share/bash-completion/completions/gitpod > /dev/null diff --git a/components/local-app/README.md b/components/local-app/README.md index fd754b3a3e81f8..5b8ce3b65d675f 100644 --- a/components/local-app/README.md +++ b/components/local-app/README.md @@ -1,4 +1,4 @@ - # local-app +# local-app ## gitpod-cli @@ -27,6 +27,20 @@ Start by logging in with `gitpod login`, which will also create a default contex To develop the CLI with Gitpod, you can run it just like locally, but in Gitpod workspaces, a browser and a keyring are not available. To log in despite these limitations, provide a PAT via the `GITPOD_TOKEN` environment variable, or use the `--token` flag with the login command. +#### in Gitpod workspace + +[![Open in Gitpod](https://www.gitpod.io/svg/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/gitpod-io/gitpod) + +You will have gitpod-cli ready as `gitpod` in your CDE (Cloud Development Environments) workspace, will commands below you can install again easily. + +``` +# Install as `gitpod` again +leeway run components/local-app:install-cli + +# Add completion again +leeway run components/local-app:cli-completion +``` + ## local-app **Beware**: this is very much work in progress and will likely break things. diff --git a/components/local-app/cmd/root.go b/components/local-app/cmd/root.go index 6ea0cf3f0f09ed..d8b0e1a8d77972 100644 --- a/components/local-app/cmd/root.go +++ b/components/local-app/cmd/root.go @@ -101,7 +101,13 @@ var rootTestingOpts struct { WriterOut io.Writer } +var clientCache *client.Gitpod + func getGitpodClient(ctx context.Context) (*client.Gitpod, error) { + // There will be only one client in a command context right now + if clientCache != nil { + return clientCache, nil + } cfg := config.FromContext(ctx) gpctx, err := cfg.GetActiveContext() if err != nil { @@ -154,6 +160,7 @@ func getGitpodClient(ctx context.Context) (*client.Gitpod, error) { if err != nil { return nil, err } + clientCache = res return res, nil } diff --git a/components/local-app/cmd/workspace-create.go b/components/local-app/cmd/workspace-create.go index 9c40350056c054..34c5761e8f0f6d 100644 --- a/components/local-app/cmd/workspace-create.go +++ b/components/local-app/cmd/workspace-create.go @@ -143,10 +143,53 @@ var workspaceCreateOpts struct { Editor string } +func classCompletionFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ctx := cmd.Context() + gitpod, err := getGitpodClient(ctx) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + resp, err := gitpod.Workspaces.ListWorkspaceClasses(ctx, connect.NewRequest(&v1.ListWorkspaceClassesRequest{})) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + items := resp.Msg.GetResult() + completionStr := []string{} + for _, cls := range items { + defaultDesc := "" + if cls.IsDefault { + defaultDesc = "(default)" + } + completionStr = append(completionStr, fmt.Sprintf("%s\t%s%s - %s", cls.Id, cls.DisplayName, defaultDesc, cls.Description)) + } + return completionStr, cobra.ShellCompDirectiveNoFileComp +} + +func editorCompletionFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ctx := cmd.Context() + gitpod, err := getGitpodClient(ctx) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + resp, err := gitpod.Editors.ListEditorOptions(ctx, connect.NewRequest(&v1.ListEditorOptionsRequest{})) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + items := resp.Msg.GetResult() + completionStr := []string{} + for _, editor := range items { + completionStr = append(completionStr, fmt.Sprintf("%s\t%s", editor.Id, editor.Title)) + } + return completionStr, cobra.ShellCompDirectiveNoFileComp +} + func init() { workspaceCmd.AddCommand(workspaceCreateCmd) addWorkspaceStartOptions(workspaceCreateCmd, &workspaceCreateOpts.StartOpts) workspaceCreateCmd.Flags().StringVar(&workspaceCreateOpts.WorkspaceClass, "class", "", "the workspace class") workspaceCreateCmd.Flags().StringVar(&workspaceCreateOpts.Editor, "editor", "code", "the editor to use") + + _ = workspaceCreateCmd.RegisterFlagCompletionFunc("class", classCompletionFunc) + _ = workspaceCreateCmd.RegisterFlagCompletionFunc("editor", editorCompletionFunc) } diff --git a/components/local-app/cmd/workspace-up.go b/components/local-app/cmd/workspace-up.go index c7505ac40d3477..4eb5bffb4a63f4 100644 --- a/components/local-app/cmd/workspace-up.go +++ b/components/local-app/cmd/workspace-up.go @@ -291,4 +291,7 @@ func init() { workspaceUpCmd.Flags().StringVar(&workspaceCreateOpts.WorkspaceClass, "class", "", "the workspace class") workspaceUpCmd.Flags().StringVar(&workspaceCreateOpts.Editor, "editor", "code", "the editor to use") + + _ = workspaceUpCmd.RegisterFlagCompletionFunc("class", classCompletionFunc) + _ = workspaceUpCmd.RegisterFlagCompletionFunc("editor", editorCompletionFunc) } From 7dfb8840bbb340eaea4bd7f882d211c9b907aaf4 Mon Sep 17 00:00:00 2001 From: Christian Weichel Date: Tue, 7 Nov 2023 21:47:45 +0100 Subject: [PATCH 7/8] Print information after login (#19029) * Print information after login * Adress review feedback --- components/local-app/cmd/login.go | 19 ++++++++++++-- components/local-app/cmd/whoami.go | 41 ++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/components/local-app/cmd/login.go b/components/local-app/cmd/login.go index 5ee43740e822b3..d0625563b36ec0 100644 --- a/components/local-app/cmd/login.go +++ b/components/local-app/cmd/login.go @@ -66,7 +66,11 @@ var loginCmd = &cobra.Command{ err = auth.SetToken(loginOpts.Host, token) if err != nil { - slog.Warn("could not write token to keyring, storing in config file instead", "err", err) + if slog.Default().Enabled(cmd.Context(), slog.LevelDebug) { + slog.Debug("could not write token to keyring, storing in config file instead", "err", err) + } else { + slog.Warn("could not write token to keyring, storing in config file instead. Use -v to see the error.") + } gpctx.Token = token } @@ -115,7 +119,18 @@ var loginCmd = &cobra.Command{ return err } - return nil + client, err := getGitpodClient(config.ToContext(cmd.Context(), cfg)) + if err != nil { + return err + } + who, err := whoami(cmd.Context(), client, gpctx) + if err != nil { + return err + } + + slog.Info("Login succesfull") + fmt.Println() + return WriteTabular(who, formatOpts{}, prettyprint.WriterFormatNarrow) }, } diff --git a/components/local-app/cmd/whoami.go b/components/local-app/cmd/whoami.go index d61ad5ffec0d4a..0170b259937ec9 100644 --- a/components/local-app/cmd/whoami.go +++ b/components/local-app/cmd/whoami.go @@ -5,7 +5,10 @@ package cmd import ( + "context" + "github.com/bufbuild/connect-go" + "github.com/gitpod-io/gitpod/components/public-api/go/client" v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1" "github.com/gitpod-io/local-app/pkg/config" "github.com/gitpod-io/local-app/pkg/prettyprint" @@ -28,27 +31,37 @@ var whoamiCmd = &cobra.Command{ return err } - user, err := client.User.GetAuthenticatedUser(cmd.Context(), &connect.Request[v1.GetAuthenticatedUserRequest]{}) - if err != nil { - return err - } - org, err := client.Teams.GetTeam(cmd.Context(), &connect.Request[v1.GetTeamRequest]{Msg: &v1.GetTeamRequest{TeamId: gpctx.OrganizationID}}) + who, err := whoami(cmd.Context(), client, gpctx) if err != nil { return err } - return WriteTabular([]whoamiResult{ - { - Name: user.Msg.GetUser().Name, - ID: user.Msg.GetUser().Id, - Org: org.Msg.GetTeam().Name, - OrgID: org.Msg.GetTeam().Id, - Host: gpctx.Host.String(), - }, - }, whoamiOpts.Format, prettyprint.WriterFormatNarrow) + return WriteTabular(who, whoamiOpts.Format, prettyprint.WriterFormatNarrow) }, } +// whoami returns information about the currently logged in user +func whoami(ctx context.Context, client *client.Gitpod, gpctx *config.ConnectionContext) ([]whoamiResult, error) { + user, err := client.User.GetAuthenticatedUser(ctx, &connect.Request[v1.GetAuthenticatedUserRequest]{}) + if err != nil { + return nil, err + } + org, err := client.Teams.GetTeam(ctx, &connect.Request[v1.GetTeamRequest]{Msg: &v1.GetTeamRequest{TeamId: gpctx.OrganizationID}}) + if err != nil { + return nil, err + } + + return []whoamiResult{ + { + Name: user.Msg.GetUser().Name, + ID: user.Msg.GetUser().Id, + Org: org.Msg.GetTeam().Name, + OrgID: org.Msg.GetTeam().Id, + Host: gpctx.Host.String(), + }, + }, nil +} + type whoamiResult struct { Name string `print:"user name"` ID string `print:"user id"` From 1b90b8ac39706735fdf08ee12d2f470ec0fd6da4 Mon Sep 17 00:00:00 2001 From: Christian Weichel Date: Tue, 7 Nov 2023 21:48:45 +0100 Subject: [PATCH 8/8] Improve log level printing (#19030) --- components/local-app/cmd/root.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/components/local-app/cmd/root.go b/components/local-app/cmd/root.go index d8b0e1a8d77972..8858f2bd498bcb 100644 --- a/components/local-app/cmd/root.go +++ b/components/local-app/cmd/root.go @@ -55,11 +55,29 @@ var rootCmd = &cobra.Command{ var noColor bool if !isatty.IsTerminal(os.Stdout.Fd()) { noColor = true + color.Disable() } slog.SetDefault(slog.New(tint.NewHandler(os.Stdout, &tint.Options{ Level: level, NoColor: noColor, TimeFormat: time.StampMilli, + ReplaceAttr: func(groups []string, attr slog.Attr) slog.Attr { + if attr.Key != "level" { + return attr + } + + switch attr.Value.String() { + case slog.LevelDebug.String(): + attr.Value = slog.StringValue(color.Gray.Render("[DEBUG]")) + case slog.LevelInfo.String(): + attr.Value = slog.StringValue(color.Green.Render("[INFO ]")) + case slog.LevelWarn.String(): + attr.Value = slog.StringValue(color.Yellow.Render("[WARN ]")) + case slog.LevelError.String(): + attr.Value = slog.StringValue(color.Red.Render("[ERROR]")) + } + return attr + }, }))) cfg, err := config.LoadConfig(rootOpts.ConfigLocation)