Skip to content

Commit 5ae1c8c

Browse files
authored
fix: etcd install fail (#156)
* fix: etcd install fail * refactor: change kubeversion name * style: sort package * refactor: add default kube version v1.20.0
1 parent 5035501 commit 5ae1c8c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/helm/helm.go

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"helm.sh/helm/v3/pkg/action"
3232
"helm.sh/helm/v3/pkg/chart"
3333
"helm.sh/helm/v3/pkg/chart/loader"
34+
"helm.sh/helm/v3/pkg/chartutil"
3435
"helm.sh/helm/v3/pkg/cli"
3536
"helm.sh/helm/v3/pkg/registry"
3637
. "helm.sh/helm/v3/pkg/repo"
@@ -45,6 +46,11 @@ const (
4546
helmFieldTag = "helm"
4647
)
4748

49+
var (
50+
// KubeVersion is the target version of the kubernetes.
51+
KubeVersion string = "v1.20.0"
52+
)
53+
4854
// Manager is the Helm charts manager. The implementation is based on Helm SDK.
4955
// The main purpose of Manager is:
5056
// 1. Load the chart from remote charts and save them in cache directory.
@@ -318,13 +324,19 @@ func (r *Manager) isInChartsCache(packageName string) bool {
318324
}
319325

320326
func (r *Manager) newHelmClient(releaseName, namespace string) (*action.Install, error) {
327+
kubeVersion, err := chartutil.ParseKubeVersion(KubeVersion)
328+
if err != nil {
329+
return nil, fmt.Errorf("invalid kube version '%s': %s", kubeVersion, err)
330+
}
331+
321332
helmClient := action.NewInstall(new(action.Configuration))
322333
helmClient.DryRun = true
323334
helmClient.ReleaseName = releaseName
324335
helmClient.Replace = true
325336
helmClient.ClientOnly = true
326337
helmClient.IncludeCRDs = true
327338
helmClient.Namespace = namespace
339+
helmClient.KubeVersion = kubeVersion
328340

329341
return helmClient, nil
330342
}

pkg/kube/client.go

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import (
4242
"k8s.io/client-go/util/homedir"
4343

4444
greptimev1alpha1 "github.com/GreptimeTeam/greptimedb-operator/apis/v1alpha1"
45+
46+
"github.com/GreptimeTeam/gtctl/pkg/helm"
4547
)
4648

4749
type Client struct {
@@ -103,6 +105,12 @@ func NewClient(kubeconfig string) (*Client, error) {
103105
}
104106
})
105107

108+
kubeVersion, err := kubeClient.ServerVersion()
109+
if err != nil {
110+
return nil, fmt.Errorf("failed to get kubernetes server version: %v\n", err)
111+
}
112+
helm.KubeVersion = kubeVersion.String()
113+
106114
return &Client{
107115
kubeClient: kubeClient,
108116
dynamicKubeClient: dynamicKubeClient,

0 commit comments

Comments
 (0)