Skip to content

Commit

Permalink
chore: set cluster cv (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldming authored Jul 17, 2024
1 parent 5b21d03 commit b9882b4
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion addons
Submodule addons updated 413 files
2 changes: 1 addition & 1 deletion docs/user_docs/cli/kbcli_cluster_create_elasticsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ kbcli cluster create elasticsearch NAME [flags]
--publicly-accessible Specify whether the cluster can be accessed from the public internet.
--rbac-enabled Specify whether rbac resources will be created by client, otherwise KubeBlocks server will try to create rbac resources.
--replicas int The number of replicas, for single-node mode, the replicas is 1, for multi-node mode, the default replicas is 3. Value range [1, 5]. (default 1)
--service-version string The version of ElasticSearch. (default "8.8.2")
--storage float Storage size, the unit is Gi. Value range [1, 10000]. (default 20)
--tenancy string The tenancy of cluster. Legal values [SharedNode, DedicatedNode]. (default "SharedNode")
--termination-policy string The termination policy of cluster. Legal values [DoNotTerminate, Halt, Delete, WipeOut]. (default "Delete")
--version string The version of ElasticSearch.
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion docs/user_docs/cli/kbcli_cluster_create_qdrant.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ kbcli cluster create qdrant NAME [flags]
--storage-class-name string Storage class name of the data volume
--tenancy string The tenancy of cluster. Legal values [SharedNode, DedicatedNode]. (default "SharedNode")
--termination-policy string The termination policy of cluster. Legal values [DoNotTerminate, Halt, Delete, WipeOut]. (default "Delete")
--version string The version of Qdrant. (default "1.10.0")
--version string The version of Qdrant.
```

### Options inherited from parent commands
Expand Down
5 changes: 3 additions & 2 deletions docs/user_docs/cli/kbcli_cluster_create_xinference.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ kbcli cluster create xinference NAME [flags]

```
--availability-policy string The availability policy of cluster. Legal values [none, node, zone]. (default "node")
--cpu float CPU cores. Value range [0.5, 64]. (default 2)
--cpu float CPU cores. Value range [0, 64].
--cpu-mode Set to true if no GPU is available
--disable-exporter Enable or disable monitor. (default true)
--gpu float GPU cores. Value range [0, 64]. (default 1)
-h, --help help for xinference
--host-network-accessible Specify whether the cluster can be accessed from within the VPC.
--memory float Memory, the unit is Gi. Value range [0.5, 1000]. (default 6)
--memory float Memory, the unit is Gi. Value range [0, 1000].
--publicly-accessible Specify whether the cluster can be accessed from the public internet.
--rbac-enabled Specify whether rbac resources will be created by client, otherwise KubeBlocks server will try to create rbac resources.
--replicas int The number of replicas, for standalone mode, the replicas is 1, for replication mode, the default replicas is 2. Value range [1, 5]. (default 1)
--shm-size string shm size (default "64Mi")
--tenancy string The tenancy of cluster. Legal values [SharedNode, DedicatedNode]. (default "SharedNode")
--termination-policy string The termination policy of cluster. Legal values [DoNotTerminate, Halt, Delete, WipeOut]. (default "Delete")
```
Expand Down
Binary file modified pkg/cluster/charts/apecloud-mysql-cluster.tgz
Binary file not shown.
Binary file modified pkg/cluster/charts/elasticsearch-cluster.tgz
Binary file not shown.
Binary file modified pkg/cluster/charts/kafka-cluster.tgz
Binary file not shown.
Binary file modified pkg/cluster/charts/postgresql-cluster.tgz
Binary file not shown.
45 changes: 45 additions & 0 deletions pkg/cmd/cluster/create_subcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util"

"github.com/apecloud/kbcli/pkg/action"
Expand Down Expand Up @@ -155,10 +156,14 @@ func (o *CreateSubCmdsOptions) complete(cmd *cobra.Command) error {
}

func (o *CreateSubCmdsOptions) validate() error {
if err := o.validateVersion(); err != nil {
return err
}
return cluster.ValidateValues(o.ChartInfo, o.Values)
}

func (o *CreateSubCmdsOptions) Run() error {

objs, err := o.getObjectsInfo()
if err != nil {
return err
Expand Down Expand Up @@ -236,6 +241,46 @@ func (o *CreateSubCmdsOptions) Run() error {
return nil
}

func (o *CreateSubCmdsOptions) validateVersion() error {
var err error
cv, ok := o.Values[cluster.VersionSchemaProp.String()].(string)
if ok && cv != "" {
if err = cluster.ValidateClusterVersion(o.Dynamic, o.ChartInfo.ClusterDef, cv); err == nil {
return nil
}
if err = cluster.ValidateClusterVersionByComponentDef(o.Dynamic, o.ChartInfo.ComponentDef, cv); err == nil {
return nil
}
return fmt.Errorf("cluster version \"%s\" does not exist", cv)
}
if o.ChartInfo.ClusterDef != "" {
cv, _ = cluster.GetDefaultVersion(o.Dynamic, o.ChartInfo.ClusterDef)
}
if len(o.ChartInfo.ComponentDef) != 0 {
cv, _ = cluster.GetDefaultVersionByCompDefs(o.Dynamic, o.ChartInfo.ComponentDef)
}
if cv == "" {
klog.V(1).Info("failed to find default cluster version referencing cluster definition or component definition")
}

// set cluster version
o.Values[cluster.VersionSchemaProp.String()] = cv

dryRun, err := o.GetDryRunStrategy()
if err != nil {
return err
}
// if dryRun is set, run in quiet mode, avoid to output yaml file with the info
if dryRun != action.DryRunNone {
return nil
}

if cv != "" {
fmt.Fprintf(o.Out, "Info: --version is not specified, %s is applied by default.\n", cv)
}
return nil
}

// getObjectsInfo returns all objects in helm charts along with their GVK information.
func (o *CreateSubCmdsOptions) getObjectsInfo() ([]*objectInfo, error) {
// move values that belong to sub chart to sub map
Expand Down

0 comments on commit b9882b4

Please sign in to comment.