Skip to content

Remove endpoint /quitquitquit from admin server - #3347

Merged
knative-prow-robot merged 1 commit into
knative:masterfrom
andrew-su:issue/3279/hide-admin-endpoint
Mar 11, 2019
Merged

knative-prow-robot merged 1 commit into
knative:masterfrom
andrew-su:issue/3279/hide-admin-endpoint

Conversation

@andrew-su

Copy link
Copy Markdown
Contributor

In this PR the goal is to avoid exposing the admin port to all other pods while maintaining liveness and readiness probing.

  • Port 8022 is no longer exposed through deployment
  • Admin server is now only bound to localhost
  • Liveness and Readiness probes are now executing the queue application to hit its own endpoints.
    • This was done to avoid either updating the base image to have something like curl or creating another binary whose sole purpose is to query the admin endpoints.
    • To query health or quit it's now /ko-app/queue exec health and /ko-app/queue exec quit

Fixes #3279

/lint
/wip
/hold

Open questions:

  • Should the executable path be configurable through a ConfigMap? Separate PR?

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 1, 2019
@googlebot

Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 1, 2019

@knative-prow-robot knative-prow-robot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@xtreme-andrew-su: 4 warnings.

Details

In response to this:

In this PR the goal is to avoid exposing the admin port to all other pods while maintaining liveness and readiness probing.

  • Port 8022 is no longer exposed through deployment
  • Admin server is now only bound to localhost
  • Liveness and Readiness probes are now executing the queue application to hit its own endpoints.
  • This was done to avoid either updating the base image to have something like curl or creating another binary whose sole purpose is to query the admin endpoints.
  • To query health or quit it's now /ko-app/queue exec health and /ko-app/queue exec quit

Fixes #3279

/lint
/wip
/hold

Open questions:

  • Should the executable path be configurable through a ConfigMap? Separate PR?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Comment thread cmd/queue/main.go Resolved
Comment thread pkg/queue/constants.go Resolved
Comment thread pkg/queue/constants.go Resolved
Comment thread pkg/queue/constants.go Resolved
@andrew-su
andrew-su force-pushed the issue/3279/hide-admin-endpoint branch 2 times, most recently from 535db98 to 5a342d7 Compare March 1, 2019 16:12

@andrew-su andrew-su left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed linter errors.

Comment thread pkg/queue/constants.go Resolved
Comment thread pkg/queue/constants.go Resolved
Comment thread pkg/queue/constants.go Resolved
@andrew-su

Copy link
Copy Markdown
Contributor Author

I signed it!

@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@andrew-su

Copy link
Copy Markdown
Contributor Author

It looks like the version of ko used by the CI is on an older version. This is causing the path to live on /ko-app rather than /ko-app/queue

@vagababov vagababov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So the main question is: if this is an admin tool that someone has to launch somehow (how?): then why is it in queue binary at all?

Comment thread cmd/queue/main.go Resolved
Comment thread cmd/queue/main.go Resolved
@tcnghia

tcnghia commented Mar 1, 2019

Copy link
Copy Markdown
Contributor

So the main question is: if this is an admin tool that someone has to launch somehow (how?): then why is it in queue binary at all?

@vagababov it is launched by the kubelet by the readiness probe and the lifecycle hook. My guess of why @xtreme-andrew-su puts it in the queue binary is that because ko builds one binary into one container.

@jonjohnsonjr is there a way to have ko build two go binaries into one container?

@andrew-su
andrew-su force-pushed the issue/3279/hide-admin-endpoint branch 2 times, most recently from ac56291 to d1c6464 Compare March 1, 2019 20:44
Comment thread cmd/queue/main.go Resolved

@vagababov vagababov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just stylistic.
Thanks!

Comment thread cmd/queue/main.go Resolved
Comment thread cmd/queue/main.go Resolved
@andrew-su
andrew-su force-pushed the issue/3279/hide-admin-endpoint branch from bc11798 to 10c98a6 Compare March 4, 2019 19:20

@vagababov vagababov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm
Thanks,

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 4, 2019
@andrew-su

Copy link
Copy Markdown
Contributor Author

