From 4ebe037355639c5f9a4350ac425667c2d2cec6c1 Mon Sep 17 00:00:00 2001 From: mengyipeng <413183498@qq.com> Date: Thu, 29 Aug 2024 16:30:50 +0800 Subject: [PATCH 1/2] support create sharding cluster --- pkg/cmd/cluster/create_subcmds.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/cluster/create_subcmds.go b/pkg/cmd/cluster/create_subcmds.go index dc8407ba5..8496b8257 100644 --- a/pkg/cmd/cluster/create_subcmds.go +++ b/pkg/cmd/cluster/create_subcmds.go @@ -133,10 +133,10 @@ func (o *CreateSubCmdsOptions) complete(cmd *cobra.Command) error { if !ok { return fmt.Errorf("cannot find spec in cluster object") } + if o.ChartInfo.ComponentDef == nil { + o.ChartInfo.ComponentDef = []string{} + } if compSpec, ok := spec["componentSpecs"].([]interface{}); ok { - if o.ChartInfo.ComponentDef == nil { - o.ChartInfo.ComponentDef = []string{} - } for i := range compSpec { comp := compSpec[i].(map[string]interface{}) if compDef, ok := comp["componentDef"]; ok { @@ -144,11 +144,20 @@ func (o *CreateSubCmdsOptions) complete(cmd *cobra.Command) error { } } } + if shardingSpec, ok := spec["shardingSpecs"].([]interface{}); ok { + for i := range shardingSpec { + shard := shardingSpec[i].(map[string]interface{}) + compSpec := shard["template"].(map[string]interface{}) + if compDef, ok := compSpec["componentDef"]; ok { + o.ChartInfo.ComponentDef = append(o.ChartInfo.ComponentDef, compDef.(string)) + } + } + } if clusterDef, ok := spec["clusterDefinitionRef"].(string); ok { o.ChartInfo.ClusterDef = clusterDef } if o.ChartInfo.ClusterDef == "" && len(o.ChartInfo.ComponentDef) == 0 { - return fmt.Errorf("cannot find clusterDefinitionRef in cluster spec or componentDef in componentSpecs") + return fmt.Errorf("cannot find clusterDefinitionRef in cluster spec or componentDef in componentSpecs or shardingSpecs") } return nil From b0dea8830166b537704e35a2b17aca7716a9d056 Mon Sep 17 00:00:00 2001 From: mengyipeng <413183498@qq.com> Date: Thu, 29 Aug 2024 16:34:43 +0800 Subject: [PATCH 2/2] fix --- pkg/cmd/cluster/create_subcmds.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/cluster/create_subcmds.go b/pkg/cmd/cluster/create_subcmds.go index 8496b8257..c89c75cc6 100644 --- a/pkg/cmd/cluster/create_subcmds.go +++ b/pkg/cmd/cluster/create_subcmds.go @@ -147,9 +147,10 @@ func (o *CreateSubCmdsOptions) complete(cmd *cobra.Command) error { if shardingSpec, ok := spec["shardingSpecs"].([]interface{}); ok { for i := range shardingSpec { shard := shardingSpec[i].(map[string]interface{}) - compSpec := shard["template"].(map[string]interface{}) - if compDef, ok := compSpec["componentDef"]; ok { - o.ChartInfo.ComponentDef = append(o.ChartInfo.ComponentDef, compDef.(string)) + if compSpec, ok := shard["template"].(map[string]interface{}); ok { + if compDef, ok := compSpec["componentDef"]; ok { + o.ChartInfo.ComponentDef = append(o.ChartInfo.ComponentDef, compDef.(string)) + } } } }