-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create server handler include findNetworkNamespacePath and connectBridge #13
Conversation
Codecov Report
@@ Coverage Diff @@
## master #13 +/- ##
=======================================
Coverage 75.21% 75.21%
=======================================
Files 4 4
Lines 117 117
=======================================
Hits 88 88
Misses 20 20
Partials 9 9 Continue to review full report at Codecov.
|
server/netlink-handler.go
Outdated
md := hash.Sum(nil) | ||
mdStr := hex.EncodeToString(md) | ||
hostVethName := "veth" + mdStr[0:8] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move out to independent function in utils package
server/netlink-handler.go
Outdated
} | ||
|
||
func (s *server) ConnectBridge(ctx context.Context, req *pb.ConnectBridgeRequest) (*pb.ConnectBridgeResponse, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove newline
server/netlink-handler.go
Outdated
) | ||
|
||
func (s *server) FindNetworkNamespacePath(ctx context.Context, req *pb.FindNetworkNamespacePathRequest) (*pb.FindNetworkNamespacePathResponse, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove newline
server/netlink-handler.go
Outdated
} | ||
|
||
func (s *server) ConnectBridge(ctx context.Context, req *pb.ConnectBridgeRequest) (*pb.ConnectBridgeResponse, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runtime.LockOSThread()
https://github.com/containernetworking/plugins/tree/master/pkg/ns
server/utils/utils.go
Outdated
hash.Write([]byte(UUID)) | ||
md := hash.Sum(nil) | ||
mdStr := hex.EncodeToString(md) | ||
return mdStr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
func sha256(str string) string {
hash := sha256.New()
hash.Write([]byte(str))
md := hash.Sum(nil)
return fmt.Sprintf("%s", hex.EncodeToString(md))
}
func GenerateVethName(uuid string) string {
str := sha256(uuid)
return fmt.Sprintf("veth%s", str[0:8])
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be fmt.Sprintf("%x", hex.EncodeToString(md))
I think, not %s
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, refactor is needed because the sha256
function is defined and used in more than one packages.
We can move it to github.com/linkernetworks/utils
and in other packages, just import it.
server/netlink-handler.go
Outdated
}, err | ||
} | ||
|
||
hostVethName := fmt.Sprintf("veth%s", utils.HashUUID(req.PodUUID)[0:8]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use hostVethName := GenerateVethName(req.PodUUID)
would be more clear and we even can reduce fmt
dependency by moving fmt.Sprintf("veth%s", utils.HashUUID(req.PodUUID)[0:8])
to utils package.
findNetworkNamespacePath
: UsePod Name
,K8sNamespace
,PodUUID
to get Network Namespace
connectBridge
: Connect bridge[veth]<--->[veth]container