@@ -308,54 +308,62 @@ var _ = Describe("ComponentParameter Controller", func() {
308308 })
309309
310310 It ("should render both new PD and legacy PCR files in mixed mode" , func () {
311- templateObj , _ , compObj , _ , _ := mockReconcileResource ()
311+ const legacyFile = "log.conf"
312+ mockReconcileResource (func (templateObj * corev1.ConfigMap , compDefObj * appsv1.ComponentDefinition ) {
313+ By ("prepare the legacy PCR compatibility resources before creating the Component" )
314+ Eventually (testapps .GetAndChangeObj (& testCtx , client .ObjectKeyFromObject (templateObj ), func (tpl * corev1.ConfigMap ) {
315+ tpl .Data [legacyFile ] = "slow_query_log=1\n "
316+ })).Should (Succeed ())
317+
318+ legacyPD := testparameters .NewParametersDefinitionFactory ("legacy-log-params" ).
319+ SetConfigFile (legacyFile ).
320+ Create (& testCtx ).
321+ GetObject ()
322+ Expect (testapps .GetAndChangeObjStatus (& testCtx , client .ObjectKeyFromObject (legacyPD ), func (obj * parametersv1alpha1.ParametersDefinition ) {
323+ obj .Status .Phase = parametersv1alpha1 .PDAvailablePhase
324+ })()).Should (Succeed ())
325+
326+ pcr := & parametersv1alpha1.ParamConfigRenderer {
327+ ObjectMeta : metav1.ObjectMeta {Name : pdcrName + "-mixed" },
328+ Spec : parametersv1alpha1.ParamConfigRendererSpec {
329+ ComponentDef : compDefObj .Name ,
330+ ServiceVersion : "8.0.30" ,
331+ ParametersDefs : []string {legacyPD .Name },
332+ Configs : []parametersv1alpha1.ComponentConfigDescription {{
333+ Name : legacyFile ,
334+ TemplateName : configSpecName ,
335+ FileFormatConfig : & parametersv1alpha1.FileFormatConfig {
336+ Format : parametersv1alpha1 .Properties ,
337+ },
338+ }},
339+ },
340+ }
341+ Expect (testCtx .CreateObj (testCtx .Ctx , pcr )).Should (Succeed ())
342+
343+ By ("wait until the controller cache resolves both new and legacy parameter bindings" )
344+ Eventually (func (g Gomega ) {
345+ cachedTemplate := & corev1.ConfigMap {}
346+ g .Expect (testCtx .Cli .Get (testCtx .Ctx , client .ObjectKeyFromObject (templateObj ), cachedTemplate )).Should (Succeed ())
347+ g .Expect (cachedTemplate .Data ).Should (HaveKeyWithValue (legacyFile , "slow_query_log=1\n " ))
348+
349+ cachedCompDef := & appsv1.ComponentDefinition {}
350+ g .Expect (testCtx .Cli .Get (testCtx .Ctx , client .ObjectKeyFromObject (compDefObj ), cachedCompDef )).Should (Succeed ())
351+ configDescs , paramsDefs , err := parameters .ResolveCmpdParametersDefs (testCtx .Ctx , testCtx .Cli , cachedCompDef )
352+ g .Expect (err ).ShouldNot (HaveOccurred ())
353+ g .Expect (configDescs ).Should (HaveLen (2 ))
354+ g .Expect (paramsDefs ).Should (HaveLen (2 ))
355+ g .Expect (configDescs ).Should (ContainElement (HaveField ("Name" , legacyFile )))
356+ g .Expect (paramsDefs ).Should (ContainElement (HaveField ("Name" , legacyPD .Name )))
357+ }).Should (Succeed ())
358+ })
312359
313360 cfgKey := client.ObjectKey {
314361 Namespace : testCtx .DefaultNamespace ,
315362 Name : core .GenerateComponentConfigurationName (clusterName , defaultCompName ),
316363 }
317364 Eventually (testapps .CheckObj (& testCtx , cfgKey , func (g Gomega , cfg * parametersv1alpha1.ComponentParameter ) {
318365 g .Expect (cfg .Status .Phase ).Should (BeEquivalentTo (parametersv1alpha1 .CFinishedPhase ))
319- })).Should (Succeed ())
320-
321- By ("add a legacy-only file to the component template" )
322- const legacyFile = "log.conf"
323- Eventually (testapps .GetAndChangeObj (& testCtx , client .ObjectKeyFromObject (templateObj ), func (tpl * corev1.ConfigMap ) {
324- tpl .Data [legacyFile ] = "slow_query_log=1\n "
325- })).Should (Succeed ())
326-
327- By ("create a legacy-only ParametersDefinition and ParamConfigRenderer binding" )
328- legacyPD := testparameters .NewParametersDefinitionFactory ("legacy-log-params" ).
329- SetConfigFile (legacyFile ).
330- Create (& testCtx ).
331- GetObject ()
332- Expect (testapps .GetAndChangeObjStatus (& testCtx , client .ObjectKeyFromObject (legacyPD ), func (obj * parametersv1alpha1.ParametersDefinition ) {
333- obj .Status .Phase = parametersv1alpha1 .PDAvailablePhase
334- })()).Should (Succeed ())
335-
336- pcr := & parametersv1alpha1.ParamConfigRenderer {
337- ObjectMeta : metav1.ObjectMeta {Name : pdcrName + "-mixed" },
338- Spec : parametersv1alpha1.ParamConfigRendererSpec {
339- ComponentDef : compObj .Spec .CompDef ,
340- ServiceVersion : "8.0.30" ,
341- ParametersDefs : []string {legacyPD .Name },
342- Configs : []parametersv1alpha1.ComponentConfigDescription {{
343- Name : legacyFile ,
344- TemplateName : configSpecName ,
345- FileFormatConfig : & parametersv1alpha1.FileFormatConfig {
346- Format : parametersv1alpha1 .Properties ,
347- },
348- }},
349- },
350- }
351- Expect (testCtx .CreateObj (testCtx .Ctx , pcr )).Should (Succeed ())
352-
353- By ("touch the component to regenerate ComponentParameter from mixed sources" )
354- Eventually (testapps .GetAndChangeObj (& testCtx , client .ObjectKeyFromObject (compObj ), func (comp * appsv1.Component ) {
355- if comp .Annotations == nil {
356- comp .Annotations = map [string ]string {}
357- }
358- comp .Annotations ["parameters.kubeblocks.io/mixed-mode-test" ] = "true"
366+ g .Expect (parameters .GetConfigTemplateItem (& cfg .Spec , configSpecName )).ShouldNot (BeNil ())
359367 })).Should (Succeed ())
360368
361369 configKey := client.ObjectKey {
0 commit comments