-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add spring cloud gateway cli #8037
Changes from all commits
cf29687
5e50736
036a88c
dc0c56f
eb0ef11
3a60fdb
c6b0743
b5a96de
26cb728
813a1ca
218c10e
28bcc64
6d6e81e
5dac9c2
2e47e63
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 |
---|---|---|
|
@@ -213,7 +213,7 @@ def load_command_table(self, args): | |
with self.command_group('containerapp job replica', is_preview=True) as g: | ||
g.custom_show_command('list', 'list_replica_containerappsjob') | ||
|
||
with self.command_group('containerapp env java-component nacos') as g: | ||
with self.command_group('containerapp env java-component nacos', is_preview=True) as g: | ||
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. Why update 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. The nacos should be in preview status, and the preview is removed from java component level, we need add the preview back to nacos level. Just add in this pr for convenience |
||
g.custom_command('create', 'create_nacos', supports_no_wait=True) | ||
g.custom_command('update', 'update_nacos', supports_no_wait=True) | ||
g.custom_show_command('show', 'show_nacos') | ||
|
@@ -225,6 +225,12 @@ def load_command_table(self, args): | |
g.custom_show_command('show', 'show_admin_for_spring') | ||
g.custom_command('delete', 'delete_admin_for_spring', confirmation=True, supports_no_wait=True) | ||
|
||
with self.command_group('containerapp env java-component gateway-for-spring', is_preview=True) as g: | ||
g.custom_command('create', 'create_gateway_for_spring', supports_no_wait=True) | ||
g.custom_command('update', 'update_gateway_for_spring', supports_no_wait=True) | ||
g.custom_show_command('show', 'show_gateway_for_spring') | ||
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. what about list? 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. The list command is consistent with other Java components at the Java component level. |
||
g.custom_command('delete', 'delete_gateway_for_spring', confirmation=True, supports_no_wait=True) | ||
|
||
with self.command_group('containerapp env dotnet-component', is_preview=True) as g: | ||
g.custom_command('list', 'list_dotnet_components') | ||
g.custom_show_command('show', 'show_dotnet_component') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
from azure.cli.core.commands import AzCliCommand | ||
from azure.cli.core.azclierror import ValidationError, CLIInternalError | ||
from azure.cli.command_modules.containerapp.base_resource import BaseResource | ||
from azure.cli.command_modules.containerapp._decorator_utils import load_yaml_file | ||
from azure.cli.core.commands.client_factory import get_subscription_id | ||
|
||
from ._constants import CONTAINER_APPS_RP, MANAGED_ENVIRONMENT_RESOURCE_TYPE | ||
|
@@ -61,10 +62,14 @@ def get_argument_min_replicas(self): | |
def get_argument_max_replicas(self): | ||
return self.get_param("max_replicas") | ||
|
||
def get_argument_route_yaml(self): | ||
return self.get_param("route_yaml") | ||
|
||
def construct_payload(self): | ||
self.java_component_def["properties"]["componentType"] = self.get_argument_target_java_component_type() | ||
self.set_up_service_bindings() | ||
self.set_up_unbind_service_bindings() | ||
self.set_up_gateway_route() | ||
if self.get_argument_min_replicas() is not None and self.get_argument_max_replicas() is not None: | ||
self.java_component_def["properties"]["scale"] = { | ||
"minReplicas": self.get_argument_min_replicas(), | ||
|
@@ -149,7 +154,7 @@ def set_up_service_bindings(self): | |
self.java_component_def["properties"]["serviceBinds"].append(update_item) | ||
|
||
def set_up_unbind_service_bindings(self): | ||
if self.get_argument_unbind_service_bindings(): | ||
if self.get_argument_unbind_service_bindings() is not None: | ||
new_template = self.java_component_def.setdefault("properties", {}) | ||
existing_template = self.java_component_def["properties"] | ||
|
||
|
@@ -165,3 +170,47 @@ def set_up_unbind_service_bindings(self): | |
if item in service_bindings_dict: | ||
new_template["serviceBinds"] = [binding for binding in new_template["serviceBinds"] if | ||
binding["name"] != item] | ||
|
||
def set_up_gateway_route(self): | ||
if self.get_argument_route_yaml() is not None: | ||
self.java_component_def["properties"]["springCloudGatewayRoutes"] = self.process_loaded_scg_route() | ||
|
||
def process_loaded_scg_route(self): | ||
yaml_scg_routes = load_yaml_file(self.get_argument_route_yaml()) | ||
|
||
# Check if the loaded YAML is a dictionary | ||
if not isinstance(yaml_scg_routes, dict): | ||
raise ValidationError('Invalid YAML provided. Please see https://aka.ms/gateway-for-spring-routes-yaml for a valid Gateway for Spring routes YAML spec.') | ||
|
||
# Ensure that 'springCloudGatewayRoutes' is present and is a list (can be empty) | ||
routes = yaml_scg_routes.get('springCloudGatewayRoutes') | ||
if routes is None: | ||
return [] | ||
|
||
if not isinstance(routes, list): | ||
raise ValidationError('The "springCloudGatewayRoutes" field must be a list. Please see https://aka.ms/gateway-for-spring-routes-yaml for a valid Gateway for Spring routes YAML spec.') | ||
|
||
# Loop through each route and validate the required fields | ||
for route in routes: | ||
if not isinstance(route, dict): | ||
raise ValidationError('Each route must be a dictionary. Please see https://aka.ms/gateway-for-spring-routes-yaml for a valid Gateway for Spring routes YAML spec.') | ||
|
||
# Ensure each route has 'id' and 'uri' fields | ||
if 'id' not in route or not route['id']: | ||
raise ValidationError(f'Route is missing required "id" field: {route} Please see https://aka.ms/gateway-for-spring-routes-yaml for a valid Gateway for Spring routes YAML spec.') | ||
|
||
if 'uri' not in route or not route['uri']: | ||
raise ValidationError(f'Route is missing required "uri" field: {route} Please see https://aka.ms/gateway-for-spring-routes-yaml for a valid Gateway for Spring routes YAML spec.') | ||
|
||
# Ensure predicates and filters are lists; set to empty lists if not provided | ||
if 'predicates' not in route: | ||
route['predicates'] = [] | ||
elif not isinstance(route['predicates'], list): | ||
raise ValidationError(f'The "predicates" field must be a list in route {route["id"]}. Please see https://aka.ms/gateway-for-spring-routes-yaml for a valid Gateway for Spring routes YAML spec.') | ||
|
||
if 'filters' not in route: | ||
route['filters'] = [] | ||
elif not isinstance(route['filters'], list): | ||
raise ValidationError(f'The "filters" field must be a list in route {route["id"]}. Please see https://aka.ms/gateway-for-spring-routes-yaml for a valid Gateway for Spring routes YAML spec.') | ||
Comment on lines
+181
to
+214
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. Should we put these check in the RP? If you put them in CLI, if schema in the RP change, it will break CLI. 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. Sync with rp coder, we do not have such kind of check in RP, the check is still necessary for a short time period. |
||
|
||
return yaml_scg_routes.get('springCloudGatewayRoutes') |
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.
I tried https://aka.ms/gateway-for-spring-routes-yaml
But seems it doesn't work.
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 link will point to our SCG doc, we will release the doc after the cli released, and make the link available.