Example #1
0
def destroy_deployment(api: client.AppsV1Api, namespace, name):
    if len(
            api.list_namespaced_deployment(
                namespace=namespace,
                field_selector=f'metadata.name={name}').items) == 1:
        logger.info(f'destroying Deployment: {namespace}/{name}')
        api.delete_namespaced_deployment(name=name, namespace=namespace)
    else:
        logger.info(f'cannot find Deployment to destroy: {namespace}/{name}')
Example #2
0
def ensure_deployment(api: client.AppsV1Api, deployment, namespace, name):
    if len(
            api.list_namespaced_deployment(
                namespace=namespace,
                field_selector=f'metadata.name={name}').items) == 0:
        logger.info(f'creating Deployment: {namespace}/{name}')
        api.create_namespaced_deployment(body=deployment, namespace=namespace)
    else:
        logger.info(f'Deployment exists: {namespace}/{name}')
Example #3
0
def get(client: AppsV1Api, log: BoundLogger, namespace: V1Namespace,
        dep: V1Deployment) -> Optional[V1Deployment]:
    return common_k8s.get_resource(
        lambda: client.list_namespaced_deployment(namespace=namespace.metadata.
                                                  name), log, 'deployment',
        dep.metadata.name)