-
Notifications
You must be signed in to change notification settings - Fork 25
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
[VC-35738] Stop the API server when the context is cancelled #604
Conversation
296359b
to
fddc921
Compare
How did you catch this bug? Was it by running the If not, we should add some form of test case somewhere. I'd suggest adding a comment to https://venafi.atlassian.net/browse/VC-35565 to mention that |
server.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
}) | ||
log.Info("Readyz endpoints enabled", "path", "/readyz") |
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.
Nit, unimportant: weird that we start a readiness and liveness server when running --one-shot
, but that's all right IMO
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 agree it's weird, perhaps in a future PR we can make it so that the API server is not started in one-shot mode.
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
It'd be great to have some fast test that uses a fake Venafi Cloud API to test that --one-shot
immediately returns. It could look like the test cases in
jetstack-secure/pkg/agent/config_test.go
Line 615 in 1f00f09
func Test_ValidateAndCombineConfig_VenafiCloudKeyPair(t *testing.T) { |
Run
func
29a5520
to
c214e58
Compare
@maelvls I added a test. Before: $ go test ./pkg/agent/... --run TestRunOneShot -v
=== RUN TestRunOneShot
run_test.go:50: Running child process
run_test.go:68: STDOUT
I1105 11:47:58.084463 81129 logs.go:158] "Preflight agent version: development ()" source="agent"
I1105 11:47:58.084574 81129 logs.go:158] "Using the Jetstack Secure API Token auth mode since --api-token was specified." source="agent"
I1105 11:47:58.085278 81129 logs.go:158] "Reading data from local file: testdata/success/input.json" source="agent"
I1105 11:47:58.085357 81129 logs.go:158] "Data saved to local file: /dev/null" source="agent"
run_test.go:69: STDERR
run_test.go:70:
Error Trace: /home/richard/projects/venafi/venafi-kubernetes-agent/pkg/agent/run_test.go:70
Error: Received unexpected error:
signal: killed
Test: TestRunOneShot
Messages: context deadline exceeded
--- FAIL: TestRunOneShot (3.01s)
FAIL
FAIL github.com/jetstack/preflight/pkg/agent 3.033s
FAIL After: $ go test ./pkg/agent/... --run TestRunOneShot -v -count 1
=== RUN TestRunOneShot
run_test.go:50: Running child process
run_test.go:68: STDOUT
I1105 11:48:56.732058 82228 logs.go:158] "Preflight agent version: development ()" source="agent"
I1105 11:48:56.732211 82228 logs.go:158] "Using the Jetstack Secure API Token auth mode since --api-token was specified." source="agent"
I1105 11:48:56.732225 82228 run.go:117] "Healthz endpoints enabled" logger="APIServer" addr=":8081" path="/healthz"
I1105 11:48:56.732235 82228 run.go:121] "Readyz endpoints enabled" logger="APIServer" addr=":8081" path="/readyz"
I1105 11:48:56.732305 82228 run.go:447] "Starting" logger="APIServer.ListenAndServe" addr=":8081"
I1105 11:48:56.733181 82228 logs.go:158] "Reading data from local file: testdata/success/input.json" source="agent"
I1105 11:48:56.733250 82228 logs.go:158] "Data saved to local file: /dev/null" source="agent"
I1105 11:48:56.733258 82228 run.go:461] "Shutting down" logger="APIServer.ListenAndServe" addr=":8081"
I1105 11:48:56.733332 82228 run.go:476] "Shutdown complete" logger="APIServer.ListenAndServe" addr=":8081"
PASS
run_test.go:69: STDERR
--- PASS: TestRunOneShot (0.03s)
PASS
ok github.com/jetstack/preflight/pkg/agent 0.052s |
Signed-off-by: Richard Wall <richard.wall@venafi.com>
Signed-off-by: Richard Wall <richard.wall@venafi.com>
c214e58
to
46960df
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.
Well done with the test. Thanks. LGTM
In #601 I broke the
--one-shot
feature, because I added the HTTP server to the errgroup, but didn't provide a way to stop the HTTP server after the single gather loop.This PR introduces a simple function which starts the server and calls shutdown when the supplied context is cancelled.
Success:
Example of an error when the port is already occupied.