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

Automate DNS redirection to Consul DNS #833

Merged
merged 9 commits into from
Nov 10, 2021
Merged

Automate DNS redirection to Consul DNS #833

merged 9 commits into from
Nov 10, 2021

Conversation

ndhanushkodi
Copy link
Contributor

@ndhanushkodi ndhanushkodi commented Nov 3, 2021

Changes proposed in this PR:

  • When DNS is enabled, get the DNS Service IP and redirect DNS requests to the Consul DNS service.
  • Add kubedns as a recursor for Consul DNS

Corresponding consul PR: hashicorp/consul#11480

How I've tested this PR:

helm install -n consul consul ../charts/consul --set connectInject.enabled=true --set global.image=ashwinvenkatesh/consul@sha256:d02bf8201499a0a6be82fdf279bb1c5f9d2bc1eda2c5fac47ca832c879444292 --set global.imageK8S=ashwinvenkatesh/consul-k8s@sha256:ce817f69f109e7dcb27ba01f1cad29fcfedeff5ed424db21fa095e0e3d582fe9 --set dns.enableRedirection=true --set controller.enabled=true
k apply -f demo.yaml #included in this PR for testing, remove before merging

Then, exec onto the frontend pod, and

curl backend
nslookup backend.service.consul

and verify it returns a pod ip for backend. We can't curl backend.service.consul because envoy only knows to direct traffic based on VIPs not pod ips

How I expect reviewers to test this PR:

  • Code Review
  • Re-try above steps

Checklist:

  • Tests added
  • CHANGELOG entry added

    HashiCorp engineers only, community PRs should not add a changelog entry.
    Entries should use present tense (e.g. Add support for...)

@ndhanushkodi ndhanushkodi marked this pull request as draft November 3, 2021 07:52
demo.yaml Outdated
app: frontend
annotations:
"consul.hashicorp.com/connect-inject": "true"
"consul.hashicorp.com/transparent-proxy-exclude-outbound-cidrs": "151.101.2.133,151.101.66.133,151.101.130.133,151.101.194.133"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

will let us apk update && apk add stuff

ottaviohartman pushed a commit to ottaviohartman/consul-k8s that referenced this pull request Nov 3, 2021
Force delete pods that are still running after `helm uninstall` so the
next installation can begin immediately.
@thisisnotashwin thisisnotashwin force-pushed the automate-dns branch 4 times, most recently from 5475539 to 462098b Compare November 9, 2021 16:03
@thisisnotashwin thisisnotashwin requested review from ishustava, a team and lkysow and removed request for a team November 9, 2021 17:01
@thisisnotashwin thisisnotashwin marked this pull request as ready for review November 9, 2021 17:01
Copy link
Contributor

@ishustava ishustava left a comment

Choose a reason for hiding this comment

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

great work Ashwin and Nitya! I've left some comments/questions inline.

charts/consul/templates/client-daemonset.yaml Outdated Show resolved Hide resolved
charts/consul/templates/server-statefulset.yaml Outdated Show resolved Hide resolved
charts/consul/templates/server-statefulset.yaml Outdated Show resolved Hide resolved
charts/consul/templates/server-statefulset.yaml Outdated Show resolved Hide resolved
charts/consul/test/unit/connect-inject-deployment.bats Outdated Show resolved Hide resolved
charts/consul/values.yaml Show resolved Hide resolved
demo.yaml Outdated Show resolved Hide resolved
Copy link
Member

@lkysow lkysow left a comment

Choose a reason for hiding this comment

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

Still looking but wanted to get feedback on my question about namespaces.

charts/consul/templates/_helpers.tpl Outdated Show resolved Hide resolved
charts/consul/templates/client-daemonset.yaml Outdated Show resolved Hide resolved
charts/consul/templates/connect-inject-deployment.yaml Outdated Show resolved Hide resolved
control-plane/connect-inject/container_init.go Outdated Show resolved Hide resolved
charts/consul/values.yaml Outdated Show resolved Hide resolved
Copy link
Member

@lkysow lkysow left a comment

Choose a reason for hiding this comment

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

Looks mostly good but wondering about how we're finding the ClusterIP.

Also for acceptance tests what are we thinking? Is this gonna be a separate PR?

control-plane/connect-inject/container_init.go Outdated Show resolved Hide resolved

var consulDNSIP string
if dnsEnabled {
for _, e := range os.Environ() {
Copy link
Member

Choose a reason for hiding this comment

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

I found this kinda confusing. I think it could use a comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

@thisisnotashwin thisisnotashwin requested review from lkysow and thisisnotashwin and removed request for thisisnotashwin November 10, 2021 01:00
@thisisnotashwin
Copy link
Contributor

Also for acceptance tests what are we thinking? Is this gonna be a separate PR?

@lkysow Acceptance tests are a great question. The approach I was considering for acceptance testing this change was indirectly using the changes the will be added for transparent proxy for x-partition communication. I will update the fixtures to support transparent proxying the upstream which should test the usage of Consul DNS we ultimately care about.

Copy link
Member

@lkysow lkysow left a comment

Choose a reason for hiding this comment

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

I think we can clean up the env var things now?

control-plane/connect-inject/container_init.go Outdated Show resolved Hide resolved
@@ -138,6 +138,10 @@ type Handler struct {
// from mesh services.
EnableConsulDNS bool

// ReleasePrefix is the prefix used for the installation which is used to determine the Service
// name of the Consul DNS service.
ReleasePrefix string
Copy link
Member

Choose a reason for hiding this comment

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

Can you use ResourcePrefix to match server-acl-init, create-federation-job and others

control-plane/subcommand/inject-connect/command.go Outdated Show resolved Hide resolved
control-plane/connect-inject/container_init.go Outdated Show resolved Hide resolved
charts/consul/templates/connect-inject-deployment.yaml Outdated Show resolved Hide resolved
Comment on lines 546 to 554
@test "connectInject/Deployment: -release-prefix unset by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq -c -r '.spec.template.spec.containers[0].command | join(" ") | contains("-release-prefix=RELEASE-NAME-consul")' | tee /dev/stderr)
[ "${actual}" = "false" ]
}

@test "connectInject/Deployment: -release-prefix is true if dns.enabled=true and dns.enableRedirection=true" {
cd `chart_dir`
local actual=$(helm template \
-s templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set 'dns.enableRedirection=true' \
. | tee /dev/stderr |
yq -c -r '.spec.template.spec.containers[0].command | join(" ") | contains("-release-prefix=RELEASE-NAME-consul")' | tee /dev/stderr)
[ "${actual}" = "true" ]
}
Copy link
Member

Choose a reason for hiding this comment

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

don't need these now

// If Consul DNS is enabled, we find the environment variable that has the value
// of the ClusterIP of the Consul DNS Service. constructDNSServiceHostName returns
// the name of the env variable whose value is the ClusterIP of the Consul DNS Service.
consulDNSClusterIP = os.Getenv(h.constructDNSServiceHostName())
Copy link
Member

Choose a reason for hiding this comment

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

this should error out if the env var is not found

@thisisnotashwin thisisnotashwin force-pushed the automate-dns branch 4 times, most recently from 705b8b9 to 7a4ab00 Compare November 10, 2021 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants