Comment 0 for bug 1956291

Revision history for this message
AnonSaber (anonsaber) wrote :

The advertise-address of kube-api in some nodes has obtained the cni address.

For this case:

$ juju run --unit kubernetes-master/0 "network-get --format yaml kube-control"
bind-addresses:
- mac-address: 16:fa:03:ce:ef:83
  interface-name: flannel.1
  addresses:
  - hostname: ""
    address: 172.31.42.0
    cidr: 172.31.42.0/32
  macaddress: 16:fa:03:ce:ef:83
  interfacename: flannel.1
- mac-address: 52:54:00:d4:84:a7
  interface-name: eth0
  addresses:
  - hostname: ""
    address: 172.31.72.18
    cidr: 172.31.72.0/23
  - hostname: ""
    address: 172.31.72.4
    cidr: 172.31.72.4/32
  macaddress: 52:54:00:d4:84:a7
  interfacename: eth0
egress-subnets:
- 172.31.42.0/32
ingress-addresses:
- 172.31.42.0
- 172.31.72.18
- 172.31.72.4

So these code in kubernetes_common.py will obtain the kube-control address to 172.31.42.0

```python
def get_ingress_address(endpoint_name, ignore_addresses=None):
    try:
        network_info = hookenv.network_get(endpoint_name)
    except NotImplementedError:
        network_info = {}

    if not network_info or "ingress-addresses" not in network_info:
        # if they don't have ingress-addresses they are running a juju that
        # doesn't support spaces, so just return the private address
        return hookenv.unit_get("private-address")

    addresses = network_info["ingress-addresses"]

    if ignore_addresses:
        hookenv.log("ingress-addresses before filtering: {}".format(addresses))
        iter_filter = filter(lambda item: item not in ignore_addresses, addresses)
        addresses = list(iter_filter)
        hookenv.log("ingress-addresses after filtering: {}".format(addresses))

    # Need to prefer non-fan IP addresses due to various issues, e.g.
    # https://bugs.launchpad.net/charm-gcp-integrator/+bug/1822997
    # Fan typically likes to use IPs in the 240.0.0.0/4 block, so we'll
    # prioritize those last. Not technically correct, but good enough.
    try:
        sort_key = lambda a: int(a.partition(".")[0]) >= 240 # noqa: E731
        addresses = sorted(addresses, key=sort_key)
    except Exception:
        hookenv.log(traceback.format_exc())

    return addresses[0]
```

Maybe we need to ignore these network interfaces:

lxdbr
flannel
cni
virbr
docker
cali
kube-ipvs