(fix) Give systemd service access to env
- The service to register the rack controller pod does not have access to the MAAS_API_KEY env var so it fails to deregister when needed. Change-Id: I16bc63ef14a2dab463dfdca11b7e3ca13d508a9e
This commit is contained in:
parent
7f50e96ff3
commit
8d56122554
@ -6,11 +6,48 @@ set -x
|
||||
# to source the maas system_id
|
||||
HOST_MOUNT_PATH=${HOST_MOUNT_PATH:-"/host_cloud-init/"}
|
||||
|
||||
get_impacted_nets() {
|
||||
system_id="$1"
|
||||
maas local fabrics read | jq -cr 'map(.vlans) | map(.[]) | map(select(.primary_rack == "'"$system_id"'" or .secondary_rack == "'"$system_id"'")) | .[] | {vid, fabric_id}'
|
||||
}
|
||||
|
||||
detach_rack_controller() {
|
||||
system_id="$1"
|
||||
for net in $(get_impacted_nets "$system_id");
|
||||
do
|
||||
vid=$(echo "$net" | jq -r .vid)
|
||||
fid=$(echo "$net" | jq -r .fabric_id)
|
||||
maas local vlan update "$fid" "$vid" primary_rack='' secondary_rack=''
|
||||
done
|
||||
}
|
||||
|
||||
unregister_maas_rack() {
|
||||
sys_id="$1"
|
||||
echo "Deregister this pod as MAAS rack controller ${sys_id}."
|
||||
|
||||
maas login local "$MAAS_ENDPOINT" "$MAAS_API_KEY"
|
||||
maas local rack-controller delete "$sys_id"
|
||||
|
||||
if [[ $? -ne 0 ]];
|
||||
then
|
||||
echo "Could not login to MAAS API."
|
||||
exit $?
|
||||
fi
|
||||
|
||||
detach_rack_controller "$sys_id"
|
||||
|
||||
while [ 1 ];
|
||||
do
|
||||
maas local rack-controller delete "$sys_id"
|
||||
|
||||
if [[ $? -ne 0 ]];
|
||||
then
|
||||
echo "Could not delete rack controller."
|
||||
sleep 10
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
rm -f ~maas/maas_id
|
||||
rm -f ~maas/secret
|
||||
}
|
||||
@ -28,7 +65,7 @@ register_maas_rack() {
|
||||
# register forever
|
||||
while [ 1 ];
|
||||
do
|
||||
if maas-rack register --url=${MAAS_ENDPOINT} --secret="${MAAS_REGION_SECRET}";
|
||||
if maas-rack register --url="${MAAS_ENDPOINT}" --secret="${MAAS_REGION_SECRET}";
|
||||
then
|
||||
echo "Successfully registered with MaaS Region Controller"
|
||||
break
|
||||
@ -70,7 +107,12 @@ then
|
||||
if [[ "$HOST_SYSTEM_ID" != "$POD_SYSTEM_ID" ]]
|
||||
then
|
||||
unregister_maas_rack "$POD_SYSTEM_ID"
|
||||
register_maas_rack "$HOST_SYTEM_ID"
|
||||
if $?;
|
||||
then
|
||||
echo "Unregister of $POD_SYSTEM_ID failed, exitting."
|
||||
exit 1
|
||||
fi
|
||||
register_maas_rack "$HOST_SYSTEM_ID"
|
||||
else
|
||||
echo "Found existing maas_id, assuming already registered."
|
||||
fi
|
||||
|
@ -19,7 +19,8 @@ RUN apt-get -qq update && \
|
||||
software-properties-common \
|
||||
libvirt-bin \
|
||||
systemd \
|
||||
patch
|
||||
patch \
|
||||
jq
|
||||
# Don't start any optional services except for the few we need.
|
||||
|
||||
RUN find /etc/systemd/system \
|
||||
|
@ -5,7 +5,7 @@ After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
PassEnvironment=MAAS_ENDPOINT MAAS_REGION_SECRET
|
||||
PassEnvironment=MAAS_ENDPOINT MAAS_REGION_SECRET MAAS_API_KEY HOST_MOUNT_PATH
|
||||
ExecStart=/usr/local/bin/register-rack-controller.sh
|
||||
|
||||
[Install]
|
||||
|
Loading…
Reference in New Issue
Block a user