Skip to content

Conversation

@JacksonMei
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @JacksonMei, 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 introduces enhanced flexibility for environment service creation by allowing users to define custom service names, which directly translates to Kubernetes resource names. It also includes robust validation for these custom names to adhere to Kubernetes standards. Furthermore, a critical fix for environment variable handling ensures that service configurations are correctly propagated across the system.

Highlights

  • Custom Service Naming: Users can now specify a custom service name when creating an environment service via the CLI and API, providing more control over Kubernetes resource naming.
  • Kubernetes Naming Validation: Custom service names are validated against Kubernetes DNS naming conventions to ensure compatibility and prevent deployment issues.
  • Environment Variable Fix: A bug was corrected where environment variables were not being properly applied due to a mismatch in key names (environmentVariables vs environment_variables) between different components.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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.

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
Collaborator

@kangoal kangoal left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@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

This pull request introduces the ability to specify a custom service name when creating a service, which is a great feature. The changes span across the Python client, Go backend, and documentation. My review focuses on improving the validation of the new service name, ensuring consistency in configuration keys, and simplifying some of the new logic. I've found a high-severity issue with the service name validation that could lead to invalid names being accepted by the CLI. I've also included suggestions to improve code style and documentation accuracy.

Comment on lines 228 to 240
if service_name:
import re
# Kubernetes DNS-1123 subdomain: lowercase alphanumeric, hyphens, dots; max 253 chars; must start/end with alphanumeric
dns_pattern = r'^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$'
if not re.match(dns_pattern, service_name) or len(service_name) > 253:
console.print(
"[red]Error:[/red] Invalid service name. Service name must:\n"
" - Use only lowercase letters, numbers, hyphens, and dots\n"
" - Start and end with an alphanumeric character\n"
" - Be no longer than 253 characters\n"
f" - Example: 'my-service', 'app-v1', 'web-frontend-prod'"
)
raise click.Abort()
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This validation block for service_name has a couple of issues:

  1. Incorrect Validation: The validation does not correctly enforce Kubernetes DNS-1123 label standards for a service name. It allows dots (.) and checks for a maximum length of 253 characters, while a service name (a single label) must not contain dots and be at most 63 characters long. This could lead to users providing invalid service names that will be rejected by the Kubernetes API.
  2. Local Import: The import re statement is inside the function. According to PEP 8, imports should be at the top of the file for better readability and to easily see module dependencies.

I've provided a code suggestion to fix the validation logic. Please also move import re to the top of the file.

Suggested change
if service_name:
import re
# Kubernetes DNS-1123 subdomain: lowercase alphanumeric, hyphens, dots; max 253 chars; must start/end with alphanumeric
dns_pattern = r'^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$'
if not re.match(dns_pattern, service_name) or len(service_name) > 253:
console.print(
"[red]Error:[/red] Invalid service name. Service name must:\n"
" - Use only lowercase letters, numbers, hyphens, and dots\n"
" - Start and end with an alphanumeric character\n"
" - Be no longer than 253 characters\n"
f" - Example: 'my-service', 'app-v1', 'web-frontend-prod'"
)
raise click.Abort()
if service_name:
# A Kubernetes service name must be a valid DNS-1123 label.
# - must be at most 63 characters long
# - must consist of lower case alphanumeric characters or '-'
# - must start and end with an alphanumeric character
dns_label_pattern = r'^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'
if not re.match(dns_label_pattern, service_name) or len(service_name) > 63:
console.print(
"[red]Error:[/red] Invalid service name. A service name must be a valid DNS-1123 label, which means it:\n"
" - Must be no longer than 63 characters\n"
" - Must use only lowercase letters, numbers, and hyphens ('-')\n"
" - Must start and end with an alphanumeric character\n"
f" - Example: 'my-service', 'app-v1', 'web-frontend-prod'"
)
raise click.Abort()

Comment on lines +121 to +123
if req.ServiceName != "" {
backendEnv.DeployConfig["serviceName"] = req.ServiceName
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The key serviceName (camelCase) is being used to store the custom service name in DeployConfig. However, this PR is also fixing other keys in DeployConfig to use snake_case (e.g., environment_variables). For consistency across the codebase, please use service_name (snake_case) as the key.

Suggested change
if req.ServiceName != "" {
backendEnv.DeployConfig["serviceName"] = req.ServiceName
}
if req.ServiceName != "" {
backendEnv.DeployConfig["service_name"] = req.ServiceName
}

Comment on lines +169 to +182
// Generate service name: use custom serviceName from DeployConfig if provided, otherwise auto-generate
var serviceName string
if customServiceName, ok := aenvHubEnv.DeployConfig["serviceName"]; ok {
if customServiceNameStr, ok := customServiceName.(string); ok && customServiceNameStr != "" {
serviceName = customServiceNameStr
klog.Infof("Using custom service name: %s", serviceName)
}
}

// If no custom serviceName provided, auto-generate using envName and random suffix
if serviceName == "" {
serviceName = fmt.Sprintf("%s-svc-%s", aenvHubEnv.Name, RandString(6))
klog.Infof("Auto-generated service name: %s", serviceName)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This block of code for determining the service name can be improved in two ways:

  1. Consistency: The key serviceName should be service_name to be consistent with other DeployConfig keys (like environment_variables) and the API request model. I've made a corresponding suggestion in api-service/controller/env_service.go.
  2. Readability: The logic can be refactored into a more concise if/else structure to improve readability.
Suggested change
// Generate service name: use custom serviceName from DeployConfig if provided, otherwise auto-generate
var serviceName string
if customServiceName, ok := aenvHubEnv.DeployConfig["serviceName"]; ok {
if customServiceNameStr, ok := customServiceName.(string); ok && customServiceNameStr != "" {
serviceName = customServiceNameStr
klog.Infof("Using custom service name: %s", serviceName)
}
}
// If no custom serviceName provided, auto-generate using envName and random suffix
if serviceName == "" {
serviceName = fmt.Sprintf("%s-svc-%s", aenvHubEnv.Name, RandString(6))
klog.Infof("Auto-generated service name: %s", serviceName)
}
// Generate service name: use custom serviceName from DeployConfig if provided, otherwise auto-generate
var serviceName string
if customName, ok := aenvHubEnv.DeployConfig["service_name"].(string); ok && customName != "" {
serviceName = customName
klog.Infof("Using custom service name: %s", serviceName)
} else {
serviceName = fmt.Sprintf("%s-svc-%s", aenvHubEnv.Name, RandString(6))
klog.Infof("Auto-generated service name: %s", serviceName)
}

Comment on lines +644 to +649
- **Service Name**: Custom service names must follow Kubernetes DNS naming conventions:
- Use only lowercase letters, numbers, hyphens, and dots
- Start and end with an alphanumeric character
- Be no longer than 253 characters
- Example: `my-service`, `app-v1`, `web-frontend-prod`
- If not specified, auto-generated as `{envName}-svc-{random}` (e.g., `myapp-svc-abc123`)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This documentation for service name constraints is incorrect and reflects the faulty validation logic in the CLI. A Kubernetes service name must be a DNS-1123 label, which does not allow dots and has a maximum length of 63 characters. The documentation should be updated to reflect the correct constraints.

Suggested change
- **Service Name**: Custom service names must follow Kubernetes DNS naming conventions:
- Use only lowercase letters, numbers, hyphens, and dots
- Start and end with an alphanumeric character
- Be no longer than 253 characters
- Example: `my-service`, `app-v1`, `web-frontend-prod`
- If not specified, auto-generated as `{envName}-svc-{random}` (e.g., `myapp-svc-abc123`)
- **Service Name**: Custom service names must follow Kubernetes DNS-1123 label standards:
- Must be no longer than 63 characters
- Must use only lowercase letters, numbers, and hyphens ('-')
- Must start and end with an alphanumeric character
- Example: `my-service`, `app-v1`, `web-frontend-prod`
- If not specified, auto-generated as `{envName}-svc-{random}` (e.g., `myapp-svc-abc123`)

@kangoal kangoal merged commit a65f5d9 into main Jan 19, 2026
1 check passed
@kangoal kangoal deleted the fix/service-env branch January 19, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants