Skip to content

Commit a6b3864

Browse files
committed
feat : support kubectl rollout history for statefulset
1 parent 2957526 commit a6b3864

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlRollout.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.kubernetes.client.openapi.models.V1ObjectMeta;
2626
import io.kubernetes.client.openapi.models.V1PodTemplateSpec;
2727
import io.kubernetes.client.openapi.models.V1ReplicaSet;
28+
import io.kubernetes.client.openapi.models.V1StatefulSet;
2829
import io.kubernetes.client.util.labels.LabelSelector;
2930
import java.util.ArrayList;
3031
import java.util.HashMap;
@@ -77,6 +78,10 @@ public List<History> execute() throws KubectlException {
7778
} else if (apiTypeClass.equals(V1DaemonSet.class)) {
7879
V1DaemonSet daemonSet = api.readNamespacedDaemonSet(name, namespace, null, null, null);
7980
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);
8085
} else {
8186
throw new KubectlException("Unsupported class for rollout history: " + apiTypeClass);
8287
}
@@ -171,6 +176,25 @@ private V1DaemonSet applyDaemonSetHistory(V1ControllerRevision history)
171176
PatchHelper.dryRunStrategyMergePatch(getGenericApi(), patch, namespace, name);
172177
}
173178

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+
174198
private void parseHistory(List<V1ControllerRevision> historyList, PodTemplateParser parser)
175199
throws ApiException, KubectlException {
176200
Map<Long, V1ControllerRevision> historyInfo = new HashMap<>();

0 commit comments

Comments
 (0)