kubernetes-the-hard-way-openstack icon indicating copy to clipboard operation
kubernetes-the-hard-way-openstack copied to clipboard

Quering IPs for DNS not working properly when creating Compute Resources

Open Syphdias opened this issue 3 years ago • 4 comments
trafficstars

I noticed there are two occasions where you query IP from the DNS server. At least with my openstackclient version this least to some issues since the format changes from no options to using -f value. Without any format specification:

❯ openstack server show dns.${DOMAIN} |grep addresses
| addresses                   | kubernetes-the-hard-way=10.240.0.100, 1.2.3.4                     |

but with -f value

❯ openstack server show dns.${DOMAIN} -f value -c addresses
{'kubernetes-the-hard-way': ['10.240.0.100', '1.2.3.4']}

This leads to problems with two lines:

DNS_INTERNAL_IP=$(openstack server show dns.${DOMAIN} -f value -c addresses | awk -F'[=,]' '{print $2}')

and

DNS_EXTERNAL_IP=$(openstack server show dns.${DOMAIN} -f value -c addresses | awk '{ print $2 }')

Proposed Solutions

I think for the internal IP we could just use 10.240.0.100 since it is hard coded further up anyway. Or we could set DNS_INTERNAL_IP="10.240.0.100" and use it in a later section. I am not sure, if you want to have each code section self-contained. If so, I'd set the variable in both cases.

For the external IP, I see several options how to fix this:

  1. Split up creation of floating IP to write it into DNS_EXTERNAL_IP
  2. Fix awk extraction
  3. Use json and jq: openstack server show dns.${DOMAIN} -f json -c addresses |jq -r '.["addresses"]["kubernetes-the-hard-way"][]|select(contains("10.240.0.100")|not)'

I am not a fan of option 2 since it might be different in different CLI versions. If you want to keep the sections absolutely self-contained, I think option 3 is the most stable, but it requires jq and is not exactly easy to read, if you are not familiar with the syntax. Option 1 would cut down on the self-containment of code sections, if you set DNS_EXTERNAL_IP when creating the floating IP and just reuse it in the section below. If someone starts over or switches the terminal this would not work.

Please let me know which approach you favor and I'll open a PR – or you fix it yourself, if you want, of course. :wink:

Syphdias avatar May 29 '22 12:05 Syphdias

Same for LB_EXTERNAL_IP

Syphdias avatar May 29 '22 12:05 Syphdias

Apparently querying the IP need to happen quite a lot and fails every time for me. This should work:

openstack server show $server -f json -c addresses | jq -r '.["addresses"]["kubernetes-the-hard-way"]|last'

Syphdias avatar May 29 '22 13:05 Syphdias

Thanks for your help! I don't have an openstack environment at my disposal unfortunately so if you can send the PR it would be awesome. I prefer the jq approach as it seems more elegant than using awk if you agree. Thanks again!

e-minguez avatar May 29 '22 17:05 e-minguez

Absolutely!

I will finish it tomorrow probably.

Syphdias avatar May 29 '22 20:05 Syphdias