Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Proxy initial commit#1

Merged
sameo merged 10 commits intokata-containers:masterfrom
bergwolf:proxy
Nov 29, 2017
Merged

Proxy initial commit#1
sameo merged 10 commits intokata-containers:masterfrom
bergwolf:proxy

Conversation

@bergwolf
Copy link
Member

No description provided.

.travis.yml Outdated
- sudo apt-get install -y -qq automake

install:
- cd ${TRAVIS_BUILD_DIR}

Choose a reason for hiding this comment

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

Nit: for consistency with the script section below, you could do this on one line using &&.

go build proxy.go
make -C test

test: all

Choose a reason for hiding this comment

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

This is slightly unusual in that it's the "other way round" to normal (atleast in my mind ;). It might be clearer to have:

all: build test 

build:
    go build proxy.go

test:
    make -C test test

Copy link
Member Author

Choose a reason for hiding this comment

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

I would prefer make command w/o arguments to just build the project rather than running tests altogether. That is also how most Makefiles work.

Choose a reason for hiding this comment

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

Ah - yes, sorry. It hadn't registered that all is the default rule. I guess it's fine as-is or you could make it:

default: build

all: default test

@@ -0,0 +1,10 @@
all:

Choose a reason for hiding this comment

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

Just a general comment - could you add standard copyright headers to all the files? I've just noticed that https://github.com/clearcontainers/proxy/blob/master/Makefile is actually missing one, but it should really match the comment header here for example: https://github.com/clearcontainers/runtime/blob/master/Makefile.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need to have apache 2 licensing statement in every file? There is already an apche LICENSE file in the top directory and I don't think we will use other licenses in the project, right?

OTOH, if it is an Intel open source project policy, I'm willing to follow it.

Copy link
Contributor

Choose a reason for hiding this comment

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

To add to that - I'll note that we are looking at using 'SPDX' style license headers for these new projects - a much smaller and cleaner method than placing the full or part license text in each file.
For reference:
https://github.com/kata-containers/ksm-throttler/pull/1/files#diff-360cbfd0e0c83e21065226e59696f652R5
https://spdx.org/using-spdx

Copy link
Member Author

Choose a reason for hiding this comment

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

SPDX sounds good to me.

proxy.go Outdated
"github.com/hashicorp/yamux"
)

// @channel is the unix socket address we want to multiplex

Choose a reason for hiding this comment

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

Looks like this comment might have become detached from the variable it describes (in main()?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, it was left over from previous versions. I'll just drop it.

Choose a reason for hiding this comment

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

Great - thanks.

proxy.go Outdated
"net"
"sync"

"github.com/golang/glog"

Choose a reason for hiding this comment

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

It might be worth looking at https://github.com/sirupsen/logrus as a very powerful alternative to glog which we're using in all projects currently.

Copy link
Member Author

Choose a reason for hiding this comment

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

All hyper projects use glog instead. We should make a decision on which log system to use for kata and migrate to it.

Choose a reason for hiding this comment

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

Agreed. What's your view @sameo, @grahamwhaley? Do we need to document this somewhere maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've taken the question to the slack channel. Let's discuss it there.

proxy.go Outdated

func main() {
channel := flag.String("s", "/tmp/target.sock", "unix socket to multiplex on")
proxyAddr := flag.String("l", "/tmp/proxy.sock", "unix socket to listen at")

Choose a reason for hiding this comment

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

Do we need these default paths? Also, it would be useful if the options accepted full URIs here (unix:///foo/bar.sock).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I'll add URI support here. And I agree that default paths are useless.

test/test-cmd.sh Outdated
pkill server
pkill proxy

rm -f /tmp/proxy.sock /tmp/target.sock

Choose a reason for hiding this comment

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

It might be better to define a variable for these sockets to avoid the duplication.

test/test-cmd.sh Outdated
pkill proxy

rm -f /tmp/proxy.sock /tmp/target.sock
echo test result is $?

Choose a reason for hiding this comment

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

I think this line is redundant as it will only return the value of the rm?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was using it as a indicator that the test is done because otherwise there is no output. But you do have a valid point that $? is redundant here.

test/test-cmd.sh Outdated
# start server
./server &
# sleep a bit to let server spin up
sleep 2

Choose a reason for hiding this comment

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

This should certainly be sufficient time for the server to start but at some point, it would be better long-term if we had a shell function that performs a check repeatedly (but with a timeout) here (and below).

Copy link
Member Author

Choose a reason for hiding this comment

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

I tend to think that busy pulling with a timeout is a bit over-skill just for this little test script.

Choose a reason for hiding this comment

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

Yes, it's a very simple script at present, so I don't think this is a "blocker" to get this landed. It's just something we need to think about going forward as the script grows to avoid odd failures on (very ;) slow systems.

Copy link
Member Author

Choose a reason for hiding this comment

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

Overall the proxy program will be very simple & small. But yeah, who knows ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we have seen problems with fixed timeouts (even quite large timeouts) when running CI tests on cloud based VM machines - so we've become wary of fixed timeouts and try to avoid them when we can. Flaky CI failures can become the bane of our lives otherwise :-)

test/test-cmd.sh Outdated
output=$(./client -f ${f})
result=$(echo ${output}|grep SUCCESS 2>/dev/null || true)
if [ x"${result}" == "x" ]; then
echo test failed with ${output}

Choose a reason for hiding this comment

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

Maybe add >&2 to denote an error message?

Copy link
Member Author

Choose a reason for hiding this comment

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

The error message from grep is useless. We just need to know if grep succeeds or not.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
Signed-off-by: Peng Tao <bergwolf@gmail.com>
@bergwolf bergwolf force-pushed the proxy branch 3 times, most recently from 5dab6ae to 1234db5 Compare November 20, 2017 11:10
@bergwolf
Copy link
Member Author

updated and CI green. @jodh-intel @grahamwhaley PTAL.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
Signed-off-by: Peng Tao <bergwolf@gmail.com>
Signed-off-by: Peng Tao <bergwolf@gmail.com>
Signed-off-by: Peng Tao <bergwolf@gmail.com>
@sameo
Copy link

sameo commented Nov 27, 2017

@bergwolf I assume you're going to rebase this PR based on the final gRPC definition? Or do you want us to give it a final review and merge it without gRPC support first?

@bergwolf
Copy link
Member Author

@sameo please review it as is. The proxy does not rely on gRPC support.

@sameo
Copy link

sameo commented Nov 27, 2017

@bergwolf ah right, your implementation copies all frames coming from the shim into the yamux endpoint, so it's not a gRPC server itself. I guess doing otherwise would be more secure but also much more complex.

Copy link

@sameo sameo left a comment

Choose a reason for hiding this comment

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

Overall, this looks pretty good. I just have a few minor comments.
One missing piece here are unit tests. The 2 test programs could be implemented as unit tests, which would be easier to use and CI.

Gopkg.toml Outdated
name = "github.com/golang/glog"

[[constraint]]
branch = "master"
Copy link

Choose a reason for hiding this comment

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

Could we stick to a specific revision/SHA1?

proxy.go Outdated

func main() {
var channel, proxyAddr string
flag.StringVar(&channel, "s", "", "unix socket to multiplex on")
Copy link

Choose a reason for hiding this comment

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

Could we give a clearer name for that option? -mux-socket for example.

proxy.go Outdated
func main() {
var channel, proxyAddr string
flag.StringVar(&channel, "s", "", "unix socket to multiplex on")
flag.StringVar(&proxyAddr, "l", "", "unix socket to listen on")
Copy link

Choose a reason for hiding this comment

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

Ditto. -shim-socket or -listen-socket

proxy.go Outdated
"github.com/hashicorp/yamux"
)

func serv(servConn io.ReadWriteCloser, proto, addr string) error {
Copy link

Choose a reason for hiding this comment

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

nit: serve instead of serv?

glog.Error("channel and proxy address must be set")
return
}

Copy link

Choose a reason for hiding this comment

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

This block should be the first check we run (before the prefix/scheme ones).

if strings.HasPrefix(proxyAddr, unixURI) {
proxyAddr = proxyAddr[len(unixURI):]
}

Copy link

Choose a reason for hiding this comment

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

I think you want to use the net/url to safely parse (url.Parse()) the URI you get as an input and verify that we either have a unix scheme or no scheme at all.

proxy.go Outdated
glog.Errorf("fail to accept new connection: %s", err)
return err
}
stream, err := session.Open()
Copy link

Choose a reason for hiding this comment

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

Could you please put the whole stream opening, stream copy and sync logic into a dedicated function and call a go routine on it for each accept? I think this would make the code more readable.

@WeiZhang555
Copy link
Member

WeiZhang555 commented Nov 29, 2017

Oh, please, logrus 👍
glog 👎

I can see some glog lost log problems due to it's buffer/cache, prefer "logrus" much more

Signed-off-by: Peng Tao <bergwolf@gmail.com>
Replace test dir with go testing UT.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
In future we'll use a wrapper above logrus to print glog format logs.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
Signed-off-by: Peng Tao <bergwolf@gmail.com>
@bergwolf
Copy link
Member Author

updated to address @sameo's comments and added unit tests. glog is also replaced with logrus. We'll add a wrapper above logrus to print glog format logs when need.

@sameo
Copy link

sameo commented Nov 29, 2017

@bergwolf Thanks for the update.
LGTM

@sameo sameo merged commit 4520f46 into kata-containers:master Nov 29, 2017
jcvenegas added a commit to jcvenegas/kata-proxy that referenced this pull request Apr 25, 2018
do no merge - only to check move to go 1.10 works

note: make issue number

Fixes: kata-containers#1

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
@jcvenegas jcvenegas mentioned this pull request Apr 25, 2018
jcvenegas added a commit to jcvenegas/kata-proxy that referenced this pull request Apr 25, 2018
do no merge - only to check move to go 1.10 works

note: make issue number

Fixes: kata-containers#1

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
jcvenegas added a commit to jcvenegas/kata-proxy that referenced this pull request Apr 25, 2018
do no merge - only to check move to go 1.10 works

note: make issue number

Fixes: kata-containers#1

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
kalyxin02 added a commit to kalyxin02/proxy that referenced this pull request Aug 3, 2018
Fixes: kata-containers#57

Signed-off-by: Kaly Xin <Kaly.Xin@arm.com>
kalyxin02 added a commit to kalyxin02/proxy that referenced this pull request Aug 8, 2018
Fixes kata-containers#57

Signed-off-by: Kaly Xin <Kaly.Xin@arm.com>
grahamwhaley pushed a commit to grahamwhaley/kata-containers-proxy that referenced this pull request Mar 19, 2019
Add a fake fixes line as well ;-)

Fixes: kata-containers#1

Signed-off-by: Graham Whaley <graham.whaley@intel.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants