Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: compatible sharding and instance #318

Merged
merged 5 commits into from
Apr 23, 2024
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
1 change: 1 addition & 0 deletions docs/user_docs/cli/kbcli_cluster_configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ kbcli cluster configure NAME --set key=value[,key=value] [--components=component
-o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml)
--replace Boolean flag to enable replacing config file. Default with false.
--set strings Specify parameters list to be updated. For more details, refer to 'kbcli cluster describe-config'.
--shardings strings sharding names to this operations
--ttlSecondsAfterSucceed int Time to live after the OpsRequest succeed
```

Expand Down
1 change: 1 addition & 0 deletions docs/user_docs/cli/kbcli_cluster_edit-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ kbcli cluster edit-config NAME [--component=component-name] [--config-spec=confi
-o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml)
--replace Boolean flag to enable replacing config file. Default with false.
--set strings Specify parameters list to be updated. For more details, refer to 'kbcli cluster describe-config'.
--shardings strings sharding names to this operations
--ttlSecondsAfterSucceed int Time to live after the OpsRequest succeed
```

Expand Down
1 change: 1 addition & 0 deletions docs/user_docs/cli/kbcli_cluster_expose.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ kbcli cluster expose NAME --enable=[true|false] --type=[vpc|internet] [flags]
-h, --help help for expose
--name string OpsRequest name. if not specified, it will be randomly generated
-o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml)
--shardings strings sharding names to this operations
--ttlSecondsAfterSucceed int Time to live after the OpsRequest succeed
--type string Expose type, currently supported types are 'vpc', 'internet'
```
Expand Down
1 change: 1 addition & 0 deletions docs/user_docs/cli/kbcli_cluster_hscale.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ kbcli cluster hscale NAME [flags]
--name string OpsRequest name. if not specified, it will be randomly generated
-o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml)
--replicas int Replicas with the specified components
--shardings strings sharding names to this operations
--ttlSecondsAfterSucceed int Time to live after the OpsRequest succeed
```

