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

Add pool manager daemon #115

Merged
merged 1 commit into from
Jul 15, 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 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
Loading