Skip to content

Commit

Permalink
[NET-10733] fix generation of xds resources (#21603)
Browse files Browse the repository at this point in the history
fix generation of xds resources
  • Loading branch information
jm96441n committed Aug 14, 2024
1 parent a570858 commit 8555404
Showing 1 changed file with 62 additions and 68 deletions.
130 changes: 62 additions & 68 deletions agent/xds/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,25 +445,25 @@ func getConnectProxyTransparentProxyGoldenTestCases() []goldenTestCase {
}

func getConnectProxyDiscoChainTests(enterprise bool) []goldenTestCase {
return []goldenTestCase{
cases := []goldenTestCase{
{
name: "connect-proxy-with-chain",
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "simple", false, nil, nil)
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "simple", enterprise, nil, nil)
},
alsoRunTestForV2: true,
},
{
name: "connect-proxy-with-chain-external-sni",
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "external-sni", false, nil, nil)
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "external-sni", enterprise, nil, nil)
},
alsoRunTestForV2: true,
},
{
name: "connect-proxy-with-chain-and-failover",
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "failover", false, nil, nil)
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "failover", enterprise, nil, nil)
},
alsoRunTestForV2: true,
},
Expand All @@ -487,10 +487,9 @@ func getConnectProxyDiscoChainTests(enterprise bool) []goldenTestCase {
name: "custom-upstream-default-chain",
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "default", enterprise, func(ns *structs.NodeService) {
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] =
customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
})
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] = customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
})
}, nil)
},
// TODO(proxystate): requires custom cluster work
Expand Down Expand Up @@ -602,10 +601,9 @@ func getConnectProxyDiscoChainTests(enterprise bool) []goldenTestCase {
name: "connect-proxy-with-default-chain-and-custom-cluster",
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "default", enterprise, func(ns *structs.NodeService) {
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] =
customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
})
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] = customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
})
}, nil)
},
// TODO(proxystate): requires custom cluster work
Expand Down Expand Up @@ -667,10 +665,9 @@ func getConnectProxyDiscoChainTests(enterprise bool) []goldenTestCase {

uid := proxycfg.NewUpstreamID(&ns.Proxy.Upstreams[i])

ns.Proxy.Upstreams[i].Config["envoy_listener_json"] =
customListenerJSON(t, customListenerJSONOptions{
Name: uid.EnvoyID() + ":custom-upstream",
})
ns.Proxy.Upstreams[i].Config["envoy_listener_json"] = customListenerJSON(t, customListenerJSONOptions{
Name: uid.EnvoyID() + ":custom-upstream",
})
}
}, nil)
},
Expand Down Expand Up @@ -731,6 +728,14 @@ func getConnectProxyDiscoChainTests(enterprise bool) []goldenTestCase {
alsoRunTestForV2: true,
},
}

if enterprise {
for i := range cases {
cases[i].name = "enterprise-" + cases[i].name
}
}

return cases
}

func getMeshGatewayGoldenTestCases() []goldenTestCase {
Expand Down Expand Up @@ -896,6 +901,7 @@ func getMeshGatewayGoldenTestCases() []goldenTestCase {
},
}
}

