Ejemplo n.º 1
0
def update_quota(name, namespace, maxmem="0Mi", maxcpu="0m", maxpods="0", priorityclass="common"):
    try:
        config.load_kube_config()
    except:
        config.load_incluster_config()

    api = client.CoreV1Api()
    name = namespace
    body = client.V1ResourceQuota(
                api_version='v1',
                kind="ResourceQuota",
                metadata=client.V1ObjectMeta(name=namespace, namespace=namespace),
                spec=client.V1ResourceQuotaSpec(
                    hard={"cpu":maxcpu, "memory":maxmem, "pods":maxpods},
                    scope_selector=client.V1ScopeSelector(match_expressions=[
                        client.V1ScopedResourceSelectorRequirement(operator="In",scope_name="PriorityClass", values=[priorityclass])
                    ])
                )
            )
    pretty = 'true'

    try:
        api_response = api.patch_namespaced_resource_quota(namespace, name, body, pretty=pretty)
    except ApiException as e:
        print("Exception when calling CoreV1Api->create_namespaced_limit_range: %s\n" % e)
Ejemplo n.º 2
0
def create_resource_quota(quota_name, hard_quotas, **kwargs):
    v1 = client.CoreV1Api()

    quota_namespace = kwargs[
        'namespace'] if 'namespace' in kwargs else 'default'
    quota_labels = kwargs['labels'] if 'labels' in kwargs else {}
    quota_annotations = kwargs[
        'annotations'] if 'annotations' in kwargs else {}

    quota = v1.create_namespaced_resource_quota(
        quota_namespace,
        body=client.V1ResourceQuota(
            api_version='v1',
            kind='ResourceQuota',
            metadata=client.V1ObjectMeta(name=quota_name,
                                         namespace=quota_namespace,
                                         annotations=quota_annotations,
                                         labels=quota_labels),
            spec=client.V1ResourceQuotaSpec(
                scope_selector=client.V1ScopeSelector(match_expressions=[
                    # TODO: Selector for namespace and/or user labels
                    #client.V1ScopedResourceSelectorRequirement(
                    # scop
                    #)
                ]),
                hard=hard_quotas)))
    return quota