Example #1
0
def resume(
    id: Optional[str],
    namespace: references.Namespace,
    peering_name: str,
) -> None:
    """ Resume the resource handling in the cluster. """
    identity = peering.Identity(id) if id else peering.detect_own_id(
        manual=True)
    registry = registries.SmartOperatorRegistry()
    settings = configuration.OperatorSettings()
    settings.peering.name = peering_name
    vault = credentials.Vault()
    auth.vault_var.set(vault)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        asyncio.wait({
            activities.authenticate(registry=registry,
                                    settings=settings,
                                    vault=vault),
            peering.touch(
                identity=identity,
                settings=settings,
                namespace=namespace,
                lifetime=0,
            ),
        }))
Example #2
0
def freeze(
    id: Optional[str],
    message: Optional[str],
    lifetime: int,
    namespace: Optional[str],
    peering_name: str,
    priority: int,
) -> None:
    """ Freeze the resource handling in the cluster. """
    ourserlves = peering.Peer(
        id=id or peering.detect_own_id(manual=True),
        name=peering_name,
        namespace=namespace,
        priority=priority,
        lifetime=lifetime,
    )
    registry = registries.SmartOperatorRegistry()
    settings = configuration.OperatorSettings()
    vault = credentials.Vault()
    auth.vault_var.set(vault)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        asyncio.wait({
            activities.authenticate(registry=registry,
                                    settings=settings,
                                    vault=vault),
            ourserlves.keepalive(),
        }))
Example #3
0
def login(
    verify: bool = False,  # DEPRECATED: kept for backward compatibility
    *,
    loop: Optional[asyncio.AbstractEventLoop] = None,
) -> None:
    """
    Login to Kubernetes cluster, locally or remotely.

    Keep the logged in state or config object in the global variable,
    so that it is available for future operator runs.
    """
    warnings.warn(
        "kopf.login() is deprecated; the operator now authenticates "
        "internally; cease using kopf.login().", DeprecationWarning)

    # Remember the credentials store for later usage in the actual operator.
    # Set the global vault for the legacy login()->run() scenario.
    global global_vault
    global_vault = credentials.Vault()

    # Perform the initial one-time authentication in presumably the same loop.
    loop = loop if loop is not None else asyncio.get_event_loop()
    registry = registries.get_default_registry()
    settings = configuration.OperatorSettings()
    try:
        loop.run_until_complete(
            activities.authenticate(
                registry=registry,
                settings=settings,
                vault=global_vault,
            ))
    except asyncio.CancelledError:
        pass
    except activities.ActivityError as e:
        # Detect and re-raise the original LoginErrors, not the general activity error.
        # This is only needed for the legacy one-shot login, not for a background job.
        for outcome in e.outcomes.values():
            if isinstance(outcome.exception, credentials.LoginError):
                raise outcome.exception
        raise
Example #4
0
def resume(
    id: Optional[str],
    namespace: Optional[str],
    peering_name: str,
) -> None:
    """ Resume the resource handling in the cluster. """
    ourselves = peering.Peer(
        id=id or peering.detect_own_id(manual=True),
        name=peering_name,
        namespace=namespace,
    )
    registry = registries.SmartOperatorRegistry()
    settings = configuration.OperatorSettings()
    vault = credentials.Vault()
    auth.vault_var.set(vault)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        asyncio.wait({
            activities.authenticate(registry=registry,
                                    settings=settings,
                                    vault=vault),
            ourselves.disappear(),
        }))