Skip to content

Commit

Permalink
fix: etcd install fail (#156)
Browse files Browse the repository at this point in the history
* fix: etcd install fail

* refactor: change kubeversion name

* style: sort package

* refactor: add default kube version v1.20.0
  • Loading branch information
daviderli614 committed Sep 30, 2023
1 parent 5035501 commit 5ae1c8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/registry"
. "helm.sh/helm/v3/pkg/repo"
Expand All @@ -45,6 +46,11 @@ const (
helmFieldTag = "helm"
)

var (
// KubeVersion is the target version of the kubernetes.
KubeVersion string = "v1.20.0"
)

// Manager is the Helm charts manager. The implementation is based on Helm SDK.
// The main purpose of Manager is:
// 1. Load the chart from remote charts and save them in cache directory.
Expand Down Expand Up @@ -318,13 +324,19 @@ func (r *Manager) isInChartsCache(packageName string) bool {
}

func (r *Manager) newHelmClient(releaseName, namespace string) (*action.Install, error) {
kubeVersion, err := chartutil.ParseKubeVersion(KubeVersion)
if err != nil {
return nil, fmt.Errorf("invalid kube version '%s': %s", kubeVersion, err)
}

helmClient := action.NewInstall(new(action.Configuration))
helmClient.DryRun = true
helmClient.ReleaseName = releaseName
helmClient.Replace = true
helmClient.ClientOnly = true
helmClient.IncludeCRDs = true
helmClient.Namespace = namespace
helmClient.KubeVersion = kubeVersion

return helmClient, nil
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
"k8s.io/client-go/util/homedir"

greptimev1alpha1 "github.com/GreptimeTeam/greptimedb-operator/apis/v1alpha1"

"github.com/GreptimeTeam/gtctl/pkg/helm"
)

type Client struct {
Expand Down Expand Up @@ -103,6 +105,12 @@ func NewClient(kubeconfig string) (*Client, error) {
}
})

kubeVersion, err := kubeClient.ServerVersion()
if err != nil {
return nil, fmt.Errorf("failed to get kubernetes server version: %v\n", err)
}
helm.KubeVersion = kubeVersion.String()

return &Client{
kubeClient: kubeClient,
dynamicKubeClient: dynamicKubeClient,
Expand Down

0 comments on commit 5ae1c8c

Please sign in to comment.