added cpu_shares flag for v2

This commit is contained in:
kozlowskim6 2021-08-18 10:32:01 +02:00 committed by Muayyad Alsadi
parent 2d0aad6692
commit bfb57b9ba2

View File

@ -584,6 +584,7 @@ def get_secret_args(compose, cnt, secret):
def container_to_res_args(cnt, podman_args): def container_to_res_args(cnt, podman_args):
# v2 < https://docs.docker.com/compose/compose-file/compose-file-v2/#cpu-and-other-resources # v2 < https://docs.docker.com/compose/compose-file/compose-file-v2/#cpu-and-other-resources
cpus_limit_v2 = try_float(cnt.get('cpus', None), None) cpus_limit_v2 = try_float(cnt.get('cpus', None), None)
cpu_shares_v2 = try_int(cnt.get('cpu_shares', None), None)
mem_limit_v2 = cnt.get('mem_limit', None) mem_limit_v2 = cnt.get('mem_limit', None)
mem_res_v2 = cnt.get('mem_reservation', None) mem_res_v2 = cnt.get('mem_reservation', None)
# v3 < https://docs.docker.com/compose/compose-file/compose-file-v3/#resources # v3 < https://docs.docker.com/compose/compose-file/compose-file-v3/#resources
@ -600,6 +601,8 @@ def container_to_res_args(cnt, podman_args):
cpus = cpus_limit_v3 or cpus_limit_v2 cpus = cpus_limit_v3 or cpus_limit_v2
if cpus: if cpus:
podman_args.extend(('--cpus', str(cpus),)) podman_args.extend(('--cpus', str(cpus),))
if cpu_shares_v2:
podman_args.extend(('--cpu_shares', str(cpu_shares_v2),))
mem = mem_limit_v3 or mem_limit_v2 mem = mem_limit_v3 or mem_limit_v2
if mem: if mem:
podman_args.extend(('-m', str(mem).lower(),)) podman_args.extend(('-m', str(mem).lower(),))