@tcnghia

Do you have a bit more context on this snippet?

// This PreStop hook is actually calling an endpoint on the queue-proxy
// because of the way PreStop hooks are called by kubelet. We use this
// to block the user-container from exiting before the queue-proxy is ready
// to exit so we can guarantee that there are no more requests in flight.
userLifecycle = &corev1.Lifecycle{
PreStop: &corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{
Port: intstr.FromInt(v1alpha1.RequestQueueAdminPort),
Path: queue.RequestQueueQuitPath,
},
},
}
I just noticed that when combing through the code again for usages of quit.

@tcnghia

tcnghia commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

@xtreme-andrew-su good find. The context here is that the user-container will need to wait for queue-proxy to drain properly.

So in this case we probably have to keep the admin port but won't expose /quitquitquit, only expose something like /wait-for-drain to be used by user-container. /wait-for-drain will be similar to what /quitquitquit does currently but it is a read-only endpoint.

Please let me know if this make sense?

@andrew-su

Copy link
Copy Markdown
Contributor Author

@xtreme-andrew-su good find. The context here is that the user-container will need to wait for queue-proxy to drain properly.

So in this case we probably have to keep the admin port but won't expose /quitquitquit, only expose something like /wait-for-drain to be used by user-container. /wait-for-drain will be similar to what /quitquitquit does currently but it is a read-only endpoint.

Please let me know if this make sense?

The idea makes sense to have the user container finish processing what it has already accepted while it makes the queue-proxy container not "ready" thus requests are no longer routed to it. The /quitquitquit endpoint currently imposes a 20s delay before it shuts down the queue server. If I understood your response correctly, the idea would be to create /wait-for-drain on the admin port to do the 20s delay then return successfully?

@tcnghia

tcnghia commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

@xtreme-andrew-su If that is all /quitquitquit does, then I would rather name the new endpoint /sleep that takes a duration parameter.

@markusthoemmes

Copy link
Copy Markdown
Contributor

@tcnghia I fear that what you're suggesting is not feasible in this case. It sleeps for 20s (we had that historically, I think we can revisit that sleep at this point) and then calls Shutdown on the queue-server. Shutdown blocks until all requests have been drained. In that sense, the Shutdown call is part of the drain but also eventually kills the server, making it non-idempotent.

@andrew-su

andrew-su commented Mar 5, 2019 •

Copy link
Copy Markdown
Contributor Author

Do we really need the exec in that case? As-in: Do we need a prestop at all for the queue?

Yeah, we still want the prestop for the queue container. Since we want the prestop on queue container to marks itself as not-ready and begin shutdown. The user-container won't have access to do that as the endpoint for shutdown won't exist anymore and can't call the queue binary.

@andrew-su

Copy link
Copy Markdown
Contributor Author

I'd like to do a fact check with y'all.

  1. We want the user container to terminate only after the queue-proxy container.
    • This means we want connections that was accepted by queue-proxy to be handled by user-container.
  2. We don't want to accept any more connections when we are about to terminate this pod
    • The queue-proxy container should not be ready during termination.

What we have today:
The /quitquitquit endpoint marks the queue-proxy container as "not ready" and shuts down the proxy server.
This endpoint is called by the pre-stop of both queue-proxy and user-container.

  • The user-container calls this because it wants to wait for the connections to fully terminate.
  • The queue-proxy calls this because it wants to stop accepting new connections.

