-
Notifications
You must be signed in to change notification settings - Fork 944
refactor: Extract stream manager as the public part #1725
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: Extract stream manager as the public part #1725
Conversation
6ac64ba to
fc71fc7
Compare
Codecov Report
@@ Coverage Diff @@
## master #1725 +/- ##
=========================================
- Coverage 41.76% 39.46% -2.3%
=========================================
Files 278 277 -1
Lines 18244 19258 +1014
=========================================
- Hits 7619 7601 -18
- Misses 9699 10719 +1020
- Partials 926 938 +12
|
|
Sounds good to me, while I still wish @YaoZengzeng @fuweid could take a review for this. |
fuweid
left a comment
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.
The change is acceptable and reasonable. But there needs little change in this commit. Please take a look.
cri/stream/config.go
Outdated
| package stream | ||
|
|
||
| import ( | ||
| "github.com/alibaba/pouch/cri/stream/constant" |
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.
split packages into two groups~
cri/stream/config.go
Outdated
| // Address is the addr:port address the server will listen on. | ||
| Address string | ||
|
|
||
| // BaseURL is the optional base URL for constructing streaming URLs. If empty, the baseURL will be constructed from the serve address. |
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.
Could we fold the comment into two lines, since this line is too long? 😄
cri/stream/config.go
Outdated
|
|
||
| // DefaultConfig provides default values for server Config. | ||
| var DefaultConfig = Config{ | ||
| StreamIdleTimeout: 4 * time.Hour, |
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.
use DefaultStreamIdleTimeout instead of 4*time.Hour ?
cri/stream/runtime.go
Outdated
| } | ||
|
|
||
| // Exec executes a command inside the container. | ||
| func (s *streamRuntime) Exec(containerID string, cmd []string, streamOpts *remotecommand.Options, streams *remotecommand.Streams) (uint32, 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.
can we add the context as first argument? If we have the ctx, we can handle the progress by the upstream.
f622d61 to
bddb6e6
Compare
fuweid
left a comment
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.
ping @YaoZengzeng
cri/stream/portforward/httpstream.go
Outdated
| package portforward | ||
|
|
||
| import ( | ||
| con "context" |
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.
I think we should use the context here to make the word readable, because the con might be the connection.
cri/stream/portforward/httpstream.go
Outdated
| } | ||
|
|
||
| func handleHTTPStreams(w http.ResponseWriter, req *http.Request, portForwarder PortForwarder, podName string, idleTimeout, streamCreationTimeout time.Duration, supportedPortForwardProtocols []string) error { | ||
| func handleHTTPStreams(cont con.Context, w http.ResponseWriter, req *http.Request, portForwarder PortForwarder, podName string, idleTimeout, streamCreationTimeout time.Duration, supportedPortForwardProtocols []string) 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.
the var of context.Context can be named by ctx.
| // connections; i.e., multiple `curl http://localhost:8888/` requests will be | ||
| // handled by a single invocation of ServePortForward. | ||
| func ServePortForward(w http.ResponseWriter, req *http.Request, portForwarder PortForwarder, podName string, idleTimeout time.Duration, streamCreationTimeout time.Duration, supportedProtocols []string) { | ||
| func ServePortForward(cont con.Context, w http.ResponseWriter, req *http.Request, portForwarder PortForwarder, podName string, idleTimeout time.Duration, streamCreationTimeout time.Duration, supportedProtocols []string) { |
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.
for the name rule, please check the last comment
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.
All mentioned above is because there's a structure called context, we could renamed it in the next PR.
| return fmt.Errorf("failed to attach to container %q: %v", containerID, err) | ||
| } | ||
|
|
||
| <-streams.StreamCh |
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.
The channel is just used for the notify event?
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.
cc @YaoZengzeng
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.
@fuweid Yes, it is used to notify the container io has been closed and then the Attach function could return, the http connection could be closed.
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.
roger
cri/v1alpha1/server.go
Outdated
| } | ||
|
|
||
| func (s *server) serveExec(w http.ResponseWriter, r *http.Request) { | ||
| ctx := context.Background() |
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.
we can use r.Context() instead of context.Background().
bddb6e6 to
ac2ce18
Compare
Signed-off-by: Starnop <[email protected]>
ac2ce18 to
206c597
Compare
fuweid
left a comment
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.
LGTM @YaoZengzeng please help us to check again.
|
LGTM |
Signed-off-by: Starnop [email protected]
Ⅰ. Describe what this PR did
For now,The organization of the code about stream Manager is unreasonable,we should reorganize the file structure: extract stream manager as the public part.
Ⅱ. Does this pull request fix one issue?
fixes part of #1524
Ⅲ. Describe how you did it
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews