From 52f9de349600e08a0b991226e0063b471b316cc2 Mon Sep 17 00:00:00 2001 From: 24kpure <1033237526@qq.com> Date: Tue, 24 Dec 2024 18:00:45 +0800 Subject: [PATCH] changes for code review --- CHANGES.md | 1 + .../apollo/kubernetes/KubernetesManager.java | 14 ++++++++++++-- .../additional-spring-configuration-metadata.json | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c2f6ac72..10017ab8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ Apollo Java 2.4.0 * [Fix monitor arg cause npe](https://github.com/apolloconfig/apollo-java/pull/86) * [Fix the concurrent issue in SpringValueRegistry.scanAndClean](https://github.com/apolloconfig/apollo-java/pull/95) * [Feature support incremental configuration synchronization client](https://github.com/apolloconfig/apollo-java/pull/90) +* [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..14f87bab 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 @@ -40,10 +40,20 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; +/** + * Manages Kubernetes ConfigMap operations. + * Required Kubernetes permissions: + * - pods: [get, list] - For pod selection and write eligibility + * - configmaps: [get, create, update] - For ConfigMap operations + */ @Service 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 +254,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",