@@ -6,11 +6,11 @@ import (
66 "github.com/google/go-cmp/cmp"
77 . "github.com/onsi/ginkgo/v2"
88 . "github.com/onsi/gomega"
9- "gopkg.in/yaml.v2"
109 corev1 "k8s.io/api/core/v1"
1110 policyv1 "k8s.io/api/policy/v1"
1211 "k8s.io/apimachinery/pkg/api/resource"
1312 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+ "k8s.io/apimachinery/pkg/runtime"
1414 "k8s.io/apimachinery/pkg/util/intstr"
1515 "sigs.k8s.io/randfill"
1616
@@ -19,8 +19,6 @@ import (
1919 "github.com/ClickHouse/clickhouse-operator/internal/controllerutil"
2020)
2121
22- type confMap map [any ]any
23-
2422var _ = Describe ("ServerRevision" , func () {
2523 var (
2624 baseCR * v1.KeeperCluster
@@ -40,7 +38,7 @@ var _ = Describe("ServerRevision", func() {
4038 },
4139 }
4240
43- baseCfgRevision , err = getConfigurationRevision (baseCR , nil )
41+ baseCfgRevision , err = getConfigurationRevision (baseCR )
4442 Expect (err ).ToNot (HaveOccurred ())
4543 Expect (baseCfgRevision ).ToNot (BeEmpty ())
4644
@@ -52,7 +50,7 @@ var _ = Describe("ServerRevision", func() {
5250 It ("should not change config revision if only replica count changes" , func () {
5351 cr := baseCR .DeepCopy ()
5452 cr .Spec .Replicas = new (int32 (3 ))
55- cfgRevisionUpdated , err := getConfigurationRevision (cr , nil )
53+ cfgRevisionUpdated , err := getConfigurationRevision (cr )
5654 Expect (err ).ToNot (HaveOccurred ())
5755 Expect (baseCfgRevision ).ToNot (BeEmpty ())
5856 Expect (cfgRevisionUpdated ).To (Equal (baseCfgRevision ), "server config revision shouldn't depend on replica count" )
@@ -66,7 +64,7 @@ var _ = Describe("ServerRevision", func() {
6664 It ("should not change sts revision if only config changes" , func () {
6765 cr := baseCR .DeepCopy ()
6866 cr .Spec .Settings .Logger .Level = "warning"
69- cfgRevisionUpdated , err := getConfigurationRevision (cr , nil )
67+ cfgRevisionUpdated , err := getConfigurationRevision (cr )
7068 Expect (err ).ToNot (HaveOccurred ())
7169 Expect (cfgRevisionUpdated ).ToNot (BeEmpty ())
7270 Expect (cfgRevisionUpdated ).ToNot (Equal (baseCfgRevision ), "configuration change should update config revision" )
@@ -79,64 +77,32 @@ var _ = Describe("ServerRevision", func() {
7977})
8078
8179var _ = Describe ("ExtraConfig" , func () {
82- var (
83- cr * v1.KeeperCluster
84- baseConfigYAML string
85- baseConfig confMap
86- )
87-
88- BeforeEach (func () {
89- cr = & v1.KeeperCluster {
90- ObjectMeta : metav1.ObjectMeta {
91- Name : "test" ,
92- },
80+ It ("should add extra config as a separate ConfigMap key" , func () {
81+ cr := & v1.KeeperCluster {
82+ ObjectMeta : metav1.ObjectMeta {Name : "test" },
9383 Spec : v1.KeeperClusterSpec {
9484 Replicas : new (int32 (1 )),
95- },
96- }
97-
98- var err error
99-
100- baseConfigYAML , err = generateConfigForSingleReplica (cr , nil , 1 )
101- Expect (err ).NotTo (HaveOccurred ())
102- Expect (yaml .Unmarshal ([]byte (baseConfigYAML ), & baseConfig )).To (Succeed ())
103- })
104-
105- It ("should reflect config changes in generated config" , func () {
106- configYAML , err := generateConfigForSingleReplica (cr , map [string ]any {
107- "keeper_server" : confMap {
108- "coordination_settings" : confMap {
109- "quorum_reads" : true ,
85+ Settings : v1.KeeperSettings {
86+ ExtraConfig : runtime.RawExtension {Raw : []byte (`{"keeper_server": {"coordination_settings": {"quorum_reads": true}}}` )},
11087 },
11188 },
112- }, 1 )
89+ }
90+ data , err := generateConfigForSingleReplica (cr , 1 )
11391 Expect (err ).NotTo (HaveOccurred ())
114-
115- var config confMap
116- Expect (yaml .Unmarshal ([]byte (configYAML ), & config )).To (Succeed ())
117- Expect (config ).ToNot (Equal (baseConfig ), cmp .Diff (config , baseConfig ))
118- //nolint:forcetypeassert
119- Expect (config ["keeper_server" ].(confMap )["coordination_settings" ].(confMap )["quorum_reads" ]).To (BeTrue ())
92+ Expect (data ).To (HaveKey (ConfigFileName ))
93+ Expect (data ).To (HaveKey (ExtraConfigFileName ))
94+ Expect (data [ExtraConfigFileName ]).To (ContainSubstring ("quorum_reads" ))
12095 })
12196
122- It ("should override existing setting by extra config" , func () {
123- configYAML , err := generateConfigForSingleReplica (cr , map [string ]any {
124- "keeper_server" : confMap {
125- "coordination_settings" : confMap {
126- "compress_logs" : true ,
127- },
128- },
129- }, 1 )
130- Expect (err ).NotTo (HaveOccurred ())
131-
132- var config confMap
133-
134- err = yaml .Unmarshal ([]byte (configYAML ), & config )
97+ It ("should not include extra config key when empty" , func () {
98+ cr := & v1.KeeperCluster {
99+ ObjectMeta : metav1.ObjectMeta {Name : "test" },
100+ Spec : v1.KeeperClusterSpec {Replicas : new (int32 (1 ))},
101+ }
102+ data , err := generateConfigForSingleReplica (cr , 1 )
135103 Expect (err ).NotTo (HaveOccurred ())
136-
137- Expect (config ).ToNot (Equal (baseConfig ), cmp .Diff (config , baseConfig ))
138- //nolint:forcetypeassert
139- Expect (config ["keeper_server" ].(confMap )["coordination_settings" ].(confMap )["compress_logs" ]).To (BeTrue ())
104+ Expect (data ).To (HaveKey (ConfigFileName ))
105+ Expect (data ).ToNot (HaveKey (ExtraConfigFileName ))
140106 })
141107})
142108
0 commit comments