Skip to content

feat: add code samples for Connect Gateway API #5299

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

Merged
merged 30 commits into from
May 29, 2025

Conversation

hodaaaaaaaaaa
Copy link
Contributor

@hodaaaaaaaaaa hodaaaaaaaaaa commented Apr 23, 2025

Description

Fixes b/369653672

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)
    Manually tested as the API call requires extensive setup shttps://cloud.google.com/kubernetes-engine/enterprise/multicluster-management/gateway/setup
  • 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)
    connectgateway.googleapis.com, gkehub.googleapis.com
  • 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

@hodaaaaaaaaaa hodaaaaaaaaaa requested review from a team as code owners April 23, 2025 21:39
@product-auto-label product-auto-label bot added api: connectgateway Issues related to the Connect Gateway API API. samples Issues that are directly related to samples. labels Apr 23, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @hodaaaaaaaaaa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces a new sample for connecting to the Connect Gateway. It adds a new directory connectgateway with Go modules and a sample Go program (list_namespaces.go) that demonstrates how to list namespaces in a Kubernetes cluster using the GKE Connect Gateway. The pull request also updates the .github/CODEOWNERS file to include codeowners for the new connectgateway directory.

Highlights

  • New Sample: Connect Gateway: A new sample directory connectgateway is added, showcasing how to connect to and interact with the GKE Connect Gateway using Go.
  • Go Modules: The pull request includes go.mod and go.sum files for managing dependencies required by the new sample.
  • List Namespaces Implementation: The list_namespaces.go file contains the implementation for listing Kubernetes namespaces using the GKE Connect Gateway.
  • Codeowners Update: The .github/CODEOWNERS file is updated to include the appropriate codeowners for the new connectgateway directory.

Changelog

Click here to see the changelog
  • .github/CODEOWNERS
    • Added /connectgateway/ with codeowners @GoogleCloudPlatform/go-samples-reviewers, @GoogleCloudPlatform/cloud-samples-reviewers, and @GoogleCloudPlatform/connect-gateway.
  • connectgateway/go.mod
    • Added a new go.mod file for the connectgateway sample.
    • Specifies the module name as main.
    • Declares dependencies on cloud.google.com/go/gkeconnect, golang.org/x/oauth2, k8s.io/api, k8s.io/apimachinery, and k8s.io/client-go.
  • connectgateway/go.sum
    • Added a new go.sum file for the connectgateway sample.
    • Lists the checksums of the dependencies specified in go.mod.
  • connectgateway/list_namespaces.go
    • Added a new Go program to list Kubernetes namespaces using the GKE Connect Gateway.
    • Includes functions to get the Gateway URL, configure the Kubernetes client, and call the List Namespaces API.
    • Uses cloud.google.com/go/gkeconnect/gateway/apiv1 to interact with the GKE Connect Gateway.
    • Uses k8s.io/client-go/kubernetes to interact with the Kubernetes API.
    • Accepts projectID, membershipID, membershipLocation, and serviceAccountKeyPath as command-line arguments.
  • go.mod
    • Added cloud.google.com/go/gkeconnect v0.12.1 as a dependency.
    • Added k8s.io/apimachinery v0.32.4 and k8s.io/client-go v0.32.4 as dependencies.
    • Added indirect dependencies related to kubernetes and other google cloud packages.
  • go.sum
    • Added checksums for cloud.google.com/go/gkeconnect v0.12.1.
    • Added checksums for k8s.io/apimachinery v0.32.4 and k8s.io/client-go v0.32.4.
    • Added checksums for indirect dependencies related to kubernetes and other google cloud packages.
  • go.work
    • Added ./connectgateway to the use directive to include the new module in the workspace.
    • Upgraded go version to 1.25
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A gateway to connect,
Kubernetes namespaces inspect,
Go code takes flight,
Listing with all its might,
Cloud samples, quite correct.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a new sample for connecting to a gateway using golang. The code appears to be well-structured and follows common Go practices. However, there are a few areas that could be improved for clarity and robustness.

Summary of Findings

  • Error Handling: The error handling in getGatewayURL could be improved by providing more context to the user about the specific failure.
  • Argument Validation: The main function could benefit from more robust argument validation to ensure that the program is called with the correct number of arguments and that the arguments are valid.
  • Dependency Versions: The go.mod file has a mix of specific versions and some older versions. It would be good to update these to the latest versions.

Merge Readiness

The pull request introduces a new sample and appears to be well-structured. However, there are a few areas that could be improved for clarity and robustness. I would recommend addressing the high severity issues before merging. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.

@hodaaaaaaaaaa hodaaaaaaaaaa changed the title Connect gateway Add code samples for Connect Gateway API Apr 24, 2025
@glasnt glasnt self-assigned this Apr 28, 2025
@glasnt glasnt added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 28, 2025
@glasnt
Copy link
Contributor

glasnt commented Apr 28, 2025

Googlers: see internal bug for updates

Copy link

snippet-bot bot commented May 1, 2025

Here is the summary of changes.

You are about to add 1 region tag.

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

@telpirion telpirion changed the title Add code samples for Connect Gateway API feat: add code samples for Connect Gateway API May 1, 2025
@telpirion telpirion self-assigned this May 1, 2025
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.

Hi @hodaaaaaaaaaa ,

Thank you for contributing this code sample! Please address the comments and I will take another look.

@glasnt glasnt removed their assignment May 2, 2025
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.

From my review, this looks very close to being ready. Thank you for addressing that first round of comments.

@glasnt -- please take another look when you get a chance.

@glasnt
Copy link
Contributor

glasnt commented May 8, 2025

Configuration changes look ok, I'm not a go-language code review to check that content.

I would ask why the root go.mod/go.sum files need changing for this sample, but if that's okay, then disregard.

@hodaaaaaaaaaa
Copy link
Contributor Author

Configuration changes look ok, I'm not a go-language code review to check that content.

I would ask why the root go.mod/go.sum files need changing for this sample, but if that's okay, then disregard.

@telpirion not updating the root go.mod/go.sum breaks the build since ./connectgateway is added to the workspace. Can you comment on whether this update is ok?

@hodaaaaaaaaaa
Copy link
Contributor Author

hodaaaaaaaaaa commented May 19, 2025

Configuration changes look ok, I'm not a go-language code review to check that content.
I would ask why the root go.mod/go.sum files need changing for this sample, but if that's okay, then disregard.

@telpirion not updating the root go.mod/go.sum breaks the build since ./connectgateway is added to the workspace. Can you comment on whether this update is ok?

I downgraded the version to 1.23 and removed the parent dir changes. All checks are passing now.

@hodaaaaaaaaaa hodaaaaaaaaaa requested a review from tonybayvas May 19, 2025 20:46
@glasnt glasnt removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 27, 2025
@telpirion telpirion merged commit bc50b3a into GoogleCloudPlatform:main May 29, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: connectgateway Issues related to the Connect Gateway API API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants