Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev] add gp-gcloud direct replacement for gcloud cli for certain gcloud cli commands #10991

Merged
merged 1 commit into from
Jul 12, 2022

Conversation

sagor999
Copy link
Contributor

@sagor999 sagor999 commented Jun 28, 2022

Description

For reference: https://github.com/gitpod-io/ops/issues/2259
We need to be able to label disks when creating instance templates used by workspace clusters.
gcloud cli does not support that. REST API or go library does.
Using REST API directly would be too bulky and not very maintainable.
Hence gp-gcloud cli was created. It acts as a direct drop in replacement for gcloud cli.
Currently only supports compute instance-templates create command.
Otherwise we can still use gcloud for other commands.

Related Issue(s)

Fixes #

How to test

Open this PR in gitpod.
Run this command that will create instance template in workspace-preview project (if you have access to it):

cd dev/gp-gcloud
go build
./gp-gcloud compute instance-templates create awesome-template-name2 --image="projects/workspace-clusters/global/images/gitpod-k3s-202204191639" --boot-disk-type=pd-ssd --network-interface="network=global/networks/default,network-tier=PREMIUM,address=" --scopes=compute-rw,storage-ro,service-management,service-control,logging-write,monitoring --metadata="block-project-ssh-keys=TRUE,enable-oslogin=FALSE,cluster-name=us444,cluster-location=test-region,disable-legacy-endpoints=true,kube-env=AUTOSCALER_ENV_VARS: os_distribution=ubuntu;os=linux" --no-restart-on-failure --labels="cluster-name=us444,cluster-location=usa,instance-type=control-plane" --tags servers-us444,us444 --boot-disk-size '512GB' --service-account="lala" --machine-type n2d-standard-4 --min-cpu-platform="AMD Milan" --project workspace-preview --region us --local-ssd interface=NVME --local-ssd interface=NVME --local-ssd interface=NVME --local-ssd interface=NVME

Release Notes

none

Documentation

Werft options:

  • /werft with-preview

@sagor999 sagor999 changed the title wip [dev] add gp-gcloud direct replacement for gcloud cli for certain gcloud cli commands Jun 29, 2022
@sagor999 sagor999 marked this pull request as ready for review June 29, 2022 21:54
@sagor999 sagor999 requested a review from a team June 29, 2022 21:54
@github-actions github-actions bot added the team: workspace Issue belongs to the Workspace team label Jun 29, 2022
@jenting
Copy link
Contributor

jenting commented Jun 30, 2022

Sorry I missed this issue https://github.com/gitpod-io/ops/issues/2259.

Looks like we decided to write a new CLI with the Go library instead of the REST API call comment?

@sagor999
Copy link
Contributor Author

@jenting yeah. I think it will be better long term then using REST API directly. (As suggested by Alejandro)

@jenting
Copy link
Contributor

jenting commented Jul 1, 2022

@jenting yeah. I think it will be better long term then using REST API directly. (As suggested by Alejandro)

The PR LGTM, thank you 😃
However, for this enhancement, I'd vote to use REST API directly.

@kylos101
Copy link
Contributor

kylos101 commented Jul 7, 2022

@sagor999 while testing I bumped into an issue.

gitpod /workspace/workspace-preview/gitpod/dev/gp-gcloud (pavel/gp-gcloud) $ go build
# github.com/gitpod-io/gitpod/gp-gcloud/cmd/compute
cmd/compute/instance-templates-create.go:228:24: undefined: strings.Cut
cmd/compute/instance-templates-create.go:246:24: undefined: strings.Cut
note: module requires Go 1.18

gitpod /workspace/workspace-preview/gitpod (main) $ go version
go version go1.17.5 linux/amd64

gitpod /workspace/workspace-preview/gitpod (main) $ printenv | grep GO
CARGO_HOME=/workspace/.cargo
GOROOT=/home/gitpod/go
GO_VERSION=1.17.5
GOPATH=/workspace/go

I think it's because the image for workspace-preview is old, still using Go 1.17. I am building again so we can use the latest. More updates to follow.

PEBKAC.

@kylos101
Copy link
Contributor

kylos101 commented Jul 7, 2022

It lives!

image

@kylos101
Copy link
Contributor

kylos101 commented Jul 7, 2022

Went through all files, except dev/gp-gcloud/cmd/compute/instance-templates-create.go. Would like a fresh pair of eyes before I ✅, and will do first thing tomorrow AM.

@kylos101
Copy link
Contributor

kylos101 commented Jul 8, 2022

Hey @sagor999 👋 , I was comparing the awesome instance template with a real one, and observed some differences.

eu51 internal xl:
image

awesome template:
image

Other feedback incoming via the code! ✉️

edit: @sagor999 wdyt of the differences? I'm thinking we should have gp-gcloud match what we're currently doing, unless there's a compelling security reason to disable everything.

Copy link
Contributor

@kylos101 kylos101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sagor999 no requested changes, just some questions to help me better understand how to test, and how some values were set.

Boot: false,
InitializeParams: &compute.AttachedDiskInitializeParams{
DiskType: "local-ssd",
Labels: labels,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the label set we cannot set w/o the CLI, right?

Can we test this w/o building an ephemeral cluster? For example, after building this template, can we curl it to determine what these properties should look like?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can check those labels by inspecting created instance template in gcp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not see them in my instance template...can you share a screenie of what you mean given a similar example created with this CLI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about equivalent rest response, thanks @sagor999 ! 🤝

I was expecting to see labels on both the boot and local SSD disks, but, only see them on boot. 🤔 Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man.

	// Labels: Labels to apply to this disk. These can be later modified by
	// the disks.setLabels method. This field is only applicable for
	// persistent disks.
	Labels map[string]string `json:"labels,omitempty"`

Sigh. So I guess labels are ONLY supported for persistent disks. It is a benefit, since once we switch to PVC we will use much less local ssd drives.
But let me look a bit further into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, local ssd drives do not support labels, since they are so ephemeral. Only persistent disks support labels. :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated code to reflect that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roger that! I just wrapped an IDE incident, and it's time to get ice cream with the Mrs., so I"ll pick this up on Monday. 👋 🍨 🥄

Thank you for the update, bud, have a nice weekend! 🎉

@sagor999
Copy link
Contributor Author

sagor999 commented Jul 8, 2022

I will double check access scopes, those should have been correct with this --scopes 'storage-ro,compute-rw,monitoring,logging-write,cloud-platform'

@sagor999
Copy link
Contributor Author

sagor999 commented Jul 8, 2022

@kylos101 fixed API scopes. Thank you for catching it!

@sagor999 sagor999 requested a review from kylos101 July 8, 2022 18:53
@kylos101
Copy link
Contributor

@kylos101 fixed API scopes. Thank you for catching it!

👍 scopes seem off still, I might be doing something wrong? They appear to be granting full access.

I see this in gen54:
image

And this in awesome template:
image

@kylos101
Copy link
Contributor

Resolved meow:
image

Copy link
Contributor

@kylos101 kylos101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @sagor999 ! Appreciate your patience on this one.

@roboquat roboquat merged commit 28821e7 into main Jul 12, 2022
@roboquat roboquat deleted the pavel/gp-gcloud branch July 12, 2022 21:39
@roboquat roboquat added deployed: workspace Workspace team change is running in production deployed Change is completely running in production labels Jul 20, 2022
Copy link

@TuckerJN TuckerJN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: workspace Workspace team change is running in production deployed Change is completely running in production release-note-none size/XXL team: workspace Issue belongs to the Workspace team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants