-
Notifications
You must be signed in to change notification settings - Fork 90
/
helm.go
51 lines (42 loc) · 1.25 KB
/
helm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package k8sutil
import (
"fmt"
"regexp"
"github.com/pkg/errors"
"helm.sh/helm/v3/pkg/chartutil"
)
func InitHelmCapabilities() error {
clientset, err := GetClientset()
if err != nil {
return errors.Wrap(err, "failed to create kubernetes clientset")
}
serverGroups, err := clientset.ServerGroups()
if err != nil {
return errors.Wrap(err, "failed to get server groups")
}
serverVersion, err := clientset.ServerVersion()
if err != nil {
return errors.Wrap(err, "failed to get server version")
}
versionSet := chartutil.VersionSet{}
for _, serverGroup := range serverGroups.Groups {
for _, version := range serverGroup.Versions {
versionSet = append(versionSet, version.GroupVersion)
}
}
// Need to remove non-digits from minor version to make valid semver
reg, err := regexp.Compile("[^0-9]+")
if err != nil {
return errors.Wrap(err, "failed to compile regex")
}
chartutil.DefaultCapabilities = &chartutil.Capabilities{
KubeVersion: chartutil.KubeVersion{
Version: fmt.Sprintf("v%s.%s.0", serverVersion.Major, reg.ReplaceAllString(serverVersion.Minor, "")),
Major: serverVersion.Major,
Minor: serverVersion.Minor,
},
APIVersions: versionSet,
HelmVersion: chartutil.DefaultCapabilities.HelmVersion,
}
return nil
}