Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class KubernetesModelConverter {
private static final Splitter FIELD_SPLITTER = Splitter.on(Pattern.compile(" +")).trimResults().omitEmptyStrings();
private static final V1IngressBackend DEFAULT_MCP_BRIDGE_BACKEND = new V1IngressBackend();
private static final Set<String> SUPPORTED_ANNOTATIONS;
private static final Set<String> BUILT_IN_LABELS;
private static final Integer DEFAULT_WEIGHT = 100;
private static final String SERVICE_FQDN_TEMPLATE = "%s.%s.svc.%s";

Expand Down Expand Up @@ -149,6 +150,28 @@ public class KubernetesModelConverter {
}
}
SUPPORTED_ANNOTATIONS = Collections.unmodifiableSet(supportedAnnotations);

Set<String> builtInLabels = new HashSet<>();
for (Field field : KubernetesConstants.Label.class.getFields()) {
if ((field.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL)) == 0) {
continue;
}
if (field.getType() != String.class) {
continue;
}
if (!field.getName().endsWith("_KEY")) {
continue;
}
try {
builtInLabels.add((String)field.get(null));
} catch (IllegalAccessException e) {
log.error("Failed to get label key from field: {}", field.getName(), e);
}
}
// To be compatible with com.alibaba.higress.sdk.service.mcp.McpServiceContextImpl.isMcpServerRoute
// TODO: Remove after refactoring com.alibaba.higress.sdk.service.mcp.McpServiceContextImpl.isMcpServerRoute
builtInLabels.remove(KubernetesConstants.Label.RESOURCE_BIZ_TYPE_KEY);
BUILT_IN_LABELS = Collections.unmodifiableSet(builtInLabels);
}

