|
25 | 25 | import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
26 | 26 | import io.kubernetes.client.openapi.models.V1PodTemplateSpec;
|
27 | 27 | import io.kubernetes.client.openapi.models.V1ReplicaSet;
|
| 28 | +import io.kubernetes.client.openapi.models.V1StatefulSet; |
28 | 29 | import io.kubernetes.client.util.labels.LabelSelector;
|
29 | 30 | import java.util.ArrayList;
|
30 | 31 | import java.util.HashMap;
|
@@ -77,6 +78,10 @@ public List<History> execute() throws KubectlException {
|
77 | 78 | } else if (apiTypeClass.equals(V1DaemonSet.class)) {
|
78 | 79 | V1DaemonSet daemonSet = api.readNamespacedDaemonSet(name, namespace, null, null, null);
|
79 | 80 | daemonSetViewHistory(daemonSet, api);
|
| 81 | + } else if (apiTypeClass.equals(V1StatefulSet.class)) { |
| 82 | + V1StatefulSet statefulSet = |
| 83 | + api.readNamespacedStatefulSet(name, namespace, null, null, null); |
| 84 | + statefulSetViewHistory(statefulSet, api); |
80 | 85 | } else {
|
81 | 86 | throw new KubectlException("Unsupported class for rollout history: " + apiTypeClass);
|
82 | 87 | }
|
@@ -171,6 +176,25 @@ private V1DaemonSet applyDaemonSetHistory(V1ControllerRevision history)
|
171 | 176 | PatchHelper.dryRunStrategyMergePatch(getGenericApi(), patch, namespace, name);
|
172 | 177 | }
|
173 | 178 |
|
| 179 | + private void statefulSetViewHistory(V1StatefulSet statefulSet, AppsV1Api api) |
| 180 | + throws ApiException, KubectlException { |
| 181 | + LabelSelector selector = LabelSelector.parse(statefulSet.getSpec().getSelector()); |
| 182 | + List<V1ControllerRevision> historyList = controlledHistory(api, statefulSet, selector); |
| 183 | + parseHistory( |
| 184 | + historyList, |
| 185 | + history -> { |
| 186 | + V1StatefulSet stsOfHistory = applyStatefulSetHistory(history); |
| 187 | + return stsOfHistory.getSpec().getTemplate(); |
| 188 | + }); |
| 189 | + } |
| 190 | + |
| 191 | + private V1StatefulSet applyStatefulSetHistory(V1ControllerRevision history) |
| 192 | + throws KubectlException, ApiException { |
| 193 | + String patch = apiClient.getJSON().serialize(history.getData()); |
| 194 | + return (V1StatefulSet) |
| 195 | + PatchHelper.dryRunStrategyMergePatch(getGenericApi(), patch, namespace, name); |
| 196 | + } |
| 197 | + |
174 | 198 | private void parseHistory(List<V1ControllerRevision> historyList, PodTemplateParser parser)
|
175 | 199 | throws ApiException, KubectlException {
|
176 | 200 | Map<Long, V1ControllerRevision> historyInfo = new HashMap<>();
|
|
0 commit comments