modify GenerateLeaderElectionID

Signed-off-by: Jian.Li <lj176172@alibaba-inc.com>
This commit is contained in:
Jian.Li
2022-02-21 16:07:21 +08:00
parent f55b839b0f
commit 23230f711c
2 changed files with 12 additions and 5 deletions
+6 -3
View File
@@ -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
}
+6 -2
View File
@@ -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
}
}