public KubernetesModelConverter(KubernetesClientService kubernetesClientService) {
Expand Down Expand Up @@ -1012,7 +1035,13 @@ private void fillCustomLabels(Route route, V1ObjectMeta metadata) {
if (metadata == null || MapUtils.isEmpty(metadata.getLabels())) {
return;
}
route.setCustomLabels(metadata.getLabels());
Map<String, String> customLabels = new HashMap<>();
for (Map.Entry<String, String> label : metadata.getLabels().entrySet()) {
if (isCustomLabel(label.getKey())) {
customLabels.put(label.getKey(), label.getValue());
}
}
route.setCustomLabels(customLabels);
}

private static void fillPathRoute(Route route, V1ObjectMeta metadata, V1HTTPIngressPath path) {
Expand Down Expand Up @@ -2048,4 +2077,11 @@ private static boolean isCustomAnnotation(String key) {
}
return true;
}

private static boolean isCustomLabel(String key) {
if (key.startsWith(KubernetesConstants.Label.DOMAIN_KEY_PREFIX)) {
return false;
}
return !BUILT_IN_LABELS.contains(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ private void filterMcpServers(List<McpServer> resultList, McpServerPageQuery que
}
}

// TODO: Use another way instead of customLabels to determine whether the route is bound to mcpServer
private boolean isMcpServerRoute(Map<String, String> customLabels) {
if (MapUtils.isEmpty(customLabels)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public void route2IngressTestPrefixPathSingleService() {

V1Ingress ingress = converter.route2Ingress(route);

V1Ingress expectedIngress = buildBasicSupportedIngress();
V1Ingress expectedIngress = buildBasicSupportedIngress(false);

V1ObjectMeta expectedMetadata = expectedIngress.getMetadata();
expectedMetadata.setName(route.getName());
Expand Down Expand Up @@ -615,7 +615,7 @@ public void route2IngressTestPrefixPathSingleServiceWithWeight() {

V1Ingress ingress = converter.route2Ingress(route);

V1Ingress expectedIngress = buildBasicSupportedIngress();
V1Ingress expectedIngress = buildBasicSupportedIngress(false);

V1ObjectMeta expectedMetadata = expectedIngress.getMetadata();
expectedMetadata.setName(route.getName());
Expand Down Expand Up @@ -643,7 +643,7 @@ public void route2IngressTestPrefixPathSingleServiceWithPort() {

V1Ingress ingress = converter.route2Ingress(route);

V1Ingress expectedIngress = buildBasicSupportedIngress();
V1Ingress expectedIngress = buildBasicSupportedIngress(false);

V1ObjectMeta expectedMetadata = expectedIngress.getMetadata();
expectedMetadata.setName(route.getName());
Expand Down Expand Up @@ -671,7 +671,7 @@ public void route2IngressTestPrefixPathSingleServiceWithPortAndVersion() {

V1Ingress ingress = converter.route2Ingress(route);

V1Ingress expectedIngress = buildBasicSupportedIngress();
V1Ingress expectedIngress = buildBasicSupportedIngress(false);

V1ObjectMeta expectedMetadata = expectedIngress.getMetadata();
expectedMetadata.setName(route.getName());
Expand Down Expand Up @@ -701,7 +701,7 @@ public void route2IngressTestPrefixPathMultipleServices() {

V1Ingress ingress = converter.route2Ingress(route);

V1Ingress expectedIngress = buildBasicSupportedIngress();
V1Ingress expectedIngress = buildBasicSupportedIngress(false);

V1ObjectMeta expectedMetadata = expectedIngress.getMetadata();
expectedMetadata.setName(route.getName());
Expand Down Expand Up @@ -730,7 +730,7 @@ public void route2IngressTestExactPathSingleService() {

V1Ingress ingress = converter.route2Ingress(route);

V1Ingress expectedIngress = buildBasicSupportedIngress();
V1Ingress expectedIngress = buildBasicSupportedIngress(false);

V1ObjectMeta expectedMetadata = expectedIngress.getMetadata();
expectedMetadata.setName(route.getName());
Expand Down Expand Up @@ -758,7 +758,7 @@ public void route2IngressTestRegularPathSingleService() {

V1Ingress ingress = converter.route2Ingress(route);

V1Ingress expectedIngress = buildBasicSupportedIngress();
V1Ingress expectedIngress = buildBasicSupportedIngress(false);

V1ObjectMeta expectedMetadata = expectedIngress.getMetadata();
expectedMetadata.setName(route.getName());
Expand Down Expand Up @@ -1934,13 +1934,19 @@ public void domainName2ConfigMapNameTestWildcardDomainNameConfigMapNameCreated()
}

private V1Ingress buildBasicSupportedIngress() {
return buildBasicSupportedIngress(true);
}

private V1Ingress buildBasicSupportedIngress(boolean setDefinerLabel) {
V1Ingress ingress = new V1Ingress();

V1ObjectMeta metadata = new V1ObjectMeta();
metadata.setNamespace(DEFAULT_NAMESPACE);
KubernetesUtil.setLabel(metadata, "higress.io/domain_higress-default-domain", "true");
KubernetesUtil.setLabel(metadata, KubernetesConstants.Label.RESOURCE_DEFINER_KEY,
KubernetesConstants.Label.RESOURCE_DEFINER_VALUE);
if (setDefinerLabel) {
KubernetesUtil.setLabel(metadata, KubernetesConstants.Label.RESOURCE_DEFINER_KEY,
KubernetesConstants.Label.RESOURCE_DEFINER_VALUE);
}
ingress.setMetadata(metadata);

V1IngressSpec spec = new V1IngressSpec();
Expand Down Expand Up @@ -1981,10 +1987,7 @@ private static Route buildBasicRoute() {
route.setPath(new RoutePredicate());
route.setCors(new CorsConfig());
route.setCustomConfigs(new HashMap<>());
route.setCustomLabels(
MapUtil.of(KubernetesConstants.Label.RESOURCE_DEFINER_KEY, KubernetesConstants.Label.RESOURCE_DEFINER_VALUE,
KubernetesConstants.Label.DOMAIN_KEY_PREFIX + HigressConstants.DEFAULT_DOMAIN,
KubernetesConstants.Label.DOMAIN_VALUE_DUMMY));
route.setCustomLabels(new HashMap<>());
route.setReadonly(false);
return route;
}
Expand Down
Loading