Browse Source

Take configs from global secret

Change-Id: I9d22f5e81c676fdd7deff15533be15b3720776b7
changes/83/442483/1
Andrey Pavlov 2 years ago
parent
commit
de9c9bf2ed
1 changed files with 18 additions and 5 deletions
  1. 18
    5
      service/files/entrypoint.py

+ 18
- 5
service/files/entrypoint.py View File

@@ -18,7 +18,7 @@ logging.basicConfig(format=LOG_FORMAT,
18 18
 LOG = logging.getLogger(__name__)
19 19
 
20 20
 GLOBALS_PATH = '/etc/ccp/globals/globals.json'
21
-
21
+GLOBALS_SECRETS_PATH = '/etc/ccp/global-secrets/global-secrets.json'
22 22
 
23 23
 def retry(f):
24 24
     @functools.wraps(f)
@@ -36,12 +36,25 @@ def retry(f):
36 36
     return wrap
37 37
 
38 38
 
39
+def merge_configs(variables, new_config):
40
+    for k, v in new_config.items():
41
+        if k not in variables:
42
+            variables[k] = v
43
+            continue
44
+        if isinstance(v, dict) and isinstance(variables[k], dict):
45
+            merge_configs(variables[k], v)
46
+        else:
47
+            variables[k] = v
48
+
49
+
39 50
 class Configuration():
40
-    def __init__(self, config_file):
41
-        LOG.info("Getting global variables from %s", config_file)
51
+    def __init__(self):
42 52
         values = {}
43
-        with open(config_file) as f:
53
+        with open(GLOBALS_PATH) as f:
44 54
             global_conf = json.load(f)
55
+        with open(GLOBALS_SECRETS_PATH) as f:
56
+            secrets = json.load(f)
57
+        merge_configs(global_conf, secrets)
45 58
         for key in ['etcd', 'namespace',  'security', 'cluster_domain']:
46 59
             values[key] = global_conf[key]
47 60
         hostname = socket.gethostname()
@@ -179,7 +192,7 @@ def _get_etcd_member_id(peers, name):
179 192
 
180 193
 
181 194
 if __name__ == "__main__":
182
-    config = Configuration(GLOBALS_PATH)
195
+    config = Configuration()
183 196
     etcd_members_api = config.members_api
184 197
     try:
185 198
         # The only reliable way to determine if etcd cluster exists is to query

Loading…
Cancel
Save