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

feature: support docker proxy #128

Merged
merged 1 commit into from
May 31, 2022

Conversation

ZYecho
Copy link
Contributor

@ZYecho ZYecho commented May 9, 2022

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

http.Error(wr, "Failed to checkpoint resource", http.StatusInternalServerError)
return
}
d.dispatcher.Dispatch(ctx, runtimeHookPath, types.PostHook, resourceExecutor.GenerateHookRequest())
Copy link
Contributor

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(""))
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Member

@jasonliu747 jasonliu747 left a 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-commenter
Copy link

codecov-commenter commented May 24, 2022

Codecov Report

Merging #128 (4696fdd) into main (dc28485) will decrease coverage by 2.70%.
The diff coverage is 3.24%.

❗ Current head 4696fdd differs from pull request most recent head 1c84f64. Consider uploading reports for the commit 1c84f64 to get more accurate results

@@            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     
Flag Coverage Δ
unittests 58.52% <3.24%> (-2.71%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/runtimeproxy/server/docker/handler.go 0.00% <0.00%> (ø)
pkg/runtimeproxy/server/docker/server.go 0.00% <0.00%> (ø)
pkg/runtimeproxy/server/docker/utils.go 17.50% <17.50%> (ø)

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 dc28485...1c84f64. Read the comment docs.

@jasonliu747 jasonliu747 linked an issue May 24, 2022 that may be closed by this pull request

ctx := context.TODO()
reqCopy := req.Clone(ctx)
if strings.Contains(req.URL.Path, "create") {
Copy link
Member

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();
}

Copy link
Contributor Author

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)
Copy link
Member

Choose a reason for hiding this comment

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

missing return ?

Copy link
Contributor Author

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]
Copy link
Member

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?

@ZYecho ZYecho force-pushed the docker-proxy branch 2 times, most recently from 8c21d7f to 347e2c4 Compare May 26, 2022 13:47
Copy link
Member

@jasonliu747 jasonliu747 left a 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
Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

Choose a reason for hiding this comment

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

missing return error response?

Copy link
Member

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)
Copy link
Member

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,
Copy link
Member

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?

@ZYecho ZYecho force-pushed the docker-proxy branch 5 times, most recently from b6bbff7 to 224d3b3 Compare May 27, 2022 07:04
Copy link
Member

@jasonliu747 jasonliu747 left a comment

Choose a reason for hiding this comment

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

image

@ZYecho ZYecho force-pushed the docker-proxy branch 2 times, most recently from e7daa54 to bff134a Compare May 28, 2022 02:07
@ZYecho ZYecho force-pushed the docker-proxy branch 6 times, most recently from 0db4e70 to 6dad85c Compare May 30, 2022 13:11
}

func (d *RuntimeManagerDockerServer) Run() error {

Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

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

tetCase -> testCase

@@ -40,16 +43,22 @@ func main() {
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

dir, _ := filepath.Split(options.RuntimeManagerEndpoint)
_ = os.Mkdir(dir, 0777)
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

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

  1. Handle error;
  2. os.MkdirAll may be better;


package docker

import (
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -40,16 +43,22 @@ func main() {
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

dir, _ := filepath.Split(options.RuntimeManagerEndpoint)
_ = os.Mkdir(dir, 0777)
Copy link
Member

Choose a reason for hiding this comment

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

  1. Handle error;
  2. 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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

Failed

@ZYecho ZYecho force-pushed the docker-proxy branch 4 times, most recently from 1efc6a6 to 4696fdd Compare May 31, 2022 08:55
Signed-off-by: Yue Zhang <huaihuan.zy@alibaba-inc.com>
@hormes
Copy link
Member

hormes commented May 31, 2022

/lgtm
/approve

@koordinator-bot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jasonliu747
Copy link
Member

/hold cancel

@koordinator-bot koordinator-bot bot merged commit a66749d into koordinator-sh:main May 31, 2022
@ZYecho ZYecho deleted the docker-proxy branch May 31, 2022 10:06
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.

[feature request] runtime-manager docker proxy
7 participants