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

refactor: make CRI Stream Server share http server with pouchd #2214

Merged
merged 1 commit into from
Sep 17, 2018

Conversation

YaoZengzeng
Copy link
Contributor

@YaoZengzeng YaoZengzeng commented Sep 7, 2018

Signed-off-by: YaoZengzeng yaozengzeng@zju.edu.cn

Ⅰ. Describe what this PR did

If the CRI enabled, pouch will launch two http server, one for pouchd and another for stream server of CRI, so we will need two different port

However port is scarce resources in company which has large scale of data center.

So maybe it is a good idea that we reuse the same http server for pouchd and stream server which only one port is needed

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

No

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@YaoZengzeng YaoZengzeng changed the title refactor: make CRI Stream Server share port(http server) with pouchd [WIP]refactor: make CRI Stream Server share port(http server) with pouchd Sep 7, 2018
@YaoZengzeng YaoZengzeng force-pushed the stream-port branch 3 times, most recently from 39743fc to d6ab819 Compare September 7, 2018 08:48
@YaoZengzeng YaoZengzeng changed the title [WIP]refactor: make CRI Stream Server share port(http server) with pouchd refactor: make CRI Stream Server share port(http server) with pouchd Sep 7, 2018
@YaoZengzeng YaoZengzeng changed the title refactor: make CRI Stream Server share port(http server) with pouchd refactor: make CRI Stream Server share http server with pouchd Sep 7, 2018
@codecov-io
Copy link

codecov-io commented Sep 7, 2018

Codecov Report

Merging #2214 into master will decrease coverage by 0.21%.
The diff coverage is 56.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2214      +/-   ##
==========================================
- Coverage   66.57%   66.36%   -0.22%     
==========================================
  Files         208      208              
  Lines       16744    16837      +93     
==========================================
+ Hits        11148    11174      +26     
- Misses       4273     4321      +48     
- Partials     1323     1342      +19
Flag Coverage Δ
#criv1alpha1test 32.63% <26%> (-0.35%) ⬇️
#criv1alpha2test 33.28% <26.66%> (-0.15%) ⬇️
#integrationtest 39.71% <12%> (-0.26%) ⬇️
#nodee2etest 33.59% <25.33%> (-0.12%) ⬇️
#unittest 23.88% <16.52%> (+0.01%) ⬆️
Impacted Files Coverage Δ
apis/server/server.go 52.5% <ø> (ø) ⬆️
apis/server/router.go 85.44% <0%> (-6.4%) ⬇️
cri/v1alpha1/cri_wrapper.go 55.3% <0%> (-0.5%) ⬇️
cri/v1alpha2/cri_wrapper.go 61.98% <0%> (-3.71%) ⬇️
daemon/daemon.go 58.37% <100%> (+0.68%) ⬆️
cri/v1alpha2/server.go 79.2% <100%> (-0.65%) ⬇️
cri/v1alpha1/server.go 79.2% <100%> (-0.65%) ⬇️
cri/v1alpha1/cri.go 61.46% <40%> (-1.11%) ⬇️
cri/v1alpha2/cri.go 71.33% <40%> (-0.87%) ⬇️
cri/criservice.go 55.95% <55.17%> (-8.76%) ⬇️
... and 14 more

@allencloud
Copy link
Collaborator

I think this feature is quite urgent for PouchContainer. PTAL ASAP. Thanks. @fuweid @starnop

