-
Notifications
You must be signed in to change notification settings - Fork 26
fix service env issue and support specify service-name #56
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -166,8 +166,20 @@ func (h *AEnvServiceHandler) createService(w http.ResponseWriter, r *http.Reques | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ctx := r.Context() | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Generate service name | ||||||||||||||||||||||||||||||||||||||||||||||||
| serviceName := fmt.Sprintf("%s-svc-%s", aenvHubEnv.Name, RandString(6)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| // 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) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+169
to
+182
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block of code for determining the service name can be improved in two ways:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Get PVC name from deploy config, default to envName | ||||||||||||||||||||||||||||||||||||||||||||||||
| pvcName := aenvHubEnv.Name // Default PVC name equals envName | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -597,6 +597,9 @@ aenv service create | |||||||||||||||||||||||||
| # Create with explicit environment name | ||||||||||||||||||||||||||
| aenv service create myapp@1.0.0 | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Create with custom service name | ||||||||||||||||||||||||||
| aenv service create myapp@1.0.0 --service-name my-custom-service | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Create with 3 replicas and custom port (no storage) | ||||||||||||||||||||||||||
| aenv service create myapp@1.0.0 --replicas 3 --port 8000 | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -611,6 +614,7 @@ aenv service create myapp@1.0.0 -e DB_HOST=postgres -e CACHE_SIZE=1024 | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| | Option | Short | Description | Default | | ||||||||||||||||||||||||||
| |---|---|---|---| | ||||||||||||||||||||||||||
| | `--service-name` | `-s` | Custom service name (must follow Kubernetes DNS naming conventions) | auto-generated as `{envName}-svc-{random}` | | ||||||||||||||||||||||||||
| | `--replicas` | `-r` | Number of replicas | 1 or from config | | ||||||||||||||||||||||||||
| | `--port` | `-p` | Service port | 8080 or from config | | ||||||||||||||||||||||||||
| | `--env` | `-e` | Environment variables (KEY=VALUE) | - | | ||||||||||||||||||||||||||
|
|
@@ -637,6 +641,17 @@ Storage settings are read from `config.json`'s `deployConfig.service`: | |||||||||||||||||||||||||
| - When storage is enabled, replicas must be 1 (enforced by backend) | ||||||||||||||||||||||||||
| - Services run indefinitely without TTL | ||||||||||||||||||||||||||
| - Services get cluster DNS service URLs for internal access | ||||||||||||||||||||||||||
| - **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`) | ||||||||||||||||||||||||||
|
Comment on lines
+644
to
+649
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
|
||||||||||||||||||||||||||
| - The service name becomes: | ||||||||||||||||||||||||||
| - Kubernetes Deployment name | ||||||||||||||||||||||||||
| - Kubernetes Service name | ||||||||||||||||||||||||||
| - Service URL prefix: `{serviceName}.{namespace}.{domain}:{port}` | ||||||||||||||||||||||||||
| - Unique identifier for all operations (get, update, delete) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #### `service list` - List Services | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key
serviceName(camelCase) is being used to store the custom service name inDeployConfig. However, this PR is also fixing other keys inDeployConfigto use snake_case (e.g.,environment_variables). For consistency across the codebase, please useservice_name(snake_case) as the key.