diff --git a/contents/common.py b/contents/common.py index 34b9f6f..b56f674 100644 --- a/contents/common.py +++ b/contents/common.py @@ -395,6 +395,16 @@ def create_pod_template_spec(data): requests=tmp_resources ) + if "resources_limits" in data: + resources_array = data["resources_limits"].split(",") + tmp_limits = dict(s.split('=', 1) for s in resources_array) + if container.resources is not None: + container.resources.limits = tmp_limits + else: + container.resources = client.V1ResourceRequirements( + limits=tmp_limits + ) + template_spec = client.V1PodSpec( containers=[container] ) diff --git a/contents/deployment-create.py b/contents/deployment-create.py index 82903e5..f16ba8b 100644 --- a/contents/deployment-create.py +++ b/contents/deployment-create.py @@ -107,6 +107,10 @@ def main(): rr = os.environ.get('RD_CONFIG_RESOURCES_REQUESTS') data["resources_requests"] = rr + if os.environ.get('RD_CONFIG_RESOURCES_LIMITS'): + rl = os.environ.get('RD_CONFIG_RESOURCES_LIMITS') + data["resources_limits"] = rl + if os.environ.get('RD_CONFIG_ANNOTATIONS'): data["annotations"] = os.environ.get('RD_CONFIG_ANNOTATIONS') diff --git a/contents/deployment-update.py b/contents/deployment-update.py index c5b6b93..41209bb 100644 --- a/contents/deployment-update.py +++ b/contents/deployment-update.py @@ -93,6 +93,14 @@ def create_deployment_object(data): requests=tmp_resources ) + if "resources_limits" in data: + resources_array = data["resources_limits"].split(",") + tmp = dict(s.split('=', 1) for s in resources_array) + if container.resources is not None: + container.resources.limits = tmp + else: + container.resources = client.V1ResourceRequirements(limits=tmp) + labels = None if "labels" in data: labels_array = data["labels"].split(',') diff --git a/contents/job-create.py b/contents/job-create.py index ddaee3b..80e483c 100644 --- a/contents/job-create.py +++ b/contents/job-create.py @@ -81,6 +81,14 @@ def create_job_object(data): requests=tmp ) + if "resources_limits" in data: + resources_array = data["resources_limits"].split(",") + tmp = dict(s.split('=', 1) for s in resources_array) + if container.resources is not None: + container.resources.limits = tmp + else: + container.resources = client.V1ResourceRequirements(limits=tmp) + if "volume_mounts" in data: mounts = common.create_volume_mount_yaml(data) container.volume_mounts = mounts @@ -241,6 +249,10 @@ def main(): if os.environ.get('RD_CONFIG_RESOURCES_REQUESTS'): req = os.environ.get('RD_CONFIG_RESOURCES_REQUESTS') data["resources_requests"] = req + + if os.environ.get('RD_CONFIG_RESOURCES_LIMITS'): + lim = os.environ.get('RD_CONFIG_RESOURCES_LIMITS') + data["resources_limits"] = lim if os.environ.get('RD_CONFIG_VOLUME_MOUNTS'): data["volume_mounts"] = os.environ.get('RD_CONFIG_VOLUME_MOUNTS') diff --git a/contents/pods-create.py b/contents/pods-create.py index 606867a..3aac1c6 100644 --- a/contents/pods-create.py +++ b/contents/pods-create.py @@ -82,6 +82,10 @@ def main(): if os.environ.get('RD_CONFIG_RESOURCES_REQUESTS'): rr = os.environ.get('RD_CONFIG_RESOURCES_REQUESTS') data["resources_requests"] = rr + + if os.environ.get('RD_CONFIG_RESOURCES_LIMITS'): + rl = os.environ.get('RD_CONFIG_RESOURCES_LIMITS') + data["resources_limits"] = rl if os.environ.get('RD_CONFIG_WAITREADY'): data["waitready"] = os.environ.get('RD_CONFIG_WAITREADY') diff --git a/plugin.yaml b/plugin.yaml index 5fc058d..45e6ce2 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -407,6 +407,13 @@ providers: required: false renderingOptions: groupName: Container + - name: resources_limits + type: String + title: "Resource Limits" + description: "Limit resources in format cpu=4,memory=1Gi" + required: false + renderingOptions: + groupName: Container - name: volume_mounts type: String title: "Volume Mounts" @@ -601,6 +608,13 @@ providers: required: false renderingOptions: groupName: Container + - name: resources_limits + type: String + title: "Resource Limits" + description: "Limit resources in format cpu=4,memory=1Gi" + required: false + renderingOptions: + groupName: Container - name: config_file type: String title: "Kubernetes Config File Path" @@ -1789,6 +1803,13 @@ providers: required: false renderingOptions: groupName: Container + - name: resources_limits + type: String + title: "Resource Limits" + description: "Limit resources in format cpu=4,memory=1Gi" + required: false + renderingOptions: + groupName: Container - name: volumes type: String title: "Volumes" @@ -2326,6 +2347,13 @@ providers: required: false renderingOptions: groupName: Container + - name: resources_limits + type: String + title: "Resource Limits" + description: "Limit resources in format cpu=4,memory=1Gi" + required: false + renderingOptions: + groupName: Container - name: volume_mounts type: String title: "Volume Mounts"