code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def down_bounce(
new_config: BounceMethodConfigDict,
new_app_running: bool,
happy_new_tasks: Collection,
old_non_draining_tasks: Sequence,
margin_factor=1.0,
) -> BounceMethodResult:
"""
Stops old apps, doesn't start any new apps.
Used for the graceful_app_drain script.
"""
retur... |
Stops old apps, doesn't start any new apps.
Used for the graceful_app_drain script.
| down_bounce | python | Yelp/paasta | paasta_tools/bounce_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/bounce_lib.py | Apache-2.0 |
def broadcast_log_all_services_running_here(line: str, soa_dir=DEFAULT_SOA_DIR) -> None:
"""Log a line of text to paasta logs of all services running on this host.
:param line: text to log
"""
system_paasta_config = load_system_paasta_config()
cluster = system_paasta_config.get_cluster()
servic... | Log a line of text to paasta logs of all services running on this host.
:param line: text to log
| broadcast_log_all_services_running_here | python | Yelp/paasta | paasta_tools/broadcast_log_to_services.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/broadcast_log_to_services.py | Apache-2.0 |
def get_registrations(self) -> List[str]:
"""
To support apollo we always register in
cassandra_<cluster>.main
"""
registrations = self.config_dict.get("registrations", [])
for registration in registrations:
try:
decompose_job_id(registration)
... |
To support apollo we always register in
cassandra_<cluster>.main
| get_registrations | python | Yelp/paasta | paasta_tools/cassandracluster_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cassandracluster_tools.py | Apache-2.0 |
def load_cassandracluster_instance_config(
service: str,
instance: str,
cluster: str,
load_deployments: bool = True,
soa_dir: str = DEFAULT_SOA_DIR,
) -> CassandraClusterDeploymentConfig:
"""Read a service instance's configuration for CassandraCluster.
If a branch isn't specified for a conf... | Read a service instance's configuration for CassandraCluster.
If a branch isn't specified for a config, the 'branch' key defaults to
paasta-${cluster}.${instance}.
:param service: The service name
:param instance: The instance of the service to retrieve
:param cluster: The cluster to read the conf... | load_cassandracluster_instance_config | python | Yelp/paasta | paasta_tools/cassandracluster_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cassandracluster_tools.py | Apache-2.0 |
def container_lifetime(
pod: V1Pod,
) -> datetime.timedelta:
"""Return a time duration for how long the pod is alive"""
st = pod.status.start_time
return datetime.datetime.now(st.tzinfo) - st | Return a time duration for how long the pod is alive | container_lifetime | python | Yelp/paasta | paasta_tools/check_flink_services_health.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/check_flink_services_health.py | Apache-2.0 |
def healthy_flink_containers_cnt(si_pods: Sequence[V1Pod], container_type: str) -> int:
"""Return count of healthy Flink containers with given type"""
return len(
[
pod
for pod in si_pods
if pod.metadata.labels["flink.yelp.com/container-type"] == container_type
... | Return count of healthy Flink containers with given type | healthy_flink_containers_cnt | python | Yelp/paasta | paasta_tools/check_flink_services_health.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/check_flink_services_health.py | Apache-2.0 |
def check_under_registered_taskmanagers(
instance_config: FlinkDeploymentConfig,
expected_count: int,
cr_name: str,
is_eks: bool,
) -> Tuple[bool, str, str]:
"""Check if not enough taskmanagers have been registered to the jobmanager and
returns both the result of the check in the form of a boole... | Check if not enough taskmanagers have been registered to the jobmanager and
returns both the result of the check in the form of a boolean and a human-readable
text to be used in logging or monitoring events.
| check_under_registered_taskmanagers | python | Yelp/paasta | paasta_tools/check_flink_services_health.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/check_flink_services_health.py | Apache-2.0 |
def get_cr_name(si_pods: Sequence[V1Pod]) -> str:
"""Returns the flink custom resource name based on the pod name. We are randomly choosing jobmanager pod here.
This change is related to FLINK-3129
"""
jobmanager_pod = [
pod
for pod in si_pods
if pod.metadata.labels["flink.yelp.... | Returns the flink custom resource name based on the pod name. We are randomly choosing jobmanager pod here.
This change is related to FLINK-3129
| get_cr_name | python | Yelp/paasta | paasta_tools/check_flink_services_health.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/check_flink_services_health.py | Apache-2.0 |
def check_kubernetes_pod_replication(
instance_config: Union[KubernetesDeploymentConfig, EksDeploymentConfig],
pods_by_service_instance: Dict[str, Dict[str, List[V1Pod]]],
replication_checker: KubeSmartstackEnvoyReplicationChecker,
dry_run: bool = False,
) -> Optional[bool]:
"""Checks a service's re... | Checks a service's replication levels based on how the service's replication
should be monitored. (smartstack/envoy or k8s)
:param instance_config: an instance of KubernetesDeploymentConfig or EksDeploymentConfig
:param replication_checker: an instance of KubeSmartstackEnvoyReplicationChecker
| check_kubernetes_pod_replication | python | Yelp/paasta | paasta_tools/check_kubernetes_services_replication.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/check_kubernetes_services_replication.py | Apache-2.0 |
def read_oom_events_from_scribe(cluster, superregion, num_lines=1000):
"""Read the latest 'num_lines' lines from OOM_EVENTS_STREAM and iterate over them."""
# paasta configs incls a map for cluster -> env that is expected by scribe
log_reader_config = load_system_paasta_config().get_log_reader()
cluster... | Read the latest 'num_lines' lines from OOM_EVENTS_STREAM and iterate over them. | read_oom_events_from_scribe | python | Yelp/paasta | paasta_tools/check_oom_events.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/check_oom_events.py | Apache-2.0 |
def latest_oom_events(cluster, superregion, interval=60):
"""
:returns: {(service, instance): [OOMEvent, OOMEvent,...] }
if the number of events > 0
"""
start_timestamp = int(time.time()) - interval
res = {}
for e in read_oom_events_from_scribe(cluster, superregion):
if e["... |
:returns: {(service, instance): [OOMEvent, OOMEvent,...] }
if the number of events > 0
| latest_oom_events | python | Yelp/paasta | paasta_tools/check_oom_events.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/check_oom_events.py | Apache-2.0 |
def compose_sensu_status(
instance, oom_events, is_check_enabled, alert_threshold, check_interval
):
"""
:param instance: InstanceConfig
:param oom_events: a list of OOMEvents
:param is_check_enabled: boolean to indicate whether the check enabled for the instance
"""
interval_string = f"{che... |
:param instance: InstanceConfig
:param oom_events: a list of OOMEvents
:param is_check_enabled: boolean to indicate whether the check enabled for the instance
| compose_sensu_status | python | Yelp/paasta | paasta_tools/check_oom_events.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/check_oom_events.py | Apache-2.0 |
def send_sensu_event(instance, oom_events, args):
"""
:param instance: InstanceConfig
:param oom_events: a list of OOMEvents
"""
check_name = compose_check_name_for_service_instance(
"oom-killer", instance.service, instance.instance
)
monitoring_overrides = instance.get_monitoring()
... |
:param instance: InstanceConfig
:param oom_events: a list of OOMEvents
| send_sensu_event | python | Yelp/paasta | paasta_tools/check_oom_events.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/check_oom_events.py | Apache-2.0 |
def set_local_vars_configuration_to_none(obj: Any, visited: Set[int] = None) -> None:
"""
Recursive function to ensure that k8s clientlib objects are pickleable.
Without this, k8s clientlib objects can't be used by multiprocessing functions
as those pickle data to shuttle between processes.
"""
... |
Recursive function to ensure that k8s clientlib objects are pickleable.
Without this, k8s clientlib objects can't be used by multiprocessing functions
as those pickle data to shuttle between processes.
| set_local_vars_configuration_to_none | python | Yelp/paasta | paasta_tools/check_services_replication_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/check_services_replication_tools.py | Apache-2.0 |
def instance_is_not_bouncing(
instance_config: Union[KubernetesDeploymentConfig, EksDeploymentConfig],
applications: List[Application],
) -> bool:
"""
:param instance_config: a KubernetesDeploymentConfig or an EksDeploymentConfig with the configuration of the instance
:param applications: a list of... |
:param instance_config: a KubernetesDeploymentConfig or an EksDeploymentConfig with the configuration of the instance
:param applications: a list of all deployments or stateful sets on the cluster that match the service
and instance of provided instance_config
| instance_is_not_bouncing | python | Yelp/paasta | paasta_tools/cleanup_kubernetes_jobs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cleanup_kubernetes_jobs.py | Apache-2.0 |
def get_applications_to_kill(
applications_dict: Dict[Tuple[str, str], List[Application]],
cluster: str,
valid_services: Set[Tuple[str, str]],
soa_dir: str,
eks: bool = False,
) -> List[Application]:
"""
:param applications_dict: A dictionary with (service, instance) as keys and a list of a... |
:param applications_dict: A dictionary with (service, instance) as keys and a list of applications for each tuple
:param cluster: paasta cluster
:param valid_services: a set with the valid (service, instance) tuples for this cluster
:param soa_dir: The SOA config directory to read from
:return: li... | get_applications_to_kill | python | Yelp/paasta | paasta_tools/cleanup_kubernetes_jobs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cleanup_kubernetes_jobs.py | Apache-2.0 |
def cleanup_unused_apps(
soa_dir: str,
cluster: str,
kill_threshold: float = 0.5,
force: bool = False,
eks: bool = False,
) -> None:
"""Clean up old or invalid jobs/apps from kubernetes. Retrieves
both a list of apps currently in kubernetes and a list of valid
app ids in order to determi... | Clean up old or invalid jobs/apps from kubernetes. Retrieves
both a list of apps currently in kubernetes and a list of valid
app ids in order to determine what to kill.
:param soa_dir: The SOA config directory to read from
:param cluster: paasta cluster to clean
:param kill_threshold: The decimal f... | cleanup_unused_apps | python | Yelp/paasta | paasta_tools/cleanup_kubernetes_jobs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cleanup_kubernetes_jobs.py | Apache-2.0 |
def write_auto_config_data(
service: str,
extra_info: str,
data: Dict[str, Any],
soa_dir: str = DEFAULT_SOA_DIR,
sub_dir: Optional[str] = None,
comment: Optional[str] = None,
) -> Optional[str]:
"""
Replaces the contents of an automated config file for a service, or creates the file if i... |
Replaces the contents of an automated config file for a service, or creates the file if it does not exist.
Returns the filename of the modified file, or None if no file was written.
| write_auto_config_data | python | Yelp/paasta | paasta_tools/config_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/config_utils.py | Apache-2.0 |
def get_currently_deployed_sha(service, deploy_group, soa_dir=DEFAULT_SOA_DIR):
"""Tries to determine the currently deployed sha for a service and deploy_group,
returns None if there isn't one ready yet"""
try:
deployments = load_v2_deployments_json(service=service, soa_dir=soa_dir)
return d... | Tries to determine the currently deployed sha for a service and deploy_group,
returns None if there isn't one ready yet | get_currently_deployed_sha | python | Yelp/paasta | paasta_tools/deployment_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/deployment_utils.py | Apache-2.0 |
def get_currently_deployed_version(
service, deploy_group, soa_dir=DEFAULT_SOA_DIR
) -> Optional[DeploymentVersion]:
"""Tries to determine the currently deployed version for a service and deploy_group,
returns None if there isn't one ready yet"""
try:
deployments = load_v2_deployments_json(servi... | Tries to determine the currently deployed version for a service and deploy_group,
returns None if there isn't one ready yet | get_currently_deployed_version | python | Yelp/paasta | paasta_tools/deployment_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/deployment_utils.py | Apache-2.0 |
def register_drain_method(
name: str,
) -> Callable[[_RegisterDrainMethod_T], _RegisterDrainMethod_T]:
"""Returns a decorator that registers a DrainMethod subclass at a given name
so get_drain_method/list_drain_methods can find it."""
def outer(drain_method: _RegisterDrainMethod_T) -> _RegisterDrainMet... | Returns a decorator that registers a DrainMethod subclass at a given name
so get_drain_method/list_drain_methods can find it. | register_drain_method | python | Yelp/paasta | paasta_tools/drain_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/drain_lib.py | Apache-2.0 |
async def drain(self, task: DrainTask) -> None:
"""Make a task stop receiving new traffic."""
raise NotImplementedError() | Make a task stop receiving new traffic. | drain | python | Yelp/paasta | paasta_tools/drain_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/drain_lib.py | Apache-2.0 |
async def stop_draining(self, task: DrainTask) -> None:
"""Make a task that has previously been downed start receiving traffic again."""
raise NotImplementedError() | Make a task that has previously been downed start receiving traffic again. | stop_draining | python | Yelp/paasta | paasta_tools/drain_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/drain_lib.py | Apache-2.0 |
async def is_draining(self, task: DrainTask) -> bool:
"""Return whether a task is being drained."""
raise NotImplementedError() | Return whether a task is being drained. | is_draining | python | Yelp/paasta | paasta_tools/drain_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/drain_lib.py | Apache-2.0 |
async def is_safe_to_kill(self, task: DrainTask) -> bool:
"""Return True if a task is drained and ready to be killed, or False if we should wait."""
raise NotImplementedError() | Return True if a task is drained and ready to be killed, or False if we should wait. | is_safe_to_kill | python | Yelp/paasta | paasta_tools/drain_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/drain_lib.py | Apache-2.0 |
def parse_success_codes(self, success_codes_str: str) -> Set[int]:
"""Expand a string like 200-399,407-409,500 to a set containing all the integers in between."""
acceptable_response_codes: Set[int] = set()
for series_str in str(success_codes_str).split(","):
if "-" in series_str:
... | Expand a string like 200-399,407-409,500 to a set containing all the integers in between. | parse_success_codes | python | Yelp/paasta | paasta_tools/drain_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/drain_lib.py | Apache-2.0 |
async def issue_request(self, url_spec: UrlSpec, task: DrainTask) -> None:
"""Issue a request to the URL specified by url_spec regarding the task given."""
format_params = self.get_format_params(task)
urls = [
self.format_url(url_spec["url_format"], param) for param in format_params
... | Issue a request to the URL specified by url_spec regarding the task given. | issue_request | python | Yelp/paasta | paasta_tools/drain_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/drain_lib.py | Apache-2.0 |
def load_eks_service_config_no_cache(
service: str,
instance: str,
cluster: str,
load_deployments: bool = True,
soa_dir: str = DEFAULT_SOA_DIR,
) -> "EksDeploymentConfig":
"""Read a service instance's configuration for EKS.
If a branch isn't specified for a config, the 'branch' key defaults... | Read a service instance's configuration for EKS.
If a branch isn't specified for a config, the 'branch' key defaults to
paasta-${cluster}.${instance}.
:param name: The service name
:param instance: The instance of the service to retrieve
:param cluster: The cluster to read the configuration for
... | load_eks_service_config_no_cache | python | Yelp/paasta | paasta_tools/eks_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/eks_tools.py | Apache-2.0 |
def are_services_up_in_pod(
envoy_host: str,
envoy_admin_port: int,
envoy_admin_endpoint_format: str,
registrations: Collection[str],
pod_ip: str,
pod_port: int,
) -> bool:
"""Returns whether a service in a k8s pod is reachable via envoy
:param envoy_host: The host that this check should... | Returns whether a service in a k8s pod is reachable via envoy
:param envoy_host: The host that this check should contact for replication information.
:param envoy_admin_port: The port that Envoy's admin interface is listening on
:param registrations: The service_name.instance_name of the services
:param... | are_services_up_in_pod | python | Yelp/paasta | paasta_tools/envoy_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/envoy_tools.py | Apache-2.0 |
def are_namespaces_up_in_eds(
envoy_eds_path: str,
namespaces: Collection[str],
pod_ip: str,
pod_port: int,
) -> bool:
"""Returns whether a Pod is registered on Envoy through the EDS
:param envoy_eds_path: path where EDS yaml files are stored
:param namespaces: list of namespaces to check
... | Returns whether a Pod is registered on Envoy through the EDS
:param envoy_eds_path: path where EDS yaml files are stored
:param namespaces: list of namespaces to check
:param pod_ip: IP of the pod
:param pod_port: The port to reach the service in the pod
| are_namespaces_up_in_eds | python | Yelp/paasta | paasta_tools/envoy_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/envoy_tools.py | Apache-2.0 |
def get_casper_endpoints(
clusters_info: Mapping[str, Any]
) -> FrozenSet[Tuple[str, int]]:
"""Filters out and returns casper endpoints from Envoy clusters."""
casper_endpoints: Set[Tuple[str, int]] = set()
for cluster_status in clusters_info["cluster_statuses"]:
if "host_statuses" in cluster_st... | Filters out and returns casper endpoints from Envoy clusters. | get_casper_endpoints | python | Yelp/paasta | paasta_tools/envoy_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/envoy_tools.py | Apache-2.0 |
def get_backends_from_eds(namespace: str, envoy_eds_path: str) -> List[Tuple[str, int]]:
"""Returns a list of backends for a given namespace. Casper backends are also returned (if present).
:param namespace: return backends for this namespace
:param envoy_eds_path: path where EDS yaml files are stored
... | Returns a list of backends for a given namespace. Casper backends are also returned (if present).
:param namespace: return backends for this namespace
:param envoy_eds_path: path where EDS yaml files are stored
:returns backends: a list of touples representing the backends for
the re... | get_backends_from_eds | python | Yelp/paasta | paasta_tools/envoy_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/envoy_tools.py | Apache-2.0 |
def get_backends(
service: str,
envoy_host: str,
envoy_admin_port: int,
envoy_admin_endpoint_format: str,
) -> Dict[str, List[Tuple[EnvoyBackend, bool]]]:
"""Fetches JSON from Envoy admin's /clusters endpoint and returns a list of backends.
:param service: If None, return backends for all servi... | Fetches JSON from Envoy admin's /clusters endpoint and returns a list of backends.
:param service: If None, return backends for all services, otherwise only return backends for this particular
service.
:param envoy_host: The host that this check should contact for replication information.
... | get_backends | python | Yelp/paasta | paasta_tools/envoy_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/envoy_tools.py | Apache-2.0 |
def get_multiple_backends(
services: Optional[Sequence[str]],
envoy_host: str,
envoy_admin_port: int,
envoy_admin_endpoint_format: str,
resolve_hostnames: bool = True,
) -> Dict[str, List[Tuple[EnvoyBackend, bool]]]:
"""Fetches JSON from Envoy admin's /clusters endpoint and returns a list of bac... | Fetches JSON from Envoy admin's /clusters endpoint and returns a list of backends.
:param services: If None, return backends for all services, otherwise only return backends for these particular
services.
:param envoy_host: The host that this check should contact for replication informatio... | get_multiple_backends | python | Yelp/paasta | paasta_tools/envoy_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/envoy_tools.py | Apache-2.0 |
def match_backends_and_pods(
backends: Iterable[EnvoyBackend],
pods: Iterable[V1Pod],
) -> List[Tuple[Optional[EnvoyBackend], Optional[V1Pod]]]:
"""Returns tuples of matching (backend, pod) pairs, as matched by IP. Each backend will be listed exactly
once. If a backend does not match with a pod, (backen... | Returns tuples of matching (backend, pod) pairs, as matched by IP. Each backend will be listed exactly
once. If a backend does not match with a pod, (backend, None) will be included.
If a pod's IP does not match with any backends, (None, pod) will be included.
:param backends: An iterable of Envoy backend ... | match_backends_and_pods | python | Yelp/paasta | paasta_tools/envoy_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/envoy_tools.py | Apache-2.0 |
def get_replication_for_all_services(
envoy_host: str,
envoy_admin_port: int,
envoy_admin_endpoint_format: str,
) -> Dict[str, int]:
"""Returns the replication level for all services known to this Envoy
:param envoy_host: The host that this check should contact for replication information.
:par... | Returns the replication level for all services known to this Envoy
:param envoy_host: The host that this check should contact for replication information.
:param envoy_admin_port: The port number that this check should contact for replication information.
:param envoy_admin_endpoint_format: The format of E... | get_replication_for_all_services | python | Yelp/paasta | paasta_tools/envoy_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/envoy_tools.py | Apache-2.0 |
def _yocalhost_rule(port, comment, protocol="tcp"):
"""Return an iptables rule allowing access to a yocalhost port."""
return iptables.Rule(
protocol=protocol,
src="0.0.0.0/0.0.0.0",
dst="169.254.255.254/255.255.255.255",
target="ACCEPT",
matches=(
("comment",... | Return an iptables rule allowing access to a yocalhost port. | _yocalhost_rule | python | Yelp/paasta | paasta_tools/firewall.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/firewall.py | Apache-2.0 |
def services_running_here():
"""Generator helper that yields (service, instance, mac address) of both
mesos tasks.
"""
for container in get_running_mesos_docker_containers():
if container["HostConfig"]["NetworkMode"] != "bridge":
continue
service = container["Labels"].get("p... | Generator helper that yields (service, instance, mac address) of both
mesos tasks.
| services_running_here | python | Yelp/paasta | paasta_tools/firewall.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/firewall.py | Apache-2.0 |
def _ensure_common_chain():
"""The common chain allows access for all services to certain resources."""
iptables.ensure_chain(
"PAASTA-COMMON",
(
# Allow return traffic for incoming connections
iptables.Rule(
protocol="ip",
src="0.0.0.0/0.0... | The common chain allows access for all services to certain resources. | _ensure_common_chain | python | Yelp/paasta | paasta_tools/firewall.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/firewall.py | Apache-2.0 |
def ensure_service_chains(service_groups, soa_dir, synapse_service_dir):
"""Ensure service chains exist and have the right rules.
service_groups is a dict {ServiceGroup: set([mac_address..])}
Returns dictionary {[service chain] => [list of mac addresses]}.
"""
chains = {}
for service, macs in ... | Ensure service chains exist and have the right rules.
service_groups is a dict {ServiceGroup: set([mac_address..])}
Returns dictionary {[service chain] => [list of mac addresses]}.
| ensure_service_chains | python | Yelp/paasta | paasta_tools/firewall.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/firewall.py | Apache-2.0 |
def general_update(soa_dir, synapse_service_dir):
"""Update iptables to match the current PaaSTA state."""
ensure_shared_chains()
service_chains = ensure_service_chains(
active_service_groups(), soa_dir, synapse_service_dir
)
ensure_dispatch_chains(service_chains)
garbage_collect_old_ser... | Update iptables to match the current PaaSTA state. | general_update | python | Yelp/paasta | paasta_tools/firewall.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/firewall.py | Apache-2.0 |
def prepare_new_container(soa_dir, synapse_service_dir, service, instance, mac):
"""Update iptables to include rules for a new (not yet running) MAC address"""
ensure_shared_chains() # probably already set, but just to be safe
service_group = ServiceGroup(service, instance)
service_group.update_rules(s... | Update iptables to include rules for a new (not yet running) MAC address | prepare_new_container | python | Yelp/paasta | paasta_tools/firewall.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/firewall.py | Apache-2.0 |
def firewall_flock(flock_path=DEFAULT_FIREWALL_FLOCK_PATH):
"""Grab an exclusive flock to avoid concurrent iptables updates"""
with io.FileIO(flock_path, "w") as f:
with timed_flock(f, seconds=DEFAULT_FIREWALL_FLOCK_TIMEOUT_SECS):
yield | Grab an exclusive flock to avoid concurrent iptables updates | firewall_flock | python | Yelp/paasta | paasta_tools/firewall.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/firewall.py | Apache-2.0 |
def load_flinkeks_instance_config(
service: str,
instance: str,
cluster: str,
load_deployments: bool = True,
soa_dir: str = DEFAULT_SOA_DIR,
) -> FlinkEksDeploymentConfig:
"""Read a service instance's configuration for Flink on EKS.
If a branch isn't specified for a config, the 'branch' key... | Read a service instance's configuration for Flink on EKS.
If a branch isn't specified for a config, the 'branch' key defaults to
paasta-${cluster}.${instance}.
:param service: The service name
:param instance: The instance of the service to retrieve
:param cluster: The cluster to read the configur... | load_flinkeks_instance_config | python | Yelp/paasta | paasta_tools/flinkeks_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/flinkeks_tools.py | Apache-2.0 |
def get_pool(self) -> Optional[str]:
"""
Parses flink_pool from a specific Flink Deployment instance's configuration data, using key 'spot'.
Args:
flink_deployment_config_data: The FlinkDeploymentConfig for a specific Flink yelpsoa instance
Returns:
The flink po... |
Parses flink_pool from a specific Flink Deployment instance's configuration data, using key 'spot'.
Args:
flink_deployment_config_data: The FlinkDeploymentConfig for a specific Flink yelpsoa instance
Returns:
The flink pool string.
| get_pool | python | Yelp/paasta | paasta_tools/flink_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py | Apache-2.0 |
def load_flink_instance_config(
service: str,
instance: str,
cluster: str,
load_deployments: bool = True,
soa_dir: str = DEFAULT_SOA_DIR,
) -> FlinkDeploymentConfig:
"""Read a service instance's configuration for Flink.
If a branch isn't specified for a config, the 'branch' key defaults to
... | Read a service instance's configuration for Flink.
If a branch isn't specified for a config, the 'branch' key defaults to
paasta-${cluster}.${instance}.
:param service: The service name
:param instance: The instance of the service to retrieve
:param cluster: The cluster to read the configuration f... | load_flink_instance_config | python | Yelp/paasta | paasta_tools/flink_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py | Apache-2.0 |
def _filter_for_endpoint(json_response: Any, endpoint: str) -> Mapping[str, Any]:
"""
Filter json response to include only a subset of fields.
"""
if endpoint == "config":
return {
key: value for (key, value) in json_response.items() if key in CONFIG_KEYS
}
if endpoint ==... |
Filter json response to include only a subset of fields.
| _filter_for_endpoint | python | Yelp/paasta | paasta_tools/flink_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py | Apache-2.0 |
def get_flink_jobs_from_paasta_api_client(
service: str, instance: str, client: PaastaOApiClient
) -> FlinkJobs:
"""Get flink jobs for (service, instance) pair by connecting to the paasta api endpoint.
Appends exception to output list if any.
:param service: The service name
:param instance: The i... | Get flink jobs for (service, instance) pair by connecting to the paasta api endpoint.
Appends exception to output list if any.
:param service: The service name
:param instance: The instance of the service to retrieve
:param client: The paasta api client
:returns: Flink jobs in the flink cluster | get_flink_jobs_from_paasta_api_client | python | Yelp/paasta | paasta_tools/flink_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py | Apache-2.0 |
async def get_flink_job_details_from_paasta_api_client(
service: str, instance: str, job_id: str, client: PaastaOApiClient
) -> FlinkJobDetails:
"""Get flink job details for (service, instance) pair by connecting to the paasta api endpoint.
Appends exception to output list if any.
:param service: The ... | Get flink job details for (service, instance) pair by connecting to the paasta api endpoint.
Appends exception to output list if any.
:param service: The service name
:param instance: The instance of the service to retrieve
:param client: The paasta api client
:returns: Flink jobs in the flink clu... | get_flink_job_details_from_paasta_api_client | python | Yelp/paasta | paasta_tools/flink_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py | Apache-2.0 |
def get_flink_config_from_paasta_api_client(
service: str, instance: str, client: PaastaOApiClient
) -> FlinkConfig:
"""Get flink config for (service, instance) pair by connecting to the paasta api endpoint.
Appends exception to output list if any.
:param service: The service name
:param instance:... | Get flink config for (service, instance) pair by connecting to the paasta api endpoint.
Appends exception to output list if any.
:param service: The service name
:param instance: The instance of the service to retrieve
:param client: The paasta api client
:returns: Flink cluster configurations | get_flink_config_from_paasta_api_client | python | Yelp/paasta | paasta_tools/flink_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py | Apache-2.0 |
def get_flink_overview_from_paasta_api_client(
service: str, instance: str, client: PaastaOApiClient
) -> FlinkClusterOverview:
"""Get flink cluster overview for (service, instance) pair by connecting to the paasta api endpoint.
Appends exception to output list if any.
:param service: The service name... | Get flink cluster overview for (service, instance) pair by connecting to the paasta api endpoint.
Appends exception to output list if any.
:param service: The service name
:param instance: The instance of the service to retrieve
:param client: The paasta api client
:returns: Flink cluster overview | get_flink_overview_from_paasta_api_client | python | Yelp/paasta | paasta_tools/flink_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py | Apache-2.0 |
def get_deploy_group_mappings(
soa_dir: str, service: str
) -> Tuple[Dict[str, V1_Mapping], V2_Mappings]:
"""Gets mappings from service:deploy_group to services-service:paasta-hash-image_version,
where hash is the current SHA at the HEAD of branch_name and image_version
can be used to provide additional... | Gets mappings from service:deploy_group to services-service:paasta-hash-image_version,
where hash is the current SHA at the HEAD of branch_name and image_version
can be used to provide additional version information for the Docker image.
This is done for all services in soa_dir.
:param soa_dir: The SOA... | get_deploy_group_mappings | python | Yelp/paasta | paasta_tools/generate_deployments_for_service.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/generate_deployments_for_service.py | Apache-2.0 |
async def get_spool(spool_url: str) -> SpoolInfo:
"""Query hacheck for the state of a task, and parse the result into a dictionary."""
if spool_url is None:
return None
# TODO: aiohttp says not to create a session per request. Fix this.
async with aiohttp.ClientSession(timeout=HACHECK_TIMEOUT) ... | Query hacheck for the state of a task, and parse the result into a dictionary. | get_spool | python | Yelp/paasta | paasta_tools/hacheck.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/hacheck.py | Apache-2.0 |
def ensure_chain(chain, rules):
"""Idempotently ensure a chain exists and has an exact set of rules.
This function creates or updates an existing chain to match the rules
passed in.
This function will not reorder existing rules, but any new rules are always
inserted at the front of the chain.
... | Idempotently ensure a chain exists and has an exact set of rules.
This function creates or updates an existing chain to match the rules
passed in.
This function will not reorder existing rules, but any new rules are always
inserted at the front of the chain.
| ensure_chain | python | Yelp/paasta | paasta_tools/iptables.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/iptables.py | Apache-2.0 |
def reorder_chain(chain_name):
"""Ensure that any REJECT rules are last, and any LOG rules are second-to-last"""
table = iptc.Table(iptc.Table.FILTER)
with iptables_txn(table):
rules = list_chain(chain_name)
chain = iptc.Chain(table, chain_name)
# sort the rules by rule_key, which ... | Ensure that any REJECT rules are last, and any LOG rules are second-to-last | reorder_chain | python | Yelp/paasta | paasta_tools/iptables.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/iptables.py | Apache-2.0 |
def list_chain(chain_name):
"""List rules in a chain.
Returns a list of iptables rules, or raises ChainDoesNotExist.
"""
table = iptc.Table(iptc.Table.FILTER)
chain = iptc.Chain(table, chain_name)
# TODO: is there any way to do this without listing all chains? (probably slow)
# If the chain... | List rules in a chain.
Returns a list of iptables rules, or raises ChainDoesNotExist.
| list_chain | python | Yelp/paasta | paasta_tools/iptables.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/iptables.py | Apache-2.0 |
def load_kafkacluster_instance_config(
service: str,
instance: str,
cluster: str,
load_deployments: bool = True,
soa_dir: str = DEFAULT_SOA_DIR,
) -> KafkaClusterDeploymentConfig:
"""Read a service instance's configuration for KafkaCluster.
If a branch isn't specified for a config, the 'bra... | Read a service instance's configuration for KafkaCluster.
If a branch isn't specified for a config, the 'branch' key defaults to
paasta-${cluster}.${instance}.
:param service: The service name
:param instance: The instance of the service to retrieve
:param cluster: The cluster to read the configur... | load_kafkacluster_instance_config | python | Yelp/paasta | paasta_tools/kafkacluster_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kafkacluster_tools.py | Apache-2.0 |
def load_kubernetes_service_config_no_cache(
service: str,
instance: str,
cluster: str,
load_deployments: bool = True,
soa_dir: str = DEFAULT_SOA_DIR,
) -> "KubernetesDeploymentConfig":
"""Read a service instance's configuration for kubernetes.
If a branch isn't specified for a config, the ... | Read a service instance's configuration for kubernetes.
If a branch isn't specified for a config, the 'branch' key defaults to
paasta-${cluster}.${instance}.
:param name: The service name
:param instance: The instance of the service to retrieve
:param cluster: The cluster to read the configuration... | load_kubernetes_service_config_no_cache | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def __new__(
cls,
component: Optional[str] = None,
config_file: Optional[str] = None,
context: Optional[str] = None,
) -> "KubeClient":
"""By @lru_cache'ing this function, repeated instantiations of KubeClient with the same arguments will return the
exact same object.... | By @lru_cache'ing this function, repeated instantiations of KubeClient with the same arguments will return the
exact same object. This makes it possible to effectively cache function calls that take a KubeClient as an
argument. | __new__ | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def allowlist_denylist_to_requirements(
allowlist: DeployWhitelist, denylist: DeployBlacklist
) -> List[Tuple[str, str, List[str]]]:
"""Converts deploy_whitelist and deploy_blacklist to a list of
requirements, which can be converted to node affinities.
"""
requirements = []
# convert whitelist i... | Converts deploy_whitelist and deploy_blacklist to a list of
requirements, which can be converted to node affinities.
| allowlist_denylist_to_requirements | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def raw_selectors_to_requirements(
raw_selectors: Mapping[str, NodeSelectorConfig]
) -> List[Tuple[str, str, List[str]]]:
"""Converts certain node_selectors into requirements, which can be
converted to node affinities.
"""
requirements: List[Tuple[str, str, List[str]]] = []
for label, configs i... | Converts certain node_selectors into requirements, which can be
converted to node affinities.
| raw_selectors_to_requirements | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_bounce_method(self) -> str:
"""Get the bounce method specified in the service's kubernetes configuration."""
# map existing bounce methods to k8s equivalents.
# but if there's an EBS volume we must downthenup to free up the volume.
# in the future we may support stateful sets to ... | Get the bounce method specified in the service's kubernetes configuration. | get_bounce_method | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_autoscaling_scaling_policy(
self,
max_replicas: int,
autoscaling_params: AutoscalingParamsDict,
) -> Dict:
"""Returns the k8s HPA scaling policy in raw JSON. Requires k8s v1.18
to work.
"""
# The HPA scaling algorithm is as follows. Every sync period (... | Returns the k8s HPA scaling policy in raw JSON. Requires k8s v1.18
to work.
| get_autoscaling_scaling_policy | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_sanitised_volume_name(self, volume_name: str, length_limit: int = 0) -> str:
"""I know but we really aren't allowed many characters..."""
volume_name = volume_name.rstrip("/")
sanitised = volume_name.replace("/", "slash-").replace(".", "dot-")
sanitised_name = sanitise_kubernetes... | I know but we really aren't allowed many characters... | get_sanitised_volume_name | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_readiness_check_script(
self, system_paasta_config: SystemPaastaConfig
) -> List[str]:
"""Script to check if a service is up in smartstack / envoy"""
enable_envoy_check = self.get_enable_envoy_readiness_check(system_paasta_config)
enable_nerve_check = self.get_enable_nerve_re... | Script to check if a service is up in smartstack / envoy | get_readiness_check_script | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_env_vars_that_use_secrets(self) -> Tuple[Dict[str, str], Dict[str, str]]:
"""Returns two dictionaries of environment variable name->value; the first is vars that use non-shared
secrets, and the second is vars that use shared secrets.
The values of the dictionaries are the secret refs as... | Returns two dictionaries of environment variable name->value; the first is vars that use non-shared
secrets, and the second is vars that use shared secrets.
The values of the dictionaries are the secret refs as formatted in yelpsoa-configs, e.g. "SECRET(foo)"
or "SHARED_SECRET(bar)". These can ... | get_env_vars_that_use_secrets | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_hacheck_prestop_sleep_seconds(self) -> int:
"""The number of seconds to sleep between hadown and terminating the hacheck container. We want hacheck to be
up for slightly longer than the main container is, so we default to pre_stop_drain_seconds + 1.
It doesn't super matter if hacheck go... | The number of seconds to sleep between hadown and terminating the hacheck container. We want hacheck to be
up for slightly longer than the main container is, so we default to pre_stop_drain_seconds + 1.
It doesn't super matter if hacheck goes down before the main container -- if it's down, healthchecks... | get_hacheck_prestop_sleep_seconds | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_datastore_credentials_secrets_volume(self) -> V1Volume:
"""
All credentials are stored in 1 Kubernetes Secret, which are mapped on an item->path
structure to /datastore/<datastore>/<credential>/<password file>.
"""
datastore_credentials = self.get_datastore_credentials()
... |
All credentials are stored in 1 Kubernetes Secret, which are mapped on an item->path
structure to /datastore/<datastore>/<credential>/<password file>.
| get_datastore_credentials_secrets_volume | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_boto_secret_signature_name(self) -> str:
"""
Keep the following signature naming convention so that bounces do not happen because boto_keys configmap signatures already exist, see PAASTA-17910
Note: Since hashing is done only on a portion of secret, it may explode if service or instance... |
Keep the following signature naming convention so that bounces do not happen because boto_keys configmap signatures already exist, see PAASTA-17910
Note: Since hashing is done only on a portion of secret, it may explode if service or instance names are too long
| get_boto_secret_signature_name | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_datastore_credentials_signature_name(self) -> str:
"""
All datastore credentials are stored in a single Kubernetes secret, so they share a name
"""
return _get_secret_signature_name(
self.get_namespace(),
"datastore-credentials",
self.get_servi... |
All datastore credentials are stored in a single Kubernetes secret, so they share a name
| get_datastore_credentials_signature_name | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def set_autoscaled_instances(
self, instance_count: int, kube_client: KubeClient
) -> None:
"""Set the number of instances in the same way that the autoscaler does."""
set_instances_for_kubernetes_service(
kube_client=kube_client, service_config=self, instance_count=instance_coun... | Set the number of instances in the same way that the autoscaler does. | set_autoscaled_instances | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_desired_instances(self) -> int:
"""For now if we have an EBS instance it means we can only have 1 instance
since we can't attach to multiple instances. In the future we might support
statefulsets which are clever enough to manage EBS for you"""
instances = super().get_desired_ins... | For now if we have an EBS instance it means we can only have 1 instance
since we can't attach to multiple instances. In the future we might support
statefulsets which are clever enough to manage EBS for you | get_desired_instances | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_enable_nerve_readiness_check(
self, system_paasta_config: SystemPaastaConfig
) -> bool:
"""Enables a k8s readiness check on the Pod to ensure that all registrations
are UP on the local synapse haproxy"""
return self.config_dict.get("bounce_health_params", {}).get(
... | Enables a k8s readiness check on the Pod to ensure that all registrations
are UP on the local synapse haproxy | get_enable_nerve_readiness_check | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_enable_envoy_readiness_check(
self, system_paasta_config: SystemPaastaConfig
) -> bool:
"""Enables a k8s readiness check on the Pod to ensure that all registrations
are UP on the local Envoy"""
return self.config_dict.get("bounce_health_params", {}).get(
"check_en... | Enables a k8s readiness check on the Pod to ensure that all registrations
are UP on the local Envoy | get_enable_envoy_readiness_check | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_namespace(self) -> str:
"""Get namespace from config, default to 'paasta'"""
return self.config_dict.get(
"namespace", f"paastasvc-{self.get_sanitised_service_name()}"
) | Get namespace from config, default to 'paasta' | get_namespace | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def format_kubernetes_job(
self,
job_label: str,
deadline_seconds: int = 3600,
keep_routable_ip: bool = False,
include_sidecars: bool = False,
) -> V1Job:
"""Create the config for launching the deployment as a Job
:param str job_label: value to set for the "j... | Create the config for launching the deployment as a Job
:param str job_label: value to set for the "job type" label
:param int deadline_seconds: maximum allowed duration for the job
:param bool keep_routable_ip: maintain routable IP annotation in pod template
:param bool include_sidecar... | format_kubernetes_job | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def format_kubernetes_app(self) -> Union[V1Deployment, V1StatefulSet]:
"""Create the configuration that will be passed to the Kubernetes REST API."""
try:
system_paasta_config = load_system_paasta_config()
docker_url = self.get_docker_url()
git_sha = get_git_sha_from... | Create the configuration that will be passed to the Kubernetes REST API. | format_kubernetes_app | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def has_routable_ip(
self,
service_namespace_config: ServiceNamespaceConfig,
system_paasta_config: SystemPaastaConfig,
) -> str:
"""Return whether the routable_ip label should be true or false.
Services with a `prometheus_port` defined or that use certain sidecars must have ... | Return whether the routable_ip label should be true or false.
Services with a `prometheus_port` defined or that use certain sidecars must have a routable IP
address to allow Prometheus shards to scrape metrics.
| has_routable_ip | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_node_selector(self) -> Mapping[str, str]:
"""Converts simple node restrictions into node selectors. Unlike node
affinities, selectors will show up in `kubectl describe`.
"""
raw_selectors: Mapping[str, Any] = self.config_dict.get("node_selectors", {})
node_selectors = {
... | Converts simple node restrictions into node selectors. Unlike node
affinities, selectors will show up in `kubectl describe`.
| get_node_selector | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_node_affinity(
self, pool_node_affinities: Dict[str, Dict[str, List[str]]] = None
) -> Optional[V1NodeAffinity]:
"""Converts deploy_whitelist and deploy_blacklist in node affinities.
note: At the time of writing, `kubectl describe` does not show affinities,
only selectors. T... | Converts deploy_whitelist and deploy_blacklist in node affinities.
note: At the time of writing, `kubectl describe` does not show affinities,
only selectors. To see affinities, use `kubectl get pod -o json` instead.
| get_node_affinity | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_pod_anti_affinity(self) -> Optional[V1PodAntiAffinity]:
"""
Converts the given anti-affinity on service and instance to pod
affinities with the "paasta.yelp.com" prefixed label selector
:return:
"""
required_terms = self.get_pod_required_anti_affinity_terms()
... |
Converts the given anti-affinity on service and instance to pod
affinities with the "paasta.yelp.com" prefixed label selector
:return:
| get_pod_anti_affinity | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def _kube_affinity_condition_to_label_selector(
self, condition: KubeAffinityCondition
) -> Optional[V1LabelSelector]:
"""Converts the given condition to label selectors with paasta prefix"""
labels = {}
if "service" in condition:
labels[PAASTA_ATTRIBUTE_PREFIX + "service... | Converts the given condition to label selectors with paasta prefix | _kube_affinity_condition_to_label_selector | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def sanitize_for_config_hash(
self, config: Union[V1Deployment, V1StatefulSet]
) -> Mapping[str, Any]:
"""Removes some data from config to make it suitable for
calculation of config hash.
:param config: complete_config hash to sanitise
:returns: sanitised copy of complete_co... | Removes some data from config to make it suitable for
calculation of config hash.
:param config: complete_config hash to sanitise
:returns: sanitised copy of complete_config hash
| sanitize_for_config_hash | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_termination_grace_period(
self, service_namespace_config: ServiceNamespaceConfig
) -> Optional[int]:
"""Return the number of seconds that kubernetes should wait for pre-stop hooks to finish (or for the main
process to exit after signaling) before forcefully terminating the pod.
... | Return the number of seconds that kubernetes should wait for pre-stop hooks to finish (or for the main
process to exit after signaling) before forcefully terminating the pod.
For smartstack services, defaults to a value long enough to allow the default pre-stop hook to finish.
For non-smartstac... | get_termination_grace_period | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_all_kubernetes_services_running_here() -> List[Tuple[str, str, int]]:
"""Returns all k8s paasta services, even if not in smartstack. Returns a service, instance, port
tuple to match the return value of other similar functions"""
services = []
try:
pods = get_k8s_pods()
except request... | Returns all k8s paasta services, even if not in smartstack. Returns a service, instance, port
tuple to match the return value of other similar functions | get_all_kubernetes_services_running_here | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def list_all_paasta_deployments(kube_client: KubeClient) -> Sequence[KubeDeployment]:
"""Gets deployments in all namespaces by passing the service label selector"""
label_selectors = "paasta.yelp.com/service"
return list_deployments_in_all_namespaces(
kube_client=kube_client, label_selector=label_se... | Gets deployments in all namespaces by passing the service label selector | list_all_paasta_deployments | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def filter_nodes_by_blacklist(
nodes: Sequence[V1Node], blacklist: DeployBlacklist, whitelist: DeployWhitelist
) -> Sequence[V1Node]:
"""Takes an input list of nodes and filters them based on the given blacklist.
The blacklist is in the form of:
[["location_type", "location]]
Where the list in... | Takes an input list of nodes and filters them based on the given blacklist.
The blacklist is in the form of:
[["location_type", "location]]
Where the list inside is something like ["region", "uswest1-prod"]
:returns: The list of nodes after the filter
| filter_nodes_by_blacklist | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def update_secret(
kube_client: KubeClient,
service_name: str,
secret_name: str,
secret_data: Dict[str, str],
namespace: str,
) -> None:
"""
Expect secret_name to exist, e.g. kubectl get secret
:param service_name: Expect unsanitised service name
:param secret_data: Expect a mapping ... |
Expect secret_name to exist, e.g. kubectl get secret
:param service_name: Expect unsanitised service name
:param secret_data: Expect a mapping of string-to-string where values are base64-encoded
:param namespace: Unsanitized namespace of a service that will use the secret
:raises ApiException:
| update_secret | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_secret_signature(
kube_client: KubeClient,
signature_name: str,
namespace: str,
) -> Optional[str]:
"""
:param signature_name: Expect the signature to exist in kubernetes configmap
:return: Kubernetes configmap as a signature
:raises ApiException:
"""
try:
signature =... |
:param signature_name: Expect the signature to exist in kubernetes configmap
:return: Kubernetes configmap as a signature
:raises ApiException:
| get_secret_signature | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def update_secret_signature(
kube_client: KubeClient,
service_name: str,
signature_name: str,
secret_signature: str,
namespace: str,
) -> None:
"""
:param service_name: Expect unsanitised service_name
:param signature_name: Expect signature_name to exist in kubernetes configmap
:para... |
:param service_name: Expect unsanitised service_name
:param signature_name: Expect signature_name to exist in kubernetes configmap
:param secret_signature: Signature to replace with
:raises ApiException:
| update_secret_signature | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def create_secret_signature(
kube_client: KubeClient,
service_name: str,
signature_name: str,
secret_signature: str,
namespace: str,
) -> None:
"""
:param service_name: Expect unsanitised service_name
:param signature_name: Expected properly formatted signature, see _get_secret_signature... |
:param service_name: Expect unsanitised service_name
:param signature_name: Expected properly formatted signature, see _get_secret_signature_name()
:param secret_signature: Signature value
:param namespace: Unsanitized namespace of a service that will use the signature
| create_secret_signature | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def sanitise_kubernetes_name(
service: str,
) -> str:
"""
Sanitizes kubernetes name so that hyphen (-) can be used a delimeter
"""
name = service.replace("_", "--")
if name.startswith("--"):
name = name.replace("--", "underscore-", 1)
return name.lower() |
Sanitizes kubernetes name so that hyphen (-) can be used a delimeter
| sanitise_kubernetes_name | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def create_pod_topology_spread_constraints(
service: str,
instance: str,
topology_spread_constraints: List[TopologySpreadConstraintDict],
) -> List[V1TopologySpreadConstraint]:
"""
Applies cluster-level topology spread constraints to every Pod template.
This allows us to configure default topolo... |
Applies cluster-level topology spread constraints to every Pod template.
This allows us to configure default topology spread constraints on EKS where we cannot configure the scheduler.
| create_pod_topology_spread_constraints | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_pod_hostname(kube_client: KubeClient, pod: V1Pod) -> str:
"""Gets the hostname of a pod's node from labels"""
if not pod.spec.node_name: # can be none, if pod not yet scheduled
return "NotScheduled"
try:
node = kube_client.core.read_node(name=pod.spec.node_name)
except ApiExcept... | Gets the hostname of a pod's node from labels | get_pod_hostname | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def _get_secret_signature_name(
namespace: str, secret_identifier: str, service_name: str, key_name: str
) -> str:
"""
:param namespace: Unsanitised namespace of a service that will use the signature
:param secret_identifier: Identifies the type of secret
:param service_name: Unsanitised service_nam... |
:param namespace: Unsanitised namespace of a service that will use the signature
:param secret_identifier: Identifies the type of secret
:param service_name: Unsanitised service_name
:param key_name: Name of the actual secret, typically specified in a configuration file
:return: Sanitised signature... | _get_secret_signature_name | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_paasta_secret_name(namespace: str, service_name: str, key_name: str) -> str:
"""
Use whenever creating or references a PaaSTA secret
:param namespace: Unsanitised namespace of a service that will use the signature
:param service_name: Unsanitised service_name
:param key_name: Name of the ac... |
Use whenever creating or references a PaaSTA secret
:param namespace: Unsanitised namespace of a service that will use the signature
:param service_name: Unsanitised service_name
:param key_name: Name of the actual secret, typically specified in a configuration file
:return: Sanitised PaaSTA secre... | get_paasta_secret_name | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_paasta_secret_signature_name(
namespace: str, service_name: str, key_name: str
) -> str:
"""
Get PaaSTA signature name stored as kubernetes configmap
:param namespace: Unsanitised namespace of a service that will use the signature
:param service_name: Unsanitised service_name
:param key... |
Get PaaSTA signature name stored as kubernetes configmap
:param namespace: Unsanitised namespace of a service that will use the signature
:param service_name: Unsanitised service_name
:param key_name: Name of the actual secret, typically specified in a configuration file
:return: Sanitised PaaSTA ... | get_paasta_secret_signature_name | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_secret(
kube_client: KubeClient,
secret_name: str,
key_name: str,
*,
namespace: str,
decode: bool = True,
) -> Union[str, bytes]:
"""
:param secret_name: Expect properly formatted kubernetes secret name and that it exists
:param key_name: Expect key_name to be a key in a data... |
:param secret_name: Expect properly formatted kubernetes secret name and that it exists
:param key_name: Expect key_name to be a key in a data section
:raises ApiException:
:raises KeyError: if key_name does not exists in kubernetes secret's data section
| get_secret | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def patch_namespaced_configmap(
name: str,
body: Dict[str, str],
*,
namespace: str,
kube_client: KubeClient,
) -> V1ConfigMap:
"""
Patches a configmap with the given body. The body should be a dictionary of key-value pairs.
"""
try:
return kube_client.core.patch_namespaced_co... |
Patches a configmap with the given body. The body should be a dictionary of key-value pairs.
| patch_namespaced_configmap | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
def get_or_create_namespaced_configmap(
configmap: str,
*,
namespace: str,
kube_client: KubeClient,
) -> Tuple[V1ConfigMap, bool]:
"""
Returns a 2-tuple of (the configmap, a bool representing whether it was just created)
"""
try:
return (
kube_client.core.read_namespa... |
Returns a 2-tuple of (the configmap, a bool representing whether it was just created)
| get_or_create_namespaced_configmap | python | Yelp/paasta | paasta_tools/kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.