@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2020package parameters
2121
2222import (
23+ "fmt"
2324 "time"
2425
2526 . "github.com/onsi/ginkgo/v2"
@@ -31,32 +32,36 @@ import (
3132
3233 appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
3334 parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
35+ workloads "github.com/apecloud/kubeblocks/apis/workloads/v1"
3436 "github.com/apecloud/kubeblocks/pkg/constant"
3537 "github.com/apecloud/kubeblocks/pkg/controller/component"
3638 "github.com/apecloud/kubeblocks/pkg/controller/sharding"
3739 "github.com/apecloud/kubeblocks/pkg/parameters"
3840 configcore "github.com/apecloud/kubeblocks/pkg/parameters/core"
41+ cfgutil "github.com/apecloud/kubeblocks/pkg/parameters/util"
3942 testapps "github.com/apecloud/kubeblocks/pkg/testutil/apps"
4043 testparameters "github.com/apecloud/kubeblocks/pkg/testutil/parameters"
4144)
4245
4346var _ = Describe ("Parameter Controller" , func () {
44-
45- var compParamKey types.NamespacedName
46- var comp * component.SynthesizedComponent
47- var clusterObj * appsv1.Cluster
47+ var (
48+ compParamKey types.NamespacedName
49+ clusterObj * appsv1.Cluster
50+ synthesizedComp * component.SynthesizedComponent
51+ itsObj * workloads.InstanceSet
52+ )
4853
4954 BeforeEach (cleanEnv )
5055
5156 AfterEach (cleanEnv )
5257
5358 prepareTestEnv := func () {
54- _ , _ , clusterObj , _ , comp = mockReconcileResource ()
59+ _ , clusterObj , _ , synthesizedComp , itsObj = mockReconcileResource ()
60+
5561 compParamKey = types.NamespacedName {
5662 Namespace : testCtx .DefaultNamespace ,
57- Name : configcore .GenerateComponentConfigurationName (comp .ClusterName , comp .Name ),
63+ Name : configcore .GenerateComponentConfigurationName (synthesizedComp .ClusterName , synthesizedComp .Name ),
5864 }
59-
6065 Eventually (testapps .CheckObj (& testCtx , compParamKey , func (g Gomega , compParameter * parametersv1alpha1.ComponentParameter ) {
6166 g .Expect (compParameter .Status .Phase ).Should (BeEquivalentTo (parametersv1alpha1 .CFinishedPhase ))
6267 g .Expect (compParameter .Status .ObservedGeneration ).Should (BeEquivalentTo (int64 (1 )))
@@ -68,13 +73,33 @@ var _ = Describe("Parameter Controller", func() {
6873 prepareTestEnv ()
6974
7075 By ("submit the parameter update request" )
71- key := testapps .GetRandomizedKey (comp .Namespace , comp .FullCompName )
72- parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , comp .ClusterName , comp .Name ).
76+ key := testapps .GetRandomizedKey (synthesizedComp .Namespace , synthesizedComp .FullCompName )
77+ parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , synthesizedComp .ClusterName , synthesizedComp .Name ).
7378 AddParameters ("innodb_buffer_pool_size" , "1024M" ).
7479 AddParameters ("max_connections" , "100" ).
7580 Create (& testCtx ).
7681 GetObject ()
7782
83+ By ("mock the reconfigure done" )
84+ itsKey := client.ObjectKey {
85+ Namespace : itsObj .Namespace ,
86+ Name : itsObj .Name ,
87+ }
88+ Expect (testapps .GetAndChangeObjStatus (& testCtx , itsKey , func (its * workloads.InstanceSet ) {
89+ its .Status .Replicas = int32 (1 )
90+ its .Status .InstanceStatus = []workloads.InstanceStatus {
91+ {
92+ PodName : fmt .Sprintf ("%s-0" , its .Name ),
93+ Configs : []workloads.InstanceConfigStatus {
94+ {
95+ Name : configSpecName ,
96+ ConfigHash : cfgutil .ToPointer ("01234" ),
97+ },
98+ },
99+ },
100+ }
101+ })()).Should (Succeed ())
102+
78103 By ("check component parameter status" )
79104 Eventually (testapps .CheckObj (& testCtx , compParamKey , func (g Gomega , compParameter * parametersv1alpha1.ComponentParameter ) {
80105 g .Expect (compParameter .Status .ObservedGeneration ).Should (BeEquivalentTo (int64 (2 )))
@@ -95,13 +120,28 @@ var _ = Describe("Parameter Controller", func() {
95120 })).Should (Succeed ())
96121
97122 By ("the second update parameters" )
98- key = testapps .GetRandomizedKey (comp .Namespace , comp .FullCompName )
99- parameterObj = testparameters .NewParameterFactory (key .Name , key .Namespace , comp .ClusterName , comp .Name ).
123+ key = testapps .GetRandomizedKey (synthesizedComp .Namespace , synthesizedComp .FullCompName )
124+ parameterObj = testparameters .NewParameterFactory (key .Name , key .Namespace , synthesizedComp .ClusterName , synthesizedComp .Name ).
100125 AddParameters ("max_connections" , "2000" ).
101126 AddParameters ("gtid_mode" , "OFF" ).
102127 Create (& testCtx ).
103128 GetObject ()
104129
130+ By ("mock the reconfigure done" )
131+ Expect (testapps .GetAndChangeObjStatus (& testCtx , itsKey , func (its * workloads.InstanceSet ) {
132+ its .Status .InstanceStatus = []workloads.InstanceStatus {
133+ {
134+ PodName : fmt .Sprintf ("%s-0" , its .Name ),
135+ Configs : []workloads.InstanceConfigStatus {
136+ {
137+ Name : configSpecName ,
138+ ConfigHash : cfgutil .ToPointer ("56789" ),
139+ },
140+ },
141+ },
142+ }
143+ })()).Should (Succeed ())
144+
105145 By ("check parameter status" )
106146 Eventually (testapps .CheckObj (& testCtx , client .ObjectKeyFromObject (parameterObj ), func (g Gomega , parameter * parametersv1alpha1.Parameter ) {
107147 g .Expect (parameter .Status .Phase ).Should (BeEquivalentTo (parametersv1alpha1 .CFinishedPhase ))
@@ -120,8 +160,8 @@ var _ = Describe("Parameter Controller", func() {
120160 prepareTestEnv ()
121161
122162 By ("submit the parameter update request with invalid max_connection" )
123- key := testapps .GetRandomizedKey (comp .Namespace , comp .FullCompName )
124- parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , comp .ClusterName , comp .Name ).
163+ key := testapps .GetRandomizedKey (synthesizedComp .Namespace , synthesizedComp .FullCompName )
164+ parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , synthesizedComp .ClusterName , synthesizedComp .Name ).
125165 AddParameters ("max_connections" , "-100" ).
126166 Create (& testCtx ).
127167 GetObject ()
@@ -144,8 +184,8 @@ var _ = Describe("Parameter Controller", func() {
144184 GetObject ()
145185
146186 By ("submit the custom template request" )
147- key := testapps .GetRandomizedKey (comp .Namespace , comp .FullCompName )
148- parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , comp .ClusterName , comp .Name ).
187+ key := testapps .GetRandomizedKey (synthesizedComp .Namespace , synthesizedComp .FullCompName )
188+ parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , synthesizedComp .ClusterName , synthesizedComp .Name ).
149189 AddCustomTemplate (configSpecName , configmap .Name , configmap .Namespace ).
150190 Create (& testCtx ).
151191 GetObject ()
@@ -166,8 +206,8 @@ var _ = Describe("Parameter Controller", func() {
166206 prepareTestEnv ()
167207
168208 By ("submit the custom template request" )
169- key := testapps .GetRandomizedKey (comp .Namespace , comp .FullCompName )
170- parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , comp .ClusterName , comp .Name ).
209+ key := testapps .GetRandomizedKey (synthesizedComp .Namespace , synthesizedComp .FullCompName )
210+ parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , synthesizedComp .ClusterName , synthesizedComp .Name ).
171211 AddCustomTemplate (configSpecName , "not-exist-tpl" , testCtx .DefaultNamespace ).
172212 Create (& testCtx ).
173213 GetObject ()
@@ -187,41 +227,63 @@ var _ = Describe("Parameter Controller", func() {
187227 shardingCompSpecList , err := sharding .GenShardingCompSpecList4Test (testCtx .Ctx , k8sClient , clusterObj , & clusterObj .Spec .Shardings [0 ])
188228 Expect (err ).ShouldNot (HaveOccurred ())
189229 for _ , spec := range shardingCompSpecList {
230+ By ("create a sharding component: " + spec .Name )
190231 shardingLabels := map [string ]string {
191- constant .AppInstanceLabelKey : comp .ClusterName ,
232+ constant .AppInstanceLabelKey : synthesizedComp .ClusterName ,
192233 constant .KBAppShardingNameLabelKey : shardingCompName ,
193234 }
194- By ("create a sharding component: " + spec .Name )
195235 comp , err := component .BuildComponent (clusterObj , spec , shardingLabels , nil )
196236 Expect (err ).ShouldNot (HaveOccurred ())
197237 Expect (testCtx .Create (testCtx .Ctx , comp )).Should (Succeed ())
198238
239+ By ("create the ITS of sharding component: " + spec .Name )
240+ mockCreateITSObject (comp .Namespace , comp .Name , synthesizedComp .ClusterName , spec .Name )
241+
242+ By ("check ComponentParameters cr for sharding component : " + spec .Name )
199243 shardingCompParamKey := types.NamespacedName {
200244 Namespace : testCtx .DefaultNamespace ,
201245 Name : configcore .GenerateComponentConfigurationName (clusterObj .Name , spec .Name ),
202246 }
203-
204- By ("check ComponentParameters cr for sharding component : " + spec .Name )
205247 Eventually (testapps .CheckObj (& testCtx , shardingCompParamKey , func (g Gomega , compParameter * parametersv1alpha1.ComponentParameter ) {
206248 g .Expect (compParameter .Status .Phase ).Should (BeEquivalentTo (parametersv1alpha1 .CFinishedPhase ))
207249 g .Expect (compParameter .Status .ObservedGeneration ).Should (BeEquivalentTo (int64 (1 )))
208250 })).Should (Succeed ())
209251 }
210252
211253 By ("submit the parameter update request" )
212- key := testapps .GetRandomizedKey (comp .Namespace , comp .FullCompName )
213- parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , comp .ClusterName , shardingCompName ).
254+ key := testapps .GetRandomizedKey (synthesizedComp .Namespace , synthesizedComp .FullCompName )
255+ parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , synthesizedComp .ClusterName , shardingCompName ).
214256 AddParameters ("innodb_buffer_pool_size" , "1024M" ).
215257 AddParameters ("max_connections" , "100" ).
216258 Create (& testCtx ).
217259 GetObject ()
218260
219261 for _ , spec := range shardingCompSpecList {
262+ By ("mock the reconfigure done" )
263+ itsKey := client.ObjectKey {
264+ Namespace : synthesizedComp .Namespace ,
265+ Name : constant .GenerateWorkloadNamePattern (synthesizedComp .ClusterName , spec .Name ),
266+ }
267+ Expect (testapps .GetAndChangeObjStatus (& testCtx , itsKey , func (its * workloads.InstanceSet ) {
268+ its .Status .Replicas = int32 (1 )
269+ its .Status .InstanceStatus = []workloads.InstanceStatus {
270+ {
271+ PodName : fmt .Sprintf ("%s-0" , its .Name ),
272+ Configs : []workloads.InstanceConfigStatus {
273+ {
274+ Name : configSpecName ,
275+ ConfigHash : cfgutil .ToPointer ("01234" ),
276+ },
277+ },
278+ },
279+ }
280+ })()).Should (Succeed ())
281+
282+ By ("check component parameter status" )
220283 shardingCompParamKey := types.NamespacedName {
221284 Namespace : testCtx .DefaultNamespace ,
222285 Name : configcore .GenerateComponentConfigurationName (clusterObj .Name , spec .Name ),
223286 }
224- By ("check component parameter status" )
225287 Eventually (testapps .CheckObj (& testCtx , shardingCompParamKey , func (g Gomega , compParameter * parametersv1alpha1.ComponentParameter ) {
226288 g .Expect (compParameter .Status .ObservedGeneration ).Should (BeEquivalentTo (int64 (2 )))
227289 g .Expect (compParameter .Status .Phase ).Should (BeEquivalentTo (parametersv1alpha1 .CFinishedPhase ))
@@ -238,8 +300,8 @@ var _ = Describe("Parameter Controller", func() {
238300 prepareTestEnv ()
239301
240302 By ("submit the parameter update request with invalid max_connection" )
241- key := testapps .GetRandomizedKey (comp .Namespace , comp .FullCompName )
242- parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , comp .ClusterName , "invalid component" ).
303+ key := testapps .GetRandomizedKey (synthesizedComp .Namespace , synthesizedComp .FullCompName )
304+ parameterObj := testparameters .NewParameterFactory (key .Name , key .Namespace , synthesizedComp .ClusterName , "invalid component" ).
243305 AddParameters ("max_connections" , "100" ).
244306 Create (& testCtx ).
245307 GetObject ()
0 commit comments