代码拉取完成,页面将自动刷新
package util
import (
"fmt"
"os"
"reflect"
"strings"
"github.com/coreos/go-semver/semver"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
const (
WorkerThreads = 50
SupportedSyncToolsVersion = "0.1.22"
)
func StrToSemVer(version string) (*semver.Version, error) {
v, err := semver.NewVersion(strings.TrimPrefix(version, "v"))
if err != nil {
return nil, err
}
return v, nil
}
func GetObjectQueue(l interface{}) chan interface{} {
s := reflect.ValueOf(l)
c := make(chan interface{}, s.Len())
for i := 0; i < s.Len(); i++ {
c <- s.Index(i).Interface()
}
close(c)
return c
}
func ErrList(e []error) error {
if len(e) > 0 {
return fmt.Errorf("%v", e)
}
return nil
}
// UniqueStringSlice - Input slice, retrun slice with unique elements. Will not maintain order.
func UniqueStringSlice(elements []string) []string {
encountered := map[string]bool{}
result := []string{}
for v := range elements {
if !encountered[elements[v]] {
encountered[elements[v]] = true
result = append(result, elements[v])
}
}
return result
}
func IsSymlink(file string) (bool, error) {
f, err := os.Lstat(file)
if err != nil {
return false, err
}
if f.Mode()&os.ModeSymlink != 0 {
return true, nil
}
return false, nil
}
// ValidateVersion - Return error if version is not valid
// Is version major.minor >= oldest major.minor supported
// Is version in the AllK8sVersions list
// Is version not in the "bad" list
func ValidateVersion(version string) error {
// Create target version and current versions list
targetVersion, err := StrToSemVer(version)
if err != nil {
return fmt.Errorf("%s is not valid semver", version)
}
currentVersionsList := []*semver.Version{}
for _, ver := range v3.K8sVersionsCurrent {
v, err := StrToSemVer(ver)
if err != nil {
return fmt.Errorf("%s in Current Versions list is not valid semver", ver)
}
currentVersionsList = append(currentVersionsList, v)
}
// Make sure Target version is greater than or equal to oldest major.minor supported.
semver.Sort(currentVersionsList)
if targetVersion.Major < currentVersionsList[0].Major {
return fmt.Errorf("%s is an unsupported Kubernetes version - see 'rke config --system-images --all' for versions supported with this release", version)
}
if targetVersion.Major == currentVersionsList[0].Major {
if targetVersion.Minor < currentVersionsList[0].Minor {
return fmt.Errorf("%s is an unsupported Kubernetes version - see 'rke config --system-images --all' for versions supported with this release", version)
}
}
// Make sure Target version is in the AllK8sVersions list.
_, ok := v3.AllK8sVersions[version]
if !ok {
return fmt.Errorf("%s is an unsupported Kubernetes version - see 'rke config --system-images --all' for versions supported with this release", version)
}
// Make sure Target version is not "bad".
_, ok = v3.K8sBadVersions[version]
if ok {
return fmt.Errorf("%s is an unsupported Kubernetes version - see 'rke config --system-images --all' for versions supported with this release", version)
}
return nil
}
func GetDefaultRKETools() string {
return v3.AllK8sVersions[v3.DefaultK8s].Alpine
}
func IsRancherBackupSupported(image string) bool {
v := strings.Split(image, ":")
last := v[len(v)-1]
sv, err := StrToSemVer(last)
if err != nil {
return false
}
supported, err := StrToSemVer(SupportedSyncToolsVersion)
if err != nil {
return false
}
if sv.LessThan(*supported) {
return false
}
return true
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。