Skip to content

Commit

Permalink
Add additional annotations to get smartstack_registrations for custom…
Browse files Browse the repository at this point in the history
… resources
  • Loading branch information
VinaySagarGonabavi committed Aug 8, 2024
1 parent bef6f61 commit 7dd8216
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
19 changes: 19 additions & 0 deletions paasta_tools/setup_kubernetes_cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@
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_annotations
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}
INSTANCE_TYPE_TO_ADDITIONAL_ANNOTATIONS_LOADER = {
"vitesscluster": load_vitess_service_annotations
}


class StdoutKubeClient:
Expand Down Expand Up @@ -363,6 +367,7 @@ def reconcile_kubernetes_resource(
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,
Expand All @@ -376,6 +381,20 @@ def reconcile_kubernetes_resource(
git_sha=git_sha,
is_eks=is_eks,
)

if crd.file_prefix in INSTANCE_TYPE_TO_ADDITIONAL_ANNOTATIONS_LOADER:
additional_annotations = INSTANCE_TYPE_TO_ADDITIONAL_ANNOTATIONS_LOADER[
crd.file_prefix
](
service=service,
instance=inst,
cluster=cluster,
soa_dir=DEFAULT_SOA_DIR,
)
formatted_resource["metadata"]["annotations"].update(
additional_annotations
)

desired_resource = KubeCustomResource(
service=service,
instance=inst,
Expand Down
30 changes: 30 additions & 0 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 @@ -655,6 +657,22 @@ def get_labels(self) -> Dict[str, str]:
labels["yelp.com/owner"] = "dre_mysql"
return labels

def get_annotations(self) -> Dict[str, str]:
# 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 @@ -838,6 +856,18 @@ def load_vitess_service_instance_configs(
return vitess_service_instance_configs


def load_vitess_service_annotations(
service: str,
instance: str,
cluster: str,
soa_dir: str = DEFAULT_SOA_DIR,
) -> Dict[str, str]:
vitess_service_annotations = load_vitess_instance_config(
service, instance, cluster, soa_dir=soa_dir
).get_annotations()
return vitess_service_annotations


# TODO: read this from CRD in service configs
def cr_id(service: str, instance: str) -> Mapping[str, str]:
return dict(
Expand Down

0 comments on commit 7dd8216

Please sign in to comment.