|
45 | 45 | import java.security.NoSuchAlgorithmException;
|
46 | 46 | import java.time.ZoneOffset;
|
47 | 47 | import java.time.format.DateTimeFormatter;
|
| 48 | +import java.util.AbstractMap; |
48 | 49 | import java.util.Date;
|
49 | 50 | import java.util.List;
|
50 | 51 | import java.util.Map;
|
@@ -168,40 +169,30 @@ public T rollUpdate(T oldObj, T newObj) {
|
168 | 169 | }
|
169 | 170 | }
|
170 | 171 |
|
171 |
| - private static <T> T applyPatch(Resource<T> resource, List<Object> list, KubernetesSerialization serialization) { |
172 |
| - return resource.patch(PatchContext.of(PatchType.JSON), serialization.asJson(list)); |
| 172 | + private static <T> T applyPatch(Resource<T> resource, Map<String, Object> map, KubernetesSerialization serialization) { |
| 173 | + return resource.patch(PatchContext.of(PatchType.JSON_MERGE), serialization.asJson(map)); |
173 | 174 | }
|
174 | 175 |
|
175 | 176 | public static <T extends HasMetadata> T resume(RollableScalableResourceOperation<T, ?, ?> resource) {
|
176 |
| - return applyPatch(resource, RollingUpdater.requestPayLoadForRolloutResume(), resource.getKubernetesSerialization()); |
| 177 | + return applyPatch(resource, RollingUpdater.requestPayLoadForRollout(null), resource.getKubernetesSerialization()); |
177 | 178 | }
|
178 | 179 |
|
179 | 180 | public static <T extends HasMetadata> T pause(RollableScalableResourceOperation<T, ?, ?> resource) {
|
180 |
| - return applyPatch(resource, RollingUpdater.requestPayLoadForRolloutPause(), resource.getKubernetesSerialization()); |
| 181 | + return applyPatch(resource, RollingUpdater.requestPayLoadForRollout(Boolean.TRUE), resource.getKubernetesSerialization()); |
181 | 182 | }
|
182 | 183 |
|
183 | 184 | public static <T extends HasMetadata> T restart(RollableScalableResourceOperation<T, ?, ?> resource) {
|
184 | 185 | return applyPatch(resource, RollingUpdater.requestPayLoadForRolloutRestart(), resource.getKubernetesSerialization());
|
185 | 186 | }
|
186 | 187 |
|
187 |
| - public static List<Object> requestPayLoadForRolloutPause() { |
188 |
| - return List.of(Map.of( |
189 |
| - "op", "add", |
190 |
| - "path", "/spec/paused", |
191 |
| - "value", true)); |
| 188 | + public static Map<String, Object> requestPayLoadForRollout(Boolean paused) { |
| 189 | + return Map.of("spec", new AbstractMap.SimpleEntry<>("paused", paused)); |
192 | 190 | }
|
193 | 191 |
|
194 |
| - public static List<Object> requestPayLoadForRolloutResume() { |
195 |
| - return List.of(Map.of( |
196 |
| - "op", "remove", |
197 |
| - "path", "/spec/paused")); |
198 |
| - } |
199 |
| - |
200 |
| - public static List<Object> requestPayLoadForRolloutRestart() { |
201 |
| - return List.of(Map.of( |
202 |
| - "op", "add", |
203 |
| - "path", "/spec/template/metadata/annotations/kubectl.kubernetes.io~1restartedAt", |
204 |
| - "value", new Date().toInstant().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))); |
| 192 | + public static Map<String, Object> requestPayLoadForRolloutRestart() { |
| 193 | + String now = new Date().toInstant().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME); |
| 194 | + return Map.of("spec", |
| 195 | + Map.of("template", Map.of("metadata", Map.of("annotations", Map.of("kubectl.kubernetes.io/restartedAt", now))))); |
205 | 196 | }
|
206 | 197 |
|
207 | 198 | /**
|
|
0 commit comments