Conversation
Signed-off-by: aicee <hhbin2000@foxmail.com>
There was a problem hiding this comment.
Summary of Changes
Hello @zrggw, 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!
This pull request significantly enhances Kmesh's command-line interface by providing a dedicated and comprehensive tool for managing IPsec encryption keys. This new functionality streamlines the process of securing inter-node communication within Kmesh deployments, offering users direct control over the lifecycle of these critical security assets.
Highlights
- New kmeshctl secret command: Introduces a new top-level command kmeshctl secret to manage IPsec encryption keys for Kmesh's secure communication.
- Comprehensive IPsec Secret Management: The kmeshctl secret command now includes create, get, and delete subcommands, allowing users to fully manage IPsec secrets stored as Kubernetes secrets.
- Flexible Key Creation: The create subcommand supports generating cryptographically secure random keys automatically or accepting a user-defined hexadecimal key string.
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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
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.
Keys in secret kept,Network whispers, safe and sound,Kmesh guards the way.
Footnotes
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces a new kmeshctl secret command with create, get, and delete subcommands to manage IPsec secrets. The implementation is well-structured, using cobra for the CLI and interacting with the Kubernetes API to manage secrets. The documentation has also been updated accordingly. My review focuses on improving context handling in Kubernetes API calls. I've identified several places where context.TODO() is used, and I recommend replacing it with the command's context (cmd.Context()) for proper cancellation and timeout handling. This is important for making the CLI tool more robust and well-behaved.
|
|
||
| ipSecKey.Length = AeadAlgoICVLength | ||
|
|
||
| secretOld, err := clientset.Kube().CoreV1().Secrets(utils.KmeshNamespace).Get(context.TODO(), SecretName, metav1.GetOptions{}) |
There was a problem hiding this comment.
Using context.TODO() is not recommended as it provides an empty, non-cancellable context. Since this function already receives the cmd object from cobra, you should use cmd.Context() for all Kubernetes API calls. This allows for proper cancellation (e.g., if the user presses Ctrl+C) and timeout handling. This change should be applied to all Kubernetes client calls in this function (lines 151, 184, and 190).
| secretOld, err := clientset.Kube().CoreV1().Secrets(utils.KmeshNamespace).Get(context.TODO(), SecretName, metav1.GetOptions{}) | |
| secretOld, err := clientset.Kube().CoreV1().Secrets(utils.KmeshNamespace).Get(cmd.Context(), SecretName, metav1.GetOptions{}) |
| func GetSecret() { | ||
| clientset := createKubeClientOrExit() | ||
|
|
||
| secret, err := clientset.Kube().CoreV1().Secrets(utils.KmeshNamespace).Get(context.TODO(), SecretName, metav1.GetOptions{}) |
There was a problem hiding this comment.
The GetSecret function uses context.TODO() for its Kubernetes API call. To enable proper context propagation and cancellation, the function should accept the command's context. You should change the function signature to func GetSecret(cmd *cobra.Command) and use cmd.Context(). You will also need to update the call to this function in the getCmd definition (line 85) to pass cmd.
| func GetSecret() { | |
| clientset := createKubeClientOrExit() | |
| secret, err := clientset.Kube().CoreV1().Secrets(utils.KmeshNamespace).Get(context.TODO(), SecretName, metav1.GetOptions{}) | |
| func GetSecret(cmd *cobra.Command) { | |
| clientset := createKubeClientOrExit() | |
| secret, err := clientset.Kube().CoreV1().Secrets(utils.KmeshNamespace).Get(cmd.Context(), SecretName, metav1.GetOptions{}) |
| func DeleteSecret() { | ||
| clientset := createKubeClientOrExit() | ||
|
|
||
| err := clientset.Kube().CoreV1().Secrets(utils.KmeshNamespace).Delete(context.TODO(), SecretName, metav1.DeleteOptions{}) |
There was a problem hiding this comment.
Similar to GetSecret, the DeleteSecret function uses context.TODO(). It should be updated to accept the command's context for proper cancellation handling. Please change the function signature to func DeleteSecret(cmd *cobra.Command), use cmd.Context() for the API call, and update the call site at line 96 to pass the cmd object.
| func DeleteSecret() { | |
| clientset := createKubeClientOrExit() | |
| err := clientset.Kube().CoreV1().Secrets(utils.KmeshNamespace).Delete(context.TODO(), SecretName, metav1.DeleteOptions{}) | |
| func DeleteSecret(cmd *cobra.Command) { | |
| clientset := createKubeClientOrExit() | |
| err := clientset.Kube().CoreV1().Secrets(utils.KmeshNamespace).Delete(cmd.Context(), SecretName, metav1.DeleteOptions{}) |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new kmeshctl secret command for comprehensive IPsec secret management in Kubernetes. The command provides create, get, and delete operations for IPsec encryption keys used in secure node-to-node communication.
- Adds three subcommands:
create,get, anddeletefor IPsec secret lifecycle management - Supports both auto-generated and user-defined encryption keys with proper validation
- Includes comprehensive documentation for all command variants
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| ctl/secret/secret.go | Implements the core secret management functionality with create, get, and delete operations |
| docs/ctl/kmeshctl_secret.md | Updated main command documentation with examples for all subcommands |
| docs/ctl/kmeshctl_secret_create.md | Documentation for the create subcommand with user-defined key support |
| docs/ctl/kmeshctl_secret_get.md | New documentation for retrieving and displaying IPsec configurations |
| docs/ctl/kmeshctl_secret_delete.md | New documentation for deleting IPsec secrets |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if !cmd.Flags().Changed("key") { | ||
| aeadKey = make([]byte, AeadKeyLength) | ||
| _, err := rand.Read(aeadKey) | ||
| if err != nil { | ||
| log.Errorf("failed to generate random key: %v", err) | ||
| os.Exit(1) | ||
| } | ||
| } else { | ||
| aeadKey, err = hex.DecodeString(aeadKeyArg) | ||
| if err != nil { | ||
| log.Errorf("failed to decode hex string: %v, input: %v", err, aeadKeyArg) | ||
| os.Exit(1) | ||
| } | ||
| } |
There was a problem hiding this comment.
[nitpick] The key generation and validation logic should be extracted into separate functions to improve readability and testability. Consider creating generateRandomKey() and validateUserKey() functions.
- Fix spacing around & operators in BPF macros to match CI expectations - Regenerate kmeshctl documentation after adding secret command - Apply consistent code formatting via make gen Signed-off-by: aicee <hhbin2000@foxmail.com>
Signed-off-by: aicee <hhbin2000@foxmail.com>
Signed-off-by: aicee <hhbin2000@foxmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Signed-off-by: aicee <hhbin2000@foxmail.com>
Signed-off-by: aicee <hhbin2000@foxmail.com>
ctl/secret/secret.go
Outdated
| } | ||
|
|
||
| func GetSecret() { | ||
| clientset := createKubeClientOrExit() |
There was a problem hiding this comment.
Ithink can move the client builde out of all the functions Get/Delete/Create
Signed-off-by: aicee <hhbin2000@foxmail.com>
| ) | ||
|
|
||
| var log = logger.NewLoggerScope("kmeshctl/secret") | ||
| var clientset kube.CLIClient |
There was a problem hiding this comment.
Basically i am not a fan of global varible, you can pass the client in the function arguments
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hzxuzhonghu The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind enhancement
What this PR does / why we need it:
This PR introduces a new
kmeshctl secretcommand that provides comprehensive management of IPsec encryption keys for Kmesh's secure communication between nodes. The command enables users to create, retrieve, and delete IPsec secrets stored as Kubernetes secrets.Command Structure
Documentation
kmeshctl_secret.md- Main command overviewkmeshctl_secret_create.md- Create command detailskmeshctl_secret_get.md- Get command detailskmeshctl_secret_delete.md- Delete command detailsWhich issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: