Browse Source

[FIX] - Fixed maas-rack reschedule issue

After a maas-rack pod rescheduling from one node to another,
only delete the node's local maas registration state, and
keep re-registering the maas-rack until success.

Change-Id: I8495ae61f38377d292a26ad09438ece40b2c53c6
Ahmad Mahmoudi 1 month ago
parent
commit
37dfe50954
1 changed files with 14 additions and 93 deletions
  1. 14
    93
      charts/maas/templates/bin/_register-rack-controller.sh.tpl

+ 14
- 93
charts/maas/templates/bin/_register-rack-controller.sh.tpl View File

@@ -2,29 +2,8 @@
2 2
 
3 3
 set -x
4 4
 
5
-# Path where the host's cloud-init data is mounted
6
-# to source the maas system_id
7
-HOST_MOUNT_PATH=${HOST_MOUNT_PATH:-"/host_cloud-init/"}
8
-
9
-get_impacted_nets() {
10
-  system_id="$1"
11
-  maas local fabrics read | jq -cr 'map(.vlans) | map(.[]) | map(select(.primary_rack == "'"$system_id"'" or .secondary_rack == "'"$system_id"'")) | .[] | {vid, fabric_id}'
12
-}
13
-
14
-detach_rack_controller() {
15
-  system_id="$1"
16
-  for net in $(get_impacted_nets "$system_id");
17
-  do
18
-    vid=$(echo "$net" | jq -r .vid)
19
-    fid=$(echo "$net" | jq -r .fabric_id)
20
-    maas local vlan update "$fid" "$vid" primary_rack='' secondary_rack='' dhcp_on=false
21
-  done
22
-}
23
-
24
-unregister_maas_rack() {
25
-  sys_id="$1"
26
-  echo "Deregister this pod as MAAS rack controller ${sys_id}."
27
-
5
+login_maas() {
6
+  echo "Logging in to MAAS region."
28 7
   maas login local "$MAAS_ENDPOINT" "$MAAS_API_KEY"
29 8
 
30 9
   if [[ $? -ne 0 ]];
@@ -32,37 +11,21 @@ unregister_maas_rack() {
32 11
     echo "Could not login to MAAS API."
33 12
     exit $?
34 13
   fi
14
+}
35 15
 
36
-  detach_rack_controller "$sys_id"
37
-
38
-  while [ 1 ];
39
-  do
40
-    maas local rack-controller delete "$sys_id"
41
-
42
-    if [[ $? -ne 0 ]];
43
-    then
44
-      echo "Could not delete rack controller."
45
-      sleep 10
46
-    else
47
-      break
48
-    fi
49
-  done
50
-
51
-  rm -f ~maas/maas_id
52
-  rm -f ~maas/secret
16
+unregister_maas_rack() {
17
+  # In oder to avoid the issue with race condition in maas,
18
+  # do not de-register the dead maas-controller from mass-region
19
+  # just delete the local state of the maas-controller's.
20
+  echo "Deregistering this pod's local state in /var/lib/maas directory."
21
+  rm -f /var/lib/maas/secret
22
+  rm -f /var/lib/maas/maas_id
53 23
 }
54 24
 
55 25
 register_maas_rack() {
56
-  sys_id=${1:-""}
57 26
   echo "register-rack-controller URL: ${MAAS_ENDPOINT}"
58 27
 
59
-  if [[ ! -z "$sys_id" ]]
60
-  then
61
-    echo "Using provided system id ${sys_id}."
62
-    echo "$sys_id" > ~maas/maas_id
63
-  fi
64
-
65
-  # register forever
28
+  # register forever until success
66 29
   while [ 1 ];
67 30
   do
68 31
     if maas-rack register --url="${MAAS_ENDPOINT}" --secret="${MAAS_REGION_SECRET}";
@@ -76,48 +39,6 @@ register_maas_rack() {
76 39
   done;
77 40
 }
78 41
 
79
-get_host_identity() {
80
-  # Check if the underlying host was deployed by MAAS
81
-  if [[ -r "${HOST_MOUNT_PATH}/instance-data.json" ]]
82
-  then
83
-    grep -E 'instance-id' "${HOST_MOUNT_PATH}/instance-data.json" | head -1 | tr -d ' ",' | cut -d: -f 2
84
-  else
85
-    echo ""
86
-  fi
87
-}
88
-
89
-get_pod_identity() {
90
-  if [[ -r ~maas/maas_id ]]
91
-  then
92
-    cat ~maas/maas_id
93
-  else
94
-    echo ""
95
-  fi
96
-}
97
-
98
-HOST_SYSTEM_ID=$(get_host_identity)
99
-POD_SYSTEM_ID=$(get_pod_identity)
100
-
101
-# This Pod state already has a MAAS identity
102
-if [[ ! -z "$POD_SYSTEM_ID" ]]
103
-then
104
-  # If the pod maas identity doesn't match the
105
-  # host maas identity, unregister the pod identity
106
-  # as a rack controller
107
-  if [[ "$HOST_SYSTEM_ID" != "$POD_SYSTEM_ID" ]]
108
-  then
109
-    unregister_maas_rack "$POD_SYSTEM_ID"
110
-    if $?;
111
-    then
112
-      echo "Unregister of $POD_SYSTEM_ID failed, exitting."
113
-      exit 1
114
-    fi
115
-    register_maas_rack "$HOST_SYSTEM_ID"
116
-  else
117
-    echo "Found existing maas_id, assuming already registered."
118
-  fi
119
-
120
-  exit 0
121
-else
122
-  register_maas_rack
123
-fi
42
+login_maas
43
+unregister_maas_rack
44
+register_maas_rack

Loading…
Cancel
Save