Skip to content

Commit

Permalink
Add explicit upstreams to multiport acceptance test (#2986)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jmurret authored Sep 23, 2023
1 parent db6c3de commit c84b059
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 13 deletions.
1 change: 1 addition & 0 deletions acceptance/ci-inputs/kind_acceptance_test_packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions acceptance/tests/fixtures/cases/v2-static-client-inject/patch.yaml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package mesh
package mesh_v2

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package mesh
package mesh_v2

import (
"context"
Expand Down Expand Up @@ -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",
Expand All @@ -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{
Expand All @@ -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.
Expand All @@ -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")

}
})
}
}

0 comments on commit c84b059

Please sign in to comment.