diff options
author | Jason Luo <cl4531@att.com> | 2019-02-25 22:01:05 +0000 |
---|---|---|
committer | Jason Luo <cl4531@att.com> | 2019-02-27 15:01:26 +0000 |
commit | c5964da80a46e45dac50832c5d2cd83077d26736 (patch) | |
tree | d30c2ef5817c3fa30ef9e90ffc38fc1b18775337 /k8s/k8sclient | |
parent | 861fc4a4f2a036a3ff8c4974abcdd5c793858bcb (diff) |
Add resource_config to specify CPU and menory
Enhance K8s plugin used by DCAE Platform to specify CPU and memory
Issue-ID: DCAEGEN2-1126
Change-Id: I2431b0b7f67f855122ed4494aa21cad0f99dcc37
Signed-off-by: Jason Luo <cl4531@att.com>
Diffstat (limited to 'k8s/k8sclient')
-rw-r--r-- | k8s/k8sclient/k8sclient.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/k8s/k8sclient/k8sclient.py b/k8s/k8sclient/k8sclient.py index 806b41e..84ca84f 100644 --- a/k8s/k8sclient/k8sclient.py +++ b/k8s/k8sclient/k8sclient.py @@ -1,7 +1,7 @@ # ============LICENSE_START======================================================= # org.onap.dcae # ================================================================================ -# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -121,7 +121,17 @@ def _create_probe(hc, port, use_tls=False): ) return probe -def _create_container_object(name, image, always_pull, use_tls=False, env={}, container_ports=[], volume_mounts = [], readiness = None): +def _create_resources(resources=None): + if resources is not None: + resources_obj = client.V1ResourceRequirements( + limits = resources.get("limits"), + requests = resources.get("requests") + ) + return resources_obj + else: + return None + +def _create_container_object(name, image, always_pull, use_tls=False, env={}, container_ports=[], volume_mounts = [], resources = None, readiness = None): # Set up environment variables # Copy any passed in environment variables env_vars = [client.V1EnvVar(name=k, value=env[k]) for k in env.keys()] @@ -139,6 +149,10 @@ def _create_container_object(name, image, always_pull, use_tls=False, env={}, co (hc_port, proto) = container_ports[0] probe = _create_probe(readiness, hc_port, use_tls) + if resources: + resources_obj = _create_resources(resources) + else: + resources_obj = None # Define container for pod return client.V1Container( name=name, @@ -147,6 +161,7 @@ def _create_container_object(name, image, always_pull, use_tls=False, env={}, co env=env_vars, ports=[client.V1ContainerPort(container_port=p, protocol=proto) for (p, proto) in container_ports], volume_mounts = volume_mounts, + resources = resources_obj, readiness_probe = probe ) @@ -326,7 +341,7 @@ def _execute_command_in_pod(namespace, pod_name, command): return {"pod" : pod_name, "output" : output} -def deploy(namespace, component_name, image, replicas, always_pull, k8sconfig, **kwargs): +def deploy(namespace, component_name, image, replicas, always_pull, k8sconfig, resources, **kwargs): ''' This will create a k8s Deployment and, if needed, one or two k8s Services. (We are being opinionated in our use of k8s... this code decides what k8s abstractions and features to use. @@ -445,7 +460,7 @@ def deploy(namespace, component_name, image, replicas, always_pull, k8sconfig, * # Create the container for the component # Make it the first container in the pod - containers.insert(0, _create_container_object(component_name, image, always_pull, use_tls, kwargs.get("env", {}), container_ports, volume_mounts, kwargs["readiness"])) + containers.insert(0, _create_container_object(component_name, image, always_pull, use_tls, kwargs.get("env", {}), container_ports, volume_mounts, resources, kwargs["readiness"])) # Build the k8s Deployment object labels = kwargs.get("labels", {}) |