wu-sheng commented on a change in pull request #4959:
URL: https://github.com/apache/skywalking/pull/4959#discussion_r455741399



##########
File path: all-dependencies-es7.txt
##########
@@ -0,0 +1,211 @@
+HdrHistogram-2.1.9.jar

Review comment:
       I think this should not be committed? And the next file?

##########
File path: oap-server/server-bootstrap/src/main/resources/application.yml
##########
@@ -264,6 +264,10 @@ configuration:
     period: ${SW_CONFIG_CONSUL_PERIOD:1}
     # Consul aclToken
     aclToken: ${SW_CONFIG_CONSUL_ACL_TOKEN:""}
+  k8s_configmap:

Review comment:
       ```suggestion
     k8s-configmap:
   ```
   
   Same here, by following other module and provider style.

##########
File path: oap-server/server-configuration/configuration-k8s_configmap/pom.xml
##########
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  ~
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <parent>
+        <artifactId>server-configuration</artifactId>
+        <groupId>org.apache.skywalking</groupId>
+        <version>8.1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>configuration-k8s_configmap</artifactId>

Review comment:
       `oap-server/server-configuration/configuration-k8s_configmap` should be 
`oap-server/server-configuration/configuration-k8s-configmap`

##########
File path: 
oap-server/server-configuration/configuration-k8s_configmap/src/main/java/org/apache/skywalking/oap/server/configuration/configmap/ConfigurationConfigmapInformer.java
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.configuration.configmap;
+
+import io.kubernetes.client.informer.SharedIndexInformer;
+import io.kubernetes.client.informer.SharedInformerFactory;
+import io.kubernetes.client.informer.cache.Lister;
+import io.kubernetes.client.openapi.ApiClient;
+import io.kubernetes.client.openapi.apis.CoreV1Api;
+import io.kubernetes.client.openapi.models.V1ConfigMap;
+import io.kubernetes.client.openapi.models.V1ConfigMapList;
+import io.kubernetes.client.util.Config;
+import java.io.IOException;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class ConfigurationConfigmapInformer {
+
+    private Lister<V1ConfigMap> configMapLister;
+
+    private SharedInformerFactory factory;
+
+    private final ExecutorService executorService = 
Executors.newSingleThreadExecutor(r -> {
+        Thread thread = new Thread(r, 
"SKYWALKING_KUBERNETES_CONFIGURATION_INFORMER");
+        thread.setDaemon(true);
+        return thread;
+    });
+
+    public ConfigurationConfigmapInformer(ConfigmapConfigurationSettings 
settings) {
+
+        try {
+            doStartConfigMapInformer(settings);
+            doAddShutdownHook();
+        } catch (IOException e) {
+            log.error("cannot connect with api server in kubernetes", e);
+        }
+
+    }
+
+    private void doAddShutdownHook() {
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            if (Objects.nonNull(factory)) {
+                factory.stopAllRegisteredInformers();
+            }
+        }));
+    }
+
+    private void doStartConfigMapInformer(final ConfigmapConfigurationSettings 
settings) throws IOException {
+        ApiClient apiClient = Config.defaultClient();
+        
apiClient.setHttpClient(apiClient.getHttpClient().newBuilder().readTimeout(0, 
TimeUnit.SECONDS).build());
+        CoreV1Api coreV1Api = new CoreV1Api(apiClient);
+
+        factory = new SharedInformerFactory(executorService);
+
+        SharedIndexInformer<V1ConfigMap> configMapSharedIndexInformer = 
factory.sharedIndexInformerFor(
+            params -> coreV1Api.listNamespacedConfigMapCall(
+                settings.getNamespace(), null, null, null, null, 
settings.getLabelSelector()
+                , 1, params.resourceVersion, params.timeoutSeconds, 
params.watch, null
+            ),
+            V1ConfigMap.class, V1ConfigMapList.class
+        );
+
+        factory.startAllRegisteredInformers();
+        configMapLister = new 
Lister<>(configMapSharedIndexInformer.getIndexer());
+
+    }
+
+    public Optional<V1ConfigMap> configMap() {
+
+        return Optional.ofNullable(configMapLister.list().size() == 1 ? 
configMapLister.list().get(0) : null);
+

Review comment:
       Many emtpy lines, please polish the code format.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to