From c84b059db281867b070461230ebea4caddb416c9 Mon Sep 17 00:00:00 2001 From: John Murret Date: Fri, 22 Sep 2023 17:53:12 -0700 Subject: [PATCH] Add explicit upstreams to multiport acceptance test (#2986) * added explicit upstream write/delete tests - most of the tests cases are based on what is currently in the endpoint controller - split some of the write cases into just testing the processing logic so that we don't have to spin up a Consul client each time which made the test very slow. --- .../kind_acceptance_test_packages.yaml | 1 + .../kustomization.yaml | 9 +++++ .../cases/v2-static-client-inject/patch.yaml | 13 +++++++ .../mesh => tests/mesh_v2}/main_test.go | 2 +- .../mesh_v2}/mesh_inject_test.go | 39 +++++++++++++------ 5 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 acceptance/tests/fixtures/cases/v2-static-client-inject/kustomization.yaml create mode 100644 acceptance/tests/fixtures/cases/v2-static-client-inject/patch.yaml rename acceptance/{tests-v2/mesh => tests/mesh_v2}/main_test.go (94%) rename acceptance/{tests-v2/mesh => tests/mesh_v2}/mesh_inject_test.go (63%) diff --git a/acceptance/ci-inputs/kind_acceptance_test_packages.yaml b/acceptance/ci-inputs/kind_acceptance_test_packages.yaml index e0e126bbda..eaf1dae73d 100644 --- a/acceptance/ci-inputs/kind_acceptance_test_packages.yaml +++ b/acceptance/ci-inputs/kind_acceptance_test_packages.yaml @@ -8,3 +8,4 @@ - {runner: 4, test-packages: "cli vault metrics"} - {runner: 5, test-packages: "api-gateway ingress-gateway sync example consul-dns"} - {runner: 6, test-packages: "config-entries terminating-gateway basic"} +- {runner: 7, test-packages: "mesh_v2"} diff --git a/acceptance/tests/fixtures/cases/v2-static-client-inject/kustomization.yaml b/acceptance/tests/fixtures/cases/v2-static-client-inject/kustomization.yaml new file mode 100644 index 0000000000..564d02a68f --- /dev/null +++ b/acceptance/tests/fixtures/cases/v2-static-client-inject/kustomization.yaml @@ -0,0 +1,9 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../../bases/static-client +patches: +- path: patch.yaml diff --git a/acceptance/tests/fixtures/cases/v2-static-client-inject/patch.yaml b/acceptance/tests/fixtures/cases/v2-static-client-inject/patch.yaml new file mode 100644 index 0000000000..41b3f192f8 --- /dev/null +++ b/acceptance/tests/fixtures/cases/v2-static-client-inject/patch.yaml @@ -0,0 +1,13 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: static-client +spec: + template: + metadata: + annotations: + "consul.hashicorp.com/mesh-inject": "true" + "consul.hashicorp.com/mesh-service-destinations": "web.port.multiport.svc:1234,admin.port.multiport.svc:2345" \ No newline at end of file diff --git a/acceptance/tests-v2/mesh/main_test.go b/acceptance/tests/mesh_v2/main_test.go similarity index 94% rename from acceptance/tests-v2/mesh/main_test.go rename to acceptance/tests/mesh_v2/main_test.go index 6889dfbd13..d510056a10 100644 --- a/acceptance/tests-v2/mesh/main_test.go +++ b/acceptance/tests/mesh_v2/main_test.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package mesh +package mesh_v2 import ( "os" diff --git a/acceptance/tests-v2/mesh/mesh_inject_test.go b/acceptance/tests/mesh_v2/mesh_inject_test.go similarity index 63% rename from acceptance/tests-v2/mesh/mesh_inject_test.go rename to acceptance/tests/mesh_v2/mesh_inject_test.go index 0ebccbc7ab..723ae2a8e8 100644 --- a/acceptance/tests-v2/mesh/mesh_inject_test.go +++ b/acceptance/tests/mesh_v2/mesh_inject_test.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package mesh +package mesh_v2 import ( "context" @@ -31,15 +31,12 @@ func TestMeshInject_MultiportService(t *testing.T) { t.Run(name, func(t *testing.T) { cfg := suite.Config() cfg.SkipWhenOpenshiftAndCNI(t) - if !cfg.EnableTransparentProxy { - t.Skipf("skipping this because -enable-transparent-proxy is not set") - } ctx := suite.Environment().DefaultContext(t) helmValues := map[string]string{ - "global.image": "ndhanushkodi/consul-dev:multiport37", - "global.imageK8S": "ndhanushkodi/consul-k8s-dev:multiport25", - "global.imageConsulDataplane": "hashicorppreview/consul-dataplane:1.3-dev", + "global.image": "jmurrethc/consul-dev", + "global.imageK8S": "jmurrethc/consul-k8s-control-plane-dev", + "global.imageConsulDataplane": "jmurrethc/consul-dataplane-dev", "global.experiments[0]": "resource-apis", // The UI is not supported for v2 in 1.17, so for now it must be disabled. "ui.enabled": "false", @@ -58,7 +55,11 @@ func TestMeshInject_MultiportService(t *testing.T) { logger.Log(t, "creating multiport static-server and static-client deployments") k8s.DeployKustomize(t, ctx.KubectlOptions(t), cfg.NoCleanupOnFailure, cfg.NoCleanup, cfg.DebugDirectory, "../../tests/fixtures/bases/v2-multiport-app") - k8s.DeployKustomize(t, ctx.KubectlOptions(t), cfg.NoCleanupOnFailure, cfg.NoCleanup, cfg.DebugDirectory, "../../tests/fixtures/cases/v2-static-client-inject-tproxy") + if cfg.EnableTransparentProxy { + k8s.DeployKustomize(t, ctx.KubectlOptions(t), cfg.NoCleanupOnFailure, cfg.NoCleanup, cfg.DebugDirectory, "../../tests/fixtures/cases/v2-static-client-inject-tproxy") + } else { + k8s.DeployKustomize(t, ctx.KubectlOptions(t), cfg.NoCleanupOnFailure, cfg.NoCleanup, cfg.DebugDirectory, "../../tests/fixtures/cases/v2-static-client-inject") + } // Check that static-client has been injected and now has 2 containers. podList, err := ctx.KubernetesClient(t).CoreV1().Pods(ctx.KubectlOptions(t).Namespace).List(context.Background(), metav1.ListOptions{ @@ -77,10 +78,18 @@ func TestMeshInject_MultiportService(t *testing.T) { require.Len(t, podList.Items[0].Spec.Containers, 3) // Check connection from static-client to multiport. - k8s.CheckStaticServerConnectionSuccessful(t, ctx.KubectlOptions(t), connhelper.StaticClientName, "http://multiport:8080") + if cfg.EnableTransparentProxy { + k8s.CheckStaticServerConnectionSuccessful(t, ctx.KubectlOptions(t), connhelper.StaticClientName, "http://multiport:8080") + } else { + k8s.CheckStaticServerConnectionSuccessful(t, ctx.KubectlOptions(t), connhelper.StaticClientName, "http://localhost:1234") + } // Check connection from static-client to multiport-admin. - k8s.CheckStaticServerConnectionSuccessfulWithMessage(t, ctx.KubectlOptions(t), connhelper.StaticClientName, "hello world from 9090 admin", "http://multiport:9090") + if cfg.EnableTransparentProxy { + k8s.CheckStaticServerConnectionSuccessfulWithMessage(t, ctx.KubectlOptions(t), connhelper.StaticClientName, "hello world from 9090 admin", "http://multiport:9090") + } else { + k8s.CheckStaticServerConnectionSuccessfulWithMessage(t, ctx.KubectlOptions(t), connhelper.StaticClientName, "hello world from 9090 admin", "http://localhost:2345") + } // Test that kubernetes readiness status is synced to Consul. This will make the multi port pods unhealthy // and check inbound connections to the multi port pods' services. @@ -95,8 +104,14 @@ func TestMeshInject_MultiportService(t *testing.T) { // We are expecting a "connection reset by peer" error because in a case of health checks, // there will be no healthy proxy host to connect to. That's why we can't assert that we receive an empty reply // from server, which is the case when a connection is unsuccessful due to intentions in other tests. - k8s.CheckStaticServerConnectionMultipleFailureMessages(t, ctx.KubectlOptions(t), connhelper.StaticClientName, false, []string{"curl: (56) Recv failure: Connection reset by peer", "curl: (52) Empty reply from server"}, "", "http://multiport:8080") - k8s.CheckStaticServerConnectionMultipleFailureMessages(t, ctx.KubectlOptions(t), connhelper.StaticClientName, false, []string{"curl: (56) Recv failure: Connection reset by peer", "curl: (52) Empty reply from server"}, "", "http://multiport:9090") + if cfg.EnableTransparentProxy { + k8s.CheckStaticServerConnectionMultipleFailureMessages(t, ctx.KubectlOptions(t), connhelper.StaticClientName, false, []string{"curl: (56) Recv failure: Connection reset by peer", "curl: (52) Empty reply from server"}, "", "http://multiport:8080") + k8s.CheckStaticServerConnectionMultipleFailureMessages(t, ctx.KubectlOptions(t), connhelper.StaticClientName, false, []string{"curl: (56) Recv failure: Connection reset by peer", "curl: (52) Empty reply from server"}, "", "http://multiport:9090") + } else { + k8s.CheckStaticServerConnectionMultipleFailureMessages(t, ctx.KubectlOptions(t), connhelper.StaticClientName, false, []string{"curl: (56) Recv failure: Connection reset by peer", "curl: (52) Empty reply from server"}, "", "http://localhost:1234") + k8s.CheckStaticServerConnectionMultipleFailureMessages(t, ctx.KubectlOptions(t), connhelper.StaticClientName, false, []string{"curl: (56) Recv failure: Connection reset by peer", "curl: (52) Empty reply from server"}, "", "http://localhost:2345") + + } }) } }