func getMeshGatewayPeeringGoldenTestCases() []goldenTestCase {
return []goldenTestCase{
{
Expand Down Expand Up @@ -1426,7 +1432,6 @@ func getAPIGatewayGoldenTestCases(t *testing.T) []goldenTestCase {
},
},
}

}, []structs.BoundRoute{
&structs.TCPRouteConfigEntry{
Name: "tcp-route",
Expand Down Expand Up @@ -1596,7 +1601,8 @@ func getAPIGatewayGoldenTestCases(t *testing.T) []goldenTestCase {
{Kind: structs.HTTPRoute, Name: "backend-route"},
{Kind: structs.HTTPRoute, Name: "frontend-route"},
{Kind: structs.HTTPRoute, Name: "generic-route"},
}},
},
},
}
},
[]structs.BoundRoute{
Expand Down Expand Up @@ -1735,10 +1741,9 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
name: "custom-upstream-default-chain",
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "default", enterprise, func(ns *structs.NodeService) {
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] =
customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
})
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] = customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
})
}, nil)
},
// TODO(proxystate): requires custom cluster work
Expand All @@ -1748,10 +1753,9 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
name: "custom-local-app",
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshot(t, func(ns *structs.NodeService) {
ns.Proxy.Config["envoy_local_cluster_json"] =
customAppClusterJSON(t, customClusterJSONOptions{
Name: "mylocal",
})
ns.Proxy.Config["envoy_local_cluster_json"] = customAppClusterJSON(t, customClusterJSONOptions{
Name: "mylocal",
})
}, nil)
},
// TODO(proxystate): requires custom cluster work
Expand All @@ -1761,10 +1765,9 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
name: "custom-upstream",
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshot(t, func(ns *structs.NodeService) {
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] =
customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
})
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] = customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
})
}, nil)
},
// TODO(proxystate): requires custom cluster work
Expand All @@ -1775,12 +1778,11 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
overrideGoldenName: "custom-upstream", // should be the same
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshot(t, func(ns *structs.NodeService) {
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] =
customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
// Attempt to override the TLS context should be ignored
TLSContext: `"allowRenegotiation": false`,
})
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] = customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
// Attempt to override the TLS context should be ignored
TLSContext: `"allowRenegotiation": false`,
})
}, nil)
},
// TODO(proxystate): requires custom cluster work
Expand All @@ -1791,7 +1793,6 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshot(t, func(ns *structs.NodeService) {
for i := range ns.Proxy.Upstreams {

switch ns.Proxy.Upstreams[i].DestinationName {
case "db":
if ns.Proxy.Upstreams[i].Config == nil {
Expand All @@ -1803,10 +1804,9 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
// Triggers an override with the presence of the escape hatch listener
ns.Proxy.Upstreams[i].DestinationType = structs.UpstreamDestTypePreparedQuery

ns.Proxy.Upstreams[i].Config["envoy_cluster_json"] =
customClusterJSON(t, customClusterJSONOptions{
Name: uid.EnvoyID() + ":custom-upstream",
})
ns.Proxy.Upstreams[i].Config["envoy_cluster_json"] = customClusterJSON(t, customClusterJSONOptions{
Name: uid.EnvoyID() + ":custom-upstream",
})

// Also test that http2 options are triggered.
// A separate upstream without an override is required to test
Expand Down Expand Up @@ -1936,10 +1936,9 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
name: "connect-proxy-with-default-chain-and-custom-cluster",
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "default", enterprise, func(ns *structs.NodeService) {
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] =
customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
})
ns.Proxy.Upstreams[0].Config["envoy_cluster_json"] = customAppClusterJSON(t, customClusterJSONOptions{
Name: "myservice",
})
}, nil)
},
// TODO(proxystate): requires custom cluster work
Expand All @@ -1949,10 +1948,9 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
name: "custom-public-listener",
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshot(t, func(ns *structs.NodeService) {
ns.Proxy.Config["envoy_public_listener_json"] =
customListenerJSON(t, customListenerJSONOptions{
Name: "custom-public-listen",
})
ns.Proxy.Config["envoy_public_listener_json"] = customListenerJSON(t, customListenerJSONOptions{
Name: "custom-public-listen",
})
}, nil)
},
},
Expand All @@ -1961,10 +1959,9 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshot(t, func(ns *structs.NodeService) {
ns.Proxy.Config["protocol"] = "http"
ns.Proxy.Config["envoy_public_listener_json"] =
customHTTPListenerJSON(t, customHTTPListenerJSONOptions{
Name: "custom-public-listen",
})
ns.Proxy.Config["envoy_public_listener_json"] = customHTTPListenerJSON(t, customHTTPListenerJSONOptions{
Name: "custom-public-listen",
})
}, nil)
},
},
Expand All @@ -1973,11 +1970,10 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshot(t, func(ns *structs.NodeService) {
ns.Proxy.Config["protocol"] = "http"
ns.Proxy.Config["envoy_public_listener_json"] =
customHTTPListenerJSON(t, customHTTPListenerJSONOptions{
Name: "custom-public-listen",
HTTPConnectionManagerName: httpConnectionManagerNewName,
})
ns.Proxy.Config["envoy_public_listener_json"] = customHTTPListenerJSON(t, customHTTPListenerJSONOptions{
Name: "custom-public-listen",
HTTPConnectionManagerName: httpConnectionManagerNewName,
})
}, nil)
},
},
Expand All @@ -1986,10 +1982,9 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshot(t, func(ns *structs.NodeService) {
ns.Proxy.Config["protocol"] = "http"
ns.Proxy.Config["envoy_public_listener_json"] =
customListenerJSON(t, customListenerJSONOptions{
Name: "custom-public-listen",
})
ns.Proxy.Config["envoy_public_listener_json"] = customListenerJSON(t, customListenerJSONOptions{
Name: "custom-public-listen",
})
}, nil)
},
},
Expand All @@ -1998,12 +1993,11 @@ func getCustomConfigurationGoldenTestCases(enterprise bool) []goldenTestCase {
overrideGoldenName: "custom-public-listener", // should be the same
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshot(t, func(ns *structs.NodeService) {
ns.Proxy.Config["envoy_public_listener_json"] =
customListenerJSON(t, customListenerJSONOptions{
Name: "custom-public-listen",
// Attempt to override the TLS context should be ignored
TLSContext: `"allowRenegotiation": false`,
})
ns.Proxy.Config["envoy_public_listener_json"] = customListenerJSON(t, customListenerJSONOptions{
Name: "custom-public-listen",
// Attempt to override the TLS context should be ignored
TLSContext: `"allowRenegotiation": false`,
})
}, nil)
},
},
Expand Down

0 comments on commit 8555404

Please sign in to comment.