Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt committed Dec 25, 2024
1 parent ac6a607 commit 0f9f06e
Show file tree
Hide file tree
Showing 21 changed files with 36 additions and 449 deletions.
4 changes: 2 additions & 2 deletions controllers/apps/transformer_component_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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).
Expand Down
63 changes: 0 additions & 63 deletions controllers/parameters/componentparameter_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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: &parametersv1alpha1.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()
Expand Down Expand Up @@ -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())
})

})
})
2 changes: 1 addition & 1 deletion controllers/parameters/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/parameters/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
6 changes: 3 additions & 3 deletions controllers/parameters/reconcile_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -63,13 +63,13 @@ func NewTaskContext(ctx context.Context, cli client.Client, componentParameter *
return nil, err
}

configDefList := &parametersv1alpha1.ParameterDrivenConfigRenderList{}
configDefList := &parametersv1alpha1.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
Expand Down
2 changes: 1 addition & 1 deletion pkg/configuration/core/config_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/configuration/core/config_patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: &parametersv1alpha1.FileFormatConfig{Format: parametersv1alpha1.Ini},
Expand Down
4 changes: 2 additions & 2 deletions pkg/configuration/core/config_patch_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/configuration/core/config_patch_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/configuration/core/reconfigure_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/configuration/config_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
124 changes: 0 additions & 124 deletions pkg/controller/configuration/envfrom_utils.go

This file was deleted.

Loading

0 comments on commit 0f9f06e

Please sign in to comment.