Skip to content

Commit 54cdf69

Browse files
authored
Fix cartridge config behaviour (#149)
1 parent 076a08e commit 54cdf69

File tree

6 files changed

+96
-11
lines changed

6 files changed

+96
-11
lines changed

docs/deploy-example-application.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Deploy example application
22

3+
## Table of Contents
4+
5+
- [Install or update application using Helm](#install-or-update-application-using-helm)
6+
- [Work with cartridge config](#work-with-cartridge-config)
7+
38
This guide provides the instructions how to install the example cartridge application.
49
To deploy your own application you'd need to build your own docker image
510
via [Cartridge CLI](https://www.tarantool.io/en/doc/latest/book/cartridge/cartridge_cli/commands/pack/docker/).
@@ -27,6 +32,11 @@ To install or upgrade the Cartridge App using Helm, run following commands from
2732
helm upgrade --install tarantool-app tarantool/cartridge --values ./values.yaml -n my-namespace [--create-namespace]
2833
```
2934

35+
### Work with cartridge config
36+
37+
- To pass cartridge cluster config fill the `tarantool.config` section in your `values.yaml` file with any valid yaml object.
38+
- If you need to remove some properties from config you should do it explicit by setting it to `null` value.
39+
3040
### Useful helm variables
3141

3242
| JSON Path | Type | Description |

pkg/reconciliation/steps/cartridge/configure.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package cartridge
22

33
import (
4-
"github.com/google/go-cmp/cmp"
54
"github.com/tarantool/tarantool-operator/pkg/api"
65
. "github.com/tarantool/tarantool-operator/pkg/reconciliation"
6+
"github.com/tarantool/tarantool-operator/pkg/utils"
77
"gopkg.in/yaml.v3"
88
)
99

@@ -26,10 +26,10 @@ func (r *ConfigureStep[ConfigType, CtxType, CtrlType]) Reconcile(ctx CtxType, ct
2626
return Error(err)
2727
}
2828

29-
if cmp.Equal(actualConfig, desiredConfig) {
30-
ctx.GetLogger().Info("Configs are equals do not upload")
29+
if utils.IsMapSubset(actualConfig, desiredConfig) {
30+
ctx.GetLogger().Info("Nothing to change in config")
3131

32-
return Error(err)
32+
return Complete()
3333
}
3434

3535
err = ctrl.GetTopology().ApplyCartridgeConfig(ctx, ctx.GetLeader(), desiredConfig)

pkg/topology/common.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,16 +371,14 @@ func (r *CommonCartridgeTopology) ApplyCartridgeConfig(ctx context.Context, lead
371371
}
372372
373373
local desiredConfig = ...
374-
local actualConfig = cartridge.config_get_readonly()
375-
for key, _ in pairs(actualConfig) do
374+
local safeConfig = {}
375+
for key, value in pairs(desiredConfig) do
376376
if not blacklist[key] then
377-
if desiredConfig[key] == nil then
378-
desiredConfig[key] = box.NULL
379-
end
377+
safeConfig[key] = value
380378
end
381379
end
382380
383-
return cartridge.config_patch_clusterwide(desiredConfig)
381+
return cartridge.config_patch_clusterwide(safeConfig)
384382
`
385383

386384
var res bool

pkg/utils/cmp.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package utils
2+
3+
import "github.com/google/go-cmp/cmp"
4+
5+
func IsMapSubset(set, subset map[string]any) bool {
6+
if len(subset) > len(set) {
7+
return false
8+
}
9+
10+
for k, subsetValue := range subset {
11+
setValue, found := set[k]
12+
if !found {
13+
return false
14+
}
15+
16+
if !cmp.Equal(setValue, subsetValue) {
17+
return false
18+
}
19+
}
20+
21+
return true
22+
}

pkg/utils/cmp_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package utils_test
2+
3+
import (
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/ginkgo/extensions/table"
6+
. "github.com/onsi/gomega"
7+
"github.com/tarantool/tarantool-operator/pkg/utils"
8+
)
9+
10+
var _ = Describe("cmp utils unit testing", func() {
11+
DescribeTable(
12+
"should return true if map is subset of another map",
13+
func(set, subset map[string]any) {
14+
Expect(utils.IsMapSubset(set, subset)).Should(BeTrue())
15+
},
16+
Entry("Empty and empty", map[string]any{}, map[string]any{}),
17+
Entry("Not empty empty", map[string]any{
18+
"key": map[string]any{"val": 1},
19+
"key.yml": "{\"val\": 1}",
20+
}, map[string]any{}),
21+
Entry("Not empty and not empty", map[string]any{
22+
"key": map[string]any{"val": 1},
23+
"key.yml": "{\"val\": 1}",
24+
}, map[string]any{
25+
"key": map[string]any{"val": 1},
26+
}),
27+
)
28+
29+
DescribeTable(
30+
"should return false if map is NOT subset of another map",
31+
func(set, subset map[string]any) {
32+
Expect(utils.IsMapSubset(set, subset)).Should(BeFalse())
33+
},
34+
Entry("contains changed ket", map[string]any{
35+
"key": map[string]any{"val": 1},
36+
"key.yml": "{\"val\": 1}",
37+
}, map[string]any{
38+
"new_key": map[string]any{"val": 1},
39+
}),
40+
Entry("contains changed value", map[string]any{
41+
"key": map[string]any{"val": 1},
42+
"key.yml": "{\"val\": 1}",
43+
}, map[string]any{
44+
"key": map[string]any{"val": 2},
45+
}),
46+
47+
Entry("empty contains new entry", map[string]any{
48+
"key": map[string]any{"val": 1},
49+
"key.yml": "{\"val\": 1}",
50+
}, map[string]any{
51+
"key": map[string]any{"val": 1},
52+
"new_key": map[string]any{"val": 2},
53+
}),
54+
)
55+
})

pkg/utils/vshard_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/tarantool/tarantool-operator/pkg/utils"
88
)
99

10-
var _ = Describe("role utils unit testing", func() {
10+
var _ = Describe("vshard utils unit testing", func() {
1111
Describe(`IsVShardRolesEquals function must compare two arrays of roles for equality, respecting the hierarchy and regardless of the order of the elements`,
1212
func() {
1313
Context("positive cases (equal arrays)", func() {

0 commit comments

Comments
 (0)