diff --git a/controllers/apps/transformer_component_tls_test.go b/controllers/apps/transformer_component_tls_test.go
index 3a673d32486..e38d61bcb28 100644
--- a/controllers/apps/transformer_component_tls_test.go
+++ b/controllers/apps/transformer_component_tls_test.go
@@ -78,7 +78,7 @@ var _ = Describe("TLS self-signed cert function", func() {
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.ConfigMapSignature, true, client.InNamespace(testCtx.DefaultNamespace))
// non-namespaced
testapps.ClearResources(&testCtx, generics.ParametersDefinitionSignature, ml)
- testapps.ClearResources(&testCtx, generics.ParameterDrivenConfigRenderSignature, ml)
+ testapps.ClearResources(&testCtx, generics.ParamConfigRendererSignature, ml)
testapps.ClearResources(&testCtx, generics.BackupPolicyTemplateSignature, ml)
}
@@ -108,7 +108,7 @@ var _ = Describe("TLS self-signed cert function", func() {
Create(&testCtx).
GetObject()
- testparameters.NewParametersDrivenConfigFactory(pdcrName).
+ testparameters.NewParamConfigRendererFactory(pdcrName).
SetParametersDefs(paramsdef.Name).
SetComponentDefinition(compDefObj.GetName()).
SetTemplateName(configTemplateName).
diff --git a/controllers/parameters/componentparameter_controller_test.go b/controllers/parameters/componentparameter_controller_test.go
index e4e44d87680..1d95c5e1ed4 100644
--- a/controllers/parameters/componentparameter_controller_test.go
+++ b/controllers/parameters/componentparameter_controller_test.go
@@ -23,9 +23,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
- corev1 "k8s.io/api/core/v1"
- "k8s.io/apimachinery/pkg/types"
-
"sigs.k8s.io/controller-runtime/pkg/client"
parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
@@ -41,24 +38,6 @@ var _ = Describe("ComponentParameter Controller", func() {
AfterEach(cleanEnv)
- updatePDCRForInjectEnv := func() {
- Eventually(testapps.GetAndChangeObj(&testCtx, types.NamespacedName{Name: pdcrName}, func(pdcr *parametersv1alpha1.ParameterDrivenConfigRender) {
- pdcr.Spec.Configs = append(pdcr.Spec.Configs, parametersv1alpha1.ComponentConfigDescription{
- Name: envTestFileKey,
- TemplateName: configSpecName,
- InjectEnvTo: []string{testapps.DefaultMySQLContainerName},
- FileFormatConfig: ¶metersv1alpha1.FileFormatConfig{
- Format: parametersv1alpha1.Properties,
- },
- })
- })).Should(Succeed())
-
- Eventually(testapps.CheckObj(&testCtx, types.NamespacedName{Name: pdcrName}, func(g Gomega, pdcr *parametersv1alpha1.ParameterDrivenConfigRender) {
- g.Expect(pdcr.Spec.Configs).Should(HaveLen(2))
- g.Expect(pdcr.Spec.Configs[1].FileFormatConfig.Format).Should(BeEquivalentTo(parametersv1alpha1.Properties))
- })).Should(Succeed())
- }
-
Context("When updating configuration", func() {
It("Should reconcile success", func() {
mockReconcileResource()
@@ -96,46 +75,4 @@ var _ = Describe("ComponentParameter Controller", func() {
})
})
-
- Context("When updating configuration with injectEnvTo", func() {
- It("Should reconcile success", func() {
- mockReconcileResource()
- updatePDCRForInjectEnv()
-
- cfgKey := client.ObjectKey{
- Name: core.GenerateComponentConfigurationName(clusterName, defaultCompName),
- Namespace: testCtx.DefaultNamespace,
- }
- envKey := client.ObjectKey{
- Name: core.GenerateEnvFromName(core.GetComponentCfgName(clusterName, defaultCompName, configSpecName)),
- Namespace: testCtx.DefaultNamespace,
- }
-
- By("reconfiguring parameters.")
- Eventually(testapps.GetAndChangeObj(&testCtx, cfgKey, func(cfg *parametersv1alpha1.ComponentParameter) {
- item := intctrlutil.GetConfigTemplateItem(&cfg.Spec, configSpecName)
- item.ConfigFileParams = map[string]parametersv1alpha1.ParametersInFile{
- envTestFileKey: {
- Parameters: map[string]*string{
- "max_connections": cfgutil.ToPointer("1000"),
- "gtid_mode": cfgutil.ToPointer("ON"),
- },
- },
- }
- })).Should(Succeed())
-
- Eventually(testapps.CheckObj(&testCtx, cfgKey, func(g Gomega, cfg *parametersv1alpha1.ComponentParameter) {
- itemStatus := intctrlutil.GetItemStatus(&cfg.Status, configSpecName)
- g.Expect(itemStatus).ShouldNot(BeNil())
- g.Expect(itemStatus.UpdateRevision).Should(BeEquivalentTo("2"))
- g.Expect(itemStatus.Phase).Should(BeEquivalentTo(parametersv1alpha1.CFinishedPhase))
- })).Should(Succeed())
-
- Eventually(testapps.CheckObj(&testCtx, envKey, func(g Gomega, envObj *corev1.ConfigMap) {
- g.Expect(envObj.Data).Should(HaveKeyWithValue("max_connections", "1000"))
- g.Expect(envObj.Data).Should(HaveKeyWithValue("gtid_mode", "ON"))
- })).Should(Succeed())
- })
-
- })
})
diff --git a/controllers/parameters/config_util.go b/controllers/parameters/config_util.go
index b82f6edc135..1b61172ed21 100644
--- a/controllers/parameters/config_util.go
+++ b/controllers/parameters/config_util.go
@@ -59,7 +59,7 @@ func checkConfigLabels(object client.Object, requiredLabs []string) bool {
return checkEnableCfgUpgrade(object)
}
-func createConfigPatch(cfg *corev1.ConfigMap, configRender *parametersv1alpha1.ParameterDrivenConfigRender, paramsDefs map[string]*parametersv1alpha1.ParametersDefinition) (*core.ConfigPatchInfo, bool, error) {
+func createConfigPatch(cfg *corev1.ConfigMap, configRender *parametersv1alpha1.ParamConfigRenderer, paramsDefs map[string]*parametersv1alpha1.ParametersDefinition) (*core.ConfigPatchInfo, bool, error) {
if configRender == nil || len(configRender.Spec.Configs) == 0 {
return nil, true, nil
}
diff --git a/controllers/parameters/configuration_test.go b/controllers/parameters/configuration_test.go
index 4dc60ab0627..15483c7ffaa 100644
--- a/controllers/parameters/configuration_test.go
+++ b/controllers/parameters/configuration_test.go
@@ -106,13 +106,13 @@ func mockReconcileResource() (*corev1.ConfigMap, *parametersv1alpha1.ParametersD
obj.Status.Phase = appsv1.AvailablePhase
})()).Should(Succeed())
- pdcr := testparameters.NewParametersDrivenConfigFactory(pdcrName).
+ pdcr := testparameters.NewParamConfigRendererFactory(pdcrName).
SetParametersDefs(paramsDef.GetName()).
SetComponentDefinition(compDefObj.GetName()).
SetTemplateName(configSpecName).
Create(&testCtx).
GetObject()
- Expect(testapps.GetAndChangeObjStatus(&testCtx, client.ObjectKeyFromObject(pdcr), func(obj *parametersv1alpha1.ParameterDrivenConfigRender) {
+ Expect(testapps.GetAndChangeObjStatus(&testCtx, client.ObjectKeyFromObject(pdcr), func(obj *parametersv1alpha1.ParamConfigRenderer) {
obj.Status.Phase = parametersv1alpha1.PDAvailablePhase
})()).Should(Succeed())
diff --git a/controllers/parameters/reconcile_task.go b/controllers/parameters/reconcile_task.go
index 2b352c15197..09b4fed2658 100644
--- a/controllers/parameters/reconcile_task.go
+++ b/controllers/parameters/reconcile_task.go
@@ -46,7 +46,7 @@ type Task struct {
type TaskContext struct {
componentParameter *parametersv1alpha1.ComponentParameter
- configRender *parametersv1alpha1.ParameterDrivenConfigRender
+ configRender *parametersv1alpha1.ParamConfigRenderer
ctx context.Context
component *component.SynthesizedComponent
paramsDefs []*parametersv1alpha1.ParametersDefinition
@@ -63,13 +63,13 @@ func NewTaskContext(ctx context.Context, cli client.Client, componentParameter *
return nil, err
}
- configDefList := ¶metersv1alpha1.ParameterDrivenConfigRenderList{}
+ configDefList := ¶metersv1alpha1.ParamConfigRendererList{}
if err := cli.List(ctx, configDefList); err != nil {
return nil, err
}
var paramsDefs []*parametersv1alpha1.ParametersDefinition
- var configRender *parametersv1alpha1.ParameterDrivenConfigRender
+ var configRender *parametersv1alpha1.ParamConfigRenderer
for i, item := range configDefList.Items {
if item.Spec.ComponentDef != cmpd.Name {
continue
diff --git a/pkg/configuration/core/config_patch.go b/pkg/configuration/core/config_patch.go
index a6ba0c1260f..e112aa3489e 100644
--- a/pkg/configuration/core/config_patch.go
+++ b/pkg/configuration/core/config_patch.go
@@ -90,7 +90,7 @@ func difference(base *cfgWrapper, target *cfgWrapper) (*ConfigPatchInfo, error)
return reconfigureInfo, nil
}
-func TransformConfigPatchFromData(data map[string]string, configRender parametersv1alpha1.ParameterDrivenConfigRenderSpec) (*ConfigPatchInfo, error) {
+func TransformConfigPatchFromData(data map[string]string, configRender parametersv1alpha1.ParamConfigRendererSpec) (*ConfigPatchInfo, error) {
emptyData := func(m map[string]string) map[string]string {
r := make(map[string]string, len(m))
for key := range m {
diff --git a/pkg/configuration/core/config_patch_test.go b/pkg/configuration/core/config_patch_test.go
index a482978291c..47e1c474179 100644
--- a/pkg/configuration/core/config_patch_test.go
+++ b/pkg/configuration/core/config_patch_test.go
@@ -130,7 +130,7 @@ func TestTransformConfigPatchFromData(t *testing.T) {
testData := "[mysqld]\nmax_connections = 2000\ngeneral_log = OFF"
t.Run("testConfigPatch", func(t *testing.T) {
- got, err := TransformConfigPatchFromData(map[string]string{configFile: testData}, parametersv1alpha1.ParameterDrivenConfigRenderSpec{
+ got, err := TransformConfigPatchFromData(map[string]string{configFile: testData}, parametersv1alpha1.ParamConfigRendererSpec{
Configs: []parametersv1alpha1.ComponentConfigDescription{{
Name: "my.cnf",
FileFormatConfig: ¶metersv1alpha1.FileFormatConfig{Format: parametersv1alpha1.Ini},
diff --git a/pkg/configuration/core/config_patch_util.go b/pkg/configuration/core/config_patch_util.go
index 6c1089c1b5b..e88a74f18f0 100644
--- a/pkg/configuration/core/config_patch_util.go
+++ b/pkg/configuration/core/config_patch_util.go
@@ -32,7 +32,7 @@ import (
)
// CreateConfigPatch creates a patch for configuration files with different version.
-func CreateConfigPatch(oldVersion, newVersion map[string]string, configRender parametersv1alpha1.ParameterDrivenConfigRenderSpec, comparableAllFiles bool) (*ConfigPatchInfo, bool, error) {
+func CreateConfigPatch(oldVersion, newVersion map[string]string, configRender parametersv1alpha1.ParamConfigRendererSpec, comparableAllFiles bool) (*ConfigPatchInfo, bool, error) {
var hasFilesUpdated = false
var keys = ResolveConfigFiles(configRender.Configs)
@@ -99,7 +99,7 @@ func FromConfigObject(name, config string, formatConfig *parametersv1alpha1.File
// TransformConfigFileToKeyValueMap transforms a config file in appsv1alpha1.CfgFileFormat format to a map in which the key is config name and the value is config value
// sectionName means the desired section of config file, such as [mysqld] section.
// If config file has no section structure, sectionName should be default to get all values in this config file.
-func TransformConfigFileToKeyValueMap(fileName string, configRender parametersv1alpha1.ParameterDrivenConfigRenderSpec, configData []byte) (map[string]string, error) {
+func TransformConfigFileToKeyValueMap(fileName string, configRender parametersv1alpha1.ParamConfigRendererSpec, configData []byte) (map[string]string, error) {
formatterConfig := ResolveConfigFormat(configRender.Configs, fileName)
if formatterConfig == nil {
return nil, fmt.Errorf("not found file formatter config: [%s]", fileName)
diff --git a/pkg/configuration/core/config_patch_util_test.go b/pkg/configuration/core/config_patch_util_test.go
index f1e6f4fd98f..d492b455c18 100644
--- a/pkg/configuration/core/config_patch_util_test.go
+++ b/pkg/configuration/core/config_patch_util_test.go
@@ -302,7 +302,7 @@ max_connections=666
})
}
}
- configRender := parametersv1alpha1.ParameterDrivenConfigRenderSpec{Configs: configs}
+ configRender := parametersv1alpha1.ParamConfigRendererSpec{Configs: configs}
got, excludeDiff, err := CreateConfigPatch(tt.args.oldVersion, tt.args.newVersion, configRender, tt.args.enableExcludeDiff)
if (err != nil) != tt.wantErr {
t.Errorf("CreateConfigPatch() error = %v, wantErr %v", err, tt.wantErr)
diff --git a/pkg/configuration/core/reconfigure_util.go b/pkg/configuration/core/reconfigure_util.go
index 2b407417be0..0b970bdf430 100644
--- a/pkg/configuration/core/reconfigure_util.go
+++ b/pkg/configuration/core/reconfigure_util.go
@@ -88,7 +88,7 @@ func trimNestedField(updatedParams any, trimField string) (any, error) {
}
// ValidateConfigPatch Verifies if the changed parameters have been removed
-func ValidateConfigPatch(patch *ConfigPatchInfo, configRender parametersv1alpha1.ParameterDrivenConfigRenderSpec) error {
+func ValidateConfigPatch(patch *ConfigPatchInfo, configRender parametersv1alpha1.ParamConfigRendererSpec) error {
if !patch.IsModify || len(patch.UpdateConfig) == 0 {
return nil
}
diff --git a/pkg/controller/configuration/config_utils.go b/pkg/controller/configuration/config_utils.go
index ebf7f6ed658..ea150402f8b 100644
--- a/pkg/controller/configuration/config_utils.go
+++ b/pkg/controller/configuration/config_utils.go
@@ -74,7 +74,7 @@ func buildConfigManagerWithComponent(rctx *render.ResourceCtx, cluster *appsv1.C
podSpec = synthesizedComp.PodSpec
configSpecs = synthesizedComp.ConfigTemplates
- configRender *parametersv1alpha1.ParameterDrivenConfigRender
+ configRender *parametersv1alpha1.ParamConfigRenderer
paramsDefs []*parametersv1alpha1.ParametersDefinition
)
@@ -270,7 +270,7 @@ func findPortByPortName(container corev1.Container) (int32, bool) {
}
// UpdateConfigPayload updates the configuration payload
-func UpdateConfigPayload(config *parametersv1alpha1.ComponentParameterSpec, component *appsv1.ComponentSpec, configRender *parametersv1alpha1.ParameterDrivenConfigRenderSpec) error {
+func UpdateConfigPayload(config *parametersv1alpha1.ComponentParameterSpec, component *appsv1.ComponentSpec, configRender *parametersv1alpha1.ParamConfigRendererSpec) error {
if len(configRender.Configs) == 0 {
return nil
}
@@ -338,7 +338,7 @@ func runningComponentParameter(ctx context.Context, reader client.Reader, comp *
return componentParameter, nil
}
-func buildComponentParameter(ctx context.Context, reader client.Reader, comp *component.SynthesizedComponent, owner *appsv1.Component, cmpd *appsv1.ComponentDefinition, configRender *parametersv1alpha1.ParameterDrivenConfigRender, paramsDefs []*parametersv1alpha1.ParametersDefinition) (*parametersv1alpha1.ComponentParameter, error) {
+func buildComponentParameter(ctx context.Context, reader client.Reader, comp *component.SynthesizedComponent, owner *appsv1.Component, cmpd *appsv1.ComponentDefinition, configRender *parametersv1alpha1.ParamConfigRenderer, paramsDefs []*parametersv1alpha1.ParametersDefinition) (*parametersv1alpha1.ComponentParameter, error) {
tpls, err := ResolveComponentTemplate(ctx, reader, cmpd)
if err != nil {
return nil, err
diff --git a/pkg/controller/configuration/envfrom_utils.go b/pkg/controller/configuration/envfrom_utils.go
deleted file mode 100644
index 8ee6224d116..00000000000
--- a/pkg/controller/configuration/envfrom_utils.go
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
-Copyright (C) 2022-2024 ApeCloud Co., Ltd
-
-This file is part of KubeBlocks project
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU Affero General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Affero General Public License for more details.
-
-You should have received a copy of the GNU Affero General Public License
-along with this program. If not, see .
-*/
-
-package configuration
-
-import (
- "github.com/spf13/cast"
- corev1 "k8s.io/api/core/v1"
-
- parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
- "github.com/apecloud/kubeblocks/pkg/configuration/core"
- cfgutil "github.com/apecloud/kubeblocks/pkg/configuration/util"
- "github.com/apecloud/kubeblocks/pkg/configuration/validate"
- "github.com/apecloud/kubeblocks/pkg/constant"
- "github.com/apecloud/kubeblocks/pkg/controller/builder"
- "github.com/apecloud/kubeblocks/pkg/controller/component"
-)
-
-func InjectTemplateEnvFrom(component *component.SynthesizedComponent,
- podSpec *corev1.PodSpec,
- configRender *parametersv1alpha1.ParameterDrivenConfigRender,
- tplObjs []*corev1.ConfigMap) ([]*corev1.ConfigMap, error) {
- withEnvSource := func(name string) corev1.EnvFromSource {
- return corev1.EnvFromSource{ConfigMapRef: &corev1.ConfigMapEnvSource{
- LocalObjectReference: corev1.LocalObjectReference{
- Name: name,
- }}}
- }
-
- injectConfigmap := func(envMap map[string]string, templateName string, injectEnvs []string) *corev1.ConfigMap {
- cmName := core.GetComponentCfgName(component.ClusterName, component.Name, templateName)
- envSourceObject := builder.NewConfigMapBuilder(component.Namespace, core.GenerateEnvFromName(cmName)).
- AddLabels(constant.CMConfigurationSpecProviderLabelKey, templateName).
- AddLabelsInMap(constant.GetCompLabels(component.ClusterName, component.Name)).
- SetData(envMap).
- GetObject()
- if podSpec != nil {
- injectEnvFrom(podSpec.Containers, injectEnvs, envSourceObject.GetName(), withEnvSource)
- injectEnvFrom(podSpec.InitContainers, injectEnvs, envSourceObject.GetName(), withEnvSource)
- }
- return envSourceObject
- }
-
- if configRender == nil || len(configRender.Spec.Configs) == 0 {
- return nil, nil
- }
-
- var cm *corev1.ConfigMap
- var envObjs []*corev1.ConfigMap
- for _, config := range configRender.Spec.Configs {
- if len(config.InjectEnvTo) == 0 || config.FileFormatConfig == nil {
- continue
- }
- if cm = resolveConfigMap(tplObjs, config.Name); cm == nil {
- continue
- }
- envMap, err := resolveParametersFromFileContent(config.FileFormatConfig, cm.Data[config.Name])
- if err != nil {
- return nil, err
- }
- envObjs = append(envObjs, injectConfigmap(envMap, config.TemplateName, config.InjectEnvTo))
- }
- return envObjs, nil
-}
-
-func resolveConfigMap(localObjs []*corev1.ConfigMap, key string) *corev1.ConfigMap {
- for _, obj := range localObjs {
- if _, ok := obj.Data[key]; ok {
- return obj
- }
- }
- return nil
-}
-
-func CheckEnvFrom(container *corev1.Container, cmName string) bool {
- for i := range container.EnvFrom {
- source := &container.EnvFrom[i]
- if source.ConfigMapRef != nil && source.ConfigMapRef.Name == cmName {
- return true
- }
- if source.SecretRef != nil && source.SecretRef.Name == cmName {
- return true
- }
- }
- return false
-}
-
-func injectEnvFrom(containers []corev1.Container, injectEnvTo []string, cmName string, fn func(string) corev1.EnvFromSource) {
- sets := cfgutil.NewSet(injectEnvTo...)
- for i := range containers {
- container := &containers[i]
- if sets.InArray(container.Name) && !CheckEnvFrom(container, cmName) {
- container.EnvFrom = append(container.EnvFrom, fn(cmName))
- }
- }
-}
-
-func resolveParametersFromFileContent(format *parametersv1alpha1.FileFormatConfig, configContext string) (map[string]string, error) {
- keyValue, err := validate.LoadConfigObjectFromContent(format.Format, configContext)
- if err != nil {
- return nil, err
- }
- envMap := make(map[string]string, len(keyValue))
- for key, v := range keyValue {
- envMap[key] = cast.ToString(v)
- }
- return envMap, nil
-}
diff --git a/pkg/controller/configuration/envfrom_utils_test.go b/pkg/controller/configuration/envfrom_utils_test.go
deleted file mode 100644
index 87836027f84..00000000000
--- a/pkg/controller/configuration/envfrom_utils_test.go
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
-Copyright (C) 2022-2024 ApeCloud Co., Ltd
-
-This file is part of KubeBlocks project
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU Affero General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Affero General Public License for more details.
-
-You should have received a copy of the GNU Affero General Public License
-along with this program. If not, see .
-*/
-
-package configuration
-
-import (
- . "github.com/onsi/ginkgo/v2"
- . "github.com/onsi/gomega"
-
- corev1 "k8s.io/api/core/v1"
-
- appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
- parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
- "github.com/apecloud/kubeblocks/pkg/configuration/core"
- "github.com/apecloud/kubeblocks/pkg/controller/component"
- intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
- "github.com/apecloud/kubeblocks/pkg/generics"
- testapps "github.com/apecloud/kubeblocks/pkg/testutil/apps"
- testutil "github.com/apecloud/kubeblocks/pkg/testutil/k8s"
- testparameters "github.com/apecloud/kubeblocks/pkg/testutil/parameters"
-)
-
-var _ = Describe("ConfigEnvFrom test", func() {
- const (
- compDefName = "test-compdef"
- clusterName = "test-cluster"
- mysqlCompName = "mysql"
- )
-
- var (
- compDef *appsv1.ComponentDefinition
- cluster *appsv1.Cluster
-
- k8sMockClient *testutil.K8sClientMockHelper
- origCMObject *corev1.ConfigMap
- configRender *parametersv1alpha1.ParameterDrivenConfigRender
- )
-
- BeforeEach(func() {
- k8sMockClient = testutil.NewK8sMockClient()
-
- cm := testparameters.NewComponentTemplateFactory("", testCtx.DefaultNamespace).
- WithRandomName().
- AddConfigFile("env-file", `
-dbStorage_rocksDB_writeBufferSizeMB=8
-dbStorage_rocksDB_sstSizeInMB=64
-dbStorage_rocksDB_blockSize=65536
-dbStorage_rocksDB_bloomFilterBitsPerKey=10
-dbStorage_rocksDB_numLevels=-1
-dbStorage_rocksDB_numFilesInLevel0=4
-dbStorage_rocksDB_maxSizeInLevel1MB=256
-`).GetObject()
-
- configRender = testparameters.NewParametersDrivenConfigFactory("").
- WithRandomName().
- SetConfigDescription("env-file", cm.Name,
- parametersv1alpha1.FileFormatConfig{Format: parametersv1alpha1.Properties}).
- GetObject()
-
- compDef = testapps.NewComponentDefinitionFactory(compDefName).
- SetDefaultSpec().
- AddConfigTemplate(cm.Name, cm.Name, testCtx.DefaultNamespace, "mysql-config").
- GetObject()
-
- pvcSpec := testapps.NewPVCSpec("1Gi")
- cluster = testapps.NewClusterFactory(testCtx.DefaultNamespace, clusterName, "").
- AddComponent(mysqlCompName, compDef.Name).
- AddVolumeClaimTemplate(testapps.DataVolumeName, pvcSpec).
- GetObject()
-
- origCMObject = cm.DeepCopy()
- origCMObject.Name = core.GetComponentCfgName(clusterName, mysqlCompName, cm.Name)
-
- _ = cluster
- })
-
- AfterEach(func() {
- k8sMockClient.Finish()
- })
-
- Context("test config template inject envfrom", func() {
- It("should inject success", func() {
- comp, err := component.BuildComponent(cluster, &cluster.Spec.ComponentSpecs[0], nil, nil)
- Expect(err).Should(Succeed())
-
- synthesizeComp, err := component.BuildSynthesizedComponent(ctx, testCtx.Cli, compDef, comp, cluster)
- Expect(err).Should(Succeed())
-
- podSpec := &corev1.PodSpec{
- Containers: []corev1.Container{
- {
- Name: testapps.DefaultMySQLContainerName,
- },
- },
- }
- desc := intctrlutil.GetComponentConfigDescription(&configRender.Spec, "env-file")
- desc.InjectEnvTo = []string{testapps.DefaultMySQLContainerName}
- objs, err := InjectTemplateEnvFrom(synthesizeComp, podSpec, configRender, []*corev1.ConfigMap{origCMObject})
- Expect(err).Should(Succeed())
- Expect(objs).Should(HaveLen(1))
- Expect(generics.FindFunc(podSpec.Containers[0].EnvFrom, func(source corev1.EnvFromSource) bool {
- return source.ConfigMapRef.Name == objs[0].Name
- })).Should(HaveLen(1))
- })
-
- // It("should SyncEnvSourceObject success", func() {
- // configSpec := compDef.Spec.Configs[0]
- // configSpec.Keys = []string{"env-config"}
- //
- // comp, err := component.BuildComponent(cluster, &cluster.Spec.ComponentSpecs[0], nil, nil)
- // Expect(err).Should(Succeed())
- //
- // synthesizeComp, err := component.BuildSynthesizedComponent(ctx, testCtx.Cli, compDef, comp, cluster)
- // Expect(err).Should(Succeed())
- //
- // cmObj := origCMObject.DeepCopy()
- // cmObj.SetName(core.GenerateEnvFromName(origCMObject.Name))
- // k8sMockClient.MockGetMethod(testutil.WithGetReturned(testutil.WithConstructSimpleGetResult([]client.Object{
- // cmObj,
- // configConstraint,
- // }), testutil.WithAnyTimes()))
- // k8sMockClient.MockUpdateMethod(testutil.WithFailed(core.MakeError("failed to patch"), testutil.WithTimes(1)),
- // testutil.WithSucceed(), testutil.WithAnyTimes())
- //
- // Expect(SyncEnvSourceObject(configSpec, origCMObject, &configConstraint.Spec, k8sMockClient.Client(), ctx, cluster, synthesizeComp)).ShouldNot(Succeed())
- // Expect(SyncEnvSourceObject(configSpec, origCMObject, &configConstraint.Spec, k8sMockClient.Client(), ctx, cluster, synthesizeComp)).Should(Succeed())
- // })
- //
- // It("SyncEnvSourceObject abnormal test", func() {
- // comp, err := component.BuildComponent(cluster, &cluster.Spec.ComponentSpecs[0], nil, nil)
- // Expect(err).Should(Succeed())
- //
- // synthesizeComp, err := component.BuildSynthesizedComponent(ctx, testCtx.Cli, compDef, comp, cluster)
- // Expect(err).Should(Succeed())
- //
- // configSpec := compDef.Spec.Configs[0]
- // configSpec.InjectEnvTo = nil
- // Expect(SyncEnvSourceObject(configSpec, origCMObject, &configConstraint.Spec, k8sMockClient.Client(), ctx, cluster, synthesizeComp)).Should(Succeed())
- //
- // configSpec.InjectEnvTo = nil
- // cmObj := origCMObject.DeepCopy()
- // cmObj.SetName(core.GenerateEnvFromName(origCMObject.Name))
- // k8sMockClient.MockGetMethod(testutil.WithGetReturned(testutil.WithConstructSimpleGetResult([]client.Object{
- // cmObj,
- // configConstraint,
- // }), testutil.WithAnyTimes()))
- // k8sMockClient.MockUpdateMethod(testutil.WithSucceed(testutil.WithAnyTimes()))
- //
- // configSpec = compDef.Spec.Configs[0]
- // configSpec.Keys = []string{"env-config", "not-exist"}
- // Expect(SyncEnvSourceObject(configSpec, origCMObject, &configConstraint.Spec, k8sMockClient.Client(), ctx, cluster, synthesizeComp)).Should(Succeed())
- // })
- })
-})
diff --git a/pkg/controller/configuration/operator_test.go b/pkg/controller/configuration/operator_test.go
index a9873991584..4b388992dfd 100644
--- a/pkg/controller/configuration/operator_test.go
+++ b/pkg/controller/configuration/operator_test.go
@@ -46,7 +46,7 @@ var _ = Describe("ConfigurationOperatorTest", func() {
var configMapObj *corev1.ConfigMap
var scriptsObj *corev1.ConfigMap
var parametersDef *parametersv1alpha1.ParametersDefinition
- var configRender *parametersv1alpha1.ParameterDrivenConfigRender
+ var configRender *parametersv1alpha1.ParamConfigRenderer
var componentParameter *parametersv1alpha1.ComponentParameter
var k8sMockClient *testutil.K8sClientMockHelper
@@ -82,7 +82,7 @@ var _ = Describe("ConfigurationOperatorTest", func() {
Component(mysqlCompName).
GetObject()
parametersDef = testparameters.NewParametersDefinitionFactory(paramsDefName).GetObject()
- configRender = testparameters.NewParametersDrivenConfigFactory(pdcrName).
+ configRender = testparameters.NewParamConfigRendererFactory(pdcrName).
SetComponentDefinition(compDefObj.Name).
SetParametersDefs(paramsDefName).
GetObject()
diff --git a/pkg/controller/configuration/pipeline.go b/pkg/controller/configuration/pipeline.go
index 32aa0534ddf..a66a7f87092 100644
--- a/pkg/controller/configuration/pipeline.go
+++ b/pkg/controller/configuration/pipeline.go
@@ -20,18 +20,15 @@ along with this program. If not, see .
package configuration
import (
- "context"
"strconv"
corev1 "k8s.io/api/core/v1"
- apierrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
"github.com/apecloud/kubeblocks/pkg/configuration/core"
"github.com/apecloud/kubeblocks/pkg/constant"
- "github.com/apecloud/kubeblocks/pkg/controller/component"
"github.com/apecloud/kubeblocks/pkg/controller/render"
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
"github.com/apecloud/kubeblocks/pkg/generics"
@@ -44,7 +41,7 @@ type pipeline struct {
ctx render.ReconcileCtx
ResourceFetcher[pipeline]
- configRender *parametersv1alpha1.ParameterDrivenConfigRender
+ configRender *parametersv1alpha1.ParamConfigRenderer
parametersDefs []*parametersv1alpha1.ParametersDefinition
}
@@ -63,7 +60,7 @@ type updatePipeline struct {
ctx render.ReconcileCtx
ResourceFetcher[updatePipeline]
- configRender *parametersv1alpha1.ParameterDrivenConfigRender
+ configRender *parametersv1alpha1.ParamConfigRenderer
parametersDefs []*parametersv1alpha1.ParametersDefinition
}
@@ -155,12 +152,8 @@ func (p *pipeline) BuildConfigManagerSidecar() *pipeline {
func (p *pipeline) UpdateConfigRelatedObject() *pipeline {
updateMeta := func() error {
- if err := syncInjectEnvFromCM(p.Context, p.Client, p.ctx.SynthesizedComponent, p.configRender, p.renderWrapper.renderedObjs, true); err != nil {
- return err
- }
return createConfigObjects(p.Client, p.Context, p.renderWrapper.renderedObjs)
}
-
return p.Wrap(updateMeta)
}
@@ -255,11 +248,6 @@ func (p *updatePipeline) UpdateConfigVersion(revision string) *updatePipeline {
// TODO(leon)
func (p *updatePipeline) Sync() *updatePipeline {
return p.Wrap(func() error {
- if !p.isDone() {
- if err := syncInjectEnvFromCM(p.Context, p.Client, p.ctx.SynthesizedComponent, p.configRender, []*corev1.ConfigMap{p.newCM}, false); err != nil {
- return err
- }
- }
if err := intctrlutil.SetControllerReference(p.ComponentParameterObj, p.newCM); err != nil {
return err
}
@@ -280,30 +268,3 @@ func (p *updatePipeline) Sync() *updatePipeline {
return core.MakeError("unexpected condition")
})
}
-
-func syncInjectEnvFromCM(ctx context.Context, cli client.Client, synthesizedComp *component.SynthesizedComponent, configRender *parametersv1alpha1.ParameterDrivenConfigRender, configMaps []*corev1.ConfigMap, onlyCreate bool) error {
- var podSpec *corev1.PodSpec
-
- if onlyCreate {
- podSpec = synthesizedComp.PodSpec
- }
- envObjs, err := InjectTemplateEnvFrom(synthesizedComp, podSpec, configRender, configMaps)
- if err != nil {
- return err
- }
- for _, obj := range envObjs {
- if err = cli.Create(ctx, obj, inDataContext()); err == nil {
- continue
- }
- if !apierrors.IsAlreadyExists(err) {
- return err
- }
- if onlyCreate {
- continue
- }
- if err = cli.Update(ctx, obj, inDataContext()); err != nil {
- return err
- }
- }
- return nil
-}
diff --git a/pkg/controller/configuration/pipeline_test.go b/pkg/controller/configuration/pipeline_test.go
index f250495596c..ccba60c6953 100644
--- a/pkg/controller/configuration/pipeline_test.go
+++ b/pkg/controller/configuration/pipeline_test.go
@@ -53,7 +53,7 @@ var _ = Describe("ConfigurationPipelineTest", func() {
var configMapObj *corev1.ConfigMap
var parametersDef *parametersv1alpha1.ParametersDefinition
var componentParameter *parametersv1alpha1.ComponentParameter
- var configRender *parametersv1alpha1.ParameterDrivenConfigRender
+ var configRender *parametersv1alpha1.ParamConfigRenderer
var k8sMockClient *testutil.K8sClientMockHelper
mockAPIResource := func(lazyFetcher testutil.Getter) {
@@ -123,7 +123,7 @@ max_connections = '1000'
GetObject()
parametersDef = testparameters.NewParametersDefinitionFactory(paramsDefName).GetObject()
- configRender = testparameters.NewParametersDrivenConfigFactory(pdcrName).
+ configRender = testparameters.NewParamConfigRendererFactory(pdcrName).
SetConfigDescription(testConfigFile, configTemplateName, parametersv1alpha1.FileFormatConfig{Format: parametersv1alpha1.Properties}).
SetComponentDefinition(compDefObj.Name).
SetParametersDefs(paramsDefName).
diff --git a/pkg/controller/configuration/template_merger.go b/pkg/controller/configuration/template_merger.go
index 8c92ff8ef60..012d1aa9ebd 100644
--- a/pkg/controller/configuration/template_merger.go
+++ b/pkg/controller/configuration/template_merger.go
@@ -43,7 +43,7 @@ type mergeContext struct {
template appsv1.ConfigTemplateExtension
configSpec appsv1.ComponentTemplateSpec
paramsDefs []*parametersv1alpha1.ParametersDefinition
- configRender *parametersv1alpha1.ParameterDrivenConfigRender
+ configRender *parametersv1alpha1.ParamConfigRenderer
}
func (m *mergeContext) renderTemplate() (map[string]string, error) {
@@ -129,7 +129,7 @@ func NewTemplateMerger(template appsv1.ConfigTemplateExtension,
templateRender render.TemplateRender,
configSpec appsv1.ComponentTemplateSpec,
paramsDefs []*parametersv1alpha1.ParametersDefinition,
- configRender *parametersv1alpha1.ParameterDrivenConfigRender,
+ configRender *parametersv1alpha1.ParamConfigRenderer,
) (TemplateMerger, error) {
templateData := &mergeContext{
configSpec: configSpec,
@@ -160,7 +160,7 @@ func mergerConfigTemplate(template appsv1.ConfigTemplateExtension,
configSpec appsv1.ComponentTemplateSpec,
baseData map[string]string,
paramsDefs []*parametersv1alpha1.ParametersDefinition,
- configRender *parametersv1alpha1.ParameterDrivenConfigRender) (map[string]string, error) {
+ configRender *parametersv1alpha1.ParamConfigRenderer) (map[string]string, error) {
templateMerger, err := NewTemplateMerger(template, templateRender, configSpec, paramsDefs, configRender)
if err != nil {
return nil, err
diff --git a/pkg/controller/configuration/template_merger_test.go b/pkg/controller/configuration/template_merger_test.go
index 7f82692847f..32bb0316519 100644
--- a/pkg/controller/configuration/template_merger_test.go
+++ b/pkg/controller/configuration/template_merger_test.go
@@ -76,7 +76,7 @@ max_connections=666
templateBuilder render.TemplateRender
configSpec appsv1.ComponentTemplateSpec
paramsDefs *parametersv1alpha1.ParametersDefinition
- pdcr *parametersv1alpha1.ParameterDrivenConfigRender
+ pdcr *parametersv1alpha1.ParamConfigRenderer
baseCMObject *corev1.ConfigMap
updatedCMObject *corev1.ConfigMap
@@ -87,7 +87,7 @@ max_connections=666
paramsDefs = testparameters.NewParametersDefinitionFactory("test-pd").
SetConfigFile(testConfigName).
GetObject()
- pdcr = testparameters.NewParametersDrivenConfigFactory("test-pdcr").
+ pdcr = testparameters.NewParamConfigRendererFactory("test-pdcr").
SetTemplateName(testConfigSpecName).
GetObject()
@@ -248,7 +248,7 @@ max_connections=666
}
tmpCM := baseCMObject.DeepCopy()
- _, err := mergerConfigTemplate(importedTemplate, templateBuilder, configSpec, tmpCM.Data, []*parametersv1alpha1.ParametersDefinition{paramsDefs}, ¶metersv1alpha1.ParameterDrivenConfigRender{})
+ _, err := mergerConfigTemplate(importedTemplate, templateBuilder, configSpec, tmpCM.Data, []*parametersv1alpha1.ParametersDefinition{paramsDefs}, ¶metersv1alpha1.ParamConfigRenderer{})
Expect(err).Should(Succeed())
})
})
diff --git a/pkg/controller/configuration/template_wrapper.go b/pkg/controller/configuration/template_wrapper.go
index f2585a3e9e4..552ce5fe02d 100644
--- a/pkg/controller/configuration/template_wrapper.go
+++ b/pkg/controller/configuration/template_wrapper.go
@@ -101,7 +101,7 @@ func (wrapper *renderWrapper) renderConfigTemplate(cluster *appsv1.Cluster,
component *component.SynthesizedComponent,
localObjs []client.Object,
componentParameter *parametersv1alpha1.ComponentParameter,
- configRender *parametersv1alpha1.ParameterDrivenConfigRender,
+ configRender *parametersv1alpha1.ParamConfigRenderer,
defs []*parametersv1alpha1.ParametersDefinition, revision string) error {
for _, configSpec := range component.ConfigTemplates {
var item *parametersv1alpha1.ConfigTemplateItemDetail
@@ -160,7 +160,7 @@ func updateConfigMetaForCM(newCMObj *corev1.ConfigMap, item *parametersv1alpha1.
return
}
-func applyUpdatedParameters(item *parametersv1alpha1.ConfigTemplateItemDetail, orig *corev1.ConfigMap, configRender *parametersv1alpha1.ParameterDrivenConfigRender, paramsDefs []*parametersv1alpha1.ParametersDefinition) (*corev1.ConfigMap, error) {
+func applyUpdatedParameters(item *parametersv1alpha1.ConfigTemplateItemDetail, orig *corev1.ConfigMap, configRender *parametersv1alpha1.ParamConfigRenderer, paramsDefs []*parametersv1alpha1.ParametersDefinition) (*corev1.ConfigMap, error) {
if configRender == nil || len(configRender.Spec.Configs) == 0 {
return nil, fmt.Errorf("not support parameter reconfigure")
}
@@ -179,7 +179,7 @@ func (wrapper *renderWrapper) rerenderConfigTemplate(cluster *appsv1.Cluster,
component *component.SynthesizedComponent,
configSpec appsv1.ComponentTemplateSpec,
item *parametersv1alpha1.ConfigTemplateItemDetail,
- configRender *parametersv1alpha1.ParameterDrivenConfigRender,
+ configRender *parametersv1alpha1.ParamConfigRenderer,
defs []*parametersv1alpha1.ParametersDefinition) (*corev1.ConfigMap, error) {
cmName := core.GetComponentCfgName(cluster.Name, component.Name, configSpec.Name)
newCMObj, err := wrapper.RenderComponentTemplate(configSpec, cmName, func(m map[string]string) error {
@@ -297,7 +297,7 @@ func UpdateCMConfigSpecLabels(cm *corev1.ConfigMap, configSpec appsv1.ComponentT
}
// validateRenderedData validates config file against constraint
-func validateRenderedData(renderedData map[string]string, paramsDefs []*parametersv1alpha1.ParametersDefinition, configRender *parametersv1alpha1.ParameterDrivenConfigRender) error {
+func validateRenderedData(renderedData map[string]string, paramsDefs []*parametersv1alpha1.ParametersDefinition, configRender *parametersv1alpha1.ParamConfigRenderer) error {
if len(paramsDefs) == 0 || configRender == nil || len(configRender.Spec.Configs) == 0 {
return nil
}
diff --git a/pkg/controller/plan/prepare_test.go b/pkg/controller/plan/prepare_test.go
index 07440023fea..38c81125f55 100644
--- a/pkg/controller/plan/prepare_test.go
+++ b/pkg/controller/plan/prepare_test.go
@@ -28,11 +28,8 @@ import (
appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
- cfgcore "github.com/apecloud/kubeblocks/pkg/configuration/core"
"github.com/apecloud/kubeblocks/pkg/controller/component"
- "github.com/apecloud/kubeblocks/pkg/controller/configuration"
"github.com/apecloud/kubeblocks/pkg/controller/render"
- intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
"github.com/apecloud/kubeblocks/pkg/generics"
testapps "github.com/apecloud/kubeblocks/pkg/testutil/apps"
testparameters "github.com/apecloud/kubeblocks/pkg/testutil/parameters"
@@ -50,7 +47,7 @@ var _ = Describe("Prepare Test", func() {
ml := client.HasLabels{testCtx.TestObjLabelKey}
// non-namespaced
- testapps.ClearResources(&testCtx, generics.ParameterDrivenConfigRenderSignature, ml)
+ testapps.ClearResources(&testCtx, generics.ParamConfigRendererSignature, ml)
testapps.ClearResources(&testCtx, generics.ParametersDefinitionSignature, ml)
testapps.ClearResources(&testCtx, generics.ComponentDefinitionSignature, ml)
@@ -110,19 +107,14 @@ var _ = Describe("Prepare Test", func() {
obj.Status.Phase = parametersv1alpha1.PDAvailablePhase
})()).Should(Succeed())
- configRender := testparameters.NewParametersDrivenConfigFactory(pdcrName).
+ configRender := testparameters.NewParamConfigRendererFactory(pdcrName).
SetConfigDescription(envFileName, testapps.DefaultConfigSpecName, parametersv1alpha1.FileFormatConfig{Format: parametersv1alpha1.Properties}).
SetComponentDefinition(compDefObj.Name).
SetParametersDefs(paramsDefName).
Create(&testCtx).
GetObject()
- Expect(testapps.GetAndChangeObj(&testCtx, client.ObjectKeyFromObject(configRender), func(obj *parametersv1alpha1.ParameterDrivenConfigRender) {
- config := intctrlutil.GetComponentConfigDescription(&obj.Spec, envFileName)
- config.InjectEnvTo = []string{compDefObj.Spec.Runtime.Containers[0].Name}
- })()).Should(Succeed())
-
- Expect(testapps.GetAndChangeObjStatus(&testCtx, client.ObjectKeyFromObject(configRender), func(obj *parametersv1alpha1.ParameterDrivenConfigRender) {
+ Expect(testapps.GetAndChangeObjStatus(&testCtx, client.ObjectKeyFromObject(configRender), func(obj *parametersv1alpha1.ParamConfigRenderer) {
obj.Status.Phase = parametersv1alpha1.PDAvailablePhase
})()).Should(Succeed())
@@ -166,7 +158,6 @@ dbStorage_rocksDB_maxSizeInLevel1MB=256
}
err = RenderConfigNScriptFiles(resCtx, cluster, comp, synthesizeComp, synthesizeComp.PodSpec, nil)
Expect(err).Should(Succeed())
- Expect(configuration.CheckEnvFrom(&synthesizeComp.PodSpec.Containers[0], cfgcore.GenerateEnvFromName(cfgcore.GetComponentCfgName(cluster.Name, synthesizeComp.Name, testapps.DefaultConfigSpecName)))).Should(BeTrue())
})
})
})
diff --git a/pkg/controllerutil/config_util.go b/pkg/controllerutil/config_util.go
index a5a5e1f83b8..27e44397332 100644
--- a/pkg/controllerutil/config_util.go
+++ b/pkg/controllerutil/config_util.go
@@ -253,14 +253,6 @@ func filterImmutableParameters(parameters map[string]any, fileName string, param
return validParameters
}
-func TransformConfigTemplate(configs []appsv1.ComponentConfigSpec) []appsv1.ComponentTemplateSpec {
- arr := make([]appsv1.ComponentTemplateSpec, 0, len(configs))
- for _, config := range configs {
- arr = append(arr, config.ComponentTemplateSpec)
- }
- return arr
-}
-
func ResolveCmpdParametersDefs(ctx context.Context, reader client.Reader, cmpd *appsv1.ComponentDefinition) (*parametersv1alpha1.ParamConfigRenderer, []*parametersv1alpha1.ParametersDefinition, error) {
var paramsDefs []*parametersv1alpha1.ParametersDefinition