Skip to content

Commit 856a342

Browse files
authored
Merge pull request kelproject#83 from Chris-Dee/add_rollout_undo
Add rollout undo feature support
2 parents ba184da + 4f95343 commit 856a342

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pykube/objects.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,33 @@ def ready(self):
169169
self.obj["status"]["updatedReplicas"] == self.replicas
170170
)
171171

172+
def rollout_undo(self, target_revision=None):
173+
"""Produces same action as kubectl rollout undo deployment command.
174+
Input variable is revision to rollback to (in kubectl, --to-revision)
175+
"""
176+
if target_revision is None:
177+
revision = {}
178+
else:
179+
revision = {
180+
"revision": target_revision
181+
}
182+
183+
params = {
184+
"kind": "DeploymentRollback",
185+
"apiVersion": self.version,
186+
"name": self.name,
187+
"rollbackTo": revision
188+
}
189+
190+
kwargs = {
191+
"version": self.version,
192+
"namespace": self.namespace,
193+
"operation": "rollback",
194+
}
195+
r = self.api.post(**self.api_kwargs(data=json.dumps(params), **kwargs))
196+
r.raise_for_status()
197+
return r.text
198+
172199

173200
class Endpoint(NamespacedAPIObject):
174201

0 commit comments

Comments
 (0)