Skip to content

Commit d0932d7

Browse files
committed
config: add isolated option on the instance level
This commit just adds the option into the cluster configuration schema. Next commits will add the relevant logic. Part of tarantool#10796 NO_DOC=tarantool/doc#4632
1 parent ad6f4a3 commit d0932d7

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## feature/config
2+
3+
* Add `isolated` option for instances (gh-10796).

src/box/lua/config/instance_config.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,37 @@ local function feedback_validate(data, w)
455455
w.error('Tarantool is built without feedback reports sending support')
456456
end
457457

458+
-- Verify that the given validation context (w) corresponds to the
459+
-- instance level of the cluster configuration or the validation
460+
-- is performed against the instance config schema.
461+
local function validate_scope_is_instance(w)
462+
local scope = w.schema.computed.annotations.scope
463+
464+
-- scope = nil means that the validation is performed against
465+
-- the instance config schema, not the cluster config.
466+
--
467+
-- The validation against the instance config is performed for
468+
-- values from the env configuration source (which collects
469+
-- the TT_* environment variables).
470+
--
471+
-- Also, it would be very counter-intuitive if
472+
-- cluster_config:instantiate() would produce a result that
473+
-- doesn't pass the instance_config:validate() check.
474+
if scope == nil then
475+
return
476+
end
477+
478+
-- scope = 'instance' means that the option is placed on the
479+
-- instance level of the cluster configuration.
480+
if scope == 'instance' then
481+
return
482+
end
483+
484+
-- Any other level of the cluster configuration (replicaset,
485+
-- group, global) scope -- raise an error.
486+
w.error('The option must not be present in the %s scope', scope)
487+
end
488+
458489
return schema.new('instance_config', schema.record({
459490
config = schema.record({
460491
reload = schema.enum({
@@ -2475,6 +2506,13 @@ return schema.new('instance_config', schema.record({
24752506
type = 'string',
24762507
}),
24772508
}),
2509+
isolated = schema.scalar({
2510+
type = 'boolean',
2511+
default = false,
2512+
validate = function(_data, w)
2513+
validate_scope_is_instance(w)
2514+
end,
2515+
}),
24782516
}, {
24792517
-- This kind of validation cannot be implemented as the
24802518
-- 'validate' annotation of a particular schema node. There

test/config-luatest/cluster_config_schema_test.lua

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local yaml = require('yaml')
22
local fio = require('fio')
33
local t = require('luatest')
4+
local instance_config = require('internal.config.instance_config')
45
local cluster_config = require('internal.config.cluster_config')
56

67
local g = t.group()
@@ -92,6 +93,7 @@ local instance_config_fields = {
9293
'failover',
9394
'compat',
9495
'labels',
96+
'isolated',
9597
}
9698

9799
-- Verify that the fields of the given schema correspond to the
@@ -427,6 +429,7 @@ g.test_defaults = function()
427429
console_session_scope_vars = 'old',
428430
wal_cleanup_delay_deprecation = 'old',
429431
},
432+
isolated = false,
430433
}
431434

432435
-- Global defaults.
@@ -739,3 +742,66 @@ g.test_additional_options_instance = function()
739742
.fields.instances.value
740743
verify_fields(schema, {})
741744
end
745+
746+
-- Attempt to pass the `isolated` option to different cluster
747+
-- configuration levels and also try to validate it against the
748+
-- instance config.
749+
--
750+
-- The option should be accepted only by the instance config or
751+
-- the instance level of the cluster config.
752+
g.test_isolated_scope = function()
753+
local function exp_err(path, scope)
754+
return ('[cluster_config] %s: The option must not be present in the ' ..
755+
'%s scope'):format(path, scope)
756+
end
757+
758+
local data = {isolated = true}
759+
760+
-- Global level: forbidden.
761+
local path = 'isolated'
762+
t.assert_error_msg_equals(exp_err(path, 'global'), function()
763+
cluster_config:validate(data)
764+
end)
765+
766+
-- Group level: forbidden.
767+
local path = 'groups.g.isolated'
768+
t.assert_error_msg_equals(exp_err(path, 'group'), function()
769+
cluster_config:validate({
770+
groups = {
771+
g = data,
772+
},
773+
})
774+
end)
775+
776+
-- Replicaset level: forbidden.
777+
local path = 'groups.g.replicasets.r.isolated'
778+
t.assert_error_msg_equals(exp_err(path, 'replicaset'), function()
779+
cluster_config:validate({
780+
groups = {
781+
g = {
782+
replicasets = {
783+
r = data,
784+
},
785+
},
786+
},
787+
})
788+
end)
789+
790+
-- Instance level: accepted.
791+
cluster_config:validate({
792+
groups = {
793+
g = {
794+
replicasets = {
795+
r = {
796+
instances = {
797+
i = data,
798+
},
799+
},
800+
},
801+
},
802+
},
803+
})
804+
805+
-- Validation against the instance config: accepted.
806+
instance_config:validate(data)
807+
end

test/config-luatest/instance_config_schema_test.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,3 +1764,8 @@ g.test_labels = function()
17641764

17651765
t.assert_equals(instance_config:apply_default({}).labels, nil)
17661766
end
1767+
1768+
g.test_isolated = function()
1769+
instance_config:validate({isolated = true})
1770+
t.assert_equals(instance_config:apply_default({}).isolated, false)
1771+
end

0 commit comments

Comments
 (0)