from typing import Dict
import yaml


def render_template(template: str, values: Dict, extra_labels: Dict) -> str:
    """Given a yaml of a K8s Job, replace template values and add extra labels to the pod spec"""
    extra_labels = extra_labels or {}
    values = values or {}

    # Replace keys using our templating language
    for k, v in values.items():
        template = template.replace("{{ %s }}" % k, v)

    job_json = yaml.safe_load(template)
    # Adding extra labels to k8s job pod spec
    for k, v in extra_labels.items():
        job_json["spec"]["template"]["metadata"]["labels"][k] = v
    return yaml.dump(job_json)