Skip to content

Commit

Permalink
feat: support to accept values file (#161)
Browse files Browse the repository at this point in the history
* refactor: use 'EnsureDir()'

Signed-off-by: zyy17 <[email protected]>

* refactore: use new artifacts manager in bare-metal deployment

Signed-off-by: zyy17 <[email protected]>

* refactor: refine helm package

1. Rename helm.Manager to helm.Loader;

2. Add 'pkg/helm/values*" to make values operation more flexiable;

3. Update unit test cases;

Signed-off-by: zyy17 <[email protected]>

* feat: support values files

Signed-off-by: zyy17 <[email protected]>

---------

Signed-off-by: zyy17 <[email protected]>
  • Loading branch information
zyy17 authored Oct 10, 2023
1 parent e32d7b0 commit 0daeecd
Show file tree
Hide file tree
Showing 12 changed files with 478 additions and 278 deletions.
11 changes: 11 additions & 0 deletions pkg/cmd/gtctl/cluster/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ type ClusterCliOptions struct {
EtcdStorageSize string
EtcdClusterSize string

// Values files that set in command line.
GreptimeDBClusterValuesFile string
EtcdClusterValuesFile string
GreptimeDBOperatorValuesFile string

// The options for deploying GreptimeDBCluster in bare-metal.
BareMetal bool
Config string
Expand Down Expand Up @@ -107,6 +112,9 @@ func NewCreateClusterCommand(l logger.Logger) *cobra.Command {
cmd.Flags().BoolVar(&options.EnableCache, "enable-cache", true, "If true, enable cache for downloading artifacts(charts and binaries).")
cmd.Flags().BoolVar(&options.RetainLogs, "retain-logs", true, "If true, always retain the logs of binary.")
cmd.Flags().BoolVar(&options.UseGreptimeCNArtifacts, "use-greptime-cn-artifacts", false, "If true, use greptime-cn artifacts(charts and binaries).")
cmd.Flags().StringVar(&options.GreptimeDBClusterValuesFile, "greptimedb-cluster-values-file", "", "The values file for greptimedb cluster.")
cmd.Flags().StringVar(&options.EtcdClusterValuesFile, "etcd-cluster-values-file", "", "The values file for etcd cluster.")
cmd.Flags().StringVar(&options.GreptimeDBOperatorValuesFile, "greptimedb-operator-values-file", "", "The values file for greptimedb operator.")

return cmd
}
Expand Down Expand Up @@ -240,6 +248,7 @@ func deployGreptimeDBOperator(ctx context.Context, l logger.Logger, options *Clu
ImageRegistry: options.ImageRegistry,
ConfigValues: options.Set.operatorConfig,
UseGreptimeCNArtifacts: options.UseGreptimeCNArtifacts,
ValuesFile: options.GreptimeDBOperatorValuesFile,
}

name := types.NamespacedName{Namespace: options.OperatorNamespace, Name: "greptimedb-operator"}.String()
Expand Down Expand Up @@ -270,6 +279,7 @@ func deployEtcdCluster(ctx context.Context, l logger.Logger, options *ClusterCli
EtcdClusterSize: options.EtcdClusterSize,
ConfigValues: options.Set.etcdConfig,
UseGreptimeCNArtifacts: options.UseGreptimeCNArtifacts,
ValuesFile: options.EtcdClusterValuesFile,
}

var name string
Expand Down Expand Up @@ -308,6 +318,7 @@ func deployGreptimeDBCluster(ctx context.Context, l logger.Logger, options *Clus
EtcdEndPoint: fmt.Sprintf("%s.%s:2379", common.EtcdClusterName(clusterName), options.EtcdNamespace),
ConfigValues: options.Set.clusterConfig,
UseGreptimeCNArtifacts: options.UseGreptimeCNArtifacts,
ValuesFile: options.GreptimeDBClusterValuesFile,
}

var name string
Expand Down
52 changes: 41 additions & 11 deletions pkg/deployer/k8s/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (
)

type deployer struct {
helmManager *helm.Manager
client *kube.Client
timeout time.Duration
logger logger.Logger
dryRun bool
helmLoader *helm.Loader
client *kube.Client
timeout time.Duration
logger logger.Logger
dryRun bool
}

const (
Expand All @@ -46,14 +46,14 @@ var _ Interface = &deployer{}
type Option func(*deployer)

func NewDeployer(l logger.Logger, opts ...Option) (Interface, error) {
hm, err := helm.NewManager(l)
hc, err := helm.NewLoader(l)
if err != nil {
return nil, err
}

d := &deployer{
helmManager: hm,
logger: l,
helmLoader: hc,
logger: l,
}

for _, opt := range opts {
Expand Down Expand Up @@ -127,7 +127,17 @@ func (d *deployer) CreateGreptimeDBCluster(ctx context.Context, name string, opt
options.ConfigValues += fmt.Sprintf("image.registry=%s,initializer.registry=%s,", AliCloudRegistry, AliCloudRegistry)
}

manifests, err := d.helmManager.LoadAndRenderChart(ctx, resourceName, resourceNamespace, artifacts.GreptimeDBChartName, options.GreptimeDBChartVersion, options.UseGreptimeCNArtifacts, *options)
opts := &helm.LoadOptions{
ReleaseName: resourceName,
Namespace: resourceNamespace,
ChartName: artifacts.GreptimeDBChartName,
ChartVersion: options.GreptimeDBChartVersion,
FromCNRegion: options.UseGreptimeCNArtifacts,
ValuesOptions: *options,
EnableCache: true,
ValuesFile: options.ValuesFile,
}
manifests, err := d.helmLoader.LoadAndRenderChart(ctx, opts)
if err != nil {
return err
}
Expand Down Expand Up @@ -186,7 +196,17 @@ func (d *deployer) CreateEtcdCluster(ctx context.Context, name string, options *
options.ConfigValues += fmt.Sprintf("image.registry=%s,", AliCloudRegistry)
}

manifests, err := d.helmManager.LoadAndRenderChart(ctx, resourceName, resourceNamespace, artifacts.EtcdChartName, artifacts.DefaultEtcdChartVersion, options.UseGreptimeCNArtifacts, *options)
opts := &helm.LoadOptions{
ReleaseName: resourceName,
Namespace: resourceNamespace,
ChartName: artifacts.EtcdChartName,
ChartVersion: artifacts.DefaultEtcdChartVersion,
FromCNRegion: options.UseGreptimeCNArtifacts,
ValuesOptions: *options,
EnableCache: true,
ValuesFile: options.ValuesFile,
}
manifests, err := d.helmLoader.LoadAndRenderChart(ctx, opts)
if err != nil {
return fmt.Errorf("error while loading helm chart: %v", err)
}
Expand Down Expand Up @@ -222,7 +242,17 @@ func (d *deployer) CreateGreptimeDBOperator(ctx context.Context, name string, op
options.ConfigValues += fmt.Sprintf("image.registry=%s,", AliCloudRegistry)
}

manifests, err := d.helmManager.LoadAndRenderChart(ctx, resourceName, resourceNamespace, artifacts.GreptimeDBOperatorChartName, options.GreptimeDBOperatorChartVersion, options.UseGreptimeCNArtifacts, *options)
opts := &helm.LoadOptions{
ReleaseName: resourceName,
Namespace: resourceNamespace,
ChartName: artifacts.GreptimeDBOperatorChartName,
ChartVersion: options.GreptimeDBOperatorChartVersion,
FromCNRegion: options.UseGreptimeCNArtifacts,
ValuesOptions: *options,
EnableCache: true,
ValuesFile: options.ValuesFile,
}
manifests, err := d.helmLoader.LoadAndRenderChart(ctx, opts)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/deployer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type ListGreptimeDBClustersOptions struct{}
type CreateGreptimeDBClusterOptions struct {
GreptimeDBChartVersion string
UseGreptimeCNArtifacts bool
ValuesFile string

ImageRegistry string `helm:"image.registry"`
InitializerImageRegistry string `helm:"initializer.registry"`
Expand All @@ -92,6 +93,7 @@ type DeleteGreptimeDBClusterOption struct{}
type CreateEtcdClusterOptions struct {
EtcdChartVersion string
UseGreptimeCNArtifacts bool
ValuesFile string

// The parameters reference: https://artifacthub.io/packages/helm/bitnami/etcd.
EtcdClusterSize string `helm:"replicaCount"`
Expand All @@ -108,6 +110,7 @@ type DeleteEtcdClusterOption struct{}
type CreateGreptimeDBOperatorOptions struct {
GreptimeDBOperatorChartVersion string
UseGreptimeCNArtifacts bool
ValuesFile string

ImageRegistry string `helm:"image.registry"`
ConfigValues string `helm:"*"`
Expand Down
207 changes: 0 additions & 207 deletions pkg/helm/helm_test.go

This file was deleted.

Loading

0 comments on commit 0daeecd

Please sign in to comment.