Skip to content

Commit

Permalink
added docstring get_sidecar_resource_requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayOO8 committed Jul 18, 2023
1 parent ba2c2f1 commit 960f850
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
30 changes: 17 additions & 13 deletions paasta_tools/kubernetes_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
from paasta_tools.utils import DockerVolume
from paasta_tools.utils import get_config_hash
from paasta_tools.utils import get_git_sha_from_dockerurl
from paasta_tools.utils import KubeContainerResourceRequest
from paasta_tools.utils import load_service_instance_config
from paasta_tools.utils import load_system_paasta_config
from paasta_tools.utils import load_v2_deployments_json
Expand Down Expand Up @@ -194,6 +195,7 @@
DEFAULT_USE_PROMETHEUS_CPU = False
DEFAULT_USE_PROMETHEUS_UWSGI = True
DEFAULT_USE_RESOURCE_METRICS_CPU = True
DEFAULT_SIDECAR_REQUEST = {"cpu": 0.1, "memory": "1024Mi", "ephemeral-storage": "256Mi"}


# conditions is None when creating a new HPA, but the client raises an error in that case.
Expand Down Expand Up @@ -283,17 +285,6 @@ def _set_disrupted_pods(self: Any, disrupted_pods: Mapping[str, datetime]) -> No
self._disrupted_pods = disrupted_pods


KubeContainerResourceRequest = TypedDict(
"KubeContainerResourceRequest",
{
"cpu": float,
"memory": str,
"ephemeral-storage": str,
},
total=False,
)


SidecarResourceRequirements = TypedDict(
"SidecarResourceRequirements",
{
Expand Down Expand Up @@ -1260,13 +1251,26 @@ def get_sidecar_resource_requirements(
sidecar_name: str,
system_paasta_config: SystemPaastaConfig,
) -> V1ResourceRequirements:
"""
Sidecar request/limits are set with varying levels of priority, with
elements further down the list taking precedence:
* hard-coded paasta default
* SystemPaastaConfig
* per-service soaconfig overrides
Additionally, for the time being we do not expose a way to set
limits separately from requests - these values will always mirror
each other
NOTE: changing any of these will cause a bounce of all services that
run the sidecars affected by the resource change
"""
config = self.config_dict.get("sidecar_resource_requirements", {}).get(
sidecar_name, {}
)
sidecar_requirements_config = (
system_paasta_config.get_sidecar_requirements_config().get(
sidecar_name,
{"cpu": 0.1, "memory": "1024Mi", "ephemeral-storage": "256Mi"},
sidecar_name, DEFAULT_SIDECAR_REQUEST
)
)
requests: KubeContainerResourceRequest = {
Expand Down
17 changes: 15 additions & 2 deletions paasta_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ class DockerParameter(TypedDict):
value: str


KubeContainerResourceRequest = TypedDict(
"KubeContainerResourceRequest",
{
"cpu": float,
"memory": str,
"ephemeral-storage": str,
},
total=False,
)


def safe_deploy_blacklist(input: UnsafeDeployBlacklist) -> DeployBlacklist:
return [(t, l) for t, l in input]

Expand Down Expand Up @@ -2012,7 +2023,7 @@ class SystemPaastaConfigDict(TypedDict, total=False):
spark_kubeconfig: str
kube_clusters: Dict
spark_use_eks_default: bool
sidecar_requirements_config: Dict[str, Dict[str, str]]
sidecar_requirements_config: Dict[str, KubeContainerResourceRequest]


def load_system_paasta_config(
Expand Down Expand Up @@ -2092,7 +2103,9 @@ def __repr__(self) -> str:
def get_spark_use_eks_default(self) -> bool:
return self.config_dict.get("spark_use_eks_default", False)

def get_sidecar_requirements_config(self) -> Mapping[str, Mapping[str, str]]:
def get_sidecar_requirements_config(
self,
) -> Dict[str, KubeContainerResourceRequest]:
return self.config_dict.get("sidecar_requirements_config", {})

def get_tron_default_pool_override(self) -> str:
Expand Down

0 comments on commit 960f850

Please sign in to comment.