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

Overwrite k8s HTTP probes when transparent proxy is enabled. #517

Merged
merged 5 commits into from
May 20, 2021

Conversation

ishustava
Copy link
Contributor

@ishustava ishustava commented May 14, 2021

When this is enabled, the mutating webhook will also overwrite the HTTP probes
of the application container to point them to Envoy, while saving the original
ports of the probes as annotations. The endpoints controller will set Expose
configuration for the proxy, setting the LocalPathPort to the port saved
in the annotation.

  • Add a new flag -transparent-proxy-default-overwrite-probes (default to true)
    to allow overwriting k8s probes.
  • Allow setting this on a per-pod basis via the "consul.hashicorp.com/transparent-proxy-overwrite-probes"
    annotation
  • Add new annotations to allow for choosing custom ports for Envoy listeners to expose
    readiness and liveness probes
  • Also, rename the -enable-transparent-proxy to -default-enable-transparent-proxy

How I've tested this PR:
Acceptance test and the helm PR here: hashicorp/consul-helm#953

How I expect reviewers to test this PR:
code review

Checklist:

  • Tests added
  • CHANGELOG entry added (HashiCorp engineers only, community PRs should not add a changelog entry)

When this is enabled, the mutating webhook will also overwrite the HTTP probes
of the application container to point them to Envoy, while saving the original
ports of the probes as annotations. The endpoints controller will set Expose
configuration for the proxy, setting the LocalPathPort to the port saved
in the annotation.

- Add a new flag -transparent-proxy-default-overwrite-probes (default to true)
  to allow overwriting k8s probes.
- Allow setting this on a per-pod basis via the "consul.hashicorp.com/transparent-proxy-overwrite-probes"
  annotation
- Add new annotations to allow for choosing custom ports for Envoy listeners to expose
  readiness and liveness probes
@ishustava ishustava added type/enhancement New feature or request theme/tproxy Items related to transparent proxy labels May 14, 2021
@ishustava ishustava requested review from a team, lkysow and thisisnotashwin and removed request for a team May 14, 2021 13:47
@ishustava ishustava requested review from ndhanushkodi and removed request for lkysow May 18, 2021 21:04
Copy link
Contributor

@thisisnotashwin thisisnotashwin left a comment

Choose a reason for hiding this comment

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

This looks very excellent.

I had a broad suggestion. I think the handler.go method overwriteProbes() should be able to set the desired values for the Port on both the probes as it should be able to read the annotations of the pod. This was the endpoint controller does not have to check the annotations to determine what the value of the port should be and it can just read it off the pod spec.

connect-inject/handler_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@thisisnotashwin thisisnotashwin left a comment

Choose a reason for hiding this comment

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

This PR should live in a museum!!

Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

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

+1 to what ashwin said :)

return nil, nil, err
}
if overwriteProbes {
if cs := pod.Spec.Containers; len(cs) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know for service name and service port we would look at the first container name/port in the past, but those were also overrideable by configuration. In this case, there's no configuration to pick which container is the app container to rewrite the healthcheck. Is it alright to assume here that it should be the first container?

I think yes because we don't support multi-port services and because it's not a limiting requirement to the app dev that the first container is their main app since there isn't an order the containers will run in. But just wanted to voice it out loud in case you thought of something along these lines as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's a really good point. Thanks for bringing this up!

You're right that with a port you could still choose a port from any container, but now we will always overwrite probes for the first container. Thinking about it, I think we could make it work and use the same container to overwrite probes as the container that has the port from the provided port annotation. That will probably be the most accurate, but I'll do it a separate PR. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think that makes sense-- if the port annotation exists, look for the container with a port that matches the annotation, else use the first container? Separate PR totally makes sense as this PR is valuable on its own!

@ishustava ishustava merged commit 7ad32ba into master May 20, 2021
@ishustava ishustava deleted the overwrite-k8s-probes branch May 20, 2021 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/tproxy Items related to transparent proxy type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants