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

agentless: Multi-cluster tproxy #1632

Merged
merged 14 commits into from
Oct 25, 2022
Merged

Conversation

ishustava
Copy link
Contributor

@ishustava ishustava commented Oct 18, 2022

Changes proposed in this PR:

  • Redirect traffic to the consul-dataplane's DNS proxy when DNS redirection is enabled. This means we no longer need to configure recursors for the clients and servers
  • To fall back to kube dns when consul cannot resolve names, we define our own DNSConfig on the pod that uses Consul first, but falls back to the config from /etc/resolv.conf in the cluster.

How I've tested this PR:
acceptance tests

How I expect reviewers to test this PR:
👀

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...)

@ishustava ishustava force-pushed the ishustava/tproxy-single-cluster branch from dc24cc4 to f092e46 Compare October 19, 2022 22:59
@ishustava ishustava force-pushed the ishustava/tproxy-multi-cluster branch 6 times, most recently from acbe0ef to f986784 Compare October 21, 2022 01:42
@ishustava ishustava changed the title Multi-cluster tproxy agentless: Multi-cluster tproxy Oct 21, 2022
@ishustava ishustava force-pushed the ishustava/tproxy-multi-cluster branch 12 times, most recently from f990912 to 34ca662 Compare October 22, 2022 00:43
@@ -1194,7 +1194,7 @@ func TestAcceptorUpdateStatusError(t *testing.T) {
reconcileErr: errors.New("this is an error"),
expStatus: v1alpha1.PeeringAcceptorStatus{
Conditions: v1alpha1.Conditions{
{
v1alpha1.Condition{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are from running linter locally

Copy link
Contributor

Choose a reason for hiding this comment

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

This is so weird. I remember getting linter failures when they initially existed and had to delete them. 🤔

Copy link
Contributor Author

@ishustava ishustava Oct 25, 2022

Choose a reason for hiding this comment

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

Yeah I'm confused as well. Maybe it's a go 1.19 thing?

@@ -59,16 +57,17 @@ func TestConsulDNS(t *testing.T) {
serverIPs = append(serverIPs, serverPod.Status.PodIP)
}

dnsPodName := fmt.Sprintf("%s-dns-pod", releaseName)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test fails sometimes because a pod with this name already exists, so making the names unique per test.

@@ -620,9 +620,9 @@ func TestReconcile_CreateUpdatePeeringAcceptor(t *testing.T) {
decodedTokenData, err := base64.StdEncoding.DecodeString(string(createdSecret.Data["data"]))
require.NoError(t, err)

require.Contains(t, string(decodedTokenData), "\"CA\":null")
require.Contains(t, string(decodedTokenData), "\"CA\":")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes are needed to support consul 1.14 peering changes so that we can use the latest binary in tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh thanks for bumping that!!

@ishustava ishustava force-pushed the ishustava/tproxy-single-cluster branch from 117ebca to 15b09df Compare October 24, 2022 19:15
@ishustava ishustava force-pushed the ishustava/tproxy-multi-cluster branch from 51475be to 57eee52 Compare October 24, 2022 19:33
Base automatically changed from ishustava/tproxy-single-cluster to main October 25, 2022 04:13
@ishustava ishustava force-pushed the ishustava/tproxy-multi-cluster branch 3 times, most recently from 8e8b5ba to 3cbacec Compare October 25, 2022 04:22
@ishustava ishustava force-pushed the ishustava/tproxy-multi-cluster branch from 3cbacec to 9437b2c Compare October 25, 2022 04:30
@ishustava ishustava marked this pull request as ready for review October 25, 2022 05:23
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.

Have a few aesthetic comments but this is excellent!! Your comments made reviewing and understanding what was happening super easy! Great job!

Comment on lines -151 to -163
{{/*
Sets up a list of recusor flags for Consul agents by iterating over the IPs of every nameserver
in /etc/resolv.conf and concatenating them into a string of arguments that can be passed directly
to the consul agent command.
*/}}
{{- define "consul.recursors" -}}
recursor_flags=""
for ip in $(cat /etc/resolv.conf | grep nameserver | cut -d' ' -f2)
do
recursor_flags="$recursor_flags -recursor=$ip"
done
{{- end -}}

Copy link
Contributor

Choose a reason for hiding this comment

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

YAYYYYY!!!!

@@ -1194,7 +1194,7 @@ func TestAcceptorUpdateStatusError(t *testing.T) {
reconcileErr: errors.New("this is an error"),
expStatus: v1alpha1.PeeringAcceptorStatus{
Conditions: v1alpha1.Conditions{
{
v1alpha1.Condition{
Copy link
Contributor

Choose a reason for hiding this comment

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

This is so weird. I remember getting linter failures when they initially existed and had to delete them. 🤔


func (w *MeshWebhook) configureDNS(pod *corev1.Pod, k8sNS string) error {
// First, we need to determine the nameservers configured in this cluster from /etc/resolv.conf.
etcResolvConf := "/etc/resolv.conf"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make this a constant. WDYT?

// configured in our /etc/resolv.conf. It's important to add Consul DNS as the first nameserver because
// if we put kube DNS first, it will return NXDOMAIN response and a DNS client will not fall back to other nameservers.
if pod.Spec.DNSConfig == nil {
consulDPAddress := "127.0.0.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

potentially make this a constant as well

Comment on lines +63 to +66
// Replace release namespace in the searches with the pod namespace.
// This is so that the searches we generate will be for the pod's namespace
// instead of the namespace of the connect-injector. E.g. instead of
// consul.svc.cluster.local it should be <pod ns>.svc.cluster.local.
Copy link
Contributor

Choose a reason for hiding this comment

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

Really appreciate the comments 🙏

@ishustava ishustava force-pushed the ishustava/tproxy-multi-cluster branch from 267355b to a488a2c Compare October 25, 2022 16:08
c.Datacenter = "acceptor-dc"
c.Connect["ca_config"] = map[string]interface{}{
"cluster_id": "00000000-2222-3333-4444-555555555555",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

if cfg.EnableTransparentProxy {
t.Skipf("skipping because no t-proxy support")
}

Copy link
Contributor

Choose a reason for hiding this comment

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

omg so this works???

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup! it works! 🎉

@ishustava ishustava force-pushed the ishustava/tproxy-multi-cluster branch from 1f83c02 to 6cff666 Compare October 25, 2022 20:59
@ishustava ishustava force-pushed the ishustava/tproxy-multi-cluster branch from 6cff666 to 486f1c4 Compare October 25, 2022 21:03
@ishustava ishustava merged commit 933cc5e into main Oct 25, 2022
@ishustava ishustava deleted the ishustava/tproxy-multi-cluster branch October 25, 2022 21:44
t-eckert pushed a commit that referenced this pull request Oct 31, 2022
* Redirect traffic to the consul-dataplane's DNS proxy when DNS redirection is enabled. This means we no longer need to configure recursors for the clients and servers
* To fall back to kube dns when consul cannot resolve names, we define our own DNSConfig on the pod that uses Consul first, but falls back to the config from /etc/resolv.conf in the cluster.
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.

4 participants