Browse Source

Update route reflector configuration when compute nodes are added to/removed from the deployment

Change-Id: I5443489a0921594381832a0ee2fedb384e85e4a9
Emma Gordon 3 years ago
parent
commit
8cd61d75c1

+ 40
- 0
deployment_scripts/calico-fuel-monitor View File

@@ -0,0 +1,40 @@
1
+#!/usr/bin/env python
2
+
3
+import pyinotify
4
+import subprocess
5
+import yaml
6
+
7
+from pluginutils import NODES_CONFIG
8
+
9
+RECONFIGURE_ROUTE_REFLECTOR = "##REPLACE_ON_INSTALL##/calico_route_reflector.sh"
10
+
11
+
12
+def _get_configured_compute_nodes():
13
+    with open(NODES_CONFIG, "r") as f:
14
+        config = yaml.safe_load(f)
15
+
16
+    compute_nodes = [node for node in config["nodes"]
17
+                     if node["role"] == "compute"]
18
+
19
+    return compute_nodes
20
+
21
+
22
+class DeploymentChangeHandler(pyinotify.ProcessEvent):
23
+    def __init__(self):
24
+        super(DeploymentChangeHandler, self).__init__()
25
+        self.compute_nodes = _get_configured_compute_nodes()
26
+
27
+    def process_IN_MODIFY(self, event):
28
+        current_compute_nodes = _get_configured_compute_nodes()
29
+        if current_compute_nodes != self.compute_nodes:
30
+            subprocess.call(RECONFIGURE_ROUTE_REFLECTOR)
31
+            self.compute_nodes = current_compute_nodes
32
+
33
+
34
+if __name__ == "__main__":
35
+    handler = DeploymentChangeHandler()
36
+    watch_manager = pyinotify.WatchManager()
37
+    notifier = pyinotify.Notifier(watch_manager, handler)
38
+    watch_manager.add_watch(NODES_CONFIG, pyinotify.IN_MODIFY)
39
+    notifier.loop()
40
+

+ 37
- 0
deployment_scripts/calico_controller.sh View File

@@ -181,4 +181,41 @@ iptables -I INPUT 1 -p tcp --dport 179 -j ACCEPT
181 181
 # controller is rebooted.
182 182
 iptables-save > /etc/iptables/rules.v4
183 183
 
184
+# Set up a service, calico-fuel-monitor, that will detect changes to the
185
+# deployment and reconfigure the calico components on the controller as
186
+# needed. For example, updating the route reflector configuration after
187
+# compute nodes are added/removed from the deployment.
188
+SERVICE_NAME=calico-fuel-monitor
189
+
190
+# Install the service's dependencies.
191
+apt-get -y install python-pip
192
+pip install pyinotify pyaml
193
+
194
+# During node deployment, the plugin deployment scripts are copied into 
195
+# /etc/fuel/plugins/<plugin_name>-<plugin_version> on the node, and this
196
+# script is run from that directory.
197
+SERVICE_DIR=$(pwd)
198
+sed -i "s@##REPLACE_ON_INSTALL##@${SERVICE_DIR}@" $SERVICE_NAME
199
+chmod +x $SERVICE_NAME
200
+
201
+cat << SERVICE_CFG >> /etc/init/calico-fuel-monitor.conf
202
+# calico-fuel-monitor - daemon to monitor for fuel deployment changes and
203
+#                       reconfigure the calico components accordingly
204
+
205
+description "Calico daemon to monitor fuel deployment changes"
206
+author "Emma Gordon <emma@projectcalico.org>"
207
+
208
+start on runlevel [2345]
209
+stop on runlevel [016]
210
+
211
+respawn
212
+
213
+script
214
+cd ${SERVICE_DIR}
215
+exec ./${SERVICE_NAME}
216
+end script
217
+SERVICE_CFG
218
+
219
+service $SERVICE_NAME start
220
+
184 221
 exit 0

+ 3
- 4
deployment_scripts/get_rr_peers.py View File

@@ -2,12 +2,11 @@
2 2
 # Copyright 2015 Metaswitch Networks
3 3
 
4 4
 import yaml
5
-from pluginutils import get_config_file_for_node_type
6 5
 
7
-def main():
8
-    config_file = get_config_file_for_node_type()
6
+from pluginutils import NODES_CONFIG
9 7
 
10
-    with open(config_file, "r") as f:
8
+def main():
9
+    with open(NODES_CONFIG, "r") as f:
11 10
         config = yaml.safe_load(f)
12 11
 
13 12
     # The route reflector should only peer with compute nodes.

+ 9
- 0
deployment_scripts/pluginutils.py View File

@@ -3,6 +3,15 @@
3 3
 
4 4
 import os
5 5
 
6
+# This config file is updated with the latest node details as the deployment
7
+# evolves. It only contains node details, not other config settings.
8
+NODES_CONFIG = "/etc/hiera/nodes.yaml"
9
+
10
+# These config files contain details of the nodes at initial deployment, but
11
+# they are not subsequently updated with node changes. However, they contain
12
+# a greater range of information, including settings and network config. They
13
+# are also created on the system earlier in the deployment process, so are
14
+# good sources of initial node information during Calico setup.
6 15
 PRIMARY_CONTROLLER_CFG = "/etc/primary-controller.yaml"
7 16
 CONTROLLER_CFG = "/etc/controller.yaml"
8 17
 COMPUTE_CFG = "/etc/compute.yaml"

Loading…
Cancel
Save