Skip to content

Commit

Permalink
Add smtp port for mastodon, add valkey restore to restore_mastodon,…
Browse files Browse the repository at this point in the history
… and update textual + rich (#327)

* remove unused function from nextcloud

* clean up the restore_mastodon function

* document smtp_port for mastodon secret keys

* update textual to 0.84, rich to 13.9 and smol-k8s-lab version to 5.18.0

* add restores for valkey primary and replica

* valkey-primary and valkey-replica pvcs added to mastodon restore individually

* make smtp port a string instead of an int for mastodon

* change pvc storage underscore to a hyphen
  • Loading branch information
jessebot authored Oct 23, 2024
1 parent eb60c8c commit 1f94f39
Show file tree
Hide file tree
Showing 7 changed files with 351 additions and 312 deletions.
174 changes: 85 additions & 89 deletions docs/assets/images/screenshots/help_text.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/k8s_apps/mastodon.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ apps:
restic_snapshot_ids:
seaweedfs_volume: latest
seaweedfs_filer: latest
mastodon_valkey_primary: latest
mastodon_valkey_replica: latest
values:
# admin user
admin_user: "tootadmin"
Expand Down Expand Up @@ -108,6 +110,9 @@ apps:
argo:
# secrets keys to make available to Argo CD ApplicationSets
secret_keys:
# smtp port on your mail server
smtp_port: '25'
# admin user for your mastodon instance
admin_user: tootadmin
# hostname that users go to in the browser
hostname: ""
Expand Down
399 changes: 207 additions & 192 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "smol_k8s_lab"
version = "5.17.4"
version = "5.18.0"
description = "CLI and TUI to quickly install slimmer Kubernetes distros and then manage apps declaratively using Argo CD"
authors = ["Jesse Hitch <[email protected]>",
"Max Roby <[email protected]>"]
Expand Down Expand Up @@ -40,10 +40,10 @@ pyjwt = "^2.9"
python = ">=3.11,<3.13"
pyyaml = "^6.0"
requests = "^2.32"
rich = "^13.8"
rich = "^13.9"
ruamel-yaml = "^0.18"
ruamel-yaml-string = "^0.1"
textual = "^0.83.0"
textual = "^0.84"
xdg-base-dirs = "^6.0"
pygame = "^2.5"
python-ulid = "^3.0"
Expand Down
5 changes: 5 additions & 0 deletions smol_k8s_lab/config/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,8 @@ apps:
# seaweedfs_master: latest
seaweedfs_volume: latest
seaweedfs_filer: latest
mastodon_valkey_primary: latest
mastodon_valkey_replica: latest
values:
# admin user
admin_user: "tootadmin"
Expand Down Expand Up @@ -840,6 +842,9 @@ apps:
argo:
# secrets keys to make available to Argo CD ApplicationSets
secret_keys:
# smtp port on your mail server
smtp_port: '25'
# admin user for your mastodon instance
admin_user: tootadmin
# hostname that users go to in the browser
hostname: ""
Expand Down
73 changes: 46 additions & 27 deletions smol_k8s_lab/k8s_apps/social/mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from smol_k8s_lab.k8s_apps.operators.minio import create_minio_alias
from smol_k8s_lab.k8s_apps.social.mastodon_secrets import generate_mastodon_secrets
from smol_k8s_lab.k8s_tools.argocd_util import ArgoCD
from smol_k8s_lab.k8s_tools.restores import restore_seaweedfs, restore_cnpg_cluster
from smol_k8s_lab.k8s_tools.restores import (restore_seaweedfs,
k8up_restore_pvc,
restore_cnpg_cluster)
from smol_k8s_lab.utils.passwords import create_password
from smol_k8s_lab.utils.rich_cli.console_logging import sub_header, header
from smol_k8s_lab.utils.run.subproc import subproc
Expand Down Expand Up @@ -453,14 +455,15 @@ def setup_bitwarden_items(argocd: ArgoCD,
f"Recieved: {e}"
)


def restore_mastodon(argocd: ArgoCD,
mastodon_hostname: str,
mastodon_namespace: str,
argo_dict: dict,
secrets: dict,
restore_dict: dict,
backup_dict: dict,
pvc_storage_class: str,
global_pvc_storage_class: str,
pgsql_cluster_name: str,
bitwarden: BwCLI) -> None:
"""
Expand All @@ -475,20 +478,18 @@ def restore_mastodon(argocd: ArgoCD,
restic_repo_password = backup_dict['restic_repo_pass']
cnpg_backup_schedule = backup_dict['postgres_schedule']


# apply the external secrets so we can immediately use them for restores
# ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️
# WARNING: change this back to main when done testing
# ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️
revision = argo_dict.get("revision", "add-pvc-helm-chart-for-mastodon")
argo_path = argo_dict["path"]
# get argo git repo info
revision = argo_dict['revision']
argo_path = argo_dict['path']

# first we grab existing bitwarden items if they exist
if bitwarden:
refresh_bweso(argocd, mastodon_hostname, bitwarden)

# apply the external secrets so we can immediately use them for restores
external_secrets_yaml = (
"https://raw.githubusercontent.com/small-hack/argocd-apps/"
f"{revision}/{argo_path}/external_secrets_argocd_appset.yaml"
f"https://raw.githubusercontent.com/small-hack/argocd-apps/{revision}/"
f"{argo_path}external_secrets_argocd_appset.yaml"
)
argocd.k8s.apply_manifests(external_secrets_yaml, argocd.namespace)

Expand All @@ -505,8 +506,10 @@ def restore_mastodon(argocd: ArgoCD,

# then we create all the seaweedfs pvcs we lost and restore them
snapshot_ids = restore_dict['restic_snapshot_ids']
s3_pvc_storage_class = secrets.get("s3_pvc_storage_class", global_pvc_storage_class)

restore_seaweedfs(
argocd.k8s,
argocd,
'mastodon',
mastodon_namespace,
revision,
Expand All @@ -517,35 +520,51 @@ def restore_mastodon(argocd: ArgoCD,
secret_access_key,
restic_repo_password,
s3_pvc_capacity,
pvc_storage_class,
s3_pvc_storage_class,
"ReadWriteOnce",
snapshot_ids['seaweedfs_volume'],
snapshot_ids['seaweedfs_filer']
)
snapshot_ids['seaweedfs_filer'])

# then we finally can restore the postgres database :D
if restore_dict.get("cnpg_restore", False):
psql_version = restore_dict.get("postgresql_version", 16)
s3_endpoint = secrets.get('s3_endpoint', "")
restore_cnpg_cluster('mastodon',
restore_cnpg_cluster(argocd.k8s,
'mastodon',
mastodon_namespace,
pgsql_cluster_name,
psql_version,
s3_endpoint,
pg_access_key_id,
pg_secret_access_key,
seaweedf_s3_endpoint,
pgsql_cluster_name,
cnpg_backup_schedule)

podconfig_yaml = (
f"https://raw.githubusercontent.com/small-hack/argocd-apps/{revision}/"
f"{argo_path}pvc_argocd_appset.yaml"
)
argocd.k8s.apply_manifests(podconfig_yaml, argocd.namespace)

# then we begin the restic restore of all the mastodon PVCs we lost
for pvc in ['valkey_primary', 'valkey_replica']:
pvc_enabled = secrets.get('valkey_pvc_enabled', 'false')
if pvc_enabled and pvc_enabled.lower() != 'false':
# restores the mastodon pvc
k8up_restore_pvc(
k8s_obj=argocd.k8s,
app='mastodon',
pvc=f'mastodon-{pvc.replace("_","-")}',
namespace='mastodon',
s3_endpoint=s3_backup_endpoint,
s3_bucket=s3_backup_bucket,
access_key_id=access_key_id,
secret_access_key=secret_access_key,
restic_repo_password=restic_repo_password,
snapshot_id=snapshot_ids[f'mastodon_{pvc}'],
pod_config="file-backups-podconfig"
)

# todo: from here on out, this could be async to start on other tasks
# install mastodon as usual
argocd.install_app('mastodon', argo_dict)

# verify mastodon rolled out
rollout = (f"kubectl rollout status -n {mastodon_namespace} "
"deployment/mastodon-web-app --watch --timeout 10m")
while True:
rolled_out = subproc([rollout])
if "NotFound" not in rolled_out:
break
# install mastodon as usual, but wait on it this time
argocd.install_app('mastodon', argo_dict, True)
1 change: 0 additions & 1 deletion smol_k8s_lab/k8s_apps/social/nextcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from smol_k8s_lab.k8s_apps.social.nextcloud_occ_commands import Nextcloud
from smol_k8s_lab.k8s_tools.argocd_util import ArgoCD
from smol_k8s_lab.k8s_tools.restores import (restore_seaweedfs,
recreate_pvc,
k8up_restore_pvc,
restore_cnpg_cluster)
from smol_k8s_lab.utils.passwords import create_password
Expand Down

0 comments on commit 1f94f39

Please sign in to comment.