main.go Outdated
@@ -69,7 +69,7 @@ func setupFlags(cmd *cobra.Command) {
flagSet := cmd.Flags()

flagSet.StringVar(&cfg.HomeDir, "home-dir", "/var/lib/pouch", "Specify root dir of pouchd")
flagSet.StringArrayVarP(&cfg.Listen, "listen", "l", []string{"unix:///var/run/pouchd.sock"}, "Specify listening addresses of Pouchd")
flagSet.StringArrayVarP(&cfg.Listen, "listen", "l", []string{"unix:///var/run/pouchd.sock", "tcp://0.0.0.0:4243"}, "Specify listening addresses of Pouchd")
Copy link
Collaborator

Choose a reason for hiding this comment

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

By default, tcp://0.0.0.0:4243 is set in pouchd? I do not think it is a good way.
Shall we still set the default value to be unix socket, and if user needs to expand the CRI within the one port, he needs to add a tcp address when startup of pouchd. Here I am afraid we need to add more explanation of the comment Specify listening addresses of Pouchd, and it is too general and hard for others to understand the real functionality of it.

In addition, I am just here to double check if we still support to set the two different port in pouchd for configuration, one for container api port, the other for cri stream server port?

@@ -57,7 +58,7 @@ const (
// Address and port of stream server.
// TODO: specify them in the parameters of pouchd.
streamServerAddress = ""
streamServerPort = "10011"
streamServerPort = "4243"
Copy link
Contributor

Choose a reason for hiding this comment

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

could we share same port with pouch daemon or create other option like what @allencloud says?

if err := <-errChan; err != nil {
return err
}
if err := <-errChan; err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

are we need the 2 in make(chan error, 2) here?

@YaoZengzeng YaoZengzeng force-pushed the stream-port branch 2 times, most recently from f9c95c2 to 429f381 Compare September 10, 2018 03:17
@YaoZengzeng
Copy link
Contributor Author

I just refactored this PR.

Now we could specify two stream server related options with pouchd.

stream-server-port: specify the port of stream server, default is 10010

stream-server-reuse-port: only this option is enabled, the stream server will share the port with pouchd.

NOTE: in this condition, we should specify a tcp socket in pouchd and the port should be same with stream-server-port, for example:

pouchd --listen tcp://0.0.0.0:4243 --stream-server-reuse-port --stream-server-port 4243

The --stream-server-reuse-port feature should only be used internally and not be make public, otherwise it will be complicated and hard to be compatible.

@allencloud @fuweid WDYT?

@YaoZengzeng YaoZengzeng force-pushed the stream-port branch 9 times, most recently from 7ac7b2a to fb10eab Compare September 11, 2018 02:50
@YaoZengzeng
Copy link
Contributor Author

I adjust the mechanism again.

  1. When stream-server-reuse-port is disabled, stream sever will listen on its own port and you can use stream-server-port of pouchd to tune it.

  2. If stream-server-reuse-port is enabled, the stream-server-port will not have any effect. Stream sever will reuse the pouchd's port and extract it from the listen option of pouchd.

@YaoZengzeng YaoZengzeng force-pushed the stream-port branch 2 times, most recently from 1a71c73 to d39c8e1 Compare September 11, 2018 05:56
@YaoZengzeng YaoZengzeng force-pushed the stream-port branch 4 times, most recently from 2e7c784 to 3069db2 Compare September 11, 2018 06:37
@@ -57,7 +58,7 @@ const (
// Address and port of stream server.
// TODO: specify them in the parameters of pouchd.
streamServerAddress = ""
streamServerPort = "10010"
streamServerPort = "4243"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should keep 10010 as default here.

streamServerPort := config.CriConfig.StreamServerPort
// If stream server reuse the pouchd's port, extract the port from pouchd's listening addresses.
if config.CriConfig.StreamServerReusePort {
streamServerAddress, streamServerPort = extractIPAndPortFromAddresses(config.Listen)
Copy link
Contributor

Choose a reason for hiding this comment

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

since the user maybe pass multiple tcp addresses, could we show the address and port which CRI stream uses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the streamServerAddress we get is 0.0.0.0, we will reacquire the concrete IP that the stream server will use in newStreamServer, so I output the log there.

Copy link
Contributor

Choose a reason for hiding this comment

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

oops, my mistake.

args: []string{"unix:///var/run/pouchd.sock", "tcp://0.0.0.0:4345"},
wantIP: "0.0.0.0",
wantPort: "4345",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

please add two tcp addresses case here

Signed-off-by: YaoZengzeng <yaozengzeng@zju.edu.cn>
Copy link
Contributor

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

@fuweid fuweid merged commit 1596dd7 into AliyunContainerService:master Sep 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants