kubernetes-the-hard-way-openstack
kubernetes-the-hard-way-openstack copied to clipboard
Quering IPs for DNS not working properly when creating Compute Resources
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:
- Split up creation of floating IP to write it into
DNS_EXTERNAL_IP - Fix
awkextraction - 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:
Same for LB_EXTERNAL_IP
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'
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!
Absolutely!
I will finish it tomorrow probably.