Skip to content

Commit

Permalink
Add pool manager daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
jkupferer committed Jul 15, 2024
1 parent d1c6e4d commit 19f2fab
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kopf-opt.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
KOPF_OPTIONS="--log-format=json"
KOPF_OPTIONS="${KOPF_OPTIONS:---log-format=json}"

# Restrict watch to operator namespace.
KOPF_NAMESPACED=false
Expand Down
35 changes: 35 additions & 0 deletions operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,41 @@ async def resource_pool_delete(
)
await resource_pool.handle_delete(logger=logger)

@kopf.daemon(Poolboy.operator_domain, Poolboy.operator_version, 'resourcepools',
cancellation_timeout = 1,
initial_delay = Poolboy.manage_pools_interval,
labels = {Poolboy.ignore_label: kopf.ABSENT},
)
async def resource_pool_daemon(
annotations: kopf.Annotations,
labels: kopf.Labels,
logger: kopf.ObjectLogger,
meta: kopf.Meta,
name: str,
namespace: str,
spec: kopf.Spec,
status: kopf.Status,
stopped: Optional[datetime],
uid: str,
**_
):
resource_pool = await ResourcePool.register(
annotations = annotations,
labels = labels,
meta = meta,
name = name,
namespace = namespace,
spec = spec,
status = status,
uid = uid,
)
try:
while not stopped:
await resource_pool.manage(logger=logger)
await asyncio.sleep(Poolboy.manage_pools_interval)
except asyncio.CancelledError:
pass


@kopf.on.event(Poolboy.operator_domain, Poolboy.operator_version, 'resourceproviders')
async def resource_provider_event(event: Mapping, logger: kopf.ObjectLogger, **_) -> None:
Expand Down
1 change: 1 addition & 0 deletions operator/poolboy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class Poolboy():
manage_claims_interval = int(os.environ.get('MANAGE_CLAIMS_INTERVAL', 60))
manage_handles_interval = int(os.environ.get('MANAGE_HANDLES_INTERVAL', 60))
manage_pools_interval = int(os.environ.get('MANAGE_POOLS_INTERVAL', 10))
operator_domain = os.environ.get('OPERATOR_DOMAIN', 'poolboy.gpte.redhat.com')
operator_version = os.environ.get('OPERATOR_VERSION', 'v1')
operator_api_version = f"{operator_domain}/{operator_version}"
Expand Down

0 comments on commit 19f2fab

Please sign in to comment.