Expand Down
1 change: 1 addition & 0 deletions docs/user_docs/cli/kbcli_cluster_restart.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ kbcli cluster restart NAME [flags]
-h, --help help for restart
--name string OpsRequest name. if not specified, it will be randomly generated
-o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml)
--shardings strings sharding names to this operations
--ttlSecondsAfterSucceed int Time to live after the OpsRequest succeed
```

Expand Down
1 change: 1 addition & 0 deletions docs/user_docs/cli/kbcli_cluster_volume-expand.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ kbcli cluster volume-expand NAME [flags]
-h, --help help for volume-expand
--name string OpsRequest name. if not specified, it will be randomly generated
-o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml)
--shardings strings sharding names to this operations
--storage string Volume storage size (required)
--ttlSecondsAfterSucceed int Time to live after the OpsRequest succeed
-t, --volume-claim-templates strings VolumeClaimTemplate names in components (required)
Expand Down
1 change: 1 addition & 0 deletions docs/user_docs/cli/kbcli_cluster_vscale.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ kbcli cluster vscale NAME [flags]
--memory string Request and limit size of component memory
--name string OpsRequest name. if not specified, it will be randomly generated
-o, --output format Prints the output in the specified format. Allowed values: JSON and YAML (default yaml)
--shardings strings sharding names to this operations
--ttlSecondsAfterSucceed int Time to live after the OpsRequest succeed
```

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuW
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h1:7RFfzj4SSt6nnvCPbCqijJi1nWCd+TqAT3bYCStRC18=
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/kubebench v0.0.0-20240327101848-6a031d3f4ebe h1:OFkCAToRcNt0VqgCndw0mw1Ke3P2XgRJLrXsNOyc3sQ=
github.com/apecloud/kubebench v0.0.0-20240327101848-6a031d3f4ebe/go.mod h1:5IZiDkFdgiZRGLsL+FOlvPsiF9LbyU55DVj4/5vT7+4=
github.com/apecloud/kubeblocks v0.9.0-beta.1 h1:spCqfGH53vXVQhrvemZeSGJpx+D60TJ36PGVJvCXENQ=
Expand Down
88 changes: 80 additions & 8 deletions pkg/action/template/cluster_operations_template.cue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ options: {
component: string
instance: string
componentNames: [...string]
shardingNames: [...string]
rebuildInstanceFrom: [
...{
componentName: string
Expand Down Expand Up @@ -110,18 +111,32 @@ content: {
name: vctName
storage: options.storage
}]
}]
},
for _, sName in options.shardingNames {
shardingName: sName
volumeClaimTemplates: [ for _, vctName in options.vctNames {
name: vctName
storage: options.storage
}]
}]
}
if options.type == "HorizontalScaling" {
horizontalScaling: [ for _, cName in options.componentNames {
componentName: cName
replicas: options.replicas
}]
},
for _, sName in options.shardingNames {
shardingName: sName
replicas: options.replicas
}]
}
if options.type == "Restart" {
restart: [ for _, cName in options.componentNames {
componentName: cName
}]
},
for _, sName in options.shardingNames {
shardingName: sName
}]
}
if options.type == "VerticalScaling" {
verticalScaling: [ for _, cName in options.componentNames {
Expand All @@ -142,7 +157,26 @@ content: {
cpu: options.cpu
}
}
}]
},
for _, sName in options.shardingNames {
shardingName: sName
requests: {
if options.memory != "" {
memory: options.memory
}
if options.cpu != "" {
cpu: options.cpu
}
}
limits: {
if options.memory != "" {
memory: options.memory
}
if options.cpu != "" {
cpu: options.cpu
}
}
}]
}
if options.type == "Reconfiguring" {
if len(options.componentNames) == 1 {
Expand Down Expand Up @@ -189,7 +223,28 @@ content: {
}
}]
}]
}]
},
for _, sName in options.shardingNames {
shardName: sName
configurations: [ {
name: options.cfgTemplateName
if options.forceRestart {
policy: "simple"
}
keys: [{
key: options.cfgFile
if options.fileContent != "" {
fileContent: options.fileContent
}
if options.hasPatch {
parameters: [ for k, v in options.keyValues {
key: k
value: v
}]
}
}]
}]
}]
}
}
if options.type == "Expose" {
Expand All @@ -209,7 +264,24 @@ content: {
}

}]
}]
},
for _, sName in options.shardingNames {
shardName: sName
if options.exposeEnabled == "true" {
switch: "Enable"
}
if options.exposeEnabled == "false" {
switch: "Disable"
}
services: [ for _, svc in options.services {
name: svc.name
serviceType: svc.serviceType
if len(svc.annotations) > 0 {
annotations: svc.annotations
}

}]
}]
}
if options.type == "Switchover" {
switchover: [{
Expand All @@ -233,9 +305,9 @@ content: {
if options.type == "Custom" {
customSpec: {
opsDefinitionRef: options.opsDefinitionName
components: [
items: [
{
name: options.component
componentName: options.component
parameters: options.params
}
]
Expand Down
38 changes: 21 additions & 17 deletions pkg/cmd/cluster/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ import (
const oceanbase = "oceanbase"

type OperationsOptions struct {
action.CreateOptions `json:"-"`
HasComponentNamesFlag bool `json:"-"`
action.CreateOptions `json:"-"`
HasCompNamesOrShardingNamesFlag bool `json:"-"`
// AutoApprove when set true, skip the double check.
AutoApprove bool `json:"-"`
ComponentNames []string `json:"componentNames,omitempty"`
ShardingNames []string `json:"shardingNames,omitempty"`
OpsRequestName string `json:"opsRequestName"`
TTLSecondsAfterSucceed int `json:"ttlSecondsAfterSucceed"`
Force bool `json:"force"`
Expand Down Expand Up @@ -117,7 +118,7 @@ type OperationsOptions struct {
}

func newBaseOperationsOptions(f cmdutil.Factory, streams genericiooptions.IOStreams,
opsType appsv1alpha1.OpsType, hasComponentNamesFlag bool) *OperationsOptions {
opsType appsv1alpha1.OpsType, hasCompNamesOrShardingNamesFlag bool) *OperationsOptions {
customOutPut := func(opt *action.CreateOptions) {
output := fmt.Sprintf("OpsRequest %s created successfully, you can view the progress:", opt.Name)
printer.PrintLine(output)
Expand All @@ -127,11 +128,11 @@ func newBaseOperationsOptions(f cmdutil.Factory, streams genericiooptions.IOStre

o := &OperationsOptions{
// nil cannot be set to a map struct in CueLang, so init the map of KeyValues.
KeyValues: map[string]*string{},
HasPatch: true,
OpsType: opsType,
HasComponentNamesFlag: hasComponentNamesFlag,
AutoApprove: false,
KeyValues: map[string]*string{},
HasPatch: true,
OpsType: opsType,
HasCompNamesOrShardingNamesFlag: hasCompNamesOrShardingNamesFlag,
AutoApprove: false,
CreateOptions: action.CreateOptions{
Factory: f,
IOStreams: streams,
Expand All @@ -155,8 +156,9 @@ func (o *OperationsOptions) addCommonFlags(cmd *cobra.Command, f cmdutil.Factory
cmd.Flags().IntVar(&o.TTLSecondsAfterSucceed, "ttlSecondsAfterSucceed", 0, "Time to live after the OpsRequest succeed")
cmd.Flags().StringVar(&o.DryRun, "dry-run", "none", `Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent.`)
cmd.Flags().Lookup("dry-run").NoOptDefVal = "unchanged"
if o.HasComponentNamesFlag {
if o.HasCompNamesOrShardingNamesFlag {
flags.AddComponentsFlag(f, cmd, &o.ComponentNames, "Component names to this operations")
cmd.Flags().StringSliceVar(&o.ShardingNames, "shardings", nil, "sharding names to this operations")
}
}

Expand All @@ -166,7 +168,7 @@ func (o *OperationsOptions) CompleteRestartOps() error {
if o.Name == "" {
return makeMissingClusterNameErr()
}
if len(o.ComponentNames) != 0 {
if len(o.ComponentNames) != 0 || len(o.ShardingNames) != 0 {
return nil
}
clusterObj, err := cluster.GetClusterByName(o.Dynamic, o.Name, o.Namespace)
Expand All @@ -178,6 +180,9 @@ func (o *OperationsOptions) CompleteRestartOps() error {
for i := range componentSpecs {
o.ComponentNames[i] = componentSpecs[i].Name
}
for i := range clusterObj.Spec.ShardingSpecs {
o.ShardingNames = append(o.ShardingNames, clusterObj.Spec.ShardingSpecs[i].Name)
}
return nil
}

Expand Down Expand Up @@ -422,8 +427,8 @@ func (o *OperationsOptions) Validate() error {
}

// common validate for componentOps
if o.HasComponentNamesFlag && len(o.ComponentNames) == 0 {
return fmt.Errorf(`missing components, please specify the "--components" flag for multi-components cluster`)
if o.HasCompNamesOrShardingNamesFlag && len(o.ComponentNames) == 0 && len(o.ShardingNames) == 0 {
return fmt.Errorf(`missing components or shardings, please specify the "--components" or "--shardings" flag for the cluster`)
}

switch o.OpsType {
Expand Down Expand Up @@ -696,7 +701,6 @@ func NewUpgradeCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra
o.addCommonFlags(cmd, f)
cmd.Flags().StringVar(&o.ClusterVersionRef, "cluster-version", "", "Reference cluster version (required)")
cmd.Flags().BoolVar(&o.AutoApprove, "auto-approve", false, "Skip interactive approval before upgrading the cluster")
_ = cmd.MarkFlagRequired("cluster-version")
return cmd
}

Expand Down Expand Up @@ -726,7 +730,7 @@ func NewVerticalScalingCmd(f cmdutil.Factory, streams genericiooptions.IOStreams
cmd.Flags().StringVar(&o.CPU, "cpu", "", "Request and limit size of component cpu")
cmd.Flags().StringVar(&o.Memory, "memory", "", "Request and limit size of component memory")
cmd.Flags().BoolVar(&o.AutoApprove, "auto-approve", false, "Skip interactive approval before vertically scaling the cluster")
_ = cmd.MarkFlagRequired("components")
cmd.MarkFlagsOneRequired("components", "shardings")
return cmd
}

Expand Down Expand Up @@ -754,10 +758,10 @@ func NewHorizontalScalingCmd(f cmdutil.Factory, streams genericiooptions.IOStrea
}

o.addCommonFlags(cmd, f)
cmd.Flags().IntVar(&o.Replicas, "replicas", o.Replicas, "Replicas with the specified components")
cmd.Flags().IntVar(&o.Replicas, "replicas", 0, "Replicas with the specified components")
cmd.Flags().BoolVar(&o.AutoApprove, "auto-approve", false, "Skip interactive approval before horizontally scaling the cluster")
_ = cmd.MarkFlagRequired("replicas")
_ = cmd.MarkFlagRequired("components")
cmd.MarkFlagsOneRequired("components", "shardings")
return cmd
}

Expand Down Expand Up @@ -789,7 +793,7 @@ func NewVolumeExpansionCmd(f cmdutil.Factory, streams genericiooptions.IOStreams
cmd.Flags().BoolVar(&o.AutoApprove, "auto-approve", false, "Skip interactive approval before expanding the cluster volume")
_ = cmd.MarkFlagRequired("volume-claim-templates")
_ = cmd.MarkFlagRequired("storage")
_ = cmd.MarkFlagRequired("components")
cmd.MarkFlagsOneRequired("components", "shardings")
return cmd
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cluster/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var _ = Describe("operations", func() {
}
o := initCommonOperationOps(appsv1alpha1.VolumeExpansionType, clusterName, true, persistentVolumeClaim)
By("validate volumeExpansion when components is null")
Expect(o.Validate()).To(MatchError(`missing components, please specify the "--components" flag for multi-components cluster`))
Expect(o.Validate()).To(MatchError(`missing components or shardings, please specify the "--components" or "--shardings" flag for the cluster`))

By("validate volumeExpansion when vct-names is null")
o.ComponentNames = []string{compName}
Expand Down
Loading