コード例 #1
0
def is_service_cidr_expansion():
    service_cidr_from_db = db.get("kubernetes-master.service-cidr")
    service_cidr_from_config = hookenv.config("service-cidr")
    if not service_cidr_from_db:
        return False

    # Do not consider as expansion if both old and new service cidr are same
    if service_cidr_from_db == service_cidr_from_config:
        return False

    current_networks = kubernetes_common.get_networks(service_cidr_from_db)
    new_networks = kubernetes_common.get_networks(service_cidr_from_config)
    if len(current_networks) != len(new_networks) or not all(
            cur.subnet_of(new)
            for cur, new in zip(current_networks, new_networks)):
        hookenv.log("WARN: New k8s service cidr not superset of old one")
        return False

    return True
コード例 #2
0
def get_kubernetes_service_ips():
    """Get the IP address(es) for the kubernetes service based on the cidr."""
    return [
        next(network.hosts()).exploded
        for network in kubernetes_common.get_networks(service_cidr())
    ]