diff --git a/.gitignore b/.gitignore index efa74dd744b..31b37d1eab0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ sky/clouds/service_catalog/data_fetchers/*.csv .vscode/ .idea/ .env + +# For editor files +*.swp diff --git a/sky/provision/kubernetes/network_utils.py b/sky/provision/kubernetes/network_utils.py index 844f84a04f5..5486214b794 100644 --- a/sky/provision/kubernetes/network_utils.py +++ b/sky/provision/kubernetes/network_utils.py @@ -75,6 +75,10 @@ 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( + ('kubernetes', 'custom_metadata', 'annotations'), {}) + labels = skypilot_config.get_nested( + ('kubernetes', 'custom_metadata', 'labels'), {}) j2_template = jinja2.Template(template) cont = j2_template.render( namespace=namespace, @@ -82,6 +86,8 @@ def fill_loadbalancer_template(namespace: str, service_name: str, ports=ports, selector_key=selector_key, selector_value=selector_value, + annotations=annotations, + labels=labels, ) content = yaml.safe_load(cont) return content @@ -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, @@ -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) diff --git a/sky/templates/kubernetes-ingress.yml.j2 b/sky/templates/kubernetes-ingress.yml.j2 index 84b3e9d6998..d419b6b2893 100644 --- a/sky/templates/kubernetes-ingress.yml.j2 +++ b/sky/templates/kubernetes-ingress.yml.j2 @@ -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: diff --git a/sky/templates/kubernetes-loadbalancer.yml.j2 b/sky/templates/kubernetes-loadbalancer.yml.j2 index 08d8b0cc64c..7afc35ab334 100644 --- a/sky/templates/kubernetes-loadbalancer.yml.j2 +++ b/sky/templates/kubernetes-loadbalancer.yml.j2 @@ -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: