Skip to content

Commit

Permalink
chore: removed configconstraint dependence on configspec.name, using …
Browse files Browse the repository at this point in the history
…env TOOLS_SCRIPTS_PATH (#4400)
  • Loading branch information
sophon-zt authored Jul 21, 2023
1 parent 97e9fa2 commit 6b25171
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 20 deletions.
4 changes: 2 additions & 2 deletions deploy/pulsar/templates/configconstraints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ spec:
# imagePullPolicy: "{{ template "pulsar.imagePullPolicy" (dict "image" .Values.images.pulsarTools "root" .) }}"
- name: init-pulsar-client-config
command:
- "/opt/kb-tools/reload/broker-config/install-pulsar-client-config.sh"
- "$(TOOLS_SCRIPTS_PATH)/install-pulsar-client-config.sh"

---
apiVersion: apps.kubeblocks.io/v1alpha1
Expand All @@ -84,4 +84,4 @@ spec:

# mysql configuration file format
formatterConfig:
format: props-plus
format: props-plus
23 changes: 15 additions & 8 deletions internal/configuration/config_manager/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ import (
)

const (
configTemplateName = "reload.yaml"
scriptVolumePrefix = "cm-script-"
configVolumePrefix = "cm-config-"
kbScriptVolumePath = "/opt/kb-tools/reload"
kbConfigVolumePath = "/opt/kb-tools/config"
configTemplateName = "reload.yaml"
scriptVolumePrefix = "cm-script-"
configVolumePrefix = "cm-config-"

scriptConfigField = "scripts"
formatterConfigField = "formatterConfig"

Expand All @@ -55,6 +54,14 @@ const (
configManagerCMPrefix = "sidecar-"
)

const (
KBScriptVolumePath = "/opt/kb-tools/reload"
KBConfigVolumePath = "/opt/kb-tools/config"

KBTOOLSScriptsPathEnv = "TOOLS_SCRIPTS_PATH"
KBConfigManagerPathEnv = "TOOLS_PATH"
)

const KBConfigSpecLazyRenderedYamlFile = "lazy-rendered-config.yaml"

func BuildConfigManagerContainerParams(cli client.Client, ctx context.Context, managerParams *CfgManagerBuildParams, volumeDirs []corev1.VolumeMount) error {
Expand Down Expand Up @@ -401,7 +408,7 @@ func checkAndUpdateReloadYaml(data map[string]string, reloadConfig string, forma
}

func buildCfgManagerScripts(options appsv1alpha1.ScriptConfig, manager *CfgManagerBuildParams, cli client.Client, ctx context.Context, configSpec appsv1alpha1.ComponentConfigSpec) error {
mountPoint := filepath.Join(kbScriptVolumePath, configSpec.Name)
mountPoint := filepath.Join(KBScriptVolumePath, configSpec.Name)
referenceCMKey := client.ObjectKey{
Namespace: options.Namespace,
Name: options.ScriptConfigMapRef,
Expand All @@ -418,11 +425,11 @@ func buildCfgManagerScripts(options appsv1alpha1.ScriptConfig, manager *CfgManag
}

func GetConfigMountPoint(configSpec appsv1alpha1.ComponentConfigSpec) string {
return filepath.Join(kbConfigVolumePath, configSpec.Name)
return filepath.Join(KBConfigVolumePath, configSpec.Name)
}

func GetScriptsMountPoint(configSpec appsv1alpha1.ComponentConfigSpec) string {
return filepath.Join(kbScriptVolumePath, configSpec.Name)
return filepath.Join(KBScriptVolumePath, configSpec.Name)
}

func GetScriptsVolumeName(configSpec appsv1alpha1.ComponentConfigSpec) string {
Expand Down
18 changes: 15 additions & 3 deletions internal/controller/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"path/filepath"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -725,7 +726,7 @@ func BuildRestoreJob(cluster *appsv1alpha1.Cluster, synthesizedComponent *compon
return job, nil
}

func BuildCfgManagerToolsContainer(sidecarRenderedParam *cfgcm.CfgManagerBuildParams, component *component.SynthesizedComponent, toolsMetas []appsv1alpha1.ToolConfig) ([]corev1.Container, error) {
func BuildCfgManagerToolsContainer(sidecarRenderedParam *cfgcm.CfgManagerBuildParams, component *component.SynthesizedComponent, toolsMetas []appsv1alpha1.ToolConfig, toolsMap map[string]cfgcm.ConfigSpecMeta) ([]corev1.Container, error) {
toolContainers := make([]corev1.Container, 0, len(toolsMetas))
for _, toolConfig := range toolsMetas {
toolContainer := corev1.Container{
Expand All @@ -740,14 +741,25 @@ func BuildCfgManagerToolsContainer(sidecarRenderedParam *cfgcm.CfgManagerBuildPa
toolContainers = append(toolContainers, toolContainer)
}
for i := range toolContainers {
if err := injectEnvs(sidecarRenderedParam.Cluster, component, sidecarRenderedParam.EnvConfigName, &toolContainers[i]); err != nil {
container := &toolContainers[i]
if err := injectEnvs(sidecarRenderedParam.Cluster, component, sidecarRenderedParam.EnvConfigName, container); err != nil {
return nil, err
}
injectZeroResourcesLimitsIfEmpty(&toolContainers[i])
injectZeroResourcesLimitsIfEmpty(container)
if meta, ok := toolsMap[container.Name]; ok {
setToolsScriptsPath(container, meta)
}
}
return toolContainers, nil
}

func setToolsScriptsPath(container *corev1.Container, meta cfgcm.ConfigSpecMeta) {
container.Env = append(container.Env, corev1.EnvVar{
Name: cfgcm.KBTOOLSScriptsPathEnv,
Value: filepath.Join(cfgcm.KBScriptVolumePath, meta.ConfigSpec.Name),
})
}

func BuildVolumeSnapshotClass(name string, driver string) (*snapshotv1.VolumeSnapshotClass, error) {
const tplFile = "volumesnapshotclass.cue"
vsc := &snapshotv1.VolumeSnapshotClass{}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ var _ = Describe("builder", func() {
{Name: "test-tool", Image: "test-image", Command: []string{"sh"}},
}

obj, err := BuildCfgManagerToolsContainer(cfgManagerParams, synthesizedComponent, toolContainers)
obj, err := BuildCfgManagerToolsContainer(cfgManagerParams, synthesizedComponent, toolContainers, map[string]cfgcm.ConfigSpecMeta{})
Expect(err).Should(BeNil())
Expect(obj).ShouldNot(BeEmpty())
})
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/plan/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func updateEnvPath(container *corev1.Container, params *cfgcm.CfgManagerBuildPar
}
if len(scriptPath) != 0 {
container.Env = append(container.Env, corev1.EnvVar{
Name: "TOOLS_PATH",
Name: cfgcm.KBConfigManagerPathEnv,
Value: strings.Join(scriptPath, ":"),
})
}
Expand Down
9 changes: 4 additions & 5 deletions internal/controller/plan/tool_image_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
cfgcm "github.com/apecloud/kubeblocks/internal/configuration/config_manager"
cfgutil "github.com/apecloud/kubeblocks/internal/configuration/util"
"github.com/apecloud/kubeblocks/internal/constant"
"github.com/apecloud/kubeblocks/internal/controller/builder"
"github.com/apecloud/kubeblocks/internal/controller/component"
Expand All @@ -46,16 +45,16 @@ func buildConfigToolsContainer(cfgManagerParams *cfgcm.CfgManagerBuildParams, po

// construct config manager tools volume
toolContainers := make([]appsv1alpha1.ToolConfig, 0)
toolSets := cfgutil.NewSet()
toolsMap := make(map[string]cfgcm.ConfigSpecMeta)
for _, buildParam := range cfgManagerParams.ConfigSpecsBuildParams {
if buildParam.ToolsImageSpec == nil {
continue
}
for _, toolConfig := range buildParam.ToolsImageSpec.ToolConfigs {
if !toolSets.InArray(toolConfig.Name) {
if _, ok := toolsMap[toolConfig.Name]; !ok {
replaceToolsImageHolder(&toolConfig, podSpec, buildParam.ConfigSpec.VolumeName)
toolContainers = append(toolContainers, toolConfig)
toolSets.Add(toolConfig.Name)
toolsMap[toolConfig.Name] = buildParam
}
}
buildToolsVolumeMount(cfgManagerParams, podSpec, buildParam.ConfigSpec.VolumeName, buildParam.ToolsImageSpec.MountPoint)
Expand All @@ -67,7 +66,7 @@ func buildConfigToolsContainer(cfgManagerParams *cfgcm.CfgManagerBuildParams, po
return nil
}

containers, err := builder.BuildCfgManagerToolsContainer(cfgManagerParams, comp, toolContainers)
containers, err := builder.BuildCfgManagerToolsContainer(cfgManagerParams, comp, toolContainers, toolsMap)
if err == nil {
cfgManagerParams.ToolsContainers = containers
}
Expand Down

0 comments on commit 6b25171

Please sign in to comment.