def filename_for(resource):
    """Generate a unique base file name for the given resource.

    :param resource: A k8s resource definition dict, expected to have at least
        a kind and metadata.name.
    :return: A base file name (no directory) that should be unique for the
        given resource (assuming the resource is itself unique).
    """
    chunks = [resource['kind']]
    ns = resource['metadata'].get('namespace')
    if ns:
        chunks.append(ns)
    chunks.append(resource['metadata']['name'])
    return '_'.join(chunks) + '.yaml'