-
Notifications
You must be signed in to change notification settings - Fork 343
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
feature: support docker proxy #128
Conversation
http.Error(wr, "Failed to checkpoint resource", http.StatusInternalServerError) | ||
return | ||
} | ||
d.dispatcher.Dispatch(ctx, runtimeHookPath, types.PostHook, resourceExecutor.GenerateHookRequest()) |
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.
dispatch posthook should be called ahead of copying info io.Copy(wr, bytes.NewReader(respBytes))
} | ||
|
||
func (d *RuntimeManagerDockerServer) failOver() error { | ||
dockerClient, err := client.NewClientWithOpts(client.WithHost("unix://"+utils.DefaultDockerSocketPath), client.WithVersion("")) |
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.
no need to get a new docker client here? before failover, the backend client should have been initialized, use this backend client instead?
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 client in failover, i import the client define in docker repo, so we not need to care about the protocol of listcontainers..
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.
please resolve conflicts.
Codecov Report
@@ Coverage Diff @@
## main #128 +/- ##
==========================================
- Coverage 61.23% 58.52% -2.71%
==========================================
Files 97 100 +3
Lines 8791 9222 +431
==========================================
+ Hits 5383 5397 +14
- Misses 2958 3374 +416
- Partials 450 451 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
||
ctx := context.TODO() | ||
reqCopy := req.Clone(ctx) | ||
if strings.Contains(req.URL.Path, "create") { |
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.
please refactor to
if contains create {
handleCreateRequest();
} else if contains xx {
handleXXRequest();
}
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.
fix it
|
||
func (d *RuntimeManagerDockerServer) ServeHTTP(wr http.ResponseWriter, req *http.Request) { | ||
if !strings.Contains(req.URL.Path, "containers") { | ||
d.Direct(wr, req) |
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.
missing return ?
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.
fix it
http.Error(wr, "Failed to Unmarshal req body to docker config ", http.StatusInternalServerError) | ||
return | ||
} | ||
config.ContainerName = req.URL.Query()["name"][0] |
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.
Query()["name"][0] Check for correctness?
8c21d7f
to
347e2c4
Compare
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.
Please fix thoses CI errors.
@@ -14,16 +14,18 @@ See the License for the specific language governing permissions and | |||
limitations under the License. | |||
*/ | |||
|
|||
package cri | |||
package resource_executor |
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 should unify the style of the package name and remove the middle bar include the package pkg/runtime-manager
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.
in next pr
// 3. send req to pre-hook | ||
runtimeHookPath := types.NoneRuntimeHookPath | ||
if response, err := d.dispatcher.Dispatch(ctx, runtimeHookPath, types.PreHook, resourceExecutor.GenerateHookRequest()); err != nil { | ||
klog.Errorf("fail to call hook server %v", err) |
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.
missing return error response?
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.
please add UT for these files.
} | ||
|
||
if response, err := d.dispatcher.Dispatch(ctx, runtimeHookPath, types.PreHook, resourceExecutor.GenerateHookRequest()); err != nil { | ||
klog.Errorf("fail to call hook server %v", err) |
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.
missing return error?
dispatcher: dispatcher.NewRuntimeDispatcher(), | ||
} | ||
criInterceptor.router = map[*regexp.Regexp]func(context.Context, http.ResponseWriter, *http.Request){ | ||
regexp.MustCompile("^/(v\\d\\.\\d+/)?containers(/\\w+)?/update$"): criInterceptor.HandleUpdateContainer, |
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 replace this custom regular implementation with a more mature route package?
b6bbff7
to
224d3b3
Compare
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.
e7daa54
to
bff134a
Compare
0db4e70
to
6dad85c
Compare
} | ||
|
||
func (d *RuntimeManagerDockerServer) Run() 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.
Redundant line
) | ||
|
||
func Test_calculateContentLength(t *testing.T) { | ||
type tetCase struct { |
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.
tetCase -> testCase
cmd/runtime-manager/main.go
Outdated
@@ -40,16 +43,22 @@ func main() { | |||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine) | |||
pflag.Parse() | |||
|
|||
dir, _ := filepath.Split(options.RuntimeManagerEndpoint) | |||
_ = os.Mkdir(dir, 0777) |
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.
is it guaranteed to succeed?
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.
- Handle error;
os.MkdirAll
may be better;
|
||
package docker | ||
|
||
import ( |
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.
please create an issue to add tests for server and handler
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.
cmd/runtime-manager/main.go
Outdated
@@ -40,16 +43,22 @@ func main() { | |||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine) | |||
pflag.Parse() | |||
|
|||
dir, _ := filepath.Split(options.RuntimeManagerEndpoint) | |||
_ = os.Mkdir(dir, 0777) |
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.
- Handle error;
os.MkdirAll
may be better;
|
||
// no need to care about the resp | ||
if _, err := d.dispatcher.Dispatch(ctx, runtimeHookPath, config.PreHook, hookReq); err != nil { | ||
klog.Errorf("fail to call pre start container hook server %v", err) |
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.
fail -> Failed
d.Direct(wr, req) | ||
|
||
if _, err := d.dispatcher.Dispatch(ctx, runtimeHookPath, config.PostHook, hookReq); err != nil { | ||
klog.Errorf("fail to call post start container hook server %v", err) |
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.
fail -> Failed
|
||
response, err := d.dispatcher.Dispatch(ctx, runtimeHookPath, config.PreHook, hookReq) | ||
if err != nil { | ||
klog.Errorf("fail to call pre update hook server %v", err) |
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.
Failed
|
||
lis, err := net.Listen("unix", options.RuntimeManagerEndpoint) | ||
if err != nil { | ||
klog.Fatal("fail to create the lis %v", err) |
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.
Failed
1efc6a6
to
4696fdd
Compare
Signed-off-by: Yue Zhang <huaihuan.zy@alibaba-inc.com>
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hormes The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold cancel |
Signed-off-by: Yue Zhang huaihuan.zy@alibaba-inc.com
Ⅰ. Describe what this PR does
to #64
Ⅱ. Does this pull request fix one issue?
Ⅲ. Describe how to verify it
Ⅳ. Special notes for reviews