From 92b19dc58bf9c0e0348eb6862bbfa224d09b1932 Mon Sep 17 00:00:00 2001 From: bharath-avesha <99859949+bharath-avesha@users.noreply.github.com> Date: Thu, 22 Jun 2023 23:35:45 +0530 Subject: [PATCH] fix(): Use nsmgr svc name derived from hash of node name (#7) * fix(): Kick the build with semantic commit Signed-off-by: Bharath Horatti * fix(): Use nsmgr svc name derived from hash of node name Signed-off-by: Bharath Horatti --------- Signed-off-by: Bharath Horatti --- main.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 037bbf9..a6f434e 100644 --- a/main.go +++ b/main.go @@ -21,12 +21,13 @@ package main import ( "context" + "crypto/md5" "crypto/tls" + "encoding/hex" "fmt" "net/url" "os" "os/signal" - "strings" "syscall" nested "github.com/antonfisher/nested-logrus-formatter" @@ -67,19 +68,14 @@ import ( "github.com/networkservicemesh/cmd-nsc-init/internal/config" ) - func getNsmgrNodeLocalServiceName() string { - nodeName := os.Getenv("MY_NODE_NAME") - // Nsmgr service name should be derived from the node name. If the node name does - // not conform to a RFC-1035 label name, it needs to be modified by replacing all - // uppercase letters to lowercase, replacing all '.' with '-', and finally truncating - // the length to 63 characters. - svcName := strings.ReplaceAll(strings.ToLower(nodeName), ".", "-") - if len(svcName) > 63 { - svcName = svcName[:63] - } - - return svcName + // The nsmgr node local service name is generated by the nsmgr init container that runs a + // bash script to get the md5 hash of the node name. It uses the echo command to pipe the + // node name to md5sum command. The echo command appends a newline character automatically at + // the end of the node name string, hence we need to do the same here to generate identical + // hash values. + nodeNameHash := md5.Sum([]byte(os.Getenv("MY_NODE_NAME") + "\n")) + return "nsm-" + hex.EncodeToString(nodeNameHash[:]) }