Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump versions #144

Merged
merged 7 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Upload a build artifact
if: always() && steps.prepare-artifact.outcome == 'success'
continue-on-error: true
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: pull-request-payload
path: pull_request_payload.json
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-merge-conflict
- id: check-toml
Expand Down
2 changes: 1 addition & 1 deletion arthur/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def main() -> None:
intents=intents,
)
async with arthur.instance as bot:
await bot.start(CONFIG.token)
await bot.start(CONFIG.token.get_secret_value())


with arthur.logger.catch():
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion arthur/apis/cloudflare/zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from arthur.config import CONFIG

AUTH_HEADER = {"Authorization": f"Bearer {CONFIG.cloudflare_token}"}
AUTH_HEADER = {"Authorization": f"Bearer {CONFIG.cloudflare_token.get_secret_value()}"}


async def list_zones(
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions arthur/apis/kubernetes/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

async def list_certificates(namespace: str) -> dict[str, Any]:
"""List certificate objects created through cert-manager."""
async with ApiClient() as api:
api = client.CustomObjectsApi(api)
async with ApiClient() as api_client:
api = client.CustomObjectsApi(api_client)
return await api.list_namespaced_custom_object(
"cert-manager.io", "v1", namespace, "certificates"
)
8 changes: 4 additions & 4 deletions arthur/apis/kubernetes/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

async def restart_deployment(deployment: str, namespace: str) -> None:
"""Patch a deployment with a custom annotation to trigger redeployment."""
async with ApiClient() as api:
api = client.AppsV1Api(api)
async with ApiClient() as api_client:
api = client.AppsV1Api(api_client)
await api.patch_namespaced_deployment(
name=deployment,
namespace=namespace,
Expand All @@ -31,6 +31,6 @@ async def restart_deployment(deployment: str, namespace: str) -> None:

async def list_deployments(namespace: str) -> V1DeploymentList:
"""Query the Kubernetes API for a list of deployments in the provided namespace."""
async with ApiClient() as api:
api = client.AppsV1Api(api)
async with ApiClient() as api_client:
api = client.AppsV1Api(api_client)
return await api.list_namespaced_deployment(namespace=namespace)
12 changes: 6 additions & 6 deletions arthur/apis/kubernetes/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@

async def list_cronjobs(namespace: str | None = None) -> V1CronJobList:
"""Query the Kubernetes API for a list of cronjobss in the provided namespace."""
async with ApiClient() as api:
api = client.BatchV1Api(api)
async with ApiClient() as api_client:
api = client.BatchV1Api(api_client)
if namespace:
return await api.list_namespaced_cron_job(namespace)
return await api.list_cron_job_for_all_namespaces()


async def get_cronjob(namespace: str, cronjob_name: str) -> V1CronJob:
"""Fetch a cronjob given the name and namespace."""
async with ApiClient() as api:
api = client.BatchV1Api(api)
async with ApiClient() as api_client:
api = client.BatchV1Api(api_client)
return await api.read_namespaced_cron_job(cronjob_name, namespace)


async def create_job(namespace: str, job_name: str, cron_spec: dict[str, Any]) -> V1Job:
"""Create a job in the specified namespace with the given specification and name."""
async with ApiClient() as api:
api = client.BatchV1Api(api)
async with ApiClient() as api_client:
api = client.BatchV1Api(api_client)
return await api.create_namespaced_job(
namespace, V1Job(metadata={"name": job_name}, spec=cron_spec)
)
14 changes: 7 additions & 7 deletions arthur/apis/kubernetes/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

async def list_nodes() -> V1NodeList:
"""List Kubernetes nodes."""
async with ApiClient() as api:
api = client.CoreV1Api(api)
async with ApiClient() as api_client:
api = client.CoreV1Api(api_client)
return await api.list_node()


async def _change_cordon(node: str, cordon: bool) -> None:
async with ApiClient() as api:
api = client.CoreV1Api(api)
async def _change_cordon(node: str, *, cordon: bool) -> None:
async with ApiClient() as api_client:
api = client.CoreV1Api(api_client)
await api.patch_node(
node,
body={"spec": {"unschedulable": cordon}},
Expand All @@ -23,9 +23,9 @@ async def _change_cordon(node: str, cordon: bool) -> None:

async def cordon_node(node: str) -> None:
"""Cordon a Kubernetes node."""
await _change_cordon(node, True)
await _change_cordon(node, cordon=True)


async def uncordon_node(node: str) -> None:
"""Uncordon a Kubernetes node."""
await _change_cordon(node, False)
await _change_cordon(node, cordon=False)
7 changes: 3 additions & 4 deletions arthur/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ async def setup_hook(self) -> None:

await self.load_extensions(exts, sync_app_commands=False)

# jishaku doesn't support 3.11 yet.
# logger.info("Loading <red>jishaku</red>")
# await self.load_extension("jishaku")
# logger.info("Loaded <red>jishaku</red>")
logger.info("Loading <red>jishaku</red>")
await self.load_extension("jishaku")
logger.info("Loaded <red>jishaku</red>")

async def is_owner(self, user: User | Member) -> bool:
"""Check if the invoker is a bot owner."""
Expand Down
5 changes: 3 additions & 2 deletions arthur/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Utilities for interacting with the config for King Arthur."""

import pydantic
from pydantic_settings import BaseSettings


Expand All @@ -12,7 +13,7 @@ class Config(
"""Configuration for King Arthur."""

# Discord bot token
token: str
token: pydantic.SecretStr

# Discord bot prefix
prefixes: tuple[str, ...] = ("arthur ", "M-x ")
Expand All @@ -21,7 +22,7 @@ class Config(
devops_role: int = 409416496733880320

# Token for authorising with the Cloudflare API
cloudflare_token: str
cloudflare_token: pydantic.SecretStr

# Guild id
guild_id: int = 267624335836053506
Expand Down
2 changes: 1 addition & 1 deletion arthur/exts/fun/devops_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def rules_group(self, ctx: Context, rules: Greedy[int]) -> None:
)

@rules_group.command(name="refresh", aliases=("fetch", "update"))
async def update_rules(self, ctx: Context) -> None:
async def update_rules(self, _: Context) -> None:
"""Re-fetch the list of rules from notion."""
await self.cog_load()

Expand Down
10 changes: 5 additions & 5 deletions arthur/exts/kubernetes/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ async def certificates_list(self, ctx: commands.Context, namespace: str = "defau
"""List TLS certificates in the selected namespace (defaults to default)."""
certs = await certificates.list_certificates(namespace)

table_data = []

for certificate in certs["items"]:
table_data.append([
table_data = [
[
certificate["metadata"]["name"],
", ".join(certificate["spec"]["dnsNames"]),
certificate["spec"]["issuerRef"]["name"],
certificate["status"]["conditions"][0]["message"],
])
]
for certificate in certs["items"]
]

table = tabulate(
table_data, headers=["Name", "DNS Names", "Issuer", "Status"], tablefmt="psql"
Expand Down
3 changes: 2 additions & 1 deletion arthur/exts/kubernetes/deployments.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The Deployments cog helps with managing Kubernetes deployments."""

from http import HTTPStatus
from textwrap import dedent

from discord import ButtonStyle, Interaction, ui
Expand Down Expand Up @@ -42,7 +43,7 @@ async def confirm(self, interaction: Interaction, _button: ui.Button) -> None:
try:
await deployments.restart_deployment(self.deployment, self.namespace)
except ApiException as e:
if e.status == 404:
if e.status == HTTPStatus.NOT_FOUND:
return await interaction.message.edit(
content=generate_error_message(
description="Could not find deployment, check the namespace.",
Expand Down
2 changes: 0 additions & 2 deletions arthur/exts/kubernetes/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from arthur.bot import KingArthur
from arthur.config import CONFIG

# from arthur.utils import generate_error_message


class CronJobView(discord.ui.View):
"""This view allows users to select and trigger a CronJob."""
Expand Down
2 changes: 1 addition & 1 deletion arthur/exts/kubernetes/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def nodes_list(self, ctx: commands.Context) -> None:

if node.spec.taints:
for taint in node.spec.taints:
statuses.append(taint.effect)
statuses.append(taint.effect) # noqa: PERF401

node_creation = node.metadata.creation_timestamp

Expand Down
4 changes: 2 additions & 2 deletions arthur/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def generate_error_message(
return f"{emote} **{title}** {description}"


def datetime_to_discord(time: datetime, format: str = "f") -> str:
def datetime_to_discord(time: datetime, date_format: str = "f") -> str:
"""Convert a datetime object to a Discord timestamp."""
return f"<t:{int(time.timestamp())}:{format}>"
return f"<t:{int(time.timestamp())}:{date_format}>"
Loading
Loading