Skip to content
This repository was archived by the owner on Jan 1, 2024. It is now read-only.

Commit 277ea60

Browse files
authored
Allow to disable persisting cluster cookie in app conf file (#339)
Added `cartridge_not_save_cookie_in_app_config` variable that allows disabling persisting cluster cookie in the application configuration file. In this case, it's the user's responsibility to configure the cluster cookie for all instances.
1 parent b6d2bf2 commit 277ea60

22 files changed

+228
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ README.md to use the newest tag with new release
2121
and specified state
2222
- `wait_cluster_has_no_issues` step to wait until cluster has no issues
2323
- availability to upload ZIP configs to TDG
24+
- `cartridge_not_save_cookie_in_app_config` variable that allows to disable persisting cluster
25+
cookie in the application configuration file
2426

2527
## [1.9.0] - 2021-04-30
2628

create-packages.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,21 @@ if [ -z "${skip_cartridge}" ]; then
133133
rm -rf ${app_name}
134134
cartridge create --name ${app_name}
135135

136+
# configure vshard group "hot"
136137
awk '{gsub(/cartridge.cfg\({/, "&\n vshard_groups = { hot = { bucket_count = 20000 } },")}1' \
137138
${app_name}/init.lua >${app_name}/temp.lua
138139
mv ${app_name}/temp.lua ${app_name}/init.lua
139140

141+
# add dependencies to app.roles.custom role
140142
awk '{gsub(/-- dependencies/, "dependencies")}1' \
141143
${app_name}/app/roles/custom.lua >${app_name}/temp.lua
142144
mv ${app_name}/temp.lua ${app_name}/app/roles/custom.lua
143145

146+
# remove setting cluster_cookie on cartridge.cfg
147+
awk '{gsub(/cluster_cookie/, "-- cluster_cookie")}1' \
148+
${app_name}/init.lua >${app_name}/temp.lua
149+
mv ${app_name}/temp.lua ${app_name}/init.lua
150+
144151
lazy_pack tgz "${app_name}" "${version}"
145152
lazy_pack rpm "${app_name}" "${version}"
146153
lazy_pack deb "${app_name}" "${version}"

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
cartridge_app_name: null
66
cartridge_cluster_cookie: null
7+
cartridge_not_save_cookie_in_app_config: false
78
cartridge_remove_temporary_files: false
89

910
# Role scenario configuration

doc/scenario.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ Input facts (set by config):
427427
- `stateboard` - indicates that the instance is a stateboard;
428428
- `cartridge_app_name` - application name;
429429
- `cartridge_cluster_cookie` - cluster cookie for all cluster instances;
430+
- `cartridge_not_save_cookie_in_app_config` - flag indicates that cluster cookie shouldn't be persisted in application configuration file;
430431
- `cartridge_defaults` - default configuration parameters values for instances;
431432
- `cartridge_app_user` - user which will own the links;
432433
- `cartridge_app_group` - group which will own the links.
@@ -447,6 +448,7 @@ Input facts (set by role):
447448
Input facts (set by config):
448449

449450
- `cartridge_cluster_cookie` - cluster cookie for all cluster instances (is needed to check if configuration file was changed);
451+
- `cartridge_not_save_cookie_in_app_config` - flag indicates that cluster cookie shouldn't be persisted in application configuration file;
450452
- `restarted` - if instance should be restarted or not (user forced decision).
451453

452454
### wait_instance_started

doc/variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ vshard bootstrapping, and failover.
88
* `cartridge_app_name` (`string`): application name, required;
99
* `cartridge_cluster_cookie` (`string`): cluster cookie for all
1010
cluster instances;
11+
* `cartridge_not_save_cookie_in_app_config` (`boolean`, default: `false`) - flag indicates that cluster cookie shouldn't be persisted in application configuration file;
1112
* `cartridge_remove_temporary_files` (`boolean`, optional, default: `false`):
1213
indicates if temporary files should be removed
1314
(more details in description of [`cleanup` step API](/doc/scenario.md#cleanup));

library/cartridge_get_cached_facts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'cartridge_auth',
1919
'cartridge_bootstrap_vshard',
2020
'cartridge_cluster_cookie',
21+
'cartridge_not_save_cookie_in_app_config',
2122
'cartridge_conf_dir',
2223
'cartridge_configure_systemd_unit_files',
2324
'cartridge_configure_tmpfiles',

library/cartridge_get_needs_restart.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'config': {'required': False, 'type': 'dict'},
1414
'cartridge_defaults': {'required': False, 'type': 'dict'},
1515
'cluster_cookie': {'required': False, 'type': 'str'},
16+
'cartridge_not_save_cookie_in_app_config': {'required': False, 'type': 'bool'},
1617
'stateboard': {'required': False, 'type': 'bool'},
1718
}
1819

@@ -64,7 +65,7 @@ def check_needs_restart_to_update_config(params, control_console):
6465
'app_name',
6566
'config',
6667
'cartridge_defaults',
67-
'cluster_cookie',
68+
'cartridge_not_save_cookie_in_app_config',
6869
'stateboard',
6970
}
7071
for arg in required_args:
@@ -75,9 +76,14 @@ def check_needs_restart_to_update_config(params, control_console):
7576
app_name = params['app_name']
7677
new_instance_conf = params['config']
7778
new_default_conf = params['cartridge_defaults']
78-
cluster_cookie = params['cluster_cookie']
79+
cluster_cookie = params.get('cluster_cookie')
80+
cartridge_not_save_cookie_in_app_config = params['cartridge_not_save_cookie_in_app_config']
7981
stateboard = params['stateboard']
8082

83+
if not cartridge_not_save_cookie_in_app_config and cluster_cookie is None:
84+
return None, "'cartridge_cluster_cookie' should be set to check for configuration updates " + \
85+
"when 'cartridge_not_save_cookie_in_app_config' is false"
86+
8187
if not os.path.exists(instance_info['conf_file']):
8288
return True, None
8389

@@ -106,7 +112,8 @@ def check_needs_restart_to_update_config(params, control_console):
106112
if err is not None:
107113
return None, "Failed to read current default config: %s" % err
108114

109-
new_default_conf.update({'cluster_cookie': cluster_cookie})
115+
if not cartridge_not_save_cookie_in_app_config:
116+
new_default_conf['cluster_cookie'] = cluster_cookie
110117
if check_conf_updated(new_default_conf, current_default_conf, helpers.DYNAMIC_BOX_CFG_PARAMS):
111118
return True, None
112119

library/cartridge_validate_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
PARAMS_THE_SAME_FOR_ALL_HOSTS = [
1515
'cartridge_app_name',
1616
'cartridge_cluster_cookie',
17+
'cartridge_not_save_cookie_in_app_config',
1718
'cartridge_auth',
1819
'cartridge_bootstrap_vshard',
1920
'cartridge_failover',
@@ -91,6 +92,7 @@
9192
'cartridge_package_path': str,
9293
'cartridge_app_name': str,
9394
'cartridge_cluster_cookie': str,
95+
'cartridge_not_save_cookie_in_app_config': bool,
9496
'cartridge_defaults': dict,
9597
'cartridge_bootstrap_vshard': bool,
9698
'cartridge_wait_buckets_discovery': bool,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../common/Dockerfile.j2
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
3+
- name: 'Configure instances'
4+
hosts: cluster
5+
roles:
6+
- ansible-cartridge
7+
become: true
8+
become_user: root
9+
gather_facts: false
10+
vars:
11+
cartridge_scenario:
12+
- eval
13+
cartridge_eval_body:
14+
return require('cartridge.cluster-cookie').cookie()
15+
16+
- name: 'Print and check instances cluster cookie'
17+
hosts: cluster
18+
become: true
19+
become_user: root
20+
gather_facts: false
21+
tasks:
22+
- name: 'Debug instance cluster cookie'
23+
debug:
24+
msg: '{{ eval_res[0] }}'
25+
26+
- name: 'Check instance cluster cookie'
27+
assert:
28+
msg: 'Default Cartridge cluster cookie should be set'
29+
success_msg: 'Default Cartridge cluster cookie is set'
30+
that: >-
31+
eval_res[0] == "secret-cluster-cookie"

0 commit comments

Comments
 (0)