From 20b48b19a2df4849a173982d5acc7df81b9ce8e0 Mon Sep 17 00:00:00 2001 From: CH3CHO Date: Tue, 12 Nov 2024 12:30:03 +0800 Subject: [PATCH] fix: Fix some bugs in AI console APIs 1. Grant permission to operate EnvoyFilters in helm chart. 2. Generate fallback resources in AiRouteServiceImpl.add as well. 3. Fill some default values shown as null previously. --- .../sdk/service/ai/AiRouteServiceImpl.java | 21 +++++++++++++++++++ helm/templates/clusterrole.yaml | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ai/AiRouteServiceImpl.java b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ai/AiRouteServiceImpl.java index dc7b065a..90237837 100644 --- a/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ai/AiRouteServiceImpl.java +++ b/backend/sdk/src/main/java/com/alibaba/higress/sdk/service/ai/AiRouteServiceImpl.java @@ -114,6 +114,7 @@ public AiRouteServiceImpl(KubernetesModelConverter kubernetesModelConverter, @Override public AiRoute add(AiRoute route) { fillDefaultValues(route); + V1ConfigMap configMap = kubernetesModelConverter.aiRoute2ConfigMap(route); V1ConfigMap newConfigMap; try { @@ -126,6 +127,7 @@ public AiRoute add(AiRoute route) { } writeAiRouteResources(route); + writeAiRouteFallbackResources(route); return kubernetesModelConverter.configMap2AiRoute(newConfigMap); } @@ -168,6 +170,7 @@ public void delete(String routeName) { @Override public AiRoute update(AiRoute route) { fillDefaultValues(route); + V1ConfigMap configMap = kubernetesModelConverter.aiRoute2ConfigMap(route); V1ConfigMap updatedConfigMap; try { @@ -187,11 +190,29 @@ public AiRoute update(AiRoute route) { } private void fillDefaultValues(AiRoute route) { + fillDefaultWeights(route.getUpstreams()); AiModelPredicate modelPredicate = route.getModelPredicate(); if (modelPredicate != null && Boolean.TRUE.equals(modelPredicate.getEnabled()) && StringUtils.isEmpty(modelPredicate.getPrefix())) { modelPredicate.setPrefix(route.getName()); } + AiRouteFallbackConfig fallbackConfig = route.getFallbackConfig(); + if (fallbackConfig != null && Boolean.TRUE.equals(fallbackConfig.getEnabled())) { + fillDefaultWeights(fallbackConfig.getUpstreams()); + if (StringUtils.isEmpty(fallbackConfig.getFallbackStrategy())) { + fallbackConfig.setFallbackStrategy(AiRouteFallbackStrategy.RANDOM); + } + } + } + + private void fillDefaultWeights(List upstreams) { + if (upstreams == null || upstreams.size() != 1) { + return; + } + AiUpstream upstream = upstreams.get(0); + if (upstream != null) { + upstream.setWeight(100); + } } private void writeAiRouteResources(AiRoute aiRoute) { diff --git a/helm/templates/clusterrole.yaml b/helm/templates/clusterrole.yaml index 13b0a062..1d7e5444 100644 --- a/helm/templates/clusterrole.yaml +++ b/helm/templates/clusterrole.yaml @@ -25,4 +25,6 @@ rules: - apiGroups: ["extensions.higress.io"] resources: ["wasmplugins"] verbs: ["*"] - + - apiGroups: ["networking.istio.io"] + resources: ["envoyfilters"] + verbs: ["*"]