Skip to content

Commit

Permalink
Add test case for gateway pod reconciliation
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancoleman committed Dec 18, 2023
1 parent 66739e7 commit e518860
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestReconcileCreatePodWithMirrorNamespaces(t *testing.T) {
expectedConsulNamespace: constants.DefaultConsulNS,
expectedWorkload: createWorkload(),
expectedHealthStatus: createPassingHealthStatus(),
expectedProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
expectedProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
},
{
name: "kitchen sink new pod, non-default ns and partition",
Expand All @@ -127,7 +127,7 @@ func TestReconcileCreatePodWithMirrorNamespaces(t *testing.T) {
expectedConsulNamespace: "bar",
expectedWorkload: createWorkload(),
expectedHealthStatus: createPassingHealthStatus(),
expectedProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
expectedProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
},
{
name: "new pod with namespace prefix",
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestReconcileCreatePodWithMirrorNamespaces(t *testing.T) {
expectedConsulNamespace: constants.DefaultConsulNS,
expectedWorkload: createWorkload(),
expectedHealthStatus: createPassingHealthStatus(),
expectedProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
expectedProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
expectedDestinations: createDestinations(),
},
{
Expand Down Expand Up @@ -273,12 +273,12 @@ func TestReconcileUpdatePodWithMirrorNamespaces(t *testing.T) {
existingConsulNamespace: "bar",
existingWorkload: createWorkload(),
existingHealthStatus: createPassingHealthStatus(),
existingProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
existingProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),

expectedConsulNamespace: "bar",
expectedWorkload: createWorkload(),
expectedHealthStatus: createPassingHealthStatus(),
expectedProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
expectedProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
},
}

Expand Down Expand Up @@ -311,7 +311,7 @@ func TestReconcileDeletePodWithMirrorNamespaces(t *testing.T) {
existingConsulNamespace: "bar",
existingWorkload: createWorkload(),
existingHealthStatus: createPassingHealthStatus(),
existingProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
existingProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),

expectedConsulNamespace: "bar",
},
Expand All @@ -330,7 +330,7 @@ func TestReconcileDeletePodWithMirrorNamespaces(t *testing.T) {
existingConsulNamespace: "bar",
existingWorkload: createWorkload(),
existingHealthStatus: createPassingHealthStatus(),
existingProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
existingProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
existingDestinations: createDestinations(),

expectedConsulNamespace: "bar",
Expand Down Expand Up @@ -415,7 +415,7 @@ func TestReconcileCreatePodWithDestinationNamespace(t *testing.T) {
expectedConsulNamespace: constants.DefaultConsulNS,
expectedWorkload: createWorkload(),
expectedHealthStatus: createPassingHealthStatus(),
expectedProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
expectedProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
},
{
name: "new pod with explicit destinations, ns and partition",
Expand All @@ -439,7 +439,7 @@ func TestReconcileCreatePodWithDestinationNamespace(t *testing.T) {
expectedConsulNamespace: constants.DefaultConsulNS,
expectedWorkload: createWorkload(),
expectedHealthStatus: createPassingHealthStatus(),
expectedProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
expectedProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
expectedDestinations: createDestinations(),
},
{
Expand All @@ -466,7 +466,7 @@ func TestReconcileCreatePodWithDestinationNamespace(t *testing.T) {
expectedConsulNamespace: "a-penguin-walks-into-a-bar",
expectedWorkload: createWorkload(),
expectedHealthStatus: createPassingHealthStatus(),
expectedProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
expectedProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
},
{
name: "namespace in Consul does not exist",
Expand Down Expand Up @@ -543,12 +543,12 @@ func TestReconcileUpdatePodWithDestinationNamespace(t *testing.T) {
existingConsulNamespace: "a-penguin-walks-into-a-bar",
existingWorkload: createWorkload(),
existingHealthStatus: createPassingHealthStatus(),
existingProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
existingProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),

expectedConsulNamespace: "a-penguin-walks-into-a-bar",
expectedWorkload: createWorkload(),
expectedHealthStatus: createPassingHealthStatus(),
expectedProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
expectedProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
},
}

Expand Down Expand Up @@ -581,7 +581,7 @@ func TestReconcileDeletePodWithDestinationNamespace(t *testing.T) {
existingConsulNamespace: "a-penguin-walks-into-a-bar",
existingWorkload: createWorkload(),
existingHealthStatus: createPassingHealthStatus(),
existingProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
existingProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),

expectedConsulNamespace: "a-penguin-walks-into-a-bar",
},
Expand All @@ -600,7 +600,7 @@ func TestReconcileDeletePodWithDestinationNamespace(t *testing.T) {
existingConsulNamespace: "a-penguin-walks-into-a-bar",
existingWorkload: createWorkload(),
existingHealthStatus: createPassingHealthStatus(),
existingProxyConfiguration: createProxyConfiguration(testPodName, pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
existingProxyConfiguration: createProxyConfiguration(testPodName, true, pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
existingDestinations: createDestinations(),

expectedConsulNamespace: "a-penguin-walks-into-a-bar",
Expand Down
79 changes: 51 additions & 28 deletions control-plane/connect-inject/controllers/pod/pod_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ func TestProxyConfigurationDelete(t *testing.T) {
{
name: "proxy configuration delete",
pod: createPod("foo", "", true, true),
existingProxyConfiguration: createProxyConfiguration("foo", pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
existingProxyConfiguration: createProxyConfiguration("foo", true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
},
}

Expand Down Expand Up @@ -1308,7 +1308,7 @@ func TestReconcileCreatePod(t *testing.T) {

testCases := []testCase{
{
name: "vanilla new pod",
name: "vanilla new mesh-injected pod",
podName: "foo",
k8sObjects: func() []runtime.Object {
pod := createPod("foo", "", true, true)
Expand All @@ -1322,7 +1322,26 @@ func TestReconcileCreatePod(t *testing.T) {
overwriteProbes: true,
expectedWorkload: createWorkload(),
expectedHealthStatus: createPassingHealthStatus(),
expectedProxyConfiguration: createProxyConfiguration("foo", pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
expectedProxyConfiguration: createProxyConfiguration("foo", true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
},
{
name: "vanilla new gateway pod (not mesh-injected)",
podName: "foo",
k8sObjects: func() []runtime.Object {
pod := createPod("foo", "", false, true)
pod.Annotations[constants.AnnotationGatewayKind] = "mesh-gateway"
pod.Annotations[constants.AnnotationMeshInject] = "false"
pod.Annotations[constants.AnnotationTransparentProxyOverwriteProbes] = "false"

return []runtime.Object{pod}
},
tproxy: true,
telemetry: true,
metrics: true,
overwriteProbes: true,
expectedWorkload: createWorkload(),
expectedHealthStatus: createPassingHealthStatus(),
expectedProxyConfiguration: createProxyConfiguration("foo", false, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
},
{
name: "pod in ignored namespace",
Expand Down Expand Up @@ -1380,7 +1399,7 @@ func TestReconcileCreatePod(t *testing.T) {
overwriteProbes: true,
expectedWorkload: createWorkload(),
expectedHealthStatus: createPassingHealthStatus(),
expectedProxyConfiguration: createProxyConfiguration("foo", pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
expectedProxyConfiguration: createProxyConfiguration("foo", true, pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
expectedDestinations: createDestinations(),
},
{
Expand Down Expand Up @@ -1827,22 +1846,22 @@ func TestReconcileDeletePod(t *testing.T) {
podName: "foo",
existingWorkload: createWorkload(),
existingHealthStatus: createPassingHealthStatus(),
existingProxyConfiguration: createProxyConfiguration("foo", pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
existingProxyConfiguration: createProxyConfiguration("foo", true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
},
{
name: "annotated delete pod",
podName: "foo",
existingWorkload: createWorkload(),
existingHealthStatus: createPassingHealthStatus(),
existingProxyConfiguration: createProxyConfiguration("foo", pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
existingProxyConfiguration: createProxyConfiguration("foo", true, pbmesh.ProxyMode_PROXY_MODE_DEFAULT),
existingDestinations: createDestinations(),
},
{
name: "delete pod w/ acls",
podName: "foo",
existingWorkload: createWorkload(),
existingHealthStatus: createPassingHealthStatus(),
existingProxyConfiguration: createProxyConfiguration("foo", pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
existingProxyConfiguration: createProxyConfiguration("foo", true, pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT),
aclsEnabled: true,
},
}
Expand Down Expand Up @@ -1989,39 +2008,43 @@ func createCriticalHealthStatus(name string, namespace string) *pbcatalog.Health

// createProxyConfiguration creates a proxyConfiguration that matches the pod from createPod,
// assuming that metrics, telemetry, and overwrite probes are enabled separately.
func createProxyConfiguration(podName string, mode pbmesh.ProxyMode) *pbmesh.ProxyConfiguration {
func createProxyConfiguration(podName string, overwriteProbes bool, mode pbmesh.ProxyMode) *pbmesh.ProxyConfiguration {
mesh := &pbmesh.ProxyConfiguration{
Workloads: &pbcatalog.WorkloadSelector{
Names: []string{podName},
},
DynamicConfig: &pbmesh.DynamicConfig{
Mode: mode,
ExposeConfig: &pbmesh.ExposeConfig{
ExposePaths: []*pbmesh.ExposePath{
{
ListenerPort: 20400,
LocalPathPort: 2001,
Path: "/livez",
},
{
ListenerPort: 20300,
LocalPathPort: 2000,
Path: "/readyz",
},
{
ListenerPort: 20500,
LocalPathPort: 2002,
Path: "/startupz",
},
},
},
Mode: mode,
ExposeConfig: nil,
},
BootstrapConfig: &pbmesh.BootstrapConfig{
PrometheusBindAddr: "0.0.0.0:1234",
TelemetryCollectorBindSocketDir: DefaultTelemetryBindSocketDir,
},
}

if overwriteProbes {
mesh.DynamicConfig.ExposeConfig = &pbmesh.ExposeConfig{
ExposePaths: []*pbmesh.ExposePath{
{
ListenerPort: 20400,
LocalPathPort: 2001,
Path: "/livez",
},
{
ListenerPort: 20300,
LocalPathPort: 2000,
Path: "/readyz",
},
{
ListenerPort: 20500,
LocalPathPort: 2002,
Path: "/startupz",
},
},
}
}

if mode == pbmesh.ProxyMode_PROXY_MODE_TRANSPARENT {
mesh.DynamicConfig.TransparentProxy = &pbmesh.TransparentProxy{
OutboundListenerPort: 15001,
Expand Down

0 comments on commit e518860

Please sign in to comment.