Skip to content

Instantly share code, notes, and snippets.

@mancubus77
Created February 12, 2022 09:54
Show Gist options
  • Save mancubus77/1d93391db0c7ed73743ac5e9ed0e3a87 to your computer and use it in GitHub Desktop.
Save mancubus77/1d93391db0c7ed73743ac5e9ed0e3a87 to your computer and use it in GitHub Desktop.
from math import floor
class CreatPodList(object):
@staticmethod
def get_antiaffinity(anti_affinity: int) -> int:
"""
Update Anti Affinity if it's blank or none
:param anti_affinity: anti affinity int (input)
:return: anti affinity int (output)
"""
if anti_affinity == 0:
return 1
else:
return anti_affinity
@staticmethod
def add_pods(pods: list) -> list:
"""
Pods generator
:param pods: list of pods
:return: Pod Spec
"""
for pod in pods:
for values in map(
lambda x: {
"app": pod["app"]
if "platform" not in pod
else f"{pod['platform']}/{pod['app']}",
"mem": int(pod["mem"]),
"cpu": int(pod["cpu"]) / 1000,
"affinity": CreatPodList.get_antiaffinity(int(pod["affinity"])),
"max_per_node": floor(
int(pod["count"])
/ CreatPodList.get_antiaffinity(int(pod["affinity"]))
)
if pod["affinity"] != ""
else None,
},
range(int(pod["count"])),
):
yield values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment