Skip to content

Commit

Permalink
Merge pull request #3931 from Yelp/u/gonabavi/DREIMP-10901_add_smarts…
Browse files Browse the repository at this point in the history
…tack_registrations_for_vitess_pods

U/gonabavi/dreimp 10901 add smartstack registrations for vitess pods
  • Loading branch information
VinaySagarGonabavi authored Aug 9, 2024
2 parents 45c88e8 + 1076dc7 commit 8a7c13e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 4 deletions.
63 changes: 59 additions & 4 deletions paasta_tools/vitesscluster_tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
import sys
from typing import Any
Expand All @@ -15,6 +16,7 @@
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
Expand Down Expand Up @@ -134,6 +136,7 @@ class GatewayConfigDict(TypedDict, total=False):
extraLabels: Dict[str, str]
replicas: int
resources: Dict[str, Any]
annotations: Mapping[str, Any]


class CellConfigDict(TypedDict, total=False):
Expand All @@ -149,6 +152,7 @@ class VitessDashboardConfigDict(TypedDict, total=False):
extraLabels: Dict[str, str]
replicas: int
resources: Dict[str, Any]
annotations: Mapping[str, Any]


class VtAdminConfigDict(TypedDict, total=False):
Expand All @@ -162,6 +166,7 @@ class VtAdminConfigDict(TypedDict, total=False):
readOnly: bool
apiResources: Dict[str, Any]
webResources: Dict[str, Any]
annotations: Mapping[str, Any]


class VtTabletDict(TypedDict, total=False):
Expand All @@ -182,6 +187,7 @@ class TabletPoolDict(TypedDict, total=False):
vttablet: VtTabletDict
externalDatastore: Dict[str, Any]
dataVolumeClaimTemplate: Dict[str, Any]
annotations: Mapping[str, Any]


class ShardTemplateDict(TypedDict, total=False):
Expand Down Expand Up @@ -229,6 +235,7 @@ def get_cell_config(
env: List[Union[KVEnvVar, KVEnvVarValueFrom]],
labels: Dict[str, str],
node_affinity: dict,
annotations: Mapping[str, Any],
) -> CellConfigDict:
"""
get vtgate config
Expand Down Expand Up @@ -264,6 +271,7 @@ def get_cell_config(
"requests": requests,
"limits": requests,
},
annotations=annotations,
),
)
return config
Expand All @@ -276,6 +284,7 @@ def get_vitess_dashboard_config(
env: List[Union[KVEnvVar, KVEnvVarValueFrom]],
labels: Dict[str, str],
node_affinity: dict,
annotations: Mapping[str, Any],
) -> VitessDashboardConfigDict:
"""
get vtctld config
Expand Down Expand Up @@ -303,6 +312,7 @@ def get_vitess_dashboard_config(
"requests": requests,
"limits": requests,
},
annotations=annotations,
)
return config

Expand All @@ -313,6 +323,7 @@ def get_vt_admin_config(
env: List[Union[KVEnvVar, KVEnvVarValueFrom]],
labels: Dict[str, str],
node_affinity: dict,
annotations: Mapping[str, Any],
) -> VtAdminConfigDict:
"""
get vtadmin config
Expand All @@ -338,6 +349,7 @@ def get_vt_admin_config(
"requests": requests,
"limits": requests,
},
annotations=annotations,
)
return config

Expand All @@ -356,6 +368,7 @@ def get_tablet_pool_config(
env: List[Union[KVEnvVar, KVEnvVarValueFrom]],
labels: Dict[str, str],
node_affinity: dict,
annotations: Mapping[str, Any],
) -> TabletPoolDict:
"""
get vttablet config
Expand Down Expand Up @@ -478,6 +491,7 @@ def get_tablet_pool_config(
"resources": {"requests": {"storage": "10Gi"}},
"storageClassName": "ebs-csi-gp3",
},
annotations=annotations,
)
return config

Expand All @@ -490,6 +504,7 @@ def get_keyspaces_config(
env: List[Union[KVEnvVar, KVEnvVarValueFrom]],
labels: Dict[str, str],
node_affinity: dict,
annotations: Mapping[str, Any],
) -> List[KeyspaceConfigDict]:
"""
get vitess keyspace config
Expand Down Expand Up @@ -548,6 +563,7 @@ def get_keyspaces_config(
env,
labels,
node_affinity,
annotations,
)
for cell in cells
]
Expand Down Expand Up @@ -655,6 +671,22 @@ def get_labels(self) -> Dict[str, str]:
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()
Expand Down Expand Up @@ -698,10 +730,17 @@ def get_cells(self) -> List[CellConfigDict]:
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
cell,
region,
vtgate_resources,
formatted_env,
labels,
node_affinity,
annotations,
)
for cell in cells
]
Expand All @@ -714,9 +753,16 @@ def get_vitess_dashboard(self) -> VitessDashboardConfigDict:
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
cells,
zk_address,
vtctld_resources,
formatted_env,
labels,
node_affinity,
annotations,
)

def get_vtadmin(self) -> VtAdminConfigDict:
Expand All @@ -726,9 +772,10 @@ def get_vtadmin(self) -> VtAdminConfigDict:
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
cells, vtadmin_resources, formatted_env, labels, node_affinity, annotations
)

def get_keyspaces(self) -> List[KeyspaceConfigDict]:
Expand All @@ -740,9 +787,17 @@ def get_keyspaces(self) -> List[KeyspaceConfigDict]:
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
cells,
keyspaces,
zk_address,
region,
formatted_env,
labels,
node_affinity,
annotations,
)

def get_update_strategy(self) -> Dict[str, str]:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_vitesscluster_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
}
}
},
"annotations": {
"paasta.yelp.com/routable_ip": "false",
"smartstack_registrations": '["fake_service.fake_instance"]',
},
"extraEnv": [
{
"name": "VAULT_ADDR",
Expand Down Expand Up @@ -169,6 +173,10 @@
}
}
},
"annotations": {
"paasta.yelp.com/routable_ip": "false",
"smartstack_registrations": '["fake_service.fake_instance"]',
},
"cell": "fake_cell",
"dataVolumeClaimTemplate": {
"accessModes": ["ReadWriteOnce"],
Expand Down Expand Up @@ -353,6 +361,10 @@
}
}
},
"annotations": {
"paasta.yelp.com/routable_ip": "false",
"smartstack_registrations": '["fake_service.fake_instance"]',
},
"cell": "fake_cell",
"dataVolumeClaimTemplate": {
"accessModes": ["ReadWriteOnce"],
Expand Down Expand Up @@ -544,6 +556,10 @@
}
}
},
"annotations": {
"paasta.yelp.com/routable_ip": "false",
"smartstack_registrations": '["fake_service.fake_instance"]',
},
"cells": ["fake_cell"],
"extraEnv": [
{
Expand Down Expand Up @@ -586,6 +602,10 @@
}
}
},
"annotations": {
"paasta.yelp.com/routable_ip": "false",
"smartstack_registrations": '["fake_service.fake_instance"]',
},
"apiAddresses": ["http://localhost:15000"],
"apiResources": {
"limits": {"cpu": "100m", "memory": "256Mi"},
Expand Down

0 comments on commit 8a7c13e

Please sign in to comment.