From 3feb71488e40e2b8038d085cf6a47b8b944deb88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=88=E9=93=AD?= Date: Wed, 20 Mar 2024 19:32:20 +0800 Subject: [PATCH] support sofa registry kubernetes --- .../sofa/rpc/registry/kubernetes/KubernetesRegistry.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/registry/registry-kubernetes/src/main/java/com/alipay/sofa/rpc/registry/kubernetes/KubernetesRegistry.java b/registry/registry-kubernetes/src/main/java/com/alipay/sofa/rpc/registry/kubernetes/KubernetesRegistry.java index a8cd501b2..8f77bb7c5 100644 --- a/registry/registry-kubernetes/src/main/java/com/alipay/sofa/rpc/registry/kubernetes/KubernetesRegistry.java +++ b/registry/registry-kubernetes/src/main/java/com/alipay/sofa/rpc/registry/kubernetes/KubernetesRegistry.java @@ -125,6 +125,8 @@ public void register(ProviderConfig config) { podResource.edit(pod -> new PodBuilder(pod).editOrNewMetadata() // 将ProviderConfig存在Annotations上 .addToAnnotations(dataId, JSON.toJSONString(config, true)) + // 为了过滤而不是订阅全部pod + .addToLabels(dataId, "") .endMetadata().build()); } } @@ -154,6 +156,7 @@ public void unRegister(ProviderConfig config) { podResource.edit(pod -> new PodBuilder(pod).editOrNewMetadata() .removeFromAnnotations(dataId) + .removeFromLabels(dataId) .endMetadata() .build()); } @@ -189,9 +192,11 @@ public List subscribe(ConsumerConfig config) { ProviderInfoListener providerInfoListener = config.getProviderInfoListener(); kubernetesRegistryProviderWatcher.addProviderListener(config, providerInfoListener); + String dataId = KubernetesRegistryHelper.buildDataId(config, config.getProtocol()); FilterWatchListDeletable podPodListPodResourceFilterWatchListDeletable = kubernetesClient.pods() - .inNamespace(namespace); + .inNamespace(namespace) + .withLabel(dataId); SharedIndexInformer inform = podPodListPodResourceFilterWatchListDeletable.inform(new ResourceEventHandler() { @Override