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

feat: consume reservation samples #4407

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

BigBlackWolf
Copy link
Collaborator

@BigBlackWolf BigBlackWolf commented Sep 26, 2024

Description

Samples, which demonstrates how to create reservation, which can be consumed by:

  • any instance
  • instance, which should specify exact reservation

doc link: https://cloud.google.com/compute/docs/instances/reservations-consume

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed Contributing Guidelines from CONTRIBUTING.MD
  • Tests pass: go test -v ./.. (see Testing)
  • Code formatted: gofmt (see Formatting)
  • Vetting pass: go vet (see Formatting)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Sep 26, 2024
@BigBlackWolf BigBlackWolf changed the title Feat: consume reservations Feat: consume reservation samples Sep 26, 2024
@BigBlackWolf BigBlackWolf marked this pull request as ready for review September 26, 2024 13:52
@BigBlackWolf BigBlackWolf requested review from a team as code owners September 26, 2024 13:52
Copy link

snippet-bot bot commented Sep 26, 2024

Here is the summary of changes.

You are about to add 2 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Collaborator

@telpirion telpirion left a comment

Choose a reason for hiding this comment

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

There are a couple core issues with this PR:

  1. There is more than one function per region tag
  2. It looks like there is a lot of duplication with existing samples.

See:
https://github.com/GoogleCloudPlatform/golang-samples/blob/main/compute/reservations/create_reservation.go

)

// Creates the reservation from given template in particular zone
func createConsumableReservation(w io.Writer, projectID, zone, reservationName, sourceTemplate string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: it looks like you're duplicating the same code, createConsumableReservation() twice. Let's not do that. If the snippet needs this to run, then put all of this code into the test file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've done it in this way, to be as close as possible to the gcloud example in documentation.
There it is done in 2 steps:

  1. shows how to create a reservation (yeah, in this case, consuming any reservation, it just duplicates existing sample)
  2. actual consuming

Therefore, I thought it would be consistent to keep 2 functions. Do you think it's better to remove first and keep only consumeAnyReservation()?

)

// Creates the reservation from given template in particular zone
func createSpecificConsumableReservation(w io.Writer, projectID, zone, reservationName, sourceTemplate string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: same as previous. If this function is required as a snippet, it should be in its own code file.

See: https://googlecloudplatform.github.io/samples-style-guide/#one-per-file

Also, it looks very similar to createConsumableReservation(). Is there any code that makes it unique compared to the other function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for pointing out, but here is the same situation. In gcloud example it is separated into 2 steps, but this is still a single sample.

Is there any code that makes it unique compared to the other function.

Yes, there is additional field, which makes the difference to consuming
SpecificReservationRequired: proto.Bool(true)

I can make all actions being made in a single function, will it be better?

@telpirion telpirion self-assigned this Sep 26, 2024
@telpirion telpirion changed the title Feat: consume reservation samples feat: consume reservation samples Sep 27, 2024
@BigBlackWolf BigBlackWolf enabled auto-merge (squash) October 1, 2024 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants