Repository: apecloud/kubeblocks

Issue:
[BUG] build ComponentParameter when ExternalManaged is false
**Describe the bug**
Even if the `ExternalManaged` field in cmpd is false or nil, the controller will still construct the `ComponentParameter` object.

Discussion:

Solution patch:
diff --git a/pkg/controller/configuration/parameter_utils.go b/pkg/controller/configuration/parameter_utils.go
index aa54de94e..13abd38c1 100644
--- a/pkg/controller/configuration/parameter_utils.go
+++ b/pkg/controller/configuration/parameter_utils.go
@@ -62,6 +62,10 @@ func ResolveParameterTemplate(cmpd appsv1.ComponentDefinitionSpec, pcr parameter
 	})
 
 	for _, config := range cmpd.Configs {
+		if config.ExternalManaged == nil || !*config.ExternalManaged {
+			continue
+		}
+
 		if slices.Contains(tpls, config.Name) {
 			templates = append(templates, config)
 		}



Test patch:
diff --git a/controllers/parameters/componentdrivenparameter_controller_test.go b/controllers/parameters/componentdrivenparameter_controller_test.go
index 98310c47e..7267bba9c 100644
--- a/controllers/parameters/componentdrivenparameter_controller_test.go
+++ b/controllers/parameters/componentdrivenparameter_controller_test.go
@@ -65,7 +65,7 @@ var _ = Describe("ComponentParameterGenerator Controller", func() {
 		compDefObj := testapps.NewComponentDefinitionFactory(compDefName).
 			WithRandomName().
 			SetDefaultSpec().
-			AddConfigTemplate(configSpecName, configmap.Name, testCtx.DefaultNamespace, configVolumeName).
+			AddConfigTemplate(configSpecName, configmap.Name, testCtx.DefaultNamespace, configVolumeName, true).
 			Create(&testCtx).
 			GetObject()
 		Expect(testapps.GetAndChangeObjStatus(&testCtx, client.ObjectKeyFromObject(compDefObj), func(obj *appsv1.ComponentDefinition) {
@@ -153,7 +153,7 @@ var _ = Describe("ComponentParameterGenerator Controller", func() {
 			compDefObj := testapps.NewComponentDefinitionFactory(key.Name).
 				WithRandomName().
 				SetDefaultSpec().
-				AddConfigTemplate(configSpecName, configSpecName, testCtx.DefaultNamespace, configVolumeName).
+				AddConfigTemplate(configSpecName, configSpecName, testCtx.DefaultNamespace, configVolumeName, true).
 				Create(&testCtx).
 				GetObject()
 			Expect(testapps.GetAndChangeObjStatus(&testCtx, client.ObjectKeyFromObject(compDefObj), func(obj *appsv1.ComponentDefinition) {
diff --git a/controllers/parameters/configuration_test.go b/controllers/parameters/configuration_test.go
index b33856350..a1ff2000a 100644
--- a/controllers/parameters/configuration_test.go
+++ b/controllers/parameters/configuration_test.go
@@ -100,7 +100,7 @@ func mockReconcileResource() (*corev1.ConfigMap, *parametersv1alpha1.ParametersD
 	compDefObj := testapps.NewComponentDefinitionFactory(compDefName).
 		WithRandomName().
 		SetDefaultSpec().
-		AddConfigTemplate(configSpecName, configmap.Name, testCtx.DefaultNamespace, configVolumeName).
+		AddConfigTemplate(configSpecName, configmap.Name, testCtx.DefaultNamespace, configVolumeName, true).
 		Create(&testCtx).
 		GetObject()
 	Expect(testapps.GetAndChangeObjStatus(&testCtx, client.ObjectKeyFromObject(compDefObj), func(obj *appsv1.ComponentDefinition) {
diff --git a/controllers/parameters/paramconfigrenderer_controller_test.go b/controllers/parameters/paramconfigrenderer_controller_test.go
index c632cb761..8cb2d8a0f 100644
--- a/controllers/parameters/paramconfigrenderer_controller_test.go
+++ b/controllers/parameters/paramconfigrenderer_controller_test.go
@@ -55,7 +55,7 @@ var _ = Describe("ParamConfigRenderer Controller", func() {
 		By("Create a component definition obj and mock to available")
 		compDefObj := testapps.NewComponentDefinitionFactory(compDefName).
 			SetDefaultSpec().
-			AddConfigTemplate(configSpecName, configmap.Name, testCtx.DefaultNamespace, configVolumeName).
+			AddConfigTemplate(configSpecName, configmap.Name, testCtx.DefaultNamespace, configVolumeName, true).
 			Create(&testCtx).
 			GetObject()
 		Expect(testapps.GetAndChangeObjStatus(&testCtx, client.ObjectKeyFromObject(compDefObj), func(obj *appsv1.ComponentDefinition) {
diff --git a/pkg/controller/configuration/configuration_test.go b/pkg/controller/configuration/configuration_test.go
index 798b99e8d..40f9317c8 100644
--- a/pkg/controller/configuration/configuration_test.go
+++ b/pkg/controller/configuration/configuration_test.go
@@ -48,7 +48,7 @@ const (
 func allFieldsCompDefObj(create bool) *appsv1.ComponentDefinition {
 	compDef := testapps.NewComponentDefinitionFactory(compDefName).
 		SetDefaultSpec().
-		AddConfigTemplate(configTemplateName, mysqlConfigName, testCtx.DefaultNamespace, testapps.ConfVolumeName).
+		AddConfigTemplate(configTemplateName, mysqlConfigName, testCtx.DefaultNamespace, testapps.ConfVolumeName, true).
 		AddScriptTemplate(scriptTemplateName, mysqlScriptsTemplateName, testCtx.DefaultNamespace, testapps.ScriptsVolumeName, nil).
 		GetObject()
 	if create {
diff --git a/pkg/testutil/apps/componentdefinition_factory.go b/pkg/testutil/apps/componentdefinition_factory.go
index b370f7986..a22fbc7e5 100644
--- a/pkg/testutil/apps/componentdefinition_factory.go
+++ b/pkg/testutil/apps/componentdefinition_factory.go
@@ -171,12 +171,13 @@ func (f *MockComponentDefinitionFactory) AddServiceExt(name, serviceName string,
 	return f
 }
 
-func (f *MockComponentDefinitionFactory) AddConfigTemplate(name, configTemplate, namespace, volumeName string) *MockComponentDefinitionFactory {
+func (f *MockComponentDefinitionFactory) AddConfigTemplate(name, configTemplate, namespace, volumeName string, externalManage bool) *MockComponentDefinitionFactory {
 	config := kbappsv1.ComponentFileTemplate{
-		Name:       name,
-		Template:   configTemplate,
-		Namespace:  namespace,
-		VolumeName: volumeName,
+		Name:            name,
+		Template:        configTemplate,
+		Namespace:       namespace,
+		VolumeName:      volumeName,
+		ExternalManaged: &externalManage,
 	}
 	if f.Get().Spec.Configs == nil {
 		f.Get().Spec.Configs = make([]kbappsv1.ComponentFileTemplate, 0)