fix : fix vs rewrite when mcp protocol is http (#2203)

This commit is contained in:
EricaLiu
2025-05-09 14:03:31 +08:00
committed by GitHub
parent cd271c1f87
commit 3f67b05fab

View File

@@ -689,7 +689,7 @@ func (w *watcher) getServiceCallback(server *provider.McpServer, configGroup, da
Meta: config.Meta{ Meta: config.Meta{
GroupVersionKind: gvk.ServiceEntry, GroupVersionKind: gvk.ServiceEntry,
Name: fmt.Sprintf("%s-%s-%s", provider.IstioMcpAutoGeneratedSeName, configGroup, strings.TrimSuffix(dataId, ".json")), Name: fmt.Sprintf("%s-%s-%s", provider.IstioMcpAutoGeneratedSeName, configGroup, strings.TrimSuffix(dataId, ".json")),
Namespace: w.namespace, Namespace: "mcp",
}, },
Spec: serviceEntry, Spec: serviceEntry,
} }
@@ -706,12 +706,12 @@ func (w *watcher) getServiceCallback(server *provider.McpServer, configGroup, da
w.cache.UpdateConfigCache(gvk.DestinationRule, configKey, dr, false) w.cache.UpdateConfigCache(gvk.DestinationRule, configKey, dr, false)
} }
w.cache.UpdateConfigCache(gvk.ServiceEntry, configKey, se, false) w.cache.UpdateConfigCache(gvk.ServiceEntry, configKey, se, false)
vs := w.buildVirtualServiceForMcpServer(serviceEntry, configGroup, dataId, path, server.Name) vs := w.buildVirtualServiceForMcpServer(serviceEntry, configGroup, dataId, path, server)
w.cache.UpdateConfigCache(gvk.VirtualService, configKey, vs, false) w.cache.UpdateConfigCache(gvk.VirtualService, configKey, vs, false)
} }
} }
func (w *watcher) buildVirtualServiceForMcpServer(serviceentry *v1alpha3.ServiceEntry, group, dataId, path, serverName string) *config.Config { func (w *watcher) buildVirtualServiceForMcpServer(serviceentry *v1alpha3.ServiceEntry, group, dataId, path, server *provider.McpServer) *config.Config {
if serviceentry == nil { if serviceentry == nil {
return nil return nil
} }
@@ -728,7 +728,7 @@ func (w *watcher) buildVirtualServiceForMcpServer(serviceentry *v1alpha3.Service
common2.CreateConvertedName(constants.IstioIngressGatewayName, cleanHost)) common2.CreateConvertedName(constants.IstioIngressGatewayName, cleanHost))
} }
routeName := fmt.Sprintf("%s-%s-%s", provider.IstioMcpAutoGeneratedHttpRouteName, group, strings.TrimSuffix(dataId, ".json")) routeName := fmt.Sprintf("%s-%s-%s", provider.IstioMcpAutoGeneratedHttpRouteName, group, strings.TrimSuffix(dataId, ".json"))
mergePath := "/" + serverName mergePath := "/" + server.Name
if w.McpServerBaseUrl != "/" { if w.McpServerBaseUrl != "/" {
mergePath = strings.TrimSuffix(w.McpServerBaseUrl, "/") + mergePath mergePath = strings.TrimSuffix(w.McpServerBaseUrl, "/") + mergePath
} }
@@ -762,6 +762,12 @@ func (w *watcher) buildVirtualServiceForMcpServer(serviceentry *v1alpha3.Service
}}, }},
} }
if server.Protocol == provider.McpStreambleProtocol {
vs.Http[0].Rewrite = &v1alpha3.HTTPRewrite{
Uri: path,
}
}
mcpServerLog.Debugf("construct virtualservice %v", vs) mcpServerLog.Debugf("construct virtualservice %v", vs)
return &config.Config{ return &config.Config{