From d1e6b202d297912461fc76d3416d230c24cecdba Mon Sep 17 00:00:00 2001 From: Vinay Sagar Gonabavi Date: Wed, 11 Dec 2024 10:11:43 -0800 Subject: [PATCH] Clean up Vitess from PaaSTA --- paasta_tools/api/api_docs/oapi.yaml | 17 - paasta_tools/api/api_docs/swagger.json | 20 - paasta_tools/cli/cmds/status.py | 250 ----- paasta_tools/cli/utils.py | 7 - paasta_tools/instance/kubernetes.py | 3 - .../paastaapi/model/instance_status.py | 5 - .../model/instance_status_vitesscluster.py | 173 ---- paasta_tools/paastaapi/models/__init__.py | 1 - paasta_tools/setup_kubernetes_cr.py | 11 - paasta_tools/utils.py | 50 - paasta_tools/vitesscluster_tools.py | 940 ------------------ tests/test_utils.py | 2 - tests/test_vitesscluster_tools.py | 735 -------------- 13 files changed, 2214 deletions(-) delete mode 100644 paasta_tools/paastaapi/model/instance_status_vitesscluster.py delete mode 100644 paasta_tools/vitesscluster_tools.py delete mode 100644 tests/test_vitesscluster_tools.py diff --git a/paasta_tools/api/api_docs/oapi.yaml b/paasta_tools/api/api_docs/oapi.yaml index 1518b6b65d..41eb14e2f1 100644 --- a/paasta_tools/api/api_docs/oapi.yaml +++ b/paasta_tools/api/api_docs/oapi.yaml @@ -339,12 +339,6 @@ components: InstanceSpecCassandraCluster: description: Cassandra instance spec type: object - InstanceMetadataVitessCluster: - description: VitessCluster instance metadata - type: object - InstanceSpecVitessCluster: - description: VitessCluster instance spec - type: object InstanceStatus: properties: adhoc: @@ -383,14 +377,6 @@ components: status: $ref: '#/components/schemas/InstanceStatusCassandraCluster' type: object - vitesscluster: - description: Nullable VitessCluster instance status and metadata - properties: - metadata: - $ref: '#/components/schemas/InstanceMetadataVitessCluster' - status: - $ref: '#/components/schemas/InstanceStatusVitessCluster' - type: object kafkacluster: description: Nullable KafkaCluster instance status and metadata properties: @@ -426,9 +412,6 @@ components: InstanceStatusCassandraCluster: description: Cassandra instance status type: object - InstanceStatusVitessCluster: - description: VitessCluster instance status - type: object InstanceStatusKafkaCluster: description: Kafka instance status type: object diff --git a/paasta_tools/api/api_docs/swagger.json b/paasta_tools/api/api_docs/swagger.json index 9caa3c8cac..47ba3b875f 100644 --- a/paasta_tools/api/api_docs/swagger.json +++ b/paasta_tools/api/api_docs/swagger.json @@ -960,18 +960,6 @@ } }, "description": "Nullable CassandraCluster instance status" - }, - "vitesscluster": { - "type": "object", - "properties": { - "status": { - "$ref": "#/definitions/InstanceStatusVitessCluster" - }, - "metadata": { - "$ref": "#/definitions/InstanceMetadataVitessCluster" - } - }, - "description": "Nullable VitessCluster instance status and metadata" } } }, @@ -1756,14 +1744,6 @@ "type": "object", "description": "Cassandra instance status" }, - "InstanceStatusVitessCluster": { - "type": "object", - "description": "VitessCluster instance status" - }, - "InstanceMetadataVitessCluster": { - "type": "object", - "description": "VitessCluster instance metadata" - }, "InstanceTasks": { "type": "array", "description": "List of tasks associated with instance", diff --git a/paasta_tools/cli/cmds/status.py b/paasta_tools/cli/cmds/status.py index a831c38fb2..481daed80f 100644 --- a/paasta_tools/cli/cmds/status.py +++ b/paasta_tools/cli/cmds/status.py @@ -37,7 +37,6 @@ from typing import Sequence from typing import Tuple from typing import Type -from typing import TypedDict from typing import Union import a_sync @@ -95,14 +94,12 @@ from paasta_tools.utils import PaastaColors from paasta_tools.utils import remove_ansi_escape_sequences from paasta_tools.utils import SystemPaastaConfig -from paasta_tools.vitesscluster_tools import VitessDeploymentConfig FLINK_STATUS_MAX_THREAD_POOL_WORKERS = 50 ALLOWED_INSTANCE_CONFIG: Sequence[Type[InstanceConfig]] = [ FlinkDeploymentConfig, FlinkEksDeploymentConfig, CassandraClusterDeploymentConfig, - VitessDeploymentConfig, KafkaClusterDeploymentConfig, KubernetesDeploymentConfig, EksDeploymentConfig, @@ -115,7 +112,6 @@ FlinkDeploymentConfig, FlinkEksDeploymentConfig, CassandraClusterDeploymentConfig, - VitessDeploymentConfig, KafkaClusterDeploymentConfig, KubernetesDeploymentConfig, EksDeploymentConfig, @@ -137,7 +133,6 @@ EKS_DEPLOYMENT_CONFIGS = [ EksDeploymentConfig, FlinkEksDeploymentConfig, - VitessDeploymentConfig, ] FLINK_DEPLOYMENT_CONFIGS = [FlinkDeploymentConfig, FlinkEksDeploymentConfig] @@ -1906,250 +1901,6 @@ def print_kafka_status( return 0 -class EtcdLockServerStatus(TypedDict, total=False): - observedGeneration: int - available: str - clientServiceName: str - - -class LockServerStatus(TypedDict, total=False): - etcd: EtcdLockServerStatus - - -class VitessClusterCellStatus(TypedDict, total=False): - pendingChanges: str - gatewayAvailable: str - - -class VitessClusterKeyspaceStatus(TypedDict, total=False): - pendingChanges: str - cells: List[str] - desiredShards: int - shards: int - readyShards: int - updatedShards: int - desiredTablets: int - tablets: int - readyTablets: int - updatedTablets: int - - -class VitessDashboardStatus(TypedDict, total=False): - available: str - serviceName: str - - -class VTAdminStatus(TypedDict, total=False): - available: str - serviceName: str - - -class OrphanStatus(TypedDict, total=False): - reason: str - message: str - - -class VitessClusterStatus(TypedDict, total=False): - observedGeneration: int - globalLockserver: LockServerStatus - gatewayServiceName: str - vitessDashboard: VitessDashboardStatus - cells: Dict[str, VitessClusterCellStatus] - keyspaces: Dict[str, VitessClusterKeyspaceStatus] - vtadmin: VTAdminStatus - orphanedCells: Dict[str, OrphanStatus] - orphanedKeyspaces: Dict[str, OrphanStatus] - - -def print_vitess_status( - cluster: str, - service: str, - instance: str, - output: List[str], - vitess_status: Mapping[str, Any], - verbose: int = 0, -) -> int: - tab = " " - indent = 1 - - status: VitessClusterStatus = vitess_status.get("status") - if status is None: - output.append( - PaastaColors.red("indent * tab + Vitess cluster is not available yet") - ) - return 1 - - output.append(indent * tab + "Vitess Cluster:") - indent += 1 - - output.append( - indent * tab - + "Observed Generation: " - + str(status.get("observedGeneration", 0)) - ) - output.append( - indent * tab + "Gateway Service Name: " + status.get("gatewayServiceName", "") - ) - - output.append(indent * tab + "Cells:") - indent += 1 - cells: Dict[str, VitessClusterCellStatus] = status.get("cells") - if not cells: - output.append( - indent * tab + "Cells: " + PaastaColors.red("No cell status available") - ) - return 0 - for cell, cell_status in cells.items(): - gateway_available: str = cell_status.get("gatewayAvailable") - if gateway_available == "True": - output.append( - indent * tab - + f"Cell: {cell} - VTGate: {PaastaColors.green('available')}" - ) - else: - output.append( - indent * tab - + f"Cell: {cell} - VTGate: {PaastaColors.red('unavailable')}" - ) - cell_pending_changes: str = cell_status.get("pendingChanges", None) - if cell_pending_changes: - output.append(indent * tab + f" Pending Changes: {cell_pending_changes}") - indent -= 1 - - output.append(indent * tab + "Vitess Dashboard:") - indent += 1 - vitess_dashboard: VitessDashboardStatus = status.get("vitessDashboard") - if not vitess_dashboard: - output.append( - indent * tab - + "Vitess Dashboard: " - + PaastaColors.red("No dashboard status available") - ) - return 0 - vitess_dashboard_available: str = vitess_dashboard.get("available", "") - vitess_dashboard_service_name: str = vitess_dashboard.get("serviceName", "") - if vitess_dashboard_available == "True": - output.append( - indent * tab - + f"Vitess Dashboard: {vitess_dashboard_service_name} - {PaastaColors.green('available')}" - ) - else: - output.append( - indent * tab - + f"Vitess Dashboard: {vitess_dashboard_service_name} - {PaastaColors.red('unavailable')}" - ) - indent -= 1 - - output.append(indent * tab + "VTAdmin:") - indent += 1 - vtadmin: VTAdminStatus = status.get("vtadmin") - if not vtadmin: - output.append( - indent * tab + "VTAdmin: " + PaastaColors.red("No VTAdmin status available") - ) - return 0 - vtadmin_available: str = vtadmin.get("available", "") - vtadmin_service_name: str = vtadmin.get("serviceName", "") - if vtadmin_available == "True": - output.append( - indent * tab - + f"VTAdmin: {vtadmin_service_name} - {PaastaColors.green('available')}" - ) - else: - output.append( - indent * tab - + f"VTAdmin: {vtadmin_service_name} - {PaastaColors.red('unavailable')}" - ) - indent -= 1 - - output.append(indent * tab + "Keyspaces:") - indent += 1 - keyspaces: Dict[str, VitessClusterKeyspaceStatus] = status.get("keyspaces") - if not keyspaces: - output.append( - indent * tab - + "Keyspaces: " - + PaastaColors.red("No keyspace status available") - ) - return 0 - for keyspace, keyspace_status in keyspaces.items(): - output.append(indent * tab + f"Keyspace: {keyspace}") - indent += 1 - keyspace_pending_changes: str = keyspace_status.get("pendingChanges", None) - if keyspace_pending_changes: - output.append( - indent * tab - + f"Keyspace: {keyspace} - Pending Changes: {keyspace_pending_changes}" - ) - keyspace_cells: List[str] = keyspace_status.get("cells", []) - output.append(indent * tab + f" Cells: {', '.join(keyspace_cells)}") - desired_shards: int = keyspace_status.get("desiredShards", 0) - shards: int = keyspace_status.get("shards", 0) - ready_shards: int = keyspace_status.get("readyShards", 0) - updated_shards: int = keyspace_status.get("updatedShards", 0) - output.append( - indent * tab - + f" Shards: {shards} observed, {ready_shards}/{desired_shards} ready, {updated_shards}/{desired_shards} updated" - ) - desired_tablets: int = keyspace_status.get("desiredTablets", 0) - tablets: int = keyspace_status.get("tablets", 0) - ready_tablets: int = keyspace_status.get("readyTablets", 0) - updated_tablets: int = keyspace_status.get("updatedTablets", 0) - output.append( - indent * tab - + f" Tablets: {tablets} observed, {ready_tablets}/{desired_tablets} ready, {updated_tablets}/{desired_tablets} updated" - ) - indent -= 1 - indent -= 1 - - # This is not needed when not using etcd. We use zk instead - global_lockserver: LockServerStatus = status.get("globalLockserver", {}) - if global_lockserver: - output.append(indent * tab + "Global Lockserver:") - indent += 1 - etcd: EtcdLockServerStatus = global_lockserver.get("etcd") - if etcd: - output.append(indent * tab + "Global Lockserver:") - indent += 1 - observed_generation: int = etcd.get("observedGeneration", 0) - available: str = etcd.get("available", "") - client_service_name: str = etcd.get("clientServiceName", "") - output.append( - indent * tab - + f"Observed Generation: {observed_generation}, Available: {available}, Client Service Name: {client_service_name}" - ) - indent -= 1 - - # Orphaned Cells are not mandatorily seen each time - orphaned_cells: Dict[str, OrphanStatus] = status.get("orphanedCells", {}) - if orphaned_cells: - output.append(indent * tab + "Orphaned Cells:") - indent += 1 - for cell, orphan_status in orphaned_cells.items(): - orphaned_cell_reason: str = orphan_status.get("reason", "") - orphaned_cell_message: str = orphan_status.get("message", "") - output.append( - indent * tab - + f"Cell: {cell} - Reason: {orphaned_cell_reason}, Message: {orphaned_cell_message}" - ) - indent -= 1 - - # Orphaned Keyspaces are not mandatorily seen each time - orphaned_keyspaces: Dict[str, OrphanStatus] = status.get("orphanedKeyspaces", {}) - if orphaned_keyspaces: - output.append(indent * tab + "Orphaned Keyspaces:") - indent += 1 - for keyspace, orphan_status in orphaned_keyspaces.items(): - orphaned_keyspace_reason: str = orphan_status.get("reason", "") - orphaned_keyspace_message: str = orphan_status.get("message", "") - output.append( - indent * tab - + f"Keyspace: {keyspace} - Reason: {orphaned_keyspace_reason}, Message: {orphaned_keyspace_message}" - ) - indent -= 1 - return 0 - - def report_status_for_cluster( service: str, cluster: str, @@ -2548,5 +2299,4 @@ def _use_new_paasta_status(args, system_paasta_config) -> bool: flinkeks=print_flinkeks_status, kafkacluster=print_kafka_status, cassandracluster=print_cassandra_status, - vitesscluster=print_vitess_status, ) diff --git a/paasta_tools/cli/utils.py b/paasta_tools/cli/utils.py index b05240e1e4..868e2eab14 100644 --- a/paasta_tools/cli/utils.py +++ b/paasta_tools/cli/utils.py @@ -76,7 +76,6 @@ from paasta_tools.utils import PaastaColors from paasta_tools.utils import SystemPaastaConfig from paasta_tools.utils import validate_service_instance -from paasta_tools.vitesscluster_tools import load_vitess_instance_config try: from vault_tools.paasta_secret import get_client as get_vault_client @@ -683,9 +682,6 @@ class LongRunningInstanceTypeHandler(NamedTuple): kafkacluster=InstanceTypeHandler( get_service_instance_list, load_kafkacluster_instance_config ), - vitesscluster=InstanceTypeHandler( - get_service_instance_list, load_vitess_instance_config - ), nrtsearchservice=InstanceTypeHandler( get_service_instance_list, load_nrtsearchservice_instance_config ), @@ -716,9 +712,6 @@ class LongRunningInstanceTypeHandler(NamedTuple): kafkacluster=LongRunningInstanceTypeHandler( get_service_instance_list, load_kafkacluster_instance_config ), - vitesscluster=LongRunningInstanceTypeHandler( - get_service_instance_list, load_vitess_instance_config - ), nrtsearchservice=LongRunningInstanceTypeHandler( get_service_instance_list, load_nrtsearchservice_instance_config ), diff --git a/paasta_tools/instance/kubernetes.py b/paasta_tools/instance/kubernetes.py index 7f57b8c380..46a1892bd4 100644 --- a/paasta_tools/instance/kubernetes.py +++ b/paasta_tools/instance/kubernetes.py @@ -33,7 +33,6 @@ from paasta_tools import monkrelaycluster_tools from paasta_tools import nrtsearchservice_tools from paasta_tools import smartstack_tools -from paasta_tools import vitesscluster_tools from paasta_tools.cli.utils import LONG_RUNNING_INSTANCE_TYPE_HANDLERS from paasta_tools.instance.hpa_metrics_parser import HPAMetricsDict from paasta_tools.instance.hpa_metrics_parser import HPAMetricsParser @@ -56,7 +55,6 @@ "flinkeks", "cassandracluster", "kafkacluster", - "vitesscluster", } INSTANCE_TYPES_K8S = { "cassandracluster", @@ -71,7 +69,6 @@ flinkeks=flink_tools.cr_id, cassandracluster=cassandracluster_tools.cr_id, kafkacluster=kafkacluster_tools.cr_id, - vitesscluster=vitesscluster_tools.cr_id, nrtsearchservice=nrtsearchservice_tools.cr_id, nrtsearchserviceeks=nrtsearchservice_tools.cr_id, monkrelaycluster=monkrelaycluster_tools.cr_id, diff --git a/paasta_tools/paastaapi/model/instance_status.py b/paasta_tools/paastaapi/model/instance_status.py index b010970a86..16f1478aa4 100644 --- a/paasta_tools/paastaapi/model/instance_status.py +++ b/paasta_tools/paastaapi/model/instance_status.py @@ -38,7 +38,6 @@ def lazy_import(): from paasta_tools.paastaapi.model.instance_status_kubernetes import InstanceStatusKubernetes from paasta_tools.paastaapi.model.instance_status_kubernetes_v2 import InstanceStatusKubernetesV2 from paasta_tools.paastaapi.model.instance_status_tron import InstanceStatusTron - from paasta_tools.paastaapi.model.instance_status_vitesscluster import InstanceStatusVitesscluster globals()['InstanceStatusAdhoc'] = InstanceStatusAdhoc globals()['InstanceStatusCassandracluster'] = InstanceStatusCassandracluster globals()['InstanceStatusFlink'] = InstanceStatusFlink @@ -46,7 +45,6 @@ def lazy_import(): globals()['InstanceStatusKubernetes'] = InstanceStatusKubernetes globals()['InstanceStatusKubernetesV2'] = InstanceStatusKubernetesV2 globals()['InstanceStatusTron'] = InstanceStatusTron - globals()['InstanceStatusVitesscluster'] = InstanceStatusVitesscluster class InstanceStatus(ModelNormal): @@ -102,7 +100,6 @@ def openapi_types(): 'version': (str,), # noqa: E501 'instance': (str,), # noqa: E501 'cassandracluster': (InstanceStatusCassandracluster,), # noqa: E501 - 'vitesscluster': (InstanceStatusVitesscluster,), # noqa: E501 'kafkacluster': (InstanceStatusKafkacluster,), # noqa: E501 'kubernetes': (InstanceStatusKubernetes,), # noqa: E501 'kubernetes_v2': (InstanceStatusKubernetesV2,), # noqa: E501 @@ -123,7 +120,6 @@ def discriminator(): 'version': 'version', # noqa: E501 'instance': 'instance', # noqa: E501 'cassandracluster': 'cassandracluster', # noqa: E501 - 'vitesscluster': 'vitesscluster', # noqa: E501 'kafkacluster': 'kafkacluster', # noqa: E501 'kubernetes': 'kubernetes', # noqa: E501 'kubernetes_v2': 'kubernetes_v2', # noqa: E501 @@ -184,7 +180,6 @@ def __init__(self, *args, **kwargs): # noqa: E501 version (str): Deployment Version of a service. [optional] # noqa: E501 instance (str): Instance name. [optional] # noqa: E501 cassandracluster (InstanceStatusCassandracluster): [optional] # noqa: E501 - vitesscluster (InstanceStatusVitesscluster): [optional] # noqa: E501 kafkacluster (InstanceStatusKafkacluster): [optional] # noqa: E501 kubernetes (InstanceStatusKubernetes): [optional] # noqa: E501 kubernetes_v2 (InstanceStatusKubernetesV2): [optional] # noqa: E501 diff --git a/paasta_tools/paastaapi/model/instance_status_vitesscluster.py b/paasta_tools/paastaapi/model/instance_status_vitesscluster.py deleted file mode 100644 index 4ad8cb1d43..0000000000 --- a/paasta_tools/paastaapi/model/instance_status_vitesscluster.py +++ /dev/null @@ -1,173 +0,0 @@ -# coding: utf-8 - -""" - Paasta API - - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import re # noqa: F401 -import sys # noqa: F401 - -import nulltype # noqa: F401 - -from paasta_tools.paastaapi.model_utils import ( # noqa: F401 - ApiTypeError, - ModelComposed, - ModelNormal, - ModelSimple, - cached_property, - change_keys_js_to_python, - convert_js_args_to_python_args, - date, - datetime, - file_type, - none_type, - validate_get_composed_info, -) - - -class InstanceStatusVitesscluster(ModelNormal): - """NOTE: This class is auto generated by OpenAPI Generator. - Ref: https://openapi-generator.tech - - Do not edit the class manually. - - Attributes: - allowed_values (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - with a capitalized key describing the allowed value and an allowed - value. These dicts store the allowed enum values. - attribute_map (dict): The key is attribute name - and the value is json key in definition. - discriminator_value_class_map (dict): A dict to go from the discriminator - variable value to the discriminator class name. - validations (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - that stores validations for max_length, min_length, max_items, - min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, - inclusive_minimum, and regex. - additional_properties_type (tuple): A tuple of classes accepted - as additional properties values. - """ - - allowed_values = { - } - - validations = { - } - - additional_properties_type = None - - _nullable = False - - @cached_property - def openapi_types(): - """ - This must be a method because a model may have properties that are - of type self, this must run after the class is loaded - - Returns - openapi_types (dict): The key is attribute name - and the value is attribute type. - """ - return { - 'metadata': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},), # noqa: E501 - 'status': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},), # noqa: E501 - } - - @cached_property - def discriminator(): - return None - - - attribute_map = { - 'metadata': 'metadata', # noqa: E501 - 'status': 'status', # noqa: E501 - } - - _composed_schemas = {} - - required_properties = set([ - '_data_store', - '_check_type', - '_spec_property_naming', - '_path_to_item', - '_configuration', - '_visited_composed_classes', - ]) - - @convert_js_args_to_python_args - def __init__(self, *args, **kwargs): # noqa: E501 - """InstanceStatusVitesscluster - a model defined in OpenAPI - - Keyword Args: - _check_type (bool): if True, values for parameters in openapi_types - will be type checked and a TypeError will be - raised if the wrong type is input. - Defaults to True - _path_to_item (tuple/list): This is a list of keys or values to - drill down to the model in received_data - when deserializing a response - _spec_property_naming (bool): True if the variable names in the input data - are serialized names, as specified in the OpenAPI document. - False if the variable names in the input data - are pythonic names, e.g. snake case (default) - _configuration (Configuration): the instance to use when - deserializing a file_type parameter. - If passed, type conversion is attempted - If omitted no type conversion is done. - _visited_composed_classes (tuple): This stores a tuple of - classes that we have traveled through so that - if we see that class again we will not use its - discriminator again. - When traveling through a discriminator, the - composed schema that is - is traveled through is added to this set. - For example if Animal has a discriminator - petType and we pass in "Dog", and the class Dog - allOf includes Animal, we move through Animal - once using the discriminator, and pick Dog. - Then in Dog, we will make an instance of the - Animal class but this time we won't travel - through its discriminator because we passed in - _visited_composed_classes = (Animal,) - metadata ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): VitessCluster instance metadata. [optional] # noqa: E501 - status ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): VitessCluster instance status. [optional] # noqa: E501 - """ - - _check_type = kwargs.pop('_check_type', True) - _spec_property_naming = kwargs.pop('_spec_property_naming', False) - _path_to_item = kwargs.pop('_path_to_item', ()) - _configuration = kwargs.pop('_configuration', None) - _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) - - if args: - raise ApiTypeError( - "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( - args, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) - - self._data_store = {} - self._check_type = _check_type - self._spec_property_naming = _spec_property_naming - self._path_to_item = _path_to_item - self._configuration = _configuration - self._visited_composed_classes = _visited_composed_classes + (self.__class__,) - - for var_name, var_value in kwargs.items(): - if var_name not in self.attribute_map and \ - self._configuration is not None and \ - self._configuration.discard_unknown_keys and \ - self.additional_properties_type is None: - # discard variable. - continue - setattr(self, var_name, var_value) diff --git a/paasta_tools/paastaapi/models/__init__.py b/paasta_tools/paastaapi/models/__init__.py index 0d1278ee23..edfcf07914 100644 --- a/paasta_tools/paastaapi/models/__init__.py +++ b/paasta_tools/paastaapi/models/__init__.py @@ -39,7 +39,6 @@ from paasta_tools.paastaapi.model.instance_status_kubernetes_autoscaling_status import InstanceStatusKubernetesAutoscalingStatus from paasta_tools.paastaapi.model.instance_status_kubernetes_v2 import InstanceStatusKubernetesV2 from paasta_tools.paastaapi.model.instance_status_tron import InstanceStatusTron -from paasta_tools.paastaapi.model.instance_status_vitesscluster import InstanceStatusVitesscluster from paasta_tools.paastaapi.model.instance_tasks import InstanceTasks from paasta_tools.paastaapi.model.integer_and_error import IntegerAndError from paasta_tools.paastaapi.model.kubernetes_container import KubernetesContainer diff --git a/paasta_tools/setup_kubernetes_cr.py b/paasta_tools/setup_kubernetes_cr.py index 0d0e810368..1c02ef36f9 100644 --- a/paasta_tools/setup_kubernetes_cr.py +++ b/paasta_tools/setup_kubernetes_cr.py @@ -49,15 +49,11 @@ from paasta_tools.utils import get_git_sha_from_dockerurl from paasta_tools.utils import load_all_configs from paasta_tools.utils import load_system_paasta_config -from paasta_tools.vitesscluster_tools import load_vitess_service_instance_configs log = logging.getLogger(__name__) -INSTANCE_TYPE_TO_CONFIG_LOADER = {"vitesscluster": load_vitess_service_instance_configs} - - class StdoutKubeClient: """Replace all destructive operations in Kubernetes APIs with writing out YAML to stdout.""" @@ -355,13 +351,6 @@ def reconcile_kubernetes_resource( load_deployments=True, soa_dir=DEFAULT_SOA_DIR, ) - if crd.file_prefix in INSTANCE_TYPE_TO_CONFIG_LOADER: - config = INSTANCE_TYPE_TO_CONFIG_LOADER[crd.file_prefix]( - service=service, - instance=inst, - cluster=cluster, - soa_dir=DEFAULT_SOA_DIR, - ) git_sha = get_git_sha_from_dockerurl(soa_config.get_docker_url(), long=True) formatted_resource = format_custom_resource( instance_config=config, diff --git a/paasta_tools/utils.py b/paasta_tools/utils.py index fe71a280fe..a32d18c937 100644 --- a/paasta_tools/utils.py +++ b/paasta_tools/utils.py @@ -136,7 +136,6 @@ "flinkeks", "cassandracluster", "kafkacluster", - "vitesscluster", "monkrelays", "nrtsearchservice", "nrtsearchserviceeks", @@ -155,7 +154,6 @@ "flinkeks": "paasta-flinks", "cassandracluster": "paasta-cassandraclusters", "kafkacluster": "paasta-kafkaclusters", - "vitesscluster": "paasta-vitessclusters", "nrtsearchservice": "paasta-nrtsearchservices", "nrtsearchserviceeks": "paasta-nrtsearchservices", } @@ -2046,11 +2044,6 @@ class SystemPaastaConfigDict(TypedDict, total=False): service_auth_vault_role: str service_auth_sso_oidc_client_id: str always_authenticating_services: List[str] - vitess_images: Dict - superregion_to_region_mapping: Dict - vitess_tablet_types: List[str] - vitess_tablet_pool_type_mapping: Dict - vitess_throttling_config: Dict uses_bulkdata_default: bool enable_automated_redeploys_default: bool enable_tron_tsc: bool @@ -2773,49 +2766,6 @@ def get_service_auth_sso_oidc_client_id(self) -> str: def get_always_authenticating_services(self) -> List[str]: return self.config_dict.get("always_authenticating_services", []) - def get_vitess_images(self) -> Dict: - return self.config_dict.get( - "vitess_images", - { - "vtctld_image": "docker-paasta.yelpcorp.com:443/vitess_base:v16.0.3", - "vtgate_image": "docker-paasta.yelpcorp.com:443/vitess_base:v16.0.3", - "vttablet_image": "docker-paasta.yelpcorp.com:443/vitess_base:v16.0.3", - "vtadmin_image": "docker-paasta.yelpcorp.com:443/vtadmin:v16.0.3", - }, - ) - - def get_superregion_to_region_mapping(self) -> Dict: - return self.config_dict.get("superregion_to_region_mapping", {}) - - def get_vitess_tablet_types(self) -> List: - return self.config_dict.get("vitess_tablet_types", ["primary", "migration"]) - - def get_vitess_tablet_pool_type_mapping(self) -> Dict: - return self.config_dict.get("vitess_tablet_pool_type_mapping", {}) - - def get_vitess_throttling_config(self) -> Dict: - return self.config_dict.get( - "vitess_throttling_config", - { - "migration": { - "throttle_query_table": "migration_replication_delay", - "throttle_metrics_threshold": "7200", - }, - "read": { - "throttle_query_table": "read_replication_delay", - "throttle_metrics_threshold": "3", - }, - "reporting": { - "throttle_query_table": "reporting_replication_delay", - "throttle_metrics_threshold": "7200", - }, - "primary": { - "throttle_query_table": "read_replication_delay", - "throttle_metrics_threshold": "3", - }, - }, - ) - def get_uses_bulkdata_default(self) -> bool: return self.config_dict.get("uses_bulkdata_default", True) diff --git a/paasta_tools/vitesscluster_tools.py b/paasta_tools/vitesscluster_tools.py deleted file mode 100644 index 527cc84f9c..0000000000 --- a/paasta_tools/vitesscluster_tools.py +++ /dev/null @@ -1,940 +0,0 @@ -import json -import logging -import sys -from typing import Any -from typing import Dict -from typing import List -from typing import Mapping -from typing import Optional -from typing import TypedDict -from typing import Union - -import service_configuration_lib -from kubernetes.client import ApiClient - -from paasta_tools.kubernetes_tools import KubernetesDeploymentConfig -from paasta_tools.kubernetes_tools import KubernetesDeploymentConfigDict -from paasta_tools.kubernetes_tools import limit_size_with_hash -from paasta_tools.kubernetes_tools import sanitised_cr_name -from paasta_tools.long_running_service_tools import load_service_namespace_config -from paasta_tools.utils import BranchDictV2 -from paasta_tools.utils import deep_merge_dictionaries -from paasta_tools.utils import DEFAULT_SOA_DIR -from paasta_tools.utils import get_git_sha_from_dockerurl -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 - - -log = logging.getLogger(__name__) -log.addHandler(logging.NullHandler()) - - -KUBERNETES_NAMESPACE = "paasta-vitessclusters" - - -# Global variables -TOPO_IMPLEMENTATION = "zk2" -TOPO_GLOBAL_ROOT = "/vitess-paasta/global" -SOURCE_DB_HOST = "169.254.255.254" -WEB_PORT = "15000" -GRPC_PORT = "15999" - - -# Environment variables -VTCTLD_EXTRA_ENV = { - "WEB_PORT": WEB_PORT, - "GRPC_PORT": GRPC_PORT, -} - -VTTABLET_EXTRA_ENV = { - "WEB_PORT": WEB_PORT, - "GRPC_PORT": GRPC_PORT, - "SHARD": "0", - "EXTERNAL_DB": "1", - "ROLE": "replica", - "VAULT_ROLEID": { - "secretKeyRef": { - "name": "paasta-vitessclusters-secret-vitess-k8s-vault-vttablet-approle-roleid", - "key": "vault-vttablet-approle-roleid", - } - }, - "VAULT_SECRETID": { - "secretKeyRef": { - "name": "paasta-vitessclusters-secret-vitess-k8s-vault-vttablet-approle-secretid", - "key": "vault-vttablet-approle-secretid", - } - }, -} - -VTGATE_EXTRA_ENV = { - "VAULT_ROLEID": { - "secretKeyRef": { - "name": "paasta-vitessclusters-secret-vitess-k8s-vault-vtgate-approle-roleid", - "key": "vault-vtgate-approle-roleid", - } - }, - "VAULT_SECRETID": { - "secretKeyRef": { - "name": "paasta-vitessclusters-secret-vitess-k8s-vault-vtgate-approle-secretid", - "key": "vault-vtgate-approle-secretid", - } - }, -} - - -# Extra Flags -VTADMIN_EXTRA_FLAGS = {"grpc-allow-reflection": "true"} - -VTCTLD_EXTRA_FLAGS = { - "disable_active_reparents": "true", - "security_policy": "read-only", -} - -VTTABLET_EXTRA_FLAGS = { - "log_err_stacks": "true", - "grpc_max_message_size": "134217728", - "init_tablet_type": "replica", - "queryserver-config-schema-reload-time": "1800", - "dba_pool_size": "4", - "vreplication_heartbeat_update_interval": "60", - "vreplication_tablet_type": "REPLICA", - "keep_logs": "72h", - "enable-lag-throttler": "true", - "throttle_check_as_check_self": "true", - "db_charset": "utf8mb4", - "disable_active_reparents": "true", - "init_shard": "0", -} - - -class KVEnvVar(TypedDict, total=False): - name: str - value: str - - -class KVEnvVarValueFrom(TypedDict, total=False): - name: str - valueFrom: Dict[str, Any] - - -class RequestsDict(TypedDict, total=False): - cpu: str - memory: str - disk: str - - -class ResourceConfigDict(TypedDict, total=False): - replicas: int - requests: Dict[str, RequestsDict] - limits: Dict[str, RequestsDict] - - -class GatewayConfigDict(TypedDict, total=False): - affinity: Dict[str, Any] - extraEnv: List[Union[KVEnvVar, KVEnvVarValueFrom]] - extraFlags: Dict[str, str] - extraLabels: Dict[str, str] - extraVolumeMounts: List[Dict[str, Any]] - extraVolumes: List[Dict[str, Any]] - lifecycle: Dict[str, Dict[str, Dict[str, List[str]]]] - replicas: int - resources: Dict[str, Any] - annotations: Mapping[str, Any] - - -class CellConfigDict(TypedDict, total=False): - name: str - gateway: GatewayConfigDict - - -class VitessDashboardConfigDict(TypedDict, total=False): - cells: List[str] - affinity: Dict[str, Any] - extraEnv: List[Union[KVEnvVar, KVEnvVarValueFrom]] - extraFlags: Dict[str, str] - extraLabels: Dict[str, str] - replicas: int - resources: Dict[str, Any] - annotations: Mapping[str, Any] - - -class VtAdminConfigDict(TypedDict, total=False): - cells: List[str] - apiAddresses: List[str] - affinity: Dict[str, Any] - extraEnv: List[Union[KVEnvVar, KVEnvVarValueFrom]] - extraFlags: Dict[str, str] - extraLabels: Dict[str, str] - replicas: int - readOnly: bool - apiResources: Dict[str, Any] - webResources: Dict[str, Any] - annotations: Mapping[str, Any] - - -class VtTabletDict(TypedDict, total=False): - extraFlags: Dict[str, str] - resources: Dict[str, Any] - - -class TabletPoolDict(TypedDict, total=False): - cell: str - name: str - type: str - affinity: Dict[str, Any] - extraLabels: Dict[str, str] - extraEnv: List[Union[KVEnvVar, KVEnvVarValueFrom]] - extraVolumeMounts: List[Dict[str, Any]] - extraVolumes: List[Dict[str, Any]] - replicas: int - vttablet: VtTabletDict - externalDatastore: Dict[str, Any] - dataVolumeClaimTemplate: Dict[str, Any] - annotations: Mapping[str, Any] - - -class ShardTemplateDict(TypedDict, total=False): - databaseInitScriptSecret: Dict[str, str] - tabletPools: List[TabletPoolDict] - - -class PartitioningValueDict(TypedDict, total=False): - parts: int - shardTemplate: ShardTemplateDict - - -class KeyspaceConfigDict(TypedDict, total=False): - durabilityPolicy: str - turndownPolicy: str - partitionings: List[Dict[str, PartitioningValueDict]] - name: str - - -def get_formatted_environment_variables( - env_vars: Dict[str, Any] -) -> List[Union[KVEnvVar, KVEnvVarValueFrom]]: - """ - Helper function to take in key value pairs of environment variables and return a list of dicts - """ - updated_environment_variables: List[Union[KVEnvVar, KVEnvVarValueFrom]] = [] - for env_key, env_value in env_vars.items(): - if isinstance(env_value, str): - updated_environment_variables.append( - KVEnvVar(name=env_key, value=env_value) - ) - elif isinstance(env_value, dict): - updated_environment_variables.append( - KVEnvVarValueFrom(name=env_key, valueFrom=env_value) - ) - else: - log.error(f"Invalid environment variable {env_key}={env_value}") - return updated_environment_variables - - -def get_cell_config( - cell: str, - region: str, - vtgate_resources: ResourceConfigDict, - env: List[Union[KVEnvVar, KVEnvVarValueFrom]], - labels: Dict[str, str], - node_affinity: dict, - annotations: Mapping[str, Any], - aws_region: str, -) -> CellConfigDict: - """ - get vtgate config - """ - replicas = vtgate_resources.get("replicas") - requests = vtgate_resources.get( - "requests", RequestsDict(cpu="100m", memory="256Mi") - ) - environment_overrides: Dict[str, Any] = { - "VAULT_ADDR": f"https://vault-dre.{region}.yelpcorp.com:8200", - "VAULT_CACERT": f"/etc/vault/all_cas/acm-privateca-{region}.crt", - } - environment_overrides.update(VTGATE_EXTRA_ENV) - updated_vtgate_extra_env = ( - get_formatted_environment_variables(environment_overrides) + env - ) - - config = CellConfigDict( - name=cell, - gateway=GatewayConfigDict( - affinity={"nodeAffinity": node_affinity}, - extraEnv=updated_vtgate_extra_env, - extraFlags={ - "mysql_auth_server_impl": "vault", - "mysql_auth_vault_addr": f"https://vault-dre.{region}.yelpcorp.com:8200", - "mysql_auth_vault_path": "secrets/vitess/vt-gate/vttablet_credentials.json", - "mysql_auth_vault_tls_ca": f"/etc/vault/all_cas/acm-privateca-{region}.crt", - "mysql_auth_vault_ttl": "60s", - }, - extraVolumeMounts=[ - { - "mountPath": "/nail/srv", - "name": "srv-configs", - "readOnly": True, - }, - { - "mountPath": "/nail/etc/srv-configs", - "name": "etc-srv-configs", - "readOnly": True, - }, - ], - extraVolumes=[ - { - "name": "srv-configs", - "hostPath": {"path": "/nail/srv"}, - }, - { - "name": "etc-srv-configs", - "hostPath": {"path": "/nail/etc/srv-configs"}, - }, - ], - extraLabels=labels, - replicas=replicas, - resources={ - "requests": requests, - "limits": requests, - }, - annotations=annotations, - ), - ) - return config - - -def get_vitess_dashboard_config( - cells: List[str], - zk_address: str, - vtctld_resources: ResourceConfigDict, - env: List[Union[KVEnvVar, KVEnvVarValueFrom]], - labels: Dict[str, str], - node_affinity: dict, - annotations: Mapping[str, Any], -) -> VitessDashboardConfigDict: - """ - get vtctld config - """ - replicas = vtctld_resources.get("replicas") - requests = vtctld_resources.get( - "requests", RequestsDict(cpu="100m", memory="256Mi") - ) - environment_overrides: Dict[str, Any] = { - "TOPOLOGY_FLAGS": f"--topo_implementation {TOPO_IMPLEMENTATION} --topo_global_server_address {zk_address} --topo_global_root {TOPO_GLOBAL_ROOT}", - } - environment_overrides.update(VTCTLD_EXTRA_ENV) - updated_vtctld_extra_env = ( - get_formatted_environment_variables(environment_overrides) + env - ) - - config = VitessDashboardConfigDict( - cells=cells, - affinity={"nodeAffinity": node_affinity}, - extraEnv=updated_vtctld_extra_env, - extraFlags=VTCTLD_EXTRA_FLAGS, - extraLabels=labels, - replicas=replicas, - resources={ - "requests": requests, - "limits": requests, - }, - annotations=annotations, - ) - return config - - -def get_vt_admin_config( - cells: List[str], - vtadmin_resources: ResourceConfigDict, - env: List[Union[KVEnvVar, KVEnvVarValueFrom]], - labels: Dict[str, str], - node_affinity: dict, - annotations: Mapping[str, Any], -) -> VtAdminConfigDict: - """ - get vtadmin config - """ - replicas = vtadmin_resources.get("replicas") - requests = vtadmin_resources.get( - "requests", RequestsDict(cpu="100m", memory="256Mi") - ) - config = VtAdminConfigDict( - cells=cells, - apiAddresses=["http://localhost:15000"], - affinity={"nodeAffinity": node_affinity}, - extraLabels=labels, - extraFlags=VTADMIN_EXTRA_FLAGS, - extraEnv=env, - replicas=replicas, - readOnly=False, - apiResources={ - "requests": requests, - "limits": requests, - }, - webResources={ - "requests": requests, - "limits": requests, - }, - annotations=annotations, - ) - return config - - -def get_tablet_pool_config( - cell: str, - db_name: str, - keyspace: str, - host: str, - zk_address: str, - throttle_query_table: str, - throttle_metrics_threshold: str, - tablet_type: str, - region: str, - vttablet_resources: ResourceConfigDict, - env: List[Union[KVEnvVar, KVEnvVarValueFrom]], - labels: Dict[str, str], - node_affinity: dict, - annotations: Mapping[str, Any], -) -> TabletPoolDict: - """ - get vttablet config - """ - vttablet_extra_flags = VTTABLET_EXTRA_FLAGS.copy() - flag_overrides = { - "throttle_metrics_query": f"select max_replication_delay from max_mysql_replication_delay.{throttle_query_table};", - "throttle_metrics_threshold": throttle_metrics_threshold, - "enforce-tableacl-config": "true", - "table-acl-config": f"/nail/srv/configs/vitess_keyspace_acls/acls_for_{db_name}.json", - "table-acl-config-reload-interval": "60s", - "queryserver-config-strict-table-acl": "true", - "db-credentials-server": "vault", - "db-credentials-vault-addr": f"https://vault-dre.{region}.yelpcorp.com:8200", - "db-credentials-vault-path": "secrets/vitess/vt-tablet/vttablet_credentials.json", - "db-credentials-vault-tls-ca": f"/etc/vault/all_cas/acm-privateca-{region}.crt", - "db-credentials-vault-ttl": "60s", - } - vttablet_extra_flags.update(flag_overrides) - - environment_overrides: Dict[str, Any] = { - "VAULT_ADDR": f"https://vault-dre.{region}.yelpcorp.com:8200", - "VAULT_CACERT": f"/etc/vault/all_cas/acm-privateca-{region}.crt", - "TOPOLOGY_FLAGS": f"--topo_implementation {TOPO_IMPLEMENTATION} --topo_global_server_address ${zk_address} --topo_global_root {TOPO_GLOBAL_ROOT}", - "CELL_TOPOLOGY_SERVERS": zk_address, - "DB": db_name, - "KEYSPACE": keyspace, - } - environment_overrides.update(VTTABLET_EXTRA_ENV) - updated_vttablet_extra_env = ( - get_formatted_environment_variables(environment_overrides) + env - ) - - # Add extra pod label to filter - tablet_type_label = limit_size_with_hash(name=f"{db_name}_{tablet_type}", limit=63) - labels.update({"tablet_type": tablet_type_label}) - - try: - type = load_system_paasta_config().get_vitess_tablet_pool_type_mapping()[ - tablet_type - ] - except KeyError: - log.error( - f"Tablet type {tablet_type} not found in system paasta config vitess_tablet_pool_type_mapping" - ) - type = "externalmaster" - - replicas = vttablet_resources.get("replicas") - requests = vttablet_resources.get( - "requests", RequestsDict(cpu="100m", memory="256Mi") - ) - - config = TabletPoolDict( - cell=cell, - name=f"{db_name}_{tablet_type}", - type=type, - affinity={"nodeAffinity": node_affinity}, - extraLabels=labels, - extraEnv=updated_vttablet_extra_env, - extraVolumeMounts=[ - { - "mountPath": "/etc/vault/all_cas", - "name": "vault-secrets", - "readOnly": True, - }, - { - "mountPath": "/nail/srv", - "name": "srv-configs", - "readOnly": True, - }, - { - "mountPath": "/nail/etc/srv-configs", - "name": "etc-srv-configs", - "readOnly": True, - }, - { - "mountPath": "etc/credentials.yaml", - "name": "vttablet-fake-credentials", - "readOnly": True, - }, - { - "mountPath": "/etc/init_db.sql", - "name": "keyspace-fake-init-script", - "readOnly": True, - }, - ], - extraVolumes=[ - {"name": "vault-secrets", "hostPath": {"path": "/nail/etc/vault/all_cas"}}, - { - "name": "srv-configs", - "hostPath": {"path": "/nail/srv"}, - }, - { - "name": "etc-srv-configs", - "hostPath": {"path": "/nail/etc/srv-configs"}, - }, - {"name": "vttablet-fake-credentials", "hostPath": {"path": "/dev/null"}}, - {"name": "keyspace-fake-init-script", "hostPath": {"path": "/dev/null"}}, - ], - replicas=replicas, - vttablet={ - "extraFlags": vttablet_extra_flags, - "resources": { - "requests": requests, - "limits": requests, - }, - }, - externalDatastore={ - "database": db_name, - "host": host, - "port": 3306, - "user": "vt_app", - "credentialsSecret": { - "key": "/etc/credentials.yaml", - "volumeName": "vttablet-fake-credentials", - }, - }, - dataVolumeClaimTemplate={ - "accessModes": ["ReadWriteOnce"], - "resources": {"requests": {"storage": "10Gi"}}, - "storageClassName": "ebs-csi-gp3", - }, - annotations=annotations, - ) - return config - - -def get_keyspaces_config( - cells: List[str], - keyspaces: List[Dict[str, Any]], - zk_address: str, - region: str, - env: List[Union[KVEnvVar, KVEnvVarValueFrom]], - labels: Dict[str, str], - node_affinity: dict, - annotations: Mapping[str, Any], -) -> List[KeyspaceConfigDict]: - """ - get vitess keyspace config - """ - config = [] - - for keyspace_config in keyspaces: - keyspace = keyspace_config["keyspace"] - db_name = keyspace_config["keyspace"] - cluster = keyspace_config["cluster"] - vttablet_resources = keyspace_config.get("vttablet_resources") - - tablet_pools = [] - - # get vttablets - tablet_types = load_system_paasta_config().get_vitess_tablet_types() - for tablet_type in tablet_types: - ecosystem = region.split("-")[-1] - if tablet_type == "primary": - host = f"mysql-{cluster}.dre-{ecosystem}" - else: - host = f"mysql-{cluster}-{tablet_type}.dre-{ecosystem}" - - # We use migration_replication delay for migration tablets and read_replication_delay for everything else - # Also throttling threshold for refresh and sanitized primaries is set at 30 seconds and everything else at 3 seconds - try: - throttling_configs = ( - load_system_paasta_config().get_vitess_throttling_config() - ) - throttle_query_table = throttling_configs[tablet_type][ - "throttle_query_table" - ] - throttle_metrics_threshold = throttling_configs[tablet_type][ - "throttle_metrics_threshold" - ] - except KeyError: - log.error( - f"Throttling configs for tablet type {tablet_type} not found in system paasta config vitess_throttling_configs" - ) - - if cluster.startswith("refresh") or cluster.startswith("sanitized"): - throttle_metrics_threshold = "30" - else: - throttle_metrics_threshold = "3" - - tablet_pools.extend( - [ - get_tablet_pool_config( - cell, - db_name, - keyspace, - host, - zk_address, - throttle_query_table, - throttle_metrics_threshold, - tablet_type, - region, - vttablet_resources, - env, - labels, - node_affinity, - annotations, - ) - for cell in cells - ] - ) - keyspace_config_value = KeyspaceConfigDict( - name=keyspace, - durabilityPolicy="none", - turndownPolicy="Immediate", - partitionings=[ - { - "equal": PartitioningValueDict( - parts=1, - shardTemplate=ShardTemplateDict( - databaseInitScriptSecret={ - "volumeName": "keyspace-fake-init-script", - "key": "/etc/init_db.sql", - }, - tabletPools=tablet_pools, - ), - ) - } - ], - ) - config.append(keyspace_config_value) - return config - - -class VitessDeploymentConfigDict(KubernetesDeploymentConfigDict, total=False): - images: Dict[str, str] - cells: List[CellConfigDict] - vitessDashboard: VitessDashboardConfigDict - vtadmin: VtAdminConfigDict - keyspaces: List[KeyspaceConfigDict] - updateStrategy: Dict[str, str] - globalLockserver: Dict[str, Dict[str, str]] - - -class VitessInstanceConfigDict(KubernetesDeploymentConfigDict, total=False): - cells: List[str] - zk_address: str - vtctld_resources: ResourceConfigDict - vtgate_resources: ResourceConfigDict - vttablet_resources: ResourceConfigDict - vtadmin_resources: ResourceConfigDict - images: Dict[str, str] - keyspaces: List[Dict[str, Any]] - - -class VitessDeploymentConfig(KubernetesDeploymentConfig): - config_dict: VitessInstanceConfigDict - - config_filename_prefix = "vitesscluster" - - def __init__( - self, - service: str, - cluster: str, - instance: str, - config_dict: VitessDeploymentConfigDict, - branch_dict: Optional[BranchDictV2], - soa_dir: str = DEFAULT_SOA_DIR, - ) -> None: - super().__init__( - cluster=cluster, # superregion - instance=instance, # host-1 - service=service, # vitess - soa_dir=soa_dir, - config_dict=config_dict, - branch_dict=branch_dict, - ) - - def get_namespace(self) -> str: - return KUBERNETES_NAMESPACE - - def get_images(self) -> Dict[str, str]: - vitess_images = self.config_dict.get( - "images", load_system_paasta_config().get_vitess_images() - ) - return { - "vtctld": vitess_images["vtctld_image"], - "vtadmin": vitess_images["vtadmin_image"], - "vtgate": vitess_images["vtgate_image"], - "vttablet": vitess_images["vttablet_image"], - } - - def get_env_variables(self) -> List[Union[KVEnvVar, KVEnvVarValueFrom]]: - # get all K8s container env vars and format their keys to camel case - - # Workaround from https://github.com/kubernetes-client/python/issues/390 - api_client = ApiClient() - env = [ - api_client.sanitize_for_serialization(env) - for env in self.get_container_env() - ] - return env - - def get_labels(self) -> Dict[str, str]: - # get default labels from parent class to adhere to paasta contract - docker_url = self.get_docker_url( - system_paasta_config=load_system_paasta_config() - ) - git_sha = get_git_sha_from_dockerurl(docker_url) - labels = self.get_kubernetes_metadata(git_sha=git_sha).labels - if "yelp.com/owner" in labels.keys(): - labels["yelp.com/owner"] = "dre_mysql" - return labels - - def get_annotations(self) -> Mapping[str, Any]: - # get required annotations to be added to the formatted resource before creating or updating custom resource - service_namespace_config = load_service_namespace_config( - service=self.service, namespace=self.get_nerve_namespace() - ) - system_paasta_config = load_system_paasta_config() - has_routable_ip = self.has_routable_ip( - service_namespace_config, system_paasta_config - ) - annotations: Mapping[str, Any] = { - "smartstack_registrations": json.dumps(self.get_registrations()), - "paasta.yelp.com/routable_ip": has_routable_ip, - } - - return annotations - - def get_vitess_node_affinity(self) -> dict: - # Workaround from https://github.com/kubernetes-client/python/issues/390 - api_client = ApiClient() - node_affinity = api_client.sanitize_for_serialization(self.get_node_affinity()) - return node_affinity - - def get_region(self) -> str: - superregion = self.get_cluster() - superregion_to_region_map = ( - load_system_paasta_config().get_superregion_to_region_mapping() - ) - region = None - for superregion_prefix in superregion_to_region_map: - if superregion.startswith(superregion_prefix): - region = superregion.replace( - superregion_prefix, superregion_to_region_map[superregion_prefix] - ) - if region is None: - log.error( - f"Region not found for superregion {superregion}. Check superregion_to_region_mapping in system paasta config" - ) - # Exiting early here since region is needed to fetch secrets from vault - sys.exit(1) - return region - - def get_aws_region(self) -> str: - region = self.get_region() - return f"{region[:2]}-{region[2:6]}-{region[6:7]}" - - def get_global_lock_server(self) -> Dict[str, Dict[str, str]]: - zk_address = self.config_dict.get("zk_address") - return { - "external": { - "implementation": TOPO_IMPLEMENTATION, - "address": zk_address, - "rootPath": TOPO_GLOBAL_ROOT, - } - } - - def get_cells(self) -> List[CellConfigDict]: - cells = self.config_dict.get("cells") - region = self.get_region() - aws_region = self.get_aws_region() - vtgate_resources = self.config_dict.get("vtgate_resources") - - formatted_env = self.get_env_variables() - labels = self.get_labels() - node_affinity = self.get_vitess_node_affinity() - annotations = self.get_annotations() - - return [ - get_cell_config( - cell, - region, - vtgate_resources, - formatted_env, - labels, - node_affinity, - annotations, - aws_region, - ) - for cell in cells - ] - - def get_vitess_dashboard(self) -> VitessDashboardConfigDict: - cells = self.config_dict.get("cells") - zk_address = self.config_dict.get("zk_address") - vtctld_resources = self.config_dict.get("vtctld_resources") - - formatted_env = self.get_env_variables() - labels = self.get_labels() - node_affinity = self.get_vitess_node_affinity() - annotations = self.get_annotations() - - return get_vitess_dashboard_config( - cells, - zk_address, - vtctld_resources, - formatted_env, - labels, - node_affinity, - annotations, - ) - - def get_vtadmin(self) -> VtAdminConfigDict: - cells = self.config_dict.get("cells") - vtadmin_resources = self.config_dict.get("vtadmin_resources") - - formatted_env = self.get_env_variables() - labels = self.get_labels() - node_affinity = self.get_vitess_node_affinity() - annotations = self.get_annotations() - - return get_vt_admin_config( - cells, vtadmin_resources, formatted_env, labels, node_affinity, annotations - ) - - def get_keyspaces(self) -> List[KeyspaceConfigDict]: - cells = self.config_dict.get("cells") - zk_address = self.config_dict.get("zk_address") - region = self.get_region() - keyspaces = self.config_dict.get("keyspaces") - - formatted_env = self.get_env_variables() - labels = self.get_labels() - node_affinity = self.get_vitess_node_affinity() - annotations = self.get_annotations() - - return get_keyspaces_config( - cells, - keyspaces, - zk_address, - region, - formatted_env, - labels, - node_affinity, - annotations, - ) - - def get_update_strategy(self) -> Dict[str, str]: - return {"type": "Immediate"} - - def get_vitess_config(self) -> VitessDeploymentConfigDict: - vitess_config = VitessDeploymentConfigDict( - namespace=self.get_namespace(), - images=self.get_images(), - globalLockserver=self.get_global_lock_server(), - cells=self.get_cells(), - vitessDashboard=self.get_vitess_dashboard(), - vtadmin=self.get_vtadmin(), - keyspaces=self.get_keyspaces(), - updateStrategy=self.get_update_strategy(), - ) - return vitess_config - - def validate( - self, - params: List[str] = [ - "cpus", - "security", - "dependencies_reference", - "deploy_group", - ], - ) -> List[str]: - # Use InstanceConfig to validate shared config keys like cpus and mem - # TODO: add mem back to this list once we fix PAASTA-15582 and - # move to using the same units as flink/marathon etc. - error_msgs = super().validate(params=params) - - if error_msgs: - name = self.get_instance() - return [f"{name}: {msg}" for msg in error_msgs] - else: - return [] - - -def load_vitess_instance_config( - service: str, - instance: str, - cluster: str, - load_deployments: bool = True, - soa_dir: str = DEFAULT_SOA_DIR, -) -> VitessDeploymentConfig: - general_config = service_configuration_lib.read_service_configuration( - service, soa_dir=soa_dir - ) - instance_config = load_service_instance_config( - service, instance, "vitesscluster", cluster, soa_dir=soa_dir - ) - general_config = deep_merge_dictionaries( - overrides=instance_config, defaults=general_config - ) - - branch_dict: Optional[BranchDictV2] = None - if load_deployments: - deployments_json = load_v2_deployments_json(service, soa_dir=soa_dir) - temp_instance_config = VitessDeploymentConfig( - service=service, - cluster=cluster, - instance=instance, - config_dict=general_config, - branch_dict=None, - soa_dir=soa_dir, - ) - branch = temp_instance_config.get_branch() - deploy_group = temp_instance_config.get_deploy_group() - branch_dict = deployments_json.get_branch_dict(service, branch, deploy_group) - - vitess_deployment_config = VitessDeploymentConfig( - service=service, - cluster=cluster, - instance=instance, - config_dict=general_config, - branch_dict=branch_dict, - soa_dir=soa_dir, - ) - - return vitess_deployment_config - - -def load_vitess_service_instance_configs( - service: str, - instance: str, - cluster: str, - soa_dir: str = DEFAULT_SOA_DIR, -) -> VitessDeploymentConfigDict: - vitess_service_instance_configs = load_vitess_instance_config( - service, instance, cluster, soa_dir=soa_dir - ).get_vitess_config() - return vitess_service_instance_configs - - -# TODO: read this from CRD in service configs -def cr_id(service: str, instance: str) -> Mapping[str, str]: - return dict( - group="planetscale.com", - version="v2", - namespace=KUBERNETES_NAMESPACE, - plural="vitessclusters", - name=sanitised_cr_name(service, instance), - ) diff --git a/tests/test_utils.py b/tests/test_utils.py index 12b8442fbf..1e5ed536c5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2362,7 +2362,6 @@ def test_validate_service_instance_invalid(): mock_nrtsearch_instances = [("service1", "nrtsearch")] mock_nrtsearcheks_instances = [("service1", "nrtsearcheks")] mock_monkrelaycluster_instances = [("service1", "monkrelays")] - mock_vitesscluster_instances = [("service1", "vitesscluster")] my_service = "service1" my_instance = "main" fake_cluster = "fake_cluster" @@ -2384,7 +2383,6 @@ def test_validate_service_instance_invalid(): mock_nrtsearch_instances, mock_nrtsearcheks_instances, mock_monkrelaycluster_instances, - mock_vitesscluster_instances, ], ): with raises( diff --git a/tests/test_vitesscluster_tools.py b/tests/test_vitesscluster_tools.py deleted file mode 100644 index 58237eb9cf..0000000000 --- a/tests/test_vitesscluster_tools.py +++ /dev/null @@ -1,735 +0,0 @@ -import mock -import pytest -from kubernetes.client import V1ObjectMeta - -from paasta_tools.utils import SystemPaastaConfig -from paasta_tools.vitesscluster_tools import load_vitess_instance_config -from paasta_tools.vitesscluster_tools import load_vitess_service_instance_configs -from paasta_tools.vitesscluster_tools import VitessDeploymentConfig - - -CONFIG_DICT = { - "cells": ["fake_cell"], - "data": {}, - "dependencies": {}, - "deploy": {"pipeline": [{"step": "fake_deploy_group"}]}, - "deploy_group": "fake_deploy_group", - "description": "Test Description", - "external_link": "fake_link", - "git_url": "git@github.yelpcorp.com:services/vitess-k8s", - "healthcheck_cmd": "fake_cmd", - "healthcheck_grace_period_seconds": 60, - "healthcheck_mode": "cmd", - "keyspaces": [ - { - "cluster": "fake_cluster", - "keyspace": "fake_keyspaces", - "vttablet_resources": { - "replicas": 1, - "requests": {"cpu": "100m", "memory": "256Mi"}, - }, - } - ], - "monitoring": {}, - "node_selectors": {"fake_pool": ["fake_pool_value"]}, - "paasta_pool": "fake_pool_value", - "port": None, - "smartstack": {}, - "vtadmin_resources": { - "replicas": 1, - "requests": {"cpu": "100m", "memory": "256Mi"}, - }, - "vtctld_resources": {"replicas": 1, "requests": {"cpu": "100m", "memory": "256Mi"}}, - "vtgate_resources": {"replicas": 1, "requests": {"cpu": "100m", "memory": "256Mi"}}, - "zk_address": "fake_zk_address", -} - -MOCK_SYSTEM_PAASTA_CONFIG = SystemPaastaConfig( - config={ - "superregion_to_region_mapping": {"fake_superregion": "fake_region"}, - "vitess_tablet_pool_type_mapping": { - "primary": "externalmaster", - "migration": "externalreplica", - }, - }, - directory="/fake/config/directory", -) - -VITESS_CONFIG = { - "namespace": "paasta-vitessclusters", - "cells": [ - { - "gateway": { - "affinity": { - "nodeAffinity": { - "requiredDuringSchedulingIgnoredDuringExecution": { - "nodeSelectorTerms": [ - { - "matchExpressions": [ - { - "key": "fake_pool", - "operator": "In", - "values": ["fake_pool_value"], - } - ] - } - ] - } - } - }, - "annotations": { - "paasta.yelp.com/routable_ip": "false", - "smartstack_registrations": '["fake_service.fake_instance"]', - }, - "extraEnv": [ - { - "name": "VAULT_ADDR", - "value": "https://vault-dre.mock_region-devc.yelpcorp.com:8200", - }, - { - "name": "VAULT_CACERT", - "value": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt", - }, - { - "name": "VAULT_ROLEID", - "valueFrom": { - "secretKeyRef": { - "key": "vault-vtgate-approle-roleid", - "name": "paasta-vitessclusters-secret-vitess-k8s-vault-vtgate-approle-roleid", - } - }, - }, - { - "name": "VAULT_SECRETID", - "valueFrom": { - "secretKeyRef": { - "key": "vault-vtgate-approle-secretid", - "name": "paasta-vitessclusters-secret-vitess-k8s-vault-vtgate-approle-secretid", - } - }, - }, - ], - "extraFlags": { - "mysql_auth_server_impl": "vault", - "mysql_auth_vault_addr": "https://vault-dre.mock_region-devc.yelpcorp.com:8200", - "mysql_auth_vault_path": "secrets/vitess/vt-gate/vttablet_credentials.json", - "mysql_auth_vault_tls_ca": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt", - "mysql_auth_vault_ttl": "60s", - }, - "extraLabels": {"tablet_type": "fake_keyspaces_migration"}, - "extraVolumeMounts": [ - {"mountPath": "/nail/srv", "name": "srv-configs", "readOnly": True}, - { - "mountPath": "/nail/etc/srv-configs", - "name": "etc-srv-configs", - "readOnly": True, - }, - ], - "extraVolumes": [ - {"hostPath": {"path": "/nail/srv"}, "name": "srv-configs"}, - { - "hostPath": {"path": "/nail/etc/srv-configs"}, - "name": "etc-srv-configs", - }, - ], - "replicas": 1, - "resources": { - "limits": {"cpu": "100m", "memory": "256Mi"}, - "requests": {"cpu": "100m", "memory": "256Mi"}, - }, - }, - "name": "fake_cell", - } - ], - "globalLockserver": { - "external": { - "address": "fake_zk_address", - "implementation": "zk2", - "rootPath": "/vitess-paasta/global", - } - }, - "images": { - "vtadmin": "docker-paasta.yelpcorp.com:443/vtadmin:v16.0.3", - "vtctld": "docker-paasta.yelpcorp.com:443/vitess_base:v16.0.3", - "vtgate": "docker-paasta.yelpcorp.com:443/vitess_base:v16.0.3", - "vttablet": "docker-paasta.yelpcorp.com:443/vitess_base:v16.0.3", - }, - "keyspaces": [ - { - "durabilityPolicy": "none", - "name": "fake_keyspaces", - "partitionings": [ - { - "equal": { - "parts": 1, - "shardTemplate": { - "databaseInitScriptSecret": { - "key": "/etc/init_db.sql", - "volumeName": "keyspace-fake-init-script", - }, - "tabletPools": [ - { - "affinity": { - "nodeAffinity": { - "requiredDuringSchedulingIgnoredDuringExecution": { - "nodeSelectorTerms": [ - { - "matchExpressions": [ - { - "key": "fake_pool", - "operator": "In", - "values": [ - "fake_pool_value" - ], - } - ] - } - ] - } - } - }, - "annotations": { - "paasta.yelp.com/routable_ip": "false", - "smartstack_registrations": '["fake_service.fake_instance"]', - }, - "cell": "fake_cell", - "dataVolumeClaimTemplate": { - "accessModes": ["ReadWriteOnce"], - "resources": {"requests": {"storage": "10Gi"}}, - "storageClassName": "ebs-csi-gp3", - }, - "externalDatastore": { - "credentialsSecret": { - "key": "/etc/credentials.yaml", - "volumeName": "vttablet-fake-credentials", - }, - "database": "fake_keyspaces", - "host": "mysql-fake_cluster.dre-devc", - "port": 3306, - "user": "vt_app", - }, - "extraEnv": [ - { - "name": "VAULT_ADDR", - "value": "https://vault-dre.mock_region-devc.yelpcorp.com:8200", - }, - { - "name": "VAULT_CACERT", - "value": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt", - }, - { - "name": "TOPOLOGY_FLAGS", - "value": "--topo_implementation " - "zk2 " - "--topo_global_server_address " - "$fake_zk_address " - "--topo_global_root " - "/vitess-paasta/global", - }, - { - "name": "CELL_TOPOLOGY_SERVERS", - "value": "fake_zk_address", - }, - {"name": "DB", "value": "fake_keyspaces"}, - {"name": "KEYSPACE", "value": "fake_keyspaces"}, - {"name": "WEB_PORT", "value": "15000"}, - {"name": "GRPC_PORT", "value": "15999"}, - {"name": "SHARD", "value": "0"}, - {"name": "EXTERNAL_DB", "value": "1"}, - {"name": "ROLE", "value": "replica"}, - { - "name": "VAULT_ROLEID", - "valueFrom": { - "secretKeyRef": { - "key": "vault-vttablet-approle-roleid", - "name": "paasta-vitessclusters-secret-vitess-k8s-vault-vttablet-approle-roleid", - } - }, - }, - { - "name": "VAULT_SECRETID", - "valueFrom": { - "secretKeyRef": { - "key": "vault-vttablet-approle-secretid", - "name": "paasta-vitessclusters-secret-vitess-k8s-vault-vttablet-approle-secretid", - } - }, - }, - ], - "extraLabels": { - "tablet_type": "fake_keyspaces_migration" - }, - "extraVolumeMounts": [ - { - "mountPath": "/etc/vault/all_cas", - "name": "vault-secrets", - "readOnly": True, - }, - { - "mountPath": "/nail/srv", - "name": "srv-configs", - "readOnly": True, - }, - { - "mountPath": "/nail/etc/srv-configs", - "name": "etc-srv-configs", - "readOnly": True, - }, - { - "mountPath": "etc/credentials.yaml", - "name": "vttablet-fake-credentials", - "readOnly": True, - }, - { - "mountPath": "/etc/init_db.sql", - "name": "keyspace-fake-init-script", - "readOnly": True, - }, - ], - "extraVolumes": [ - { - "hostPath": { - "path": "/nail/etc/vault/all_cas" - }, - "name": "vault-secrets", - }, - { - "name": "srv-configs", - "hostPath": {"path": "/nail/srv"}, - }, - { - "name": "etc-srv-configs", - "hostPath": { - "path": "/nail/etc/srv-configs" - }, - }, - { - "hostPath": {"path": "/dev/null"}, - "name": "vttablet-fake-credentials", - }, - { - "hostPath": {"path": "/dev/null"}, - "name": "keyspace-fake-init-script", - }, - ], - "name": "fake_keyspaces_primary", - "replicas": 1, - "type": "externalmaster", - "vttablet": { - "extraFlags": { - "db-credentials-server": "vault", - "db-credentials-vault-addr": "https://vault-dre.mock_region-devc.yelpcorp.com:8200", - "db-credentials-vault-path": "secrets/vitess/vt-tablet/vttablet_credentials.json", - "db-credentials-vault-tls-ca": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt", - "db-credentials-vault-ttl": "60s", - "db_charset": "utf8mb4", - "dba_pool_size": "4", - "disable_active_reparents": "true", - "enable-lag-throttler": "true", - "enforce-tableacl-config": "true", - "grpc_max_message_size": "134217728", - "init_tablet_type": "replica", - "init_shard": "0", - "keep_logs": "72h", - "log_err_stacks": "true", - "queryserver-config-schema-reload-time": "1800", - "queryserver-config-strict-table-acl": "true", - "table-acl-config": "/nail/srv/configs/vitess_keyspace_acls/acls_for_fake_keyspaces.json", - "table-acl-config-reload-interval": "60s", - "throttle_check_as_check_self": "true", - "throttle_metrics_query": "select " - "max_replication_delay " - "from " - "max_mysql_replication_delay.read_replication_delay;", - "throttle_metrics_threshold": "3", - "vreplication_heartbeat_update_interval": "60", - "vreplication_tablet_type": "REPLICA", - }, - "resources": { - "limits": { - "cpu": "100m", - "memory": "256Mi", - }, - "requests": { - "cpu": "100m", - "memory": "256Mi", - }, - }, - }, - }, - { - "affinity": { - "nodeAffinity": { - "requiredDuringSchedulingIgnoredDuringExecution": { - "nodeSelectorTerms": [ - { - "matchExpressions": [ - { - "key": "fake_pool", - "operator": "In", - "values": [ - "fake_pool_value" - ], - } - ] - } - ] - } - } - }, - "annotations": { - "paasta.yelp.com/routable_ip": "false", - "smartstack_registrations": '["fake_service.fake_instance"]', - }, - "cell": "fake_cell", - "dataVolumeClaimTemplate": { - "accessModes": ["ReadWriteOnce"], - "resources": {"requests": {"storage": "10Gi"}}, - "storageClassName": "ebs-csi-gp3", - }, - "externalDatastore": { - "credentialsSecret": { - "key": "/etc/credentials.yaml", - "volumeName": "vttablet-fake-credentials", - }, - "database": "fake_keyspaces", - "host": "mysql-fake_cluster-migration.dre-devc", - "port": 3306, - "user": "vt_app", - }, - "extraEnv": [ - { - "name": "VAULT_ADDR", - "value": "https://vault-dre.mock_region-devc.yelpcorp.com:8200", - }, - { - "name": "VAULT_CACERT", - "value": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt", - }, - { - "name": "TOPOLOGY_FLAGS", - "value": "--topo_implementation " - "zk2 " - "--topo_global_server_address " - "$fake_zk_address " - "--topo_global_root " - "/vitess-paasta/global", - }, - { - "name": "CELL_TOPOLOGY_SERVERS", - "value": "fake_zk_address", - }, - {"name": "DB", "value": "fake_keyspaces"}, - {"name": "KEYSPACE", "value": "fake_keyspaces"}, - {"name": "WEB_PORT", "value": "15000"}, - {"name": "GRPC_PORT", "value": "15999"}, - {"name": "SHARD", "value": "0"}, - {"name": "EXTERNAL_DB", "value": "1"}, - {"name": "ROLE", "value": "replica"}, - { - "name": "VAULT_ROLEID", - "valueFrom": { - "secretKeyRef": { - "key": "vault-vttablet-approle-roleid", - "name": "paasta-vitessclusters-secret-vitess-k8s-vault-vttablet-approle-roleid", - } - }, - }, - { - "name": "VAULT_SECRETID", - "valueFrom": { - "secretKeyRef": { - "key": "vault-vttablet-approle-secretid", - "name": "paasta-vitessclusters-secret-vitess-k8s-vault-vttablet-approle-secretid", - } - }, - }, - ], - "extraLabels": { - "tablet_type": "fake_keyspaces_migration" - }, - "extraVolumeMounts": [ - { - "mountPath": "/etc/vault/all_cas", - "name": "vault-secrets", - "readOnly": True, - }, - { - "mountPath": "/nail/srv", - "name": "srv-configs", - "readOnly": True, - }, - { - "mountPath": "/nail/etc/srv-configs", - "name": "etc-srv-configs", - "readOnly": True, - }, - { - "mountPath": "etc/credentials.yaml", - "name": "vttablet-fake-credentials", - "readOnly": True, - }, - { - "mountPath": "/etc/init_db.sql", - "name": "keyspace-fake-init-script", - "readOnly": True, - }, - ], - "extraVolumes": [ - { - "hostPath": { - "path": "/nail/etc/vault/all_cas" - }, - "name": "vault-secrets", - }, - { - "name": "srv-configs", - "hostPath": {"path": "/nail/srv"}, - }, - { - "name": "etc-srv-configs", - "hostPath": { - "path": "/nail/etc/srv-configs" - }, - }, - { - "hostPath": {"path": "/dev/null"}, - "name": "vttablet-fake-credentials", - }, - { - "hostPath": {"path": "/dev/null"}, - "name": "keyspace-fake-init-script", - }, - ], - "name": "fake_keyspaces_migration", - "replicas": 1, - "type": "externalreplica", - "vttablet": { - "extraFlags": { - "db-credentials-server": "vault", - "db-credentials-vault-addr": "https://vault-dre.mock_region-devc.yelpcorp.com:8200", - "db-credentials-vault-path": "secrets/vitess/vt-tablet/vttablet_credentials.json", - "db-credentials-vault-tls-ca": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt", - "db-credentials-vault-ttl": "60s", - "db_charset": "utf8mb4", - "dba_pool_size": "4", - "disable_active_reparents": "true", - "enable-lag-throttler": "true", - "enforce-tableacl-config": "true", - "grpc_max_message_size": "134217728", - "init_tablet_type": "replica", - "init_shard": "0", - "keep_logs": "72h", - "log_err_stacks": "true", - "queryserver-config-schema-reload-time": "1800", - "queryserver-config-strict-table-acl": "true", - "table-acl-config": "/nail/srv/configs/vitess_keyspace_acls/acls_for_fake_keyspaces.json", - "table-acl-config-reload-interval": "60s", - "throttle_check_as_check_self": "true", - "throttle_metrics_query": "select " - "max_replication_delay " - "from " - "max_mysql_replication_delay.migration_replication_delay;", - "throttle_metrics_threshold": "3", - "vreplication_heartbeat_update_interval": "60", - "vreplication_tablet_type": "REPLICA", - }, - "resources": { - "limits": { - "cpu": "100m", - "memory": "256Mi", - }, - "requests": { - "cpu": "100m", - "memory": "256Mi", - }, - }, - }, - }, - ], - }, - } - } - ], - "turndownPolicy": "Immediate", - } - ], - "updateStrategy": {"type": "Immediate"}, - "vitessDashboard": { - "affinity": { - "nodeAffinity": { - "requiredDuringSchedulingIgnoredDuringExecution": { - "nodeSelectorTerms": [ - { - "matchExpressions": [ - { - "key": "fake_pool", - "operator": "In", - "values": ["fake_pool_value"], - } - ] - } - ] - } - } - }, - "annotations": { - "paasta.yelp.com/routable_ip": "false", - "smartstack_registrations": '["fake_service.fake_instance"]', - }, - "cells": ["fake_cell"], - "extraEnv": [ - { - "name": "TOPOLOGY_FLAGS", - "value": "--topo_implementation zk2 " - "--topo_global_server_address " - "fake_zk_address " - "--topo_global_root " - "/vitess-paasta/global", - }, - {"name": "WEB_PORT", "value": "15000"}, - {"name": "GRPC_PORT", "value": "15999"}, - ], - "extraFlags": { - "disable_active_reparents": "true", - "security_policy": "read-only", - }, - "extraLabels": {"tablet_type": "fake_keyspaces_migration"}, - "replicas": 1, - "resources": { - "limits": {"cpu": "100m", "memory": "256Mi"}, - "requests": {"cpu": "100m", "memory": "256Mi"}, - }, - }, - "vtadmin": { - "affinity": { - "nodeAffinity": { - "requiredDuringSchedulingIgnoredDuringExecution": { - "nodeSelectorTerms": [ - { - "matchExpressions": [ - { - "key": "fake_pool", - "operator": "In", - "values": ["fake_pool_value"], - } - ] - } - ] - } - } - }, - "annotations": { - "paasta.yelp.com/routable_ip": "false", - "smartstack_registrations": '["fake_service.fake_instance"]', - }, - "apiAddresses": ["http://localhost:15000"], - "apiResources": { - "limits": {"cpu": "100m", "memory": "256Mi"}, - "requests": {"cpu": "100m", "memory": "256Mi"}, - }, - "cells": ["fake_cell"], - "extraEnv": [], - "extraFlags": {"grpc-allow-reflection": "true"}, - "extraLabels": {"tablet_type": "fake_keyspaces_migration"}, - "readOnly": False, - "replicas": 1, - "webResources": { - "limits": {"cpu": "100m", "memory": "256Mi"}, - "requests": {"cpu": "100m", "memory": "256Mi"}, - }, - }, -} - - -@pytest.fixture -def mock_vitess_deployment_config(): - with mock.patch.object( - VitessDeploymentConfig, "get_region", return_value="mock_region-devc" - ), mock.patch.object( - VitessDeploymentConfig, "get_container_env", return_value=[] - ), mock.patch.object( - VitessDeploymentConfig, "get_docker_url", return_value="fake_docker_url" - ), mock.patch.object( - VitessDeploymentConfig, "get_cluster", return_value="fake_superregion" - ), mock.patch.object( - VitessDeploymentConfig, - "get_kubernetes_metadata", - return_value=V1ObjectMeta(labels={}), - ): - yield - - -@mock.patch( - "paasta_tools.vitesscluster_tools.load_vitess_instance_config", - autospec=True, -) -@mock.patch( - "paasta_tools.vitesscluster_tools.load_system_paasta_config", - autospec=True, -) -def test_load_vitess_service_instance_configs( - mock_load_system_paasta_config, - mock_load_vitess_instance_config, - mock_vitess_deployment_config, -): - mock_load_vitess_instance_config.return_value = VitessDeploymentConfig( - service="fake_service", - instance="fake_instance", - cluster="fake_cluster", - config_dict=CONFIG_DICT, - branch_dict={}, - soa_dir="fake_soa_dir", - ) - mock_load_system_paasta_config.return_value = MOCK_SYSTEM_PAASTA_CONFIG - vitess_service_instance_configs = load_vitess_service_instance_configs( - service="fake_service", - soa_dir="fake_soa_dir", - cluster="fake_cluster", - instance="fake_instance", - ) - assert vitess_service_instance_configs == VITESS_CONFIG - - -@mock.patch("paasta_tools.vitesscluster_tools.load_v2_deployments_json", autospec=True) -@mock.patch( - "paasta_tools.vitesscluster_tools.load_service_instance_config", - autospec=True, -) -@mock.patch( - "paasta_tools.vitesscluster_tools.VitessDeploymentConfig", - autospec=True, -) -def test_load_vitess_instance_config( - mock_vitess_deployment_config, - mock_load_service_instance_config, - mock_load_v2_deployments_json, -): - mock_config = { - "port": None, - "monitoring": {}, - "deploy": {}, - "data": {}, - "smartstack": {}, - "dependencies": {}, - } - vitess_deployment_config = load_vitess_instance_config( - service="fake_vitesscluster_service", - instance="fake_instance", - cluster="fake_cluster", - load_deployments=True, - soa_dir="/foo/bar", - ) - mock_load_v2_deployments_json.assert_called_with( - service="fake_vitesscluster_service", soa_dir="/foo/bar" - ) - mock_vitess_deployment_config.assert_called_with( - service="fake_vitesscluster_service", - instance="fake_instance", - cluster="fake_cluster", - config_dict=mock_config, - branch_dict=mock_load_v2_deployments_json.return_value.get_branch_dict(), - soa_dir="/foo/bar", - ) - - assert vitess_deployment_config == mock_vitess_deployment_config.return_value