diff --git a/go.mod b/go.mod index 79ae76874..8f0c2d840 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 293941b71..bd603dac8 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/cmd/addon/addon.go b/pkg/cmd/addon/addon.go index 502918e00..7b7367710 100644 --- a/pkg/cmd/addon/addon.go +++ b/pkg/cmd/addon/addon.go @@ -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 @@ -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)) } @@ -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()) } }, } @@ -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 { @@ -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) } } @@ -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 } @@ -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 diff --git a/pkg/cmd/addon/util.go b/pkg/cmd/addon/util.go index c21cc1dd7..40923b0e0 100644 --- a/pkg/cmd/addon/util.go +++ b/pkg/cmd/addon/util.go @@ -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 diff --git a/pkg/cmd/backuprepo/list.go b/pkg/cmd/backuprepo/list.go index c12cea127..2b4e28226 100644 --- a/pkg/cmd/backuprepo/list.go +++ b/pkg/cmd/backuprepo/list.go @@ -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)) }, @@ -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 } @@ -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 @@ -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 } diff --git a/pkg/cmd/cluster/config_edit.go b/pkg/cmd/cluster/config_edit.go index 067aba045..761c14e9d 100644 --- a/pkg/cmd/cluster/config_edit.go +++ b/pkg/cmd/cluster/config_edit.go @@ -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 } @@ -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) @@ -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 @@ -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 } @@ -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()) diff --git a/pkg/cmd/cluster/config_observer.go b/pkg/cmd/cluster/config_observer.go index 63919f592..b33fb37af 100644 --- a/pkg/cmd/cluster/config_observer.go +++ b/pkg/cmd/cluster/config_observer.go @@ -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 "" diff --git a/pkg/cmd/cluster/config_ops.go b/pkg/cmd/cluster/config_ops.go index 9f3b938a4..a0cb768c4 100644 --- a/pkg/cmd/cluster/config_ops.go +++ b/pkg/cmd/cluster/config_ops.go @@ -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 } diff --git a/pkg/cmd/cluster/config_util.go b/pkg/cmd/cluster/config_util.go index aa46f3489..4594252d4 100644 --- a/pkg/cmd/cluster/config_util.go +++ b/pkg/cmd/cluster/config_util.go @@ -280,7 +280,7 @@ 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 { @@ -288,7 +288,7 @@ func resolveConfigTemplate(rctx *ReconfigureContext, dynamic dynamic.Interface) } 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 } diff --git a/pkg/cmd/trace/update.go b/pkg/cmd/trace/update.go index b366b540b..4c35045fd 100644 --- a/pkg/cmd/trace/update.go +++ b/pkg/cmd/trace/update.go @@ -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 } @@ -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()) }, } diff --git a/pkg/testing/fake.go b/pkg/testing/fake.go index a78b8b479..706415805 100644 --- a/pkg/testing/fake.go +++ b/pkg/testing/fake.go @@ -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", }, }, }