Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Commit 35ec34b

Browse files
authored
Updated to fix Kubernetes scale issue (#3607)
1 parent ee73293 commit 35ec34b

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java

+20-13
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import io.kubernetes.client.openapi.models.V1Toleration;
6767
import io.kubernetes.client.openapi.models.V1Volume;
6868
import io.kubernetes.client.openapi.models.V1VolumeMount;
69+
import io.kubernetes.client.util.PatchUtils;
6970

7071
import okhttp3.Response;
7172

@@ -159,11 +160,8 @@ boolean restart(int shardId) {
159160
final int currentContainerCount = statefulSet.getSpec().getReplicas();
160161
final int newContainerCount = currentContainerCount + containersToAdd.size();
161162

162-
final V1StatefulSetSpec newSpec = new V1StatefulSetSpec();
163-
newSpec.setReplicas(newContainerCount);
164-
165163
try {
166-
doPatch(newSpec);
164+
patchStatefulsetReplicas(newContainerCount);
167165
} catch (ApiException ae) {
168166
throw new TopologyRuntimeManagementException(
169167
ae.getMessage() + "\ndetails\n" + ae.getResponseBody());
@@ -184,28 +182,37 @@ public void removeContainers(Set<PackingPlan.ContainerPlan> containersToRemove)
184182
final int currentContainerCount = statefulSet.getSpec().getReplicas();
185183
final int newContainerCount = currentContainerCount - containersToRemove.size();
186184

187-
final V1StatefulSetSpec newSpec = new V1StatefulSetSpec();
188-
newSpec.setReplicas(newContainerCount);
189-
190185
try {
191-
doPatch(newSpec);
186+
patchStatefulsetReplicas(newContainerCount);
192187
} catch (ApiException e) {
193188
throw new TopologyRuntimeManagementException(
194189
e.getMessage() + "\ndetails\n" + e.getResponseBody());
195190
}
196191
}
197192

198-
private void doPatch(V1StatefulSetSpec patchedSpec) throws ApiException {
193+
private void patchStatefulsetReplicas(int replicas) throws ApiException {
199194
final String body =
200195
String.format(JSON_PATCH_STATEFUL_SET_REPLICAS_FORMAT,
201-
patchedSpec.getReplicas().toString());
196+
replicas);
202197
final V1Patch patch = new V1Patch(body);
203-
appsClient.patchNamespacedStatefulSet(getTopologyName(),
204-
getNamespace(), patch, null, null, null, null);
198+
199+
PatchUtils.patch(V1StatefulSet.class,
200+
() ->
201+
appsClient.patchNamespacedStatefulSetCall(
202+
getTopologyName(),
203+
getNamespace(),
204+
patch,
205+
null,
206+
null,
207+
null,
208+
null,
209+
null),
210+
V1Patch.PATCH_FORMAT_JSON_PATCH,
211+
appsClient.getApiClient());
205212
}
206213

207214
private static final String JSON_PATCH_STATEFUL_SET_REPLICAS_FORMAT =
208-
"{\"op\":\"replace\",\"path\":\"/spec/replicas\",\"value\":%s}";
215+
"[{\"op\":\"replace\",\"path\":\"/spec/replicas\",\"value\":%d}]";
209216

210217
V1StatefulSet getStatefulSet() throws ApiException {
211218
return appsClient.readNamespacedStatefulSet(getTopologyName(), getNamespace(),

0 commit comments

Comments
 (0)