After an attempt at the previous proposal.. it was getting a bit ugly/messy. Taking a step back, I feel we should be moving towards:

  1. Remove the /quitquitquit endpoint.
  2. Remove the pre-stop lifecycle hook on queue-proxy
  3. Change the pre-stop lifecycle hook on user-container to hit a /wait-for-drain endpoint.
  4. Do what quit was supposed to do when SIGTERM is received on queue-proxy container.
    • Mark self as "not ready"
    • Wait for istio to sync (I believe that's what the 20s delay is)
    • Start terminating the proxy server
    • Start terminating the admin server

This should address the two goals above.

Is there something I'm missing in the purpose of /quitquitquit?

@andrew-su
andrew-su force-pushed the issue/3279/hide-admin-endpoint branch from 10c98a6 to e74e00a Compare March 8, 2019 20:03
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 8, 2019
@andrew-su
andrew-su force-pushed the issue/3279/hide-admin-endpoint branch from e74e00a to 612f549 Compare March 8, 2019 20:05
@andrew-su

Copy link
Copy Markdown
Contributor Author

/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 8, 2019
@andrew-su
andrew-su force-pushed the issue/3279/hide-admin-endpoint branch 2 times, most recently from 889441a to 4674b7c Compare March 8, 2019 20:51
@andrew-su

Copy link
Copy Markdown
Contributor Author

/retest

@markusthoemmes markusthoemmes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks superb to me. Very neat implementation, thanks @xtreme-andrew-su!

Left a few comments here and there but great overall!

/approve

cleaner()
}
return func(_ http.ResponseWriter, _ *http.Request) {
<-h.drainCh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need to send a response at all?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh I see, there is a test for that 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, I figured that if they wanted to know the actual readiness of the server they should use /health

Comment thread pkg/queue/health/health_state.go Resolved
Comment thread cmd/queue/main.go
time.Sleep(quitSleepDuration)
if err := server.Shutdown(context.Background()); err != nil {
logger.Errorf("Failed to shutdown proxy server", zap.Error(err))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shall we keep the debug log and the comment on server.Shutdown?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added comments for sleep and shutdown

Comment thread pkg/queue/constants.go Outdated
// queue-proxy.
RequestQueueHealthPath = "/health"

// RequestQueueDrainPath specifies the path for waiting on drain.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe specify what "drain" is in this case with a bit more verbosity. As you probably noted while implementing this, the "why things are the way they are" can be confusing to detangle in this case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated!

@markusthoemmes

Copy link
Copy Markdown
Contributor

@xtreme-andrew-su Want to rename the PR? The commit message will equal to the PR name and the impl. has changed a lot.

@andrew-su andrew-su changed the title Bind admin endpoint in queue-proxy to localhost Remove endpoint /quitquitquit for shutting down proxy server Mar 11, 2019
This change is to fix issue knative#3279.
Rely on SIGTERM from kubernetes to trigger drain.
User-container wait for the drain to complete instead of shutting down
the proxy server.

* Add new endpoint `/wait-for-drain`
* Remove the pre-stop lifecycle hook on queue-proxy container
* Update the pre-stop lifecycle hook on user-container to use
  `wait-for-drain`
@andrew-su
andrew-su force-pushed the issue/3279/hide-admin-endpoint branch from 4674b7c to 2f0eade Compare March 11, 2019 13:30
@andrew-su andrew-su changed the title Remove endpoint /quitquitquit for shutting down proxy server Remove endpoint /quitquitquit from admin server Mar 11, 2019

@markusthoemmes markusthoemmes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm
/approve

Very nice work 🎉

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 11, 2019
@markusthoemmes

Copy link
Copy Markdown
Contributor

/assign @mattmoor

Would you do me the honors for the reconciler changes?

return func(w http.ResponseWriter, r *http.Request) {
h.shutdown()
// DrainHandler constructs a handler that waits until the proxy server is shut down.
func (h *State) DrainHandler() func(_ http.ResponseWriter, _ *http.Request) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Considering that this is done once during the construction of the server, why not just create the channel during construction of the State? At that point the whole function can be replaced with

func (h *State) DrainHandler(_ http.ResponseWriter, _ *http.Request) {
 <- h.drainCh
}

and its invocation, as mux.HandleFunc(queue.RequestQueueDrainPath, healthState.DrainHandler)

@tcnghia

tcnghia commented Mar 11, 2019

Copy link
Copy Markdown
Contributor

/approve

@knative-prow-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: markusthoemmes, tcnghia, xtreme-andrew-su

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 11, 2019
@knative-prow-robot
knative-prow-robot merged commit 7f40e1c into knative:master Mar 11, 2019
@andrew-su
andrew-su deleted the issue/3279/hide-admin-endpoint branch March 12, 2019 13:54
@julz julz mentioned this pull request Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants