Skip to content
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

Merged
merged 3 commits into from
Jun 5, 2018

Conversation

chenyunchen
Copy link
Contributor

findNetworkNamespacePath: Use Pod Name, K8sNamespace, PodUUID
to get Network Namespace
connectBridge: Connect bridge[veth]<--->[veth]container

@codecov
Copy link

codecov bot commented Jun 4, 2018

Codecov Report

Merging #13 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48a035e...31c14b1. Read the comment docs.

md := hash.Sum(nil)
mdStr := hex.EncodeToString(md)
hostVethName := "veth" + mdStr[0:8]

Copy link
Contributor

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

}

func (s *server) ConnectBridge(ctx context.Context, req *pb.ConnectBridgeRequest) (*pb.ConnectBridgeResponse, error) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove newline

)

func (s *server) FindNetworkNamespacePath(ctx context.Context, req *pb.FindNetworkNamespacePathRequest) (*pb.FindNetworkNamespacePathResponse, error) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove newline

}

func (s *server) ConnectBridge(ctx context.Context, req *pb.ConnectBridgeRequest) (*pb.ConnectBridgeResponse, error) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hash.Write([]byte(UUID))
md := hash.Sum(nil)
mdStr := hex.EncodeToString(md)
return mdStr
Copy link
Contributor

@John-Lin John-Lin Jun 4, 2018

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])
}

Copy link
Contributor

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.

Copy link
Contributor

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.

}, err
}

hostVethName := fmt.Sprintf("veth%s", utils.HashUUID(req.PodUUID)[0:8])
Copy link
Contributor

@John-Lin John-Lin Jun 4, 2018

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.

@hwchiu hwchiu merged commit 0db9fd3 into master Jun 5, 2018
@hwchiu hwchiu deleted the alex/CreateServerHandler branch June 5, 2018 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants