diff --git a/CHANGES.md b/CHANGES.md index a8e204cf..4c398433 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ Apollo Java 2.4.0 * [Feature Support Kubernetes ConfigMap cache for Apollo java, golang client](https://github.com/apolloconfig/apollo-java/pull/79) * [Feature support pulling configuration information from multiple AppIds](https://github.com/apolloconfig/apollo-java/pull/70) * [Fix monitor arg cause npe](https://github.com/apolloconfig/apollo-java/pull/86) +* [Feature reduce conflicts when update configmap in k8](https://github.com/apolloconfig/apollo-java/pull/93) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/4?closed=1) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/kubernetes/KubernetesManager.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/kubernetes/KubernetesManager.java index 76824e08..3e778ce5 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/kubernetes/KubernetesManager.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/kubernetes/KubernetesManager.java @@ -44,6 +44,10 @@ public class KubernetesManager { private static final Logger logger = LoggerFactory.getLogger(KubernetesManager.class); + private static final String RUNNING_POD_FIELD_SELECTOR = "status.phase=Running"; + + private static final int MAX_SEARCH_NUM = 1000; + private ApiClient client; private CoreV1Api coreV1Api; private int propertyKubernetesMaxWritePods; @@ -244,8 +248,8 @@ private boolean isWritePod(String k8sNamespace) { String labelSelector = "app=" + appName; V1PodList v1PodList = coreV1Api.listNamespacedPod(k8sNamespace, null, null, - null, null, labelSelector, - null, null, null + null, RUNNING_POD_FIELD_SELECTOR, labelSelector, + MAX_SEARCH_NUM, null, null , null, null); return v1PodList.getItems().stream() diff --git a/apollo-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/apollo-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 1a268b52..5b425ee0 100644 --- a/apollo-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/apollo-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -126,6 +126,13 @@ "description": "kubernetes configmap namespace.", "defaultValue": "default" }, + { + "name": "apollo.cache.kubernetes.max-write-pods", + "type": "java.lang.String", + "sourceType": "com.ctrip.framework.apollo.util.ConfigUtil", + "description": "max number of pods that can write the configmap cache in Kubernetes.", + "defaultValue": "3" + }, { "name": "apollo.property.order.enable", "type": "java.lang.Boolean",