diff --git a/go.mod b/go.mod index 810c78269..1f263be7b 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/99designs/keyring v1.2.2 github.com/Masterminds/semver/v3 v3.2.1 github.com/apecloud/kubebench v0.0.0-20240313105909-ba8654f654fc - github.com/apecloud/kubeblocks v0.0.0-20240326022625-78469760d798 + github.com/apecloud/kubeblocks v0.0.0-20240328092917-34c21903b27b github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 github.com/benbjohnson/clock v1.3.5 github.com/briandowns/spinner v1.23.0 diff --git a/go.sum b/go.sum index af69a550e..57a37c6be 100644 --- a/go.sum +++ b/go.sum @@ -272,8 +272,8 @@ github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM= github.com/apecloud/kubebench v0.0.0-20240313105909-ba8654f654fc h1:BkFyEBEmDMdDhkWNAs9yg6zAj7xZjWON2u8b265T2a8= github.com/apecloud/kubebench v0.0.0-20240313105909-ba8654f654fc/go.mod h1:5IZiDkFdgiZRGLsL+FOlvPsiF9LbyU55DVj4/5vT7+4= -github.com/apecloud/kubeblocks v0.0.0-20240326022625-78469760d798 h1:1HKluAKHrdO1l9ETTQVZobB3rYTGjUAeSMq5hK3s34k= -github.com/apecloud/kubeblocks v0.0.0-20240326022625-78469760d798/go.mod h1:nU4ytJVEzPg+n7Py2IDbwPI8k433dsLWSGmn3U0JexU= +github.com/apecloud/kubeblocks v0.0.0-20240328092917-34c21903b27b h1:nLcuqUQDxtD685CqLnnl+4m8YkogJ5p2J20aqofdv3o= +github.com/apecloud/kubeblocks v0.0.0-20240328092917-34c21903b27b/go.mod h1:scOC+CrVliHgn7ZwfKXkoXcTOIynXQhy97dHJLiQF8g= 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/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= diff --git a/pkg/action/template/cluster_operations_template.cue b/pkg/action/template/cluster_operations_template.cue index 66a1788fa..295c77df0 100644 --- a/pkg/action/template/cluster_operations_template.cue +++ b/pkg/action/template/cluster_operations_template.cue @@ -31,7 +31,12 @@ options: { ...{ componentName: string backupName?: string - instanceNames: [...string] + instances: [ + ...{ + name: string + targetNodeName?: string + } + ] envForRestore?: [ ...{ name: string diff --git a/pkg/cmd/cluster/operations.go b/pkg/cmd/cluster/operations.go index 19b84f5ff..3211c3bb7 100755 --- a/pkg/cmd/cluster/operations.go +++ b/pkg/cmd/cluster/operations.go @@ -114,6 +114,7 @@ type OperationsOptions struct { ExecPod *corev1.Pod `json:"-"` BackupName string `json:"-"` InstanceNames []string `json:"-"` + Nodes []string `json:"-"` RebuildInstanceFrom []appsv1alpha1.RebuildInstance `json:"rebuildInstanceFrom,omitempty"` Env []string `json:"-"` } @@ -1258,6 +1259,7 @@ func NewRebuildInstanceCmd(f cmdutil.Factory, streams genericiooptions.IOStreams } compName = insCompName } + // covert envs var envVars []corev1.EnvVar for _, v := range o.Env { for _, envVar := range strings.Split(v, ",") { @@ -1271,12 +1273,28 @@ func NewRebuildInstanceCmd(f cmdutil.Factory, streams genericiooptions.IOStreams }) } } + // covert instances + nodeMap := map[string]string{} + for _, node := range o.Nodes { + kv := strings.Split(node, "=") + if len(kv) != 2 { + return fmt.Errorf("unknown format for node: %s", node) + } + nodeMap[kv[0]] = kv[1] + } + var instances []appsv1alpha1.Instance + for _, insName := range o.InstanceNames { + instances = append(instances, appsv1alpha1.Instance{ + Name: insName, + TargetNodeName: nodeMap[insName], + }) + } o.RebuildInstanceFrom = []appsv1alpha1.RebuildInstance{ { ComponentOps: appsv1alpha1.ComponentOps{ ComponentName: compName, }, - InstanceNames: o.InstanceNames, + Instances: instances, BackupName: o.BackupName, EnvForRestore: envVars, }, @@ -1300,7 +1318,8 @@ func NewRebuildInstanceCmd(f cmdutil.Factory, streams genericiooptions.IOStreams o.addCommonFlags(cmd, f) cmd.Flags().BoolVar(&o.AutoApprove, "auto-approve", false, "Skip interactive approval before rebuilding the instances.gi") cmd.Flags().StringVar(&o.BackupName, "backup", "", "instances will be rebuild by the specified backup.") - cmd.Flags().StringSliceVar(&o.InstanceNames, "instances", nil, "instances which need to rebuild.") + cmd.Flags().StringSliceVar(&o.InstanceNames, "instance", nil, "instance which need to rebuild.") + cmd.Flags().StringSliceVar(&o.Nodes, "node", nil, "specified the target node which rebuilds the instance on the node otherwise will rebuild on a randon node. format: insName1=nodeName,insName2=nodeName") cmd.Flags().StringArrayVar(&o.Env, "env", []string{}, "provide the necessary env for the 'Restore' operation from the backup. format: key1=value, key2=value") return cmd } diff --git a/pkg/testing/fake.go b/pkg/testing/fake.go index 1979c7df0..47d94f688 100644 --- a/pkg/testing/fake.go +++ b/pkg/testing/fake.go @@ -451,8 +451,8 @@ func FakeCompDef() *appsv1alpha1.ComponentDefinition { MemberLeave: defaultLifecycleActionHandler, Readonly: defaultLifecycleActionHandler, Readwrite: defaultLifecycleActionHandler, - DataPopulate: defaultLifecycleActionHandler, - DataAssemble: defaultLifecycleActionHandler, + DataDump: defaultLifecycleActionHandler, + DataLoad: defaultLifecycleActionHandler, Reconfigure: defaultLifecycleActionHandler, AccountProvision: defaultLifecycleActionHandler, },