Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/Masterminds/semver/v3 v3.3.0
github.com/NimbleMarkets/ntcharts v0.1.2
github.com/apecloud/dbctl v0.0.0-20240827084000-68a1980b1a46
github.com/apecloud/kubeblocks v1.1.0-beta.5
github.com/apecloud/kubeblocks v1.2.0-alpha.2
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
github.com/briandowns/spinner v1.23.0
github.com/chaos-mesh/chaos-mesh/api v0.0.0-20230912020346-a5d89c1c90ad
Expand Down Expand Up @@ -71,7 +71,7 @@ require (
k8s.io/client-go v12.0.0+incompatible
k8s.io/component-base v0.33.3
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.130.1
k8s.io/klog/v2 v2.140.0
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff
k8s.io/kubectl v0.33.3
k8s.io/metrics v0.29.14
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@ github.com/apecloud/dbctl v0.0.0-20240827084000-68a1980b1a46 h1:+Jcc7IjDGxPgIfIk
github.com/apecloud/dbctl v0.0.0-20240827084000-68a1980b1a46/go.mod h1:eksJtZ7z1nVcVLqDzAdcN5EfpHwXllIAvHZEks2zWys=
github.com/apecloud/kubeblocks v1.1.0-beta.5 h1:a3Jng19OOquH12SqqEBi/pd6fMAeD01NCInLZe9nTP4=
github.com/apecloud/kubeblocks v1.1.0-beta.5/go.mod h1:vx9p2tv5x4NZiShUvl1MXVl9RO343Bu1nCpbAKdcA6k=
github.com/apecloud/kubeblocks v1.2.0-alpha.2 h1:dHfjbAc8u59TPbi7Rrqqn7PdgglI7ihryXNnR04Oh2A=
github.com/apecloud/kubeblocks v1.2.0-alpha.2/go.mod h1:w00VNDQqlqrjz4GGCE48hvJjAKfdzx83V7mkZAxJPIg=
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
Expand Down Expand Up @@ -2685,6 +2687,8 @@ k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc=
k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0=
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff h1:/usPimJzUKKu+m+TE36gUyGcf03XZEP0ZIKgKj35LS4=
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff/go.mod h1:5jIi+8yX4RIb8wk3XwBo5Pq2ccx4FP10ohkbSKCZoK8=
Expand Down
11 changes: 5 additions & 6 deletions pkg/cmd/cluster/config_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
opsv1alpha1 "github.com/apecloud/kubeblocks/apis/operations/v1alpha1"
parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
configctrl "github.com/apecloud/kubeblocks/pkg/parameters"
cfgcm "github.com/apecloud/kubeblocks/pkg/parameters/configmanager"
"github.com/apecloud/kubeblocks/pkg/parameters/core"
"github.com/apecloud/kubeblocks/pkg/parameters/validate"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -111,7 +110,7 @@ func hasSchemaForFile(rctx *ReconfigureContext, configFile string) bool {
if rctx.ConfigRender == nil {
return false
}
return configctrl.GetComponentConfigDescription(&rctx.ConfigRender.Spec, configFile) != nil
return configctrl.GetComponentConfigDescription(configDescriptions(rctx), configFile) != nil
}

func (o *editConfigOptions) runWithConfigConstraints(cfgEditContext *configEditContext, rctx *ReconfigureContext, fn func() error) error {
Expand All @@ -122,7 +121,7 @@ func (o *editConfigOptions) runWithConfigConstraints(cfgEditContext *configEditC
o.CfgFile: cfgEditContext.getEdited(),
}

configPatch, fileUpdated, err := core.CreateConfigPatch(oldVersion, newVersion, rctx.ConfigRender.Spec, true)
configPatch, fileUpdated, err := core.CreateConfigPatch(oldVersion, newVersion, configDescriptions(rctx), true)
if err != nil {
return err
}
Expand All @@ -133,7 +132,7 @@ func (o *editConfigOptions) runWithConfigConstraints(cfgEditContext *configEditC

fmt.Fprintf(o.CreateOptions.Out, "Config patch(updated parameters): \n%s\n\n", string(configPatch.UpdateConfig[o.CfgFile]))
if !o.enableDelete {
if err := core.ValidateConfigPatch(configPatch, rctx.ConfigRender.Spec); err != nil {
if err := core.ValidateConfigPatch(configPatch, configDescriptions(rctx)); err != nil {
return err
}
}
Expand All @@ -146,7 +145,7 @@ func (o *editConfigOptions) runWithConfigConstraints(cfgEditContext *configEditC
}

var config *parametersv1alpha1.ComponentConfigDescription
if config = configctrl.GetComponentConfigDescription(&rctx.ConfigRender.Spec, o.CfgFile); config == nil {
if config = configctrl.GetComponentConfigDescription(configDescriptions(rctx), o.CfgFile); config == nil {
return fn()
}
var pd *parametersv1alpha1.ParametersDefinition
Expand Down Expand Up @@ -188,7 +187,7 @@ func generateReconfiguringPrompt(fileUpdated bool, configPatch *core.ConfigPatch
}

confirmPrompt := confirmApplyReconfigurePrompt
if !dynamicUpdated || !cfgcm.IsSupportReload(pd.Spec.ReloadAction) {
if !dynamicUpdated || !supportsDynamicReload(&pd.Spec) {
confirmPrompt = restartConfirmPrompt
}
return confirmPrompt, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cluster/config_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (r *configObserverOptions) printComponentConfigSpecsDescribe(rctx *Reconfig
func (r *configObserverOptions) printComponentExplainConfigure(rctx *ReconfigureContext) error {
for _, pd := range rctx.ParametersDefs {
if rctx.ConfigRender != nil {
config := configctrl.GetComponentConfigDescription(&rctx.ConfigRender.Spec, pd.Spec.FileName)
config := configctrl.GetComponentConfigDescription(configDescriptions(rctx), pd.Spec.FileName)
if config != nil {
fmt.Println("template meta:")
printer.PrintLineWithTabSeparator(
Expand Down
19 changes: 14 additions & 5 deletions pkg/cmd/cluster/config_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/apecloud/kubeblocks/pkg/client/clientset/versioned"
"github.com/apecloud/kubeblocks/pkg/generics"
configctrl "github.com/apecloud/kubeblocks/pkg/parameters"
cfgcm "github.com/apecloud/kubeblocks/pkg/parameters/configmanager"
"github.com/apecloud/kubeblocks/pkg/parameters/core"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericiooptions"
Expand Down Expand Up @@ -137,7 +136,7 @@ func (o *configOpsOptions) Validate() error {
return err
}

classifyParams, err := configctrl.ClassifyComponentParameters(o.KeyValues, rctx.ParametersDefs, rctx.Cmpd.Spec.Configs, tplObjs, rctx.ConfigRender)
classifyParams, err := configctrl.ClassifyComponentParameters(o.KeyValues, rctx.ParametersDefs, rctx.Cmpd.Spec.Configs, tplObjs, configDescriptions(rctx))
if err != nil {
return err
}
Expand All @@ -161,7 +160,7 @@ func (o *configOpsOptions) validateConfigParams(rctx *ReconfigureContext, classi
checkRestart := func(params map[string]*parametersv1alpha1.ParametersInFile) bool {
for file := range params {
match := func(pd *parametersv1alpha1.ParametersDefinition) bool {
return pd.Spec.FileName == file && cfgcm.IsSupportReload(pd.Spec.ReloadAction)
return pd.Spec.FileName == file && supportsDynamicReload(&pd.Spec)
}
if generics.FindFirstFunc(rctx.ParametersDefs, match) < 0 {
return true
Expand All @@ -173,7 +172,7 @@ func (o *configOpsOptions) validateConfigParams(rctx *ReconfigureContext, classi
transform := func(params map[string]*parametersv1alpha1.ParametersInFile) []core.ParamPairs {
var result []core.ParamPairs
for file, ps := range params {
configDescs := configctrl.GetComponentConfigDescriptions(&rctx.ConfigRender.Spec, file)
configDescs := configctrl.GetComponentConfigDescriptions(configDescriptions(rctx), file)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] GetComponentConfigDescriptions now filters by ComponentConfigDescription.TemplateName, but file here is the config file name from map[file]ParametersInFile. For normal PCR entries such as templateName=mysql-config and name=my.cnf, this returns an empty slice, so NewValueManager cannot apply the matched file format transformer before FromStringMap. JSON/YAML/TOML numeric or boolean parameters can then be validated or rendered as strings instead of their schema types. Keep the outer template name from classifyParameters and pass that to this helper.

builder := configctrl.NewValueManager(rctx.ParametersDefs, configDescs)
updatedParams, _ := core.FromStringMap(ps.Parameters, builder.BuildValueTransformer(file))
result = append(result, core.ParamPairs{
Expand All @@ -186,7 +185,7 @@ func (o *configOpsOptions) validateConfigParams(rctx *ReconfigureContext, classi

restart := false
for _, parameters := range classifyParameters {
_, err := configctrl.MergeAndValidateConfigs(mockEmptyData(parameters), transform(parameters), rctx.ParametersDefs, rctx.ConfigRender.Spec.Configs)
_, err := configctrl.MergeAndValidateConfigs(mockEmptyData(parameters), transform(parameters), rctx.ParametersDefs, configDescriptions(rctx))
if err != nil {
return err
}
Expand All @@ -209,6 +208,16 @@ func mockEmptyData(m map[string]*parametersv1alpha1.ParametersInFile) map[string
return r
}

func supportsDynamicReload(pd *parametersv1alpha1.ParametersDefinitionSpec) bool {
if pd == nil {
return false
}
if configctrl.NeedDynamicReloadAction(pd) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] This treats mergeReloadAndRestart=false as evidence that the file can be dynamically reloaded, but the controller does not use that field as the reload capability gate. v1.2 reload is allowed when the matched ComponentFileTemplate.reconfigure exists, or for legacy definitions when spec.reloadAction is valid. With the current check, a ParametersDefinition that only sets mergeReloadAndRestart=false skips kbcli restart confirmation even though the controller falls back to restart; conversely a v1.2 addon using template reconfigure without deprecated reloadAction still gets a restart warning. Please derive the prompt from the matched config template plus legacy reloadAction, not from NeedDynamicReloadAction alone.

return true
}
return pd.ReloadAction != nil && (pd.ReloadAction.AutoTrigger != nil || pd.ReloadAction.ShellTrigger != nil)
}

func fromStringPointerMap(m map[string]string) map[string]*string {
r := make(map[string]*string, len(m))
for key, value := range m {
Expand Down
16 changes: 16 additions & 0 deletions pkg/cmd/cluster/config_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"

kbappsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
kbfakeclient "github.com/apecloud/kubeblocks/pkg/client/clientset/versioned/fake"
cfgcore "github.com/apecloud/kubeblocks/pkg/parameters/core"
testapps "github.com/apecloud/kubeblocks/pkg/testutil/apps"
Expand Down Expand Up @@ -120,6 +121,21 @@ var _ = Describe("reconfigure test", func() {
Expect(o.Validate()).Should(Succeed())
})

It("detects v1.2 and legacy dynamic reload support", func() {
mergeReloadAndRestart := false
Expect(supportsDynamicReload(&parametersv1alpha1.ParametersDefinitionSpec{
MergeReloadAndRestart: &mergeReloadAndRestart,
})).Should(BeTrue())

Expect(supportsDynamicReload(&parametersv1alpha1.ParametersDefinitionSpec{
ReloadAction: &parametersv1alpha1.ReloadAction{
ShellTrigger: &parametersv1alpha1.ShellTrigger{},
},
})).Should(BeTrue())

Expect(supportsDynamicReload(&parametersv1alpha1.ParametersDefinitionSpec{})).Should(BeFalse())
})

})

func setConfigMapData(key string, value string) func(*corev1.ConfigMap) {
Expand Down
9 changes: 8 additions & 1 deletion pkg/cmd/cluster/config_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (w *ReconfigureWrapper) ConfigSpecName() string {
}
file := w.ConfigFile()
if file != "" && w.rctx.ConfigRender != nil {
config := configctrl.GetComponentConfigDescription(&w.rctx.ConfigRender.Spec, file)
config := configctrl.GetComponentConfigDescription(configDescriptions(w.rctx), file)
if config != nil {
return config.TemplateName
}
Expand All @@ -83,6 +83,13 @@ func (w *ReconfigureWrapper) ConfigFile() string {
return ""
}

func configDescriptions(rctx *ReconfigureContext) []parametersv1alpha1.ComponentConfigDescription {
if rctx == nil || rctx.ConfigRender == nil {
return nil
}
return rctx.ConfigRender.Spec.Configs
}

func GetClientFromOptionsOrDie(factory cmdutil.Factory) versioned.Interface {
config, err := factory.ToRESTConfig()
if err != nil {
Expand Down
Loading