-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[upi][vsphere] applicable static IP changes #1480
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/bin/bash | ||
# cidr_to_ip - | ||
# https://www.terraform.io/docs/providers/external/data_source.html | ||
# Based on info from here: https://gist.github.com/irvingpop/968464132ded25a206ced835d50afa6b | ||
# This script takes the CIDR address and cycles through looking for the first available address | ||
# echo '{"cidr": "139.178.89.192/26", "master_count": "3", "worker_count": "3", "cluster_domain": "dphillip.devcluster.openshift.com"}' | ./cidr_to_ip.sh | ||
function error_exit() { | ||
echo "$1" 1>&2 | ||
exit 1 | ||
} | ||
|
||
function check_deps() { | ||
test -f $(which jq) || error_exit "jq command not detected in path, please install it" | ||
test -f $(which ipcalc) || error_exit "ipcalc command not detected in path, please install it" | ||
test -f $(which dig) || error_exit "dig command not detected in path, please install it" | ||
|
||
} | ||
|
||
function parse_input() { | ||
# jq reads from stdin so we don't have to set up any inputs, but let's validate the outputs | ||
eval "$(jq -r '@sh "export CIDR=\(.cidr) master_count=\(.master_count) worker_count=\(.worker_count) cluster_domain=\(.cluster_domain)"')" | ||
if [[ -z "${CIDR}" ]]; then export CIDR=none; fi | ||
if [[ -z "${master_count}" ]]; then export master_count=none; fi | ||
if [[ -z "${worker_count}" ]]; then export worker_count=none; fi | ||
if [[ -z "${cluster_domain}" ]]; then export cluster_domain=none; fi | ||
} | ||
|
||
function produce_output() { | ||
|
||
cidr=$CIDR | ||
|
||
# range is bounded by network (-n) & broadcast (-b) addresses. | ||
lo=$(ipcalc -n $cidr | cut -f2 -d=) | ||
hi=$(ipcalc -b $cidr | cut -f2 -d=) | ||
|
||
read a b c d <<< $(echo $lo | tr . ' ') | ||
read e f g h <<< $(echo $hi | tr . ' ') | ||
IP_RANGE=$(eval echo {$a..$e}.{$b..$f}.{$c..$g}.{$d..$h}) | ||
|
||
bs_count=0 | ||
m_count=0 | ||
w_count=0 | ||
|
||
# check cluster_domain DNS first | ||
for ETCD in 0 1 2 | ||
do | ||
|
||
DNS_RECORDS+="$(dig +short etcd-$ETCD.${cluster_domain}) " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mind rebuilding on top of #1492? Then we can search for control-plane-{0,1,2}.${cluster_domain} and compute-{0,1,2}.${cluster_domain} instead of etcd. |
||
done | ||
|
||
for ENTRY in ${DNS_RECORDS} | ||
do | ||
ping -c1 -w1 $ENTRY > /dev/null 2>&1 | ||
ping_rc=$? | ||
if [[ $ping_rc -eq 0 ]] && [[ $m_count -ne $master_count ]] | ||
then | ||
bootstrap_ip="" | ||
bs_count=1 | ||
master_ips+="$ENTRY " | ||
m_count=$((m_count+1)) | ||
fi | ||
done | ||
|
||
for IPADDR in ${IP_RANGE} | ||
do | ||
|
||
if [ $IPADDR != $(ipcalc -n $cidr | cut -f2 -d=) ] && [ $IPADDR != $(ipcalc -b $cidr | cut -f2 -d=) ] | ||
then | ||
ping -c1 -w1 $IPADDR > /dev/null 2>&1 | ||
ping_rc=$? | ||
|
||
if [[ $ping_rc -eq 1 ]] && [[ $bs_count -ne 1 ]] | ||
then | ||
bootstrap_ip+="$IPADDR" | ||
bs_count=$((bs_count+1)) | ||
elif [[ $ping_rc -eq 1 ]] && [[ $m_count -ne $master_count ]] | ||
then | ||
master_ips+="$IPADDR " | ||
m_count=$((m_count+1)) | ||
elif [[ $ping_rc -eq 1 ]] && [[ $w_count -ne $worker_count ]] | ||
then | ||
worker_ips+="$IPADDR " | ||
w_count=$((w_count+1)) | ||
elif [[ $bs_count -eq 1 ]] && [[ $m_count -eq $master_count ]] && [[ $w_count -eq $worker_count ]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be in an My preference would be to break out of the for loop when we find the last compute IP address. And then put the jq after the for loop. |
||
then | ||
jq -n \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do this without requiring jq? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry. I glossed over the use of jq earlier in the script. We can leave the jq here. |
||
--arg bootstrap_ip "$bootstrap_ip" \ | ||
--arg master_ips "$master_ips" \ | ||
--arg worker_ips "$worker_ips" \ | ||
'{"bootstrap_ip":$bootstrap_ip,"master_ips":$master_ips,"worker_ips":$worker_ips}' | ||
exit 0 | ||
fi | ||
fi | ||
done | ||
} | ||
|
||
# main() | ||
check_deps | ||
parse_input | ||
produce_output |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
data "external" "ping" { | ||
program = ["bash", "${path.root}/network/cidr_to_ip.sh"] | ||
|
||
query = { | ||
cidr = "${var.machine_cidr}" | ||
master_count = "${var.master_count}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the terms control-plane and compute instead of master and worker. |
||
worker_count = "${var.worker_count}" | ||
cluster_domain = "${var.cluster_domain}" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
output "master_ips" { | ||
value = "${split(" ", trimspace(data.external.ping.result.master_ips))}" | ||
} | ||
|
||
output "worker_ips" { | ||
value = "${split(" ", trimspace(data.external.ping.result.worker_ips))}" | ||
} | ||
|
||
output "bootstrap_ip" { | ||
value = "${split(" ", trimspace(data.external.ping.result.bootstrap_ip))}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to keep this as a string instead of a list, unless it is terribly difficult otherwise. Would it work to just omit the |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
variable "machine_cidr" { | ||
type = "string" | ||
description = "This is the public network netmask." | ||
} | ||
|
||
variable "cluster_domain" { | ||
type = "string" | ||
description = "This is the cluster domain where the API record is created" | ||
} | ||
|
||
variable "master_count" { | ||
type = "string" | ||
description = "The number of master IP addresses to obtain from the machine_cidr." | ||
} | ||
|
||
variable "worker_count" { | ||
type = "string" | ||
description = "The number of worker IP addresses to obtain from the machine_cidr." | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The iteration should not be hard-coded to
0 1 2
. It needs to be based on the number of control-plane instances (and the number of compute instances).