Skip to content

Commit

Permalink
reconcile-deleted-managed-secrets: recreate them (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmeowzing authored May 28, 2024
1 parent ca43465 commit a1d8128
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/passoperator/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
"""


from typing import Any, List
from typing import Any
from pathlib import Path
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from importlib import metadata
from kubernetes import client, config
from http import HTTPStatus
from concurrent.futures import ThreadPoolExecutor
from functools import partial
from time import sleep

from passoperator.git import pull, clone
from passoperator.utils import LogLevel
Expand Down Expand Up @@ -72,6 +71,7 @@ def reconciliation(body: kopf.Body, **_: Any) -> None:

v1 = client.CoreV1Api()


try:
secret = v1.read_namespaced_secret(
name=passSecretObj.spec.managedSecret.metadata.name,
Expand All @@ -98,9 +98,20 @@ def reconciliation(body: kopf.Body, **_: Any) -> None:
)

log.info(f'Reconciliation successfully updated Secret "{_managedSecret.metadata.name}".')
else:
log.info(f'Secret "{_managedSecret.metadata.name}" is up-to-date.')
except client.ApiException as e:
raise kopf.PermanentError(e)
if e.status == HTTPStatus.NOT_FOUND:
log.warning(f'Secret "{passSecretObj.spec.managedSecret.metadata.name}" not found. Recreating managed secret.')

v1.create_namespaced_secret(
namespace=passSecretObj.spec.managedSecret.metadata.namespace,
body=client.V1Secret(
**passSecretObj.spec.managedSecret.to_client_dict(finalizers=False)
)
)
else:
raise kopf.PermanentError(e)

# @kopf.on.cleanup()
# def cleanup(**kwargs) -> None:
Expand Down

0 comments on commit a1d8128

Please sign in to comment.