aboutsummaryrefslogtreecommitdiffstats
path: root/arthur/exts/kubernetes/deployments.py
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2021-07-18 03:45:47 +0100
committerGravatar Joe Banks <[email protected]>2021-07-18 03:45:47 +0100
commit46d6d22819009f73bcdc9256d0f49fdde24fe792 (patch)
treecf4119094a3555c2a63c20fdc6aeda445a32c19a /arthur/exts/kubernetes/deployments.py
parentfeat: add spice to confirmation options (diff)
fix: linting fixes
Diffstat (limited to 'arthur/exts/kubernetes/deployments.py')
-rw-r--r--arthur/exts/kubernetes/deployments.py93
1 files changed, 50 insertions, 43 deletions
diff --git a/arthur/exts/kubernetes/deployments.py b/arthur/exts/kubernetes/deployments.py
index 2ae5db6..401dd2b 100644
--- a/arthur/exts/kubernetes/deployments.py
+++ b/arthur/exts/kubernetes/deployments.py
@@ -14,6 +14,30 @@ from arthur.bot import KingArthur
from arthur.utils import generate_error_embed
+async def restart_deployment(deployment: str, namespace: str) -> None:
+ """Patch a deployment with a custom annotation to trigger redeployment."""
+ async with ApiClient() as api:
+ v1 = client.AppsV1Api(api)
+ await v1.patch_namespaced_deployment(
+ name=deployment,
+ namespace=namespace,
+ body={
+ "spec": {
+ "template": {
+ "metadata": {
+ "annotations": {
+ "king-arthur.pydis.com/restartedAt": datetime.now(
+ timezone.utc
+ ).isoformat()
+ }
+ }
+ }
+ }
+ },
+ field_manager="King Arthur",
+ )
+
+
class Deployments(commands.Cog):
"""Commands for working with Kubernetes Deployments."""
@@ -106,7 +130,10 @@ class Deployments(commands.Cog):
await msg.edit(
embed=Embed(
title="What is the airspeed velocity of an unladen swallow?",
- description="Whatever the answer may be, it's certainly faster than you could select a confirmation option.",
+ description=(
+ "Whatever the answer may be, it's certainly "
+ "faster than you could select a confirmation option.",
+ ),
colour=Colour.greyple(),
),
components=[],
@@ -122,54 +149,34 @@ class Deployments(commands.Cog):
),
)
else:
- async with ApiClient() as api:
- v1 = client.AppsV1Api(api)
-
- try:
- await v1.patch_namespaced_deployment(
- name=deployment,
- namespace=namespace,
- body={
- "spec": {
- "template": {
- "metadata": {
- "annotations": {
- "king-arthur.pydis.com/restartedAt": datetime.now(
- timezone.utc
- ).isoformat()
- }
- }
- }
- }
- },
- field_manager="King Arthur",
- )
- except ApiException as e:
- if e.status == 404:
- return await interaction.respond(
- ephemeral=False,
- embed=generate_error_embed(
- description="Could not find deployment, check the namespace.",
- ),
- )
-
+ try:
+ await restart_deployment(deployment, namespace)
+ except ApiException as e:
+ if e.status == 404:
return await interaction.respond(
ephemeral=False,
embed=generate_error_embed(
- description=f"Unexpected error occurred, error code {e.status}"
- ),
- )
- else:
- description = f"Restarted deployment `{deployment}` in namespace `{namespace}`."
- await interaction.respond(
- ephemeral=False,
- embed=Embed(
- title="Redeployed",
- description=description,
- colour=Colour.blurple(),
+ description="Could not find deployment, check the namespace.",
),
)
+ return await interaction.respond(
+ ephemeral=False,
+ embed=generate_error_embed(
+ description=f"Unexpected error occurred, error code {e.status}"
+ ),
+ )
+ else:
+ description = f"Restarted deployment `{deployment}` in namespace `{namespace}`."
+ await interaction.respond(
+ ephemeral=False,
+ embed=Embed(
+ title="Redeployed",
+ description=description,
+ colour=Colour.blurple(),
+ ),
+ )
+
for component in components.components:
component.disabled = True