Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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.0.0-beta.35
github.com/apecloud/kubeblocks v1.0.0-beta.45
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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,8 @@ github.com/apache/arrow/go/v11 v11.0.0/go.mod h1:Eg5OsL5H+e299f7u5ssuXsuHQVEGC4x
github.com/apache/thrift v0.16.0/go.mod h1:PHK3hniurgQaNMZYaCLEqXKsYK8upmhPbmdP2FXSqgU=
github.com/apecloud/dbctl v0.0.0-20240827084000-68a1980b1a46 h1:+Jcc7IjDGxPgIfIkGX2Q5Yxj35U65zgcfjh0B9rDhjo=
github.com/apecloud/dbctl v0.0.0-20240827084000-68a1980b1a46/go.mod h1:eksJtZ7z1nVcVLqDzAdcN5EfpHwXllIAvHZEks2zWys=
github.com/apecloud/kubeblocks v1.0.0-beta.35 h1:S+Zd3Bzo72lfo/VY3dct1wPHC+rHYVFz1bnHqy79mlo=
github.com/apecloud/kubeblocks v1.0.0-beta.35/go.mod h1:Mk5xRLm2MpxoTNZKEdDcrIY3I1EpokQBU3Q9Zwse8MI=
github.com/apecloud/kubeblocks v1.0.0-beta.45 h1:Q+1ctqex9qlPe1XhoFe8N59/hh8+DbWC9WUX1xBEnNA=
github.com/apecloud/kubeblocks v1.0.0-beta.45/go.mod h1:Mk5xRLm2MpxoTNZKEdDcrIY3I1EpokQBU3Q9Zwse8MI=
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
28 changes: 14 additions & 14 deletions pkg/cmd/addon/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ func newListCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Co
Use: "list",
Short: "List addons.",
Aliases: []string{"ls"},
ValidArgsFunction: util.ResourceNameCompletionFunc(f, o.GVR),
ValidArgsFunction: util.ResourceNameCompletionFunc(f, o.ListOptions.GVR),
Run: func(cmd *cobra.Command, args []string) {
o.Names = args
o.ListOptions.Names = args
util.CheckErr(addonListRun(o))
},
}
o.AddFlags(cmd, true)
o.ListOptions.AddFlags(cmd, true)
cmd.Flags().StringArrayVar(&o.status, "status", []string{}, "Filter addons by status")
cmd.Flags().BoolVar(&o.listEngines, "engines", false, "List engine addons only")
return cmd
Expand Down Expand Up @@ -225,8 +225,8 @@ func newEnableCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.
util.CheckErr(o.fetchAddonObj())
util.CheckErr(o.validate())
util.CheckErr(o.complete(o, cmd, []string{name}))
util.CheckErr(o.CmdComplete(cmd))
util.CheckErr(o.Run())
util.CheckErr(o.PatchOptions.CmdComplete(cmd))
util.CheckErr(o.PatchOptions.Run())
if isEngineAddon(&o.addon) {
util.CheckErr(clusterCmd.RegisterClusterChart(f, streams, "", name, getAddonVersion(&o.addon), types.ClusterChartsRepoURL))
}
Expand Down Expand Up @@ -293,7 +293,7 @@ func newDisableCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra
util.CheckErr(o.checkBeforeDisable())
util.CheckErr(o.complete(o, cmd, []string{name}))
util.CheckErr(o.CmdComplete(cmd))
util.CheckErr(o.Run())
util.CheckErr(o.PatchOptions.Run())
}
},
}
Expand All @@ -303,7 +303,7 @@ func newDisableCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra
}

func (o *addonCmdOpts) init(args []string) error {
o.Names = args
o.PatchOptions.Names = args
if o.dynamic == nil {
var err error
if o.dynamic, err = o.Factory.DynamicClient(); err != nil {
Expand Down Expand Up @@ -353,7 +353,7 @@ func (o *addonCmdOpts) validate() error {
}
for _, s := range o.addon.Spec.Installable.Selectors {
if !s.MatchesFromConfig() {
return fmt.Errorf("addon %s INSTALLABLE-SELECTOR has no matching requirement", o.Names)
return fmt.Errorf("addon %s INSTALLABLE-SELECTOR has no matching requirement", o.PatchOptions.Names)
}
}

Expand Down Expand Up @@ -819,20 +819,20 @@ func (o *addonCmdOpts) buildPatch(flags []*pflag.Flag) error {
if err != nil {
return err
}
o.Patch = string(bytes)
o.PatchOptions.Patch = string(bytes)
return nil
}

func addonListRun(o *addonListOpts) error {
// if format is JSON or YAML, use default printer to output the result.
if o.Format == printer.JSON || o.Format == printer.YAML {
_, err := o.Run()
if o.ListOptions.Format == printer.JSON || o.ListOptions.Format == printer.YAML {
_, err := o.ListOptions.Run()
return err
}

// get and output the result
o.Print = false
r, err := o.Run()
o.ListOptions.Print = false
r, err := o.ListOptions.Run()
if err != nil {
return err
}
Expand Down Expand Up @@ -921,7 +921,7 @@ func addonListRun(o *addonListOpts) error {
return nil
}

if o.Format == printer.Wide {
if o.ListOptions.Format == printer.Wide {
if err = printer.PrintTable(o.Out, nil, printRows,
"NAME", "VERSION", "PROVIDER", "STATUS", "AUTO-INSTALL", "AUTO-INSTALLABLE-SELECTOR", "EXTRAS"); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/addon/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func uniqueByName(objects []searchResult) []searchResult {
func checkAddonInstalled(objects *[]searchResult, o *addonListOpts) error {
// list installed addons
var installedAddons []string
o.Print = false
o.ListOptions.Print = false
// get and output the result
o.Print = false
o.ListOptions.Print = false
r, _ := o.Run()
if r == nil {
return nil
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/backuprepo/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func newListCommand(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobr
Example: listExample,
ValidArgsFunction: util.ResourceNameCompletionFunc(f, types.BackupRepoGVR()),
Run: func(cmd *cobra.Command, args []string) {
o.Names = args
o.ListOptions.Names = args
cmdutil.CheckErr(o.Complete())
cmdutil.CheckErr(printBackupRepoList(o))
},
Expand All @@ -74,7 +74,7 @@ func newListCommand(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobr

func (o *listBackupRepoOptions) Complete() error {
var err error
o.dynamic, err = o.Factory.DynamicClient()
o.dynamic, err = o.ListOptions.Factory.DynamicClient()
if err != nil {
return err
}
Expand All @@ -83,14 +83,14 @@ func (o *listBackupRepoOptions) Complete() error {

func printBackupRepoList(o *listBackupRepoOptions) error {
// if format is JSON or YAML, use default printer to output the result.
if o.Format == printer.JSON || o.Format == printer.YAML {
if o.ListOptions.Format == printer.JSON || o.ListOptions.Format == printer.YAML {
_, err := o.Run()
return err
}

backupRepoList, err := o.dynamic.Resource(types.BackupRepoGVR()).List(context.TODO(), metav1.ListOptions{
LabelSelector: o.LabelSelector,
FieldSelector: o.FieldSelector,
LabelSelector: o.ListOptions.LabelSelector,
FieldSelector: o.ListOptions.FieldSelector,
})
if err != nil {
return err
Expand Down Expand Up @@ -140,7 +140,7 @@ func printBackupRepoList(o *listBackupRepoOptions) error {
return nil
}

if err = printer.PrintTable(o.Out, nil, printRows,
if err = printer.PrintTable(o.ListOptions.Out, nil, printRows,
"NAME", "STATUS", "STORAGE-PROVIDER", "ACCESS-METHOD", "DEFAULT", "BACKUPS", "TOTAL-SIZE"); err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/cluster/config_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var (

func (o *editConfigOptions) Run(fn func() error) error {
wrapper := o.wrapper
cfgEditContext := newConfigContext(o.CreateOptions, o.Name, wrapper.ComponentName(), wrapper.ConfigSpecName(), wrapper.ConfigFile())
cfgEditContext := newConfigContext(o.CreateOptions, o.CreateOptions.Name, wrapper.ComponentName(), wrapper.ConfigSpecName(), wrapper.ConfigFile())
if err := cfgEditContext.prepare(); err != nil {
return err
}
Expand All @@ -88,7 +88,7 @@ func (o *editConfigOptions) Run(fn func() error) error {
fmt.Println("Edit cancelled, no changes made.")
return nil
}
util.DisplayDiffWithColor(o.IOStreams.Out, diff)
util.DisplayDiffWithColor(o.CreateOptions.IOStreams.Out, diff)

if hasSchemaForFile(wrapper.rctx, wrapper.ConfigFile()) {
return o.runWithConfigConstraints(cfgEditContext, wrapper.rctx, fn)
Expand Down Expand Up @@ -131,7 +131,7 @@ func (o *editConfigOptions) runWithConfigConstraints(cfgEditContext *configEditC
return nil
}

fmt.Fprintf(o.Out, "Config patch(updated parameters): \n%s\n\n", string(configPatch.UpdateConfig[o.CfgFile]))
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 {
return err
Expand Down Expand Up @@ -199,14 +199,14 @@ func (o *editConfigOptions) confirmReconfigure(promptStr string) (bool, error) {
const noStr = "no"

confirmStr := []string{yesStr, noStr}
printer.Warning(o.Out, promptStr)
printer.Warning(o.CreateOptions.Out, promptStr)
input, err := prompt.NewPrompt("Please type [Yes/No] to confirm:",
func(input string) error {
if !slices.Contains(confirmStr, strings.ToLower(input)) {
return fmt.Errorf("typed \"%s\" does not match \"%s\"", input, confirmStr)
}
return nil
}, o.In).Run()
}, o.CreateOptions.In).Run()
if err != nil {
return false, err
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func NewEditConfigureCmd(f cmdutil.Factory, streams genericiooptions.IOStreams)
Example: editConfigExample,
ValidArgsFunction: util.ResourceNameCompletionFunc(f, types.ClusterGVR()),
Run: func(cmd *cobra.Command, args []string) {
o.Args = args
o.CreateOptions.Args = args
cmdutil.CheckErr(o.CreateOptions.Complete())
util.CheckErr(o.Complete())
util.CheckErr(o.Validate())
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 @@ -113,7 +113,7 @@ func (r *configObserverOptions) printComponentConfigSpecsDescribe(rctx *Reconfig
resolveParameterTemplate := func(tpl string) string {
for _, config := range rctx.Cmpd.Spec.Configs {
if config.Name == tpl {
return config.TemplateRef
return config.Template
}
}
return ""
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/cluster/config_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ func (o *configOpsOptions) Validate() error {
return err
}

classifyParams := configctrl.ClassifyComponentParameters(o.KeyValues, rctx.ParametersDefs, rctx.Cmpd.Spec.Configs, tplObjs)
classifyParams, err := configctrl.ClassifyComponentParameters(o.KeyValues, rctx.ParametersDefs, rctx.Cmpd.Spec.Configs, tplObjs, rctx.ConfigRender)
if err != nil {
return err
}
if err := util.ValidateParametersModified(classifyParams, rctx.ParametersDefs); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cluster/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,15 @@ func resolveConfigTemplate(rctx *ReconfigureContext, dynamic dynamic.Interface)
if _, ok := tplObjs[tpl]; ok {
continue
}
index := generics.FindFirstFunc(rctx.Cmpd.Spec.Configs, func(spec appsv1.ComponentTemplateSpec) bool {
index := generics.FindFirstFunc(rctx.Cmpd.Spec.Configs, func(spec appsv1.ComponentFileTemplate) bool {
return spec.Name == tpl
})
if index < 0 {
return nil, makeConfigSpecNotExistErr(rctx.Cluster.Name, rctx.CompName, tpl)
}
var cm = &corev1.ConfigMap{}
tplMeta := rctx.Cmpd.Spec.Configs[index]
key := client.ObjectKey{Namespace: tplMeta.Namespace, Name: tplMeta.TemplateRef}
key := client.ObjectKey{Namespace: tplMeta.Namespace, Name: tplMeta.Template}
if err := util.GetResourceObjectFromGVR(types.ConfigmapGVR(), key, dynamic, cm); err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/trace/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (o *UpdateOptions) buildPatch() error {
if err != nil {
return err
}
o.Patch = string(bytes)
o.PatchOptions.Patch = string(bytes)
return nil
}

Expand All @@ -86,9 +86,9 @@ func newUpdateCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.
Aliases: []string{"u"},
ValidArgsFunction: util.ResourceNameCompletionFunc(f, types.TraceGVR()),
Run: func(cmd *cobra.Command, args []string) {
o.Names = args
o.PatchOptions.Names = args
util.CheckErr(o.CmdComplete(cmd))
util.CheckErr(o.Run())
util.CheckErr(o.PatchOptions.Run())
},
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/testing/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,12 @@ func FakeCompDef() *kbappsv1.ComponentDefinition {
Reconfigure: &defaultAction,
AccountProvision: &defaultAction,
},
Configs: []kbappsv1.ComponentTemplateSpec{
Configs: []kbappsv1.ComponentFileTemplate{
{
Name: fakeConfigTemplateName,
TemplateRef: FakeMysqlTemplateName,
Namespace: "default",
VolumeName: "for_test",
Name: fakeConfigTemplateName,
Template: FakeMysqlTemplateName,
Namespace: "default",
VolumeName: "for_test",
},
},
}
Expand Down