Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Propagate kubernetes custom metadata annotations to sub-services #3767

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ sky/clouds/service_catalog/data_fetchers/*.csv
.vscode/
.idea/
.env

# For editor files
*.swp
12 changes: 12 additions & 0 deletions sky/provision/kubernetes/network_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,19 @@ def fill_loadbalancer_template(namespace: str, service_name: str,

with open(template_path, 'r', encoding='utf-8') as fin:
template = fin.read()
annotations = skypilot_config.get_nested(
romilbhardwaj marked this conversation as resolved.
Show resolved Hide resolved
('kubernetes', 'custom_metadata', 'annotations'), {})
romilbhardwaj marked this conversation as resolved.
Show resolved Hide resolved
labels = skypilot_config.get_nested(
('kubernetes', 'custom_metadata', 'labels'), {})
j2_template = jinja2.Template(template)
cont = j2_template.render(
namespace=namespace,
service_name=service_name,
ports=ports,
selector_key=selector_key,
selector_value=selector_value,
annotations=annotations,
labels=labels,
)
content = yaml.safe_load(cont)
return content
Expand All @@ -98,6 +104,10 @@ def fill_ingress_template(namespace: str, service_details: List[Tuple[str, int,
f'Template "{_INGRESS_TEMPLATE_NAME}" does not exist.')
with open(template_path, 'r', encoding='utf-8') as fin:
template = fin.read()
annotations = skypilot_config.get_nested(
('kubernetes', 'custom_metadata', 'annotations'), {})
labels = skypilot_config.get_nested(
('kubernetes', 'custom_metadata', 'labels'), {})
j2_template = jinja2.Template(template)
cont = j2_template.render(
namespace=namespace,
Expand All @@ -109,6 +119,8 @@ def fill_ingress_template(namespace: str, service_details: List[Tuple[str, int,
ingress_name=ingress_name,
selector_key=selector_key,
selector_value=selector_value,
annotations=annotations,
labels=labels,
)
content = yaml.safe_load(cont)

Expand Down
7 changes: 7 additions & 0 deletions sky/templates/kubernetes-ingress.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ ingress_spec:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
labels:
{%- for label_key, label_value in labels.items() %}
{{ label_key }}: {{ label_value|tojson }}
{%- endfor %}
annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
{%- for key, value in annotations.items() %}
{{ key }}: {{ value|tojson }}
{%- endfor %}
name: {{ ingress_name }}
namespace: {{ namespace }}
spec:
Expand Down
7 changes: 7 additions & 0 deletions sky/templates/kubernetes-loadbalancer.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ service_spec:
name: {{ service_name }}
labels:
parent: skypilot
{%- for label_key, label_value in labels.items() %}
{{ label_key }}: {{ label_value|tojson }}
{%- endfor %}
annotations:
{%- for key, value in annotations.items() %}
{{ key }}: {{ value|tojson }}
{%- endfor %}
spec:
type: LoadBalancer
selector:
Expand Down
Loading