-
Notifications
You must be signed in to change notification settings - Fork 20
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
test: support running integration test with envoy bin #810
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #810 +/- ##
==========================================
+ Coverage 85.68% 85.72% +0.03%
==========================================
Files 141 141
Lines 8336 8336
==========================================
+ Hits 7143 7146 +3
+ Misses 937 934 -3
Partials 256 256 ☔ View full report in Codecov by Sentry. |
228bae8
to
b5be4c0
Compare
0fc3dfd
to
5d34462
Compare
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
5d34462
to
6c22db2
Compare
portEnv, _ := strconv.Atoi(os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT")) | ||
if portEnv != 0 { | ||
port = portEnv | ||
} |
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 prefer the following method, but yours is okay.
portEnv, _ := strconv.Atoi(os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT")) | |
if portEnv != 0 { | |
port = portEnv | |
} | |
if p, err := strconv.Atoi(os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT")); err == nil && p != 0 { | |
port = p | |
} |
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, thanks! My code style is more concise.
addr["port_value"] = b.dp.Port() | ||
|
||
if isBinaryMode() { | ||
for _, l := range root["static_resources"].(map[string]interface{})["listeners"].([]interface{}) { |
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 use staticResource
defined above here?
for _, l := range root["static_resources"].(map[string]interface{})["listeners"].([]interface{}) { | |
for _, l := range staticResource["listeners"].([]interface{}) { |
httpFilters := hcm["http_filters"].([]interface{}) | ||
for _, hf := range httpFilters { |
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.
It looks like httpFilters
is only used once. I prefer to remove this middle variable. But reserving it is also good.
httpFilters := hcm["http_filters"].([]interface{}) | |
for _, hf := range httpFilters { | |
for _, hf := range hcm["http_filters"].([]interface{}) { |
|
||
err = opt.Bootstrap.WriteTo(cfgFile) | ||
cfgFile.Close() | ||
if err != nil { | ||
return nil, 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.
cfgFile
is used below. We can not close it here immediately.
err = opt.Bootstrap.WriteTo(cfgFile) | |
cfgFile.Close() | |
if err != nil { | |
return nil, err | |
} | |
defer cfgFile.Close() | |
if err = opt.Bootstrap.WriteTo(cfgFile); err != nil { | |
return nil, 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.
We only use cfgFile.Name()
later
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 fact, we must close the cfgFile immediately to ensure the written content is flushed.
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.
OK, Thank you for your detailed explanation.
image := "m.daocloud.io/docker.io/envoyproxy/envoy:contrib-v1.32.0" | ||
|
||
specifiedImage := os.Getenv("PROXY_IMAGE") | ||
if specifiedImage != "" { | ||
image = specifiedImage | ||
} |
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.
image := "m.daocloud.io/docker.io/envoyproxy/envoy:contrib-v1.32.0" | |
specifiedImage := os.Getenv("PROXY_IMAGE") | |
if specifiedImage != "" { | |
image = specifiedImage | |
} | |
image := "m.daocloud.io/docker.io/envoyproxy/envoy:contrib-v1.32.0" | |
if specifiedImage := os.Getenv("PROXY_IMAGE"); specifiedImage != "" { | |
image = specifiedImage | |
} |
hostAddr + " " + | ||
image | ||
|
||
envoyCmd = "envoy -c /etc/envoy.yaml" |
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 construct of envoyCmd
is simple, what about moving it before cmdLine
?
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.
This is too trivial to change.
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 cmdLine doesn't depend on the envoyCmd. And envoyCmd is a new neighbor of the cmdLine. Add the new code after the old one is natural.
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.
OK, it makes sense to me.
addEnvironemntVariables(cmd, opt.Envs) | ||
} | ||
|
||
out, err := cmd.CombinedOutput() |
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.
it looks like we can use following pattern here:
if out, err := cmd.CombinedOutput(); err != nil {
...
}
return nil, err | ||
} | ||
cmd.Stdout = stdout | ||
|
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 logic for stdout
are same in two branches here. So I think we can move the logic of stdout
out of the if-else
here.
It will looks like:
if stdout, err := os.Create(filepath.Join(dir, "stdout")); err != nil {
cmd.Stdout = stdout
}
if isBinaryMode() {
cmd.Stderr = ....
}
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 prefer to keep the code in the if-else block so I can write comments for it, especially to make the comment match the one in the stderr.
waitTimeEnv, _ := time.ParseDuration(os.Getenv("TEST_ENVOY_WAIT_BINARY_TO_START_TIME")) | ||
if waitTimeEnv != 0 { | ||
waitTime = waitTimeEnv | ||
} |
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.
waitTimeEnv, _ := time.ParseDuration(os.Getenv("TEST_ENVOY_WAIT_BINARY_TO_START_TIME")) | |
if waitTimeEnv != 0 { | |
waitTime = waitTimeEnv | |
} | |
if waitTimeEnv, err := time.ParseDuration(os.Getenv("TEST_ENVOY_WAIT_BINARY_TO_START_TIME")); err != nil && waitTimeEnv != 0 { | |
waitTime = waitTimeEnv | |
} |
dp.cmd.Process.Signal(syscall.SIGTERM) | ||
} else { | ||
cmd := exec.Command("docker", "stop", containerName) | ||
err = cmd.Run() |
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 that we can check err
here immediately, another branch will not return an 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.
This is too trivial to change. If we add the err next time, we have to move the err check out again.
If my points have mistakes, feel free to correct me. |
No description provided.