Skip to content

Commit e677d88

Browse files
committed
changes for code review
1 parent b56e717 commit e677d88

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Apollo Java 2.4.0
1212
* [Feature Support Kubernetes ConfigMap cache for Apollo java, golang client](https://github.com/apolloconfig/apollo-java/pull/79)
1313
* [Feature support pulling configuration information from multiple AppIds](https://github.com/apolloconfig/apollo-java/pull/70)
1414
* [Fix monitor arg cause npe](https://github.com/apolloconfig/apollo-java/pull/86)
15+
* [Feature reduce conflicts when update configmap in k8](https://github.com/apolloconfig/apollo-java/pull/93)
1516

1617
------------------
1718
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/4?closed=1)

apollo-client/src/main/java/com/ctrip/framework/apollo/kubernetes/KubernetesManager.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,20 @@
4040
import java.util.Objects;
4141
import java.util.concurrent.TimeUnit;
4242

43+
/**
44+
* Manages Kubernetes ConfigMap operations.
45+
* Required Kubernetes permissions:
46+
* - pods: [get, list] - For pod selection and write eligibility
47+
* - configmaps: [get, create, update] - For ConfigMap operations
48+
*/
4349
@Service
4450
public class KubernetesManager {
4551
private static final Logger logger = LoggerFactory.getLogger(KubernetesManager.class);
4652

53+
private static final String RUNNING_POD_FIELD_SELECTOR = "status.phase=Running";
54+
55+
private static final int MAX_SEARCH_NUM = 1000;
56+
4757
private ApiClient client;
4858
private CoreV1Api coreV1Api;
4959
private int propertyKubernetesMaxWritePods;
@@ -244,8 +254,8 @@ private boolean isWritePod(String k8sNamespace) {
244254
String labelSelector = "app=" + appName;
245255

246256
V1PodList v1PodList = coreV1Api.listNamespacedPod(k8sNamespace, null, null,
247-
null, null, labelSelector,
248-
null, null, null
257+
null, RUNNING_POD_FIELD_SELECTOR, labelSelector,
258+
MAX_SEARCH_NUM, null, null
249259
, null, null);
250260

251261
return v1PodList.getItems().stream()

apollo-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@
126126
"description": "kubernetes configmap namespace.",
127127
"defaultValue": "default"
128128
},
129+
{
130+
"name": "apollo.cache.kubernetes.max-write-pods",
131+
"type": "java.lang.String",
132+
"sourceType": "com.ctrip.framework.apollo.util.ConfigUtil",
133+
"description": "max number of pods that can write the configmap cache in Kubernetes.",
134+
"defaultValue": "3"
135+
},
129136
{
130137
"name": "apollo.property.order.enable",
131138
"type": "java.lang.Boolean",

0 commit comments

Comments
 (0)