Skip to content

Commit

Permalink
Merge pull request #147 from minrk/delete-stopped-pods
Browse files Browse the repository at this point in the history
delete pods that have stopped
  • Loading branch information
minrk committed Mar 16, 2018
2 parents 2fc303e + fcb5098 commit 86386e8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def _hub_connect_port_default(self):
set this with::
c.KubeSpawner.start_timeout = 60 * 5 # Upto 5 minutes
"""
)

Expand Down Expand Up @@ -781,6 +781,16 @@ def _hub_connect_port_default(self):
"""
)

delete_stopped_pods = Bool(
True,
config=True,
help="""
Whether to delete pods that have stopped themselves.
Set to False to leave stopped pods in the completed state,
allowing for easier debugging of why they may have stopped.
"""
)

def _expand_user_properties(self, template):
# Make sure username and servername match the restrictions for DNS labels
safe_chars = set(string.ascii_lowercase + string.digits)
Expand Down Expand Up @@ -979,6 +989,9 @@ def poll(self):
# return exit code if notebook container has terminated
if c.name == 'notebook':
if c.state.terminated:
# call self.stop to delete the pod
if self.delete_stopped_pods:
yield self.stop(now=True)
return c.state.terminated.exit_code
break
# None means pod is running or starting up
Expand Down Expand Up @@ -1059,6 +1072,7 @@ def stop(self, now=False):
grace_seconds = 1

delete_options.grace_period_seconds = grace_seconds
self.log.info("Deleting pod %s", self.pod_name)
yield self.asynchronize(
self.api.delete_namespaced_pod,
name=self.pod_name,
Expand Down

0 comments on commit 86386e8

Please sign in to comment.