Skip to content

Commit 0b8ef9b

Browse files
committed
feat : support kubectl rollout history for statefulset
1 parent a0e4771 commit 0b8ef9b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.kubernetes.client.openapi.models.V1OwnerReference;
2727
import io.kubernetes.client.openapi.models.V1PodTemplateSpec;
2828
import io.kubernetes.client.openapi.models.V1ReplicaSet;
29+
import io.kubernetes.client.openapi.models.V1StatefulSet;
2930
import io.kubernetes.client.util.labels.LabelSelector;
3031
import java.util.ArrayList;
3132
import java.util.HashMap;
@@ -94,6 +95,11 @@ public ApiType execute() throws KubectlException {
9495
V1DaemonSet daemonSet = api.readNamespacedDaemonSet(name, namespace, null, null, null);
9596
daemonSetViewHistory(daemonSet, api);
9697
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;
97103
} else {
98104
throw new KubectlException("Unsupported class for rollout history: " + apiTypeClass);
99105
}
@@ -122,7 +128,7 @@ private void validate() throws KubectlException {
122128
msg.append("Missing namespace, ");
123129
}
124130
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);
126132
}
127133
if (msg.length() > 0) {
128134
throw new KubectlException(msg.toString());
@@ -181,6 +187,25 @@ private void daemonSetViewHistory(V1DaemonSet daemonSet, AppsV1Api api) throws A
181187
});
182188
}
183189

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+
184209
private V1DaemonSet applyDaemonSetHistory(V1DaemonSet ds, V1ControllerRevision history) {
185210
String dsJson = new JSON().serialize(ds);
186211
String patch = new JSON().serialize(history.getData());

0 commit comments

Comments
 (0)