mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
modify GenerateLeaderElectionID
Signed-off-by: Jian.Li <lj176172@alibaba-inc.com>
This commit is contained in:
@@ -23,8 +23,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/oam-dev/kubevela/version"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"k8s.io/client-go/discovery"
|
||||
@@ -34,6 +32,8 @@ import (
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/client-go/util/homedir"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
|
||||
"github.com/oam-dev/kubevela/version"
|
||||
)
|
||||
|
||||
var defaultCacheDir = filepath.Join(homedir.HomeDir(), ".kube", "http-cache")
|
||||
@@ -172,5 +172,8 @@ func computeDiscoverCacheDir(parentDir, host string) string {
|
||||
|
||||
// GenerateLeaderElectionID returns the Leader Election ID.
|
||||
func GenerateLeaderElectionID(name string, versionedDeploy bool) string {
|
||||
return name + "-" + strings.ToLower(strings.ReplaceAll(version.VelaVersion, ".", "z"))
|
||||
if versionedDeploy {
|
||||
return name + "-" + strings.ToLower(strings.ReplaceAll(version.VelaVersion, ".", "-"))
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
@@ -8,8 +8,12 @@ import (
|
||||
|
||||
func TestGenerateLeaderElectionID(t *testing.T) {
|
||||
version.VelaVersion = "v10.13.0"
|
||||
if id := GenerateLeaderElectionID("kubevela", true); id != "kubevela-v10z13z0" {
|
||||
t.Errorf("id is not as expected(%s != kubevela-v10z13z0)", id)
|
||||
if id := GenerateLeaderElectionID("kubevela", true); id != "kubevela-v10-13-0" {
|
||||
t.Errorf("id is not as expected(%s != kubevela-v10-13-0)", id)
|
||||
return
|
||||
}
|
||||
if id := GenerateLeaderElectionID("kubevela", false); id != "kubevela" {
|
||||
t.Errorf("id is not as expected(%s != kubevela)", id)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user