You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/09/06 07:34:15 UTC

[GitHub] [dubbo] chickenlj commented on a diff in pull request #10543: feat: replace kube-apiserver watch with informer

chickenlj commented on code in PR #10543:
URL: https://github.com/apache/dubbo/pull/10543#discussion_r963355099


##########
dubbo-kubernetes/src/main/java/org/apache/dubbo/registry/kubernetes/KubernetesServiceDiscovery.java:
##########
@@ -168,23 +167,23 @@ public void doUnregister(ServiceInstance serviceInstance) throws RuntimeExceptio
     @Override
     public Set<String> getServices() {
         return kubernetesClient
-            .services()
-            .inNamespace(namespace)
-            .list()
-            .getItems()
-            .stream()
-            .map(service -> service.getMetadata().getName())
-            .collect(Collectors.toSet());
+                .services()
+                .inNamespace(namespace)
+                .list()
+                .getItems()
+                .stream()
+                .map(service -> service.getMetadata().getName())
+                .collect(Collectors.toSet());
     }
 
     @Override
     public List<ServiceInstance> getInstances(String serviceName) throws NullPointerException {
         Endpoints endpoints =
-            kubernetesClient
-                .endpoints()
-                .inNamespace(namespace)
-                .withName(serviceName)
-                .get();
+                kubernetesClient
+                        .endpoints()
+                        .inNamespace(namespace)
+                        .withName(serviceName)
+                        .get();

Review Comment:
   This step seems to still needs to interact with api-server directly on every event. 
   
   Is it possible for us to use the informer cache directly on each event notification? Introducing Informer guarantees that all events will be received even on connection loss but the cache hasn't been fully used. 



##########
dubbo-kubernetes/src/main/java/org/apache/dubbo/registry/kubernetes/KubernetesMeshEnvListener.java:
##########
@@ -134,42 +139,48 @@ private void subscribeDr(String appName) {
 
         try {
             Watch watch = kubernetesClient
-                .customResource(
-                    MeshConstant.getDrDefinition())
-                .watch(namespace, appName, null, new ListOptionsBuilder().build(), new Watcher<String>() {
-                    @Override
-                    public void eventReceived(Action action, String resource) {
-                        logger.info("Received VS Rule notification. AppName: " + appName + " Action:" + action + " Resource:" + resource);
+                    .genericKubernetesResources(
+                            MeshConstant.getDrDefinition())
+                    .inNamespace(namespace)
+                    .withName(appName)
+                    .watch(new Watcher<GenericKubernetesResource>() {
+                        @Override
+                        public void eventReceived(Action action, GenericKubernetesResource resource) {
+                            if (logger.isInfoEnabled()) {
+                                logger.info("Received VS Rule notification. AppName: " + appName + " Action:" + action + " Resource:" + resource);
+                            }
 
-                        if (action == Action.ADDED || action == Action.MODIFIED) {
-                            Map drRuleMap = new Gson().fromJson(resource, Map.class);
-                            String drRule = new Yaml(new SafeConstructor()).dump(drRuleMap);
+                            if (action == Action.ADDED || action == Action.MODIFIED) {
+                                Map drRuleMap = new Gson().fromJson(resource.getMetadata().getName(), Map.class);

Review Comment:
   'drRuleMap' seems to be a rule but `resource.getMetadata().getName()` seems to be only a name.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org