|
26 | 26 | import io.kubernetes.client.openapi.models.V1OwnerReference;
|
27 | 27 | import io.kubernetes.client.openapi.models.V1PodTemplateSpec;
|
28 | 28 | import io.kubernetes.client.openapi.models.V1ReplicaSet;
|
| 29 | +import io.kubernetes.client.openapi.models.V1StatefulSet; |
29 | 30 | import io.kubernetes.client.util.labels.LabelSelector;
|
30 | 31 | import java.util.ArrayList;
|
31 | 32 | import java.util.HashMap;
|
@@ -94,6 +95,11 @@ public ApiType execute() throws KubectlException {
|
94 | 95 | V1DaemonSet daemonSet = api.readNamespacedDaemonSet(name, namespace, null, null, null);
|
95 | 96 | daemonSetViewHistory(daemonSet, api);
|
96 | 97 | return (ApiType) daemonSet;
|
| 98 | + } else if (apiTypeClass.equals(V1StatefulSet.class)) { |
| 99 | + V1StatefulSet statefulSet = |
| 100 | + api.readNamespacedStatefulSet(name, namespace, null, null, null); |
| 101 | + statefulSetViewHistory(statefulSet, api); |
| 102 | + return (ApiType) statefulSet; |
97 | 103 | } else {
|
98 | 104 | throw new KubectlException("Unsupported class for rollout history: " + apiTypeClass);
|
99 | 105 | }
|
@@ -122,7 +128,7 @@ private void validate() throws KubectlException {
|
122 | 128 | msg.append("Missing namespace, ");
|
123 | 129 | }
|
124 | 130 | if (revision < 0) {
|
125 |
| - msg.append("revision must be a positive integer: ").append(revision); |
| 131 | + msg.append("Revision must be a positive integer: ").append(revision); |
126 | 132 | }
|
127 | 133 | if (msg.length() > 0) {
|
128 | 134 | throw new KubectlException(msg.toString());
|
@@ -181,6 +187,25 @@ private void daemonSetViewHistory(V1DaemonSet daemonSet, AppsV1Api api) throws A
|
181 | 187 | });
|
182 | 188 | }
|
183 | 189 |
|
| 190 | + private void statefulSetViewHistory(V1StatefulSet statefulSet, AppsV1Api api) |
| 191 | + throws ApiException { |
| 192 | + LabelSelector selector = LabelSelector.parse(statefulSet.getSpec().getSelector()); |
| 193 | + List<V1ControllerRevision> historyList = controlledHistory(api, statefulSet, selector); |
| 194 | + parseHistory( |
| 195 | + historyList, |
| 196 | + history -> { |
| 197 | + V1StatefulSet stsOfHistory = applyStatefulSetHistory(statefulSet, history); |
| 198 | + return stsOfHistory.getSpec().getTemplate(); |
| 199 | + }); |
| 200 | + } |
| 201 | + |
| 202 | + private V1StatefulSet applyStatefulSetHistory(V1StatefulSet sts, V1ControllerRevision history) { |
| 203 | + String stsJson = new JSON().serialize(sts); |
| 204 | + String patch = new JSON().serialize(history.getData()); |
| 205 | + String patched = applyDirectivePatch(stsJson, patch); |
| 206 | + return new JSON().deserialize(patched, V1StatefulSet.class); |
| 207 | + } |
| 208 | + |
184 | 209 | private V1DaemonSet applyDaemonSetHistory(V1DaemonSet ds, V1ControllerRevision history) {
|
185 | 210 | String dsJson = new JSON().serialize(ds);
|
186 | 211 | String patch = new JSON().serialize(history.getData());
|
|
0 commit comments