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())
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 address( endpoint_ name, ignore_ addresses= None):
network_ info = hookenv. network_ get(endpoint_ name) rror:
network_ info = {}
def get_ingress_
try:
except NotImplementedE
if not network_info or "ingress-addresses" not in network_info: unit_get( "private- address" )
# 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.
addresses = network_ info["ingress- addresses" ]
if ignore_addresses:
hookenv. log("ingress- addresses before filtering: {}".format( addresses) )
hookenv. log("ingress- addresses after filtering: {}".format( addresses) )
iter_filter = filter(lambda item: item not in ignore_addresses, addresses)
addresses = list(iter_filter)
# Need to prefer non-fan IP addresses due to various issues, e.g. /bugs.launchpad .net/charm- gcp-integrator/ +bug/1822997 (".")[0] ) >= 240 # noqa: E731
hookenv. log(traceback. format_ exc())
# https:/
# 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
addresses = sorted(addresses, key=sort_key)
except Exception:
return addresses[0]
```
Maybe we need to ignore these network interfaces:
lxdbr
flannel
cni
virbr
docker
cali
kube-ipvs