Skip to content

Commit

Permalink
add support to set all the arguments of greptime helm chart
Browse files Browse the repository at this point in the history
Signed-off-by: sh2 <[email protected]>
  • Loading branch information
shawnh2 committed Jul 19, 2023
1 parent 237374c commit 3ad0686
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
15 changes: 12 additions & 3 deletions pkg/cmd/gtctl/cluster/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ type createClusterCliOptions struct {
AlwaysDownload bool

// Common options.
Timeout int
DryRun bool
Timeout int
DryRun bool
Set string
SetEtcd string
SetOperator string
}

func NewCreateClusterCommand(l logger.Logger) *cobra.Command {
Expand Down Expand Up @@ -144,10 +147,13 @@ func NewCreateClusterCommand(l logger.Logger) *cobra.Command {
cmd.Flags().StringVarP(&options.Namespace, "namespace", "n", "default", "Namespace of GreptimeDB cluster.")
cmd.Flags().BoolVar(&options.DryRun, "dry-run", false, "Output the manifests without applying them.")
cmd.Flags().IntVar(&options.Timeout, "timeout", -1, "Timeout in seconds for the command to complete, default is no timeout.")
cmd.Flags().StringVar(&options.Set, "set", "", "set values on the command line for greptimedb (can specify multiple or separate values with commas: key1=val1,key2=val2).")
cmd.Flags().StringVar(&options.SetEtcd, "set-etcd", "", "set values on the command line for greptimedb-etcd.")
cmd.Flags().StringVar(&options.SetOperator, "set-operator", "", "set values on the command line for greptimedb-operator.")
cmd.Flags().StringVar(&options.GreptimeDBChartVersion, "greptimedb-chart-version", "", "The greptimedb helm chart version, use latest version if not specified.")
cmd.Flags().StringVar(&options.GreptimeDBOperatorChartVersion, "greptimedb-operator-chart-version", "", "The greptimedb-operator helm chart version, use latest version if not specified.")
cmd.Flags().StringVar(&options.EtcdChartVersion, "etcd-chart-version", "", "The greptimedb-etcd helm chart version, use latest version if not specified.")
cmd.Flags().StringVar(&options.ImageRegistry, "image-registry", "", "The image registry")
cmd.Flags().StringVar(&options.ImageRegistry, "image-registry", "", "The image registry.")
cmd.Flags().StringVar(&options.EtcdNamespace, "etcd-namespace", "default", "The namespace of etcd cluster.")
cmd.Flags().StringVar(&options.EtcdStorageClassName, "etcd-storage-class-name", "standard", "The etcd storage class name.")
cmd.Flags().StringVar(&options.EtcdStorageSize, "etcd-storage-size", "10Gi", "the etcd persistent volume size.")
Expand Down Expand Up @@ -210,6 +216,7 @@ func deployGreptimeDBOperator(ctx context.Context, l logger.Logger, options *cre
createGreptimeDBOperatorOptions := &deployer.CreateGreptimeDBOperatorOptions{
GreptimeDBOperatorChartVersion: options.GreptimeDBOperatorChartVersion,
ImageRegistry: options.ImageRegistry,
ConfigValues: options.SetOperator,
}

name := types.NamespacedName{Namespace: options.OperatorNamespace, Name: "greptimedb-operator"}.String()
Expand Down Expand Up @@ -238,6 +245,7 @@ func deployEtcdCluster(ctx context.Context, l logger.Logger, options *createClus
EtcdStorageClassName: options.EtcdStorageClassName,
EtcdStorageSize: options.EtcdStorageSize,
EtcdDataDir: options.EtcdDataDir,
ConfigValues: options.SetEtcd,
}

var name string
Expand Down Expand Up @@ -274,6 +282,7 @@ func deployGreptimeDBCluster(ctx context.Context, l logger.Logger, options *crea
DatanodeStorageSize: options.StorageSize,
DatanodeStorageRetainPolicy: options.StorageRetainPolicy,
EtcdEndPoint: fmt.Sprintf("%s.%s:2379", common.EtcdClusterName(clusterName), options.EtcdNamespace),
ConfigValues: options.Set,
}

var name string
Expand Down
3 changes: 3 additions & 0 deletions pkg/deployer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type CreateGreptimeDBClusterOptions struct {
DatanodeStorageSize string `helm:"datanode.storage.storageSize"`
DatanodeStorageRetainPolicy string `helm:"datanode.storage.storageRetainPolicy"`
EtcdEndPoint string `helm:"etcdEndpoints"`
ConfigValues string `helm:"*"`
}

// UpdateGreptimeDBClusterOptions is the options to update a GreptimeDB cluster.
Expand All @@ -94,6 +95,7 @@ type CreateEtcdClusterOptions struct {
EtcdStorageClassName string `helm:"storage.storageClassName"`
EtcdStorageSize string `helm:"storage.volumeSize"`
EtcdDataDir string `helm:"storage.dataDir"`
ConfigValues string `helm:"*"`
}

// DeleteEtcdClusterOption is the options to delete an etcd cluster.
Expand All @@ -104,4 +106,5 @@ type CreateGreptimeDBOperatorOptions struct {
GreptimeDBOperatorChartVersion string

ImageRegistry string `helm:"image.registry"`
ConfigValues string `helm:"*"`
}
8 changes: 6 additions & 2 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ func (r *Render) GenerateHelmValues(input interface{}) (map[string]interface{},
typeOf := reflect.TypeOf(input)
for i := 0; i < valueOf.NumField(); i++ {
helmValueKey := typeOf.Field(i).Tag.Get(helmFieldTag)
if helmValueKey != "" && valueOf.Field(i).Len() > 0 {
rawArgs = append(rawArgs, fmt.Sprintf("%s=%s", helmValueKey, valueOf.Field(i)))
if len(helmValueKey) > 0 && valueOf.Field(i).Len() > 0 {
if helmValueKey == "*" {
rawArgs = append(rawArgs, valueOf.Field(i).String())
} else {
rawArgs = append(rawArgs, fmt.Sprintf("%s=%s", helmValueKey, valueOf.Field(i)))
}
}
}

Expand Down

0 comments on commit 3ad0686

Please sign in to comment.