Skip to content

Commit 231e4fb

Browse files
arkodgdanehans
andauthored
envoy per gateway (#404)
* envoy per gateway * create a xdsIR per gateway * create a infraIR per gateway * use the gateway namespace-name as the key for above IRs * populate the envoy bootstrap config with a service-cluster value that matches the IR key * populate the xds server snapshot for each xds request based on the service-cluster Fixes: #349 Signed-off-by: Arko Dasgupta <arko@tetrate.io> * append proxy name to infra resources Signed-off-by: Arko Dasgupta <arko@tetrate.io> * fix provider infra service and deployment names Signed-off-by: Arko Dasgupta <arko@tetrate.io> * 1:1 b/w service-cluster and irKey (gwNs-gwName) Signed-off-by: Arko Dasgupta <arko@tetrate.io> * detect conflicts per gateway instead of across all Signed-off-by: Arko Dasgupta <arko@tetrate.io> * infra found ports per gateway Signed-off-by: danehans <daneyonhansen@gmail.com> * Updates Envoy Cert as Wildcard Hostname Signed-off-by: danehans <daneyonhansen@gmail.com> * sort to add stablity in translated o/p Signed-off-by: Arko Dasgupta <arko@tetrate.io> Signed-off-by: danehans <daneyonhansen@gmail.com> Co-authored-by: danehans <daneyonhansen@gmail.com>
1 parent 3ef5627 commit 231e4fb

69 files changed

Lines changed: 1543 additions & 1460 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/cmd/xdstest.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,19 @@ func xDSTest() error {
187187
for {
188188
time.Sleep(10 * time.Second)
189189
logger.Info("Updating the cache for first-listener with first-route")
190-
err := snapCache.GenerateNewSnapshot(cacheVersion1.GetXdsResources())
190+
err := snapCache.GenerateNewSnapshot("", cacheVersion1.GetXdsResources())
191191
if err != nil {
192192
logger.Error(err, "Something went wrong with generating a snapshot")
193193
}
194194
time.Sleep(10 * time.Second)
195195
logger.Info("Updating the cache for first-listener with second-route")
196-
err = snapCache.GenerateNewSnapshot(cacheVersion2.GetXdsResources())
196+
err = snapCache.GenerateNewSnapshot("", cacheVersion2.GetXdsResources())
197197
if err != nil {
198198
logger.Error(err, "Something went wrong with generating a snapshot")
199199
}
200200
time.Sleep(10 * time.Second)
201201
logger.Info("Updating the cache for second-listener with second-route")
202-
err = snapCache.GenerateNewSnapshot(cacheVersion3.GetXdsResources())
202+
err = snapCache.GenerateNewSnapshot("", cacheVersion3.GetXdsResources())
203203
if err != nil {
204204
logger.Error(err, "Something went wrong with generating a snapshot")
205205
}

internal/crypto/certgen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
DefaultEnvoyGatewayDNSPrefix = config.EnvoyGatewayServiceName
2222

2323
// DefaultEnvoyDNSPrefix defines the default Envoy DNS prefix.
24-
DefaultEnvoyDNSPrefix = config.EnvoyServiceName
24+
DefaultEnvoyDNSPrefix = "*"
2525

2626
// DefaultNamespace is the default Namespace name where Envoy Gateway is running.
2727
DefaultNamespace = config.EnvoyGatewayNamespace
@@ -112,7 +112,7 @@ func GenerateCerts(egCfg *v1alpha1.EnvoyGateway) (*Certificates, error) {
112112
switch egProvider {
113113
case v1alpha1.ProviderTypeKubernetes:
114114
egDNSNames = kubeServiceNames(DefaultEnvoyGatewayDNSPrefix, DefaultNamespace, DefaultDNSSuffix)
115-
envoyDNSNames = kubeServiceNames(DefaultEnvoyDNSPrefix, DefaultNamespace, DefaultDNSSuffix)
115+
envoyDNSNames = append(envoyDNSNames, fmt.Sprintf("*.%s", DefaultNamespace))
116116
default:
117117
// Kubernetes is the only supported Envoy Gateway provider.
118118
return nil, fmt.Errorf("unsupported provider type %v", egProvider)

internal/crypto/certgen_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestGenerateCerts(t *testing.T) {
4747
run(t, "no configuration - use defaults", testcase{
4848
certConfig: &Configuration{},
4949
wantEnvoyGatewayDNSName: "envoy-gateway",
50-
wantEnvoyDNSName: "envoy",
50+
wantEnvoyDNSName: "*.envoy-gateway-system",
5151
})
5252
}
5353

internal/envoygateway/config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const (
1212
EnvoyGatewayNamespace = "envoy-gateway-system"
1313
// EnvoyGatewayServiceName is the name of the Envoy Gateway service.
1414
EnvoyGatewayServiceName = "envoy-gateway"
15-
// EnvoyServiceName is the name of the Envoy Service.
16-
EnvoyServiceName = "envoy"
17-
// EnvoyDeploymentName is the name of the Envoy Deployment.
18-
EnvoyDeploymentName = "envoy"
1915
// EnvoyConfigMapName is the name of the Envoy ConfigMap.
2016
EnvoyConfigMapName = "envoy"
17+
// EnvoyServicePrefix is the prefix applied to the Envoy Service.
18+
EnvoyServicePrefix = "envoy"
19+
// EnvoyDeploymentPrefix is the prefix applied to the Envoy Deployment.
20+
EnvoyDeploymentPrefix = "envoy"
2121
)
2222

2323
// Server wraps the EnvoyGateway configuration and additional parameters

internal/gatewayapi/runner/runner.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,24 @@ func (r *Runner) subscribeAndTranslate(ctx context.Context) {
9595
yamlInfraIR, _ := yaml.Marshal(&result.InfraIR)
9696
r.Logger.WithValues("output", "infra-ir").Info(string(yamlInfraIR))
9797

98-
// Publish the IRs. Use the service name as the key
99-
// to ensure there is always one element in the map.
98+
// Publish the IRs.
10099
// Also validate the ir before sending it.
101-
if err := result.InfraIR.Validate(); err != nil {
102-
r.Logger.Error(err, "unable to validate infra ir, skipped sending it")
103-
} else {
104-
r.InfraIR.Store(r.Name(), result.InfraIR)
100+
for key, val := range result.InfraIR {
101+
if err := val.Validate(); err != nil {
102+
r.Logger.Error(err, "unable to validate infra ir, skipped sending it")
103+
} else {
104+
r.InfraIR.Store(key, val)
105+
}
105106
}
106-
107107
// Wait until all HTTPRoutes have been reconciled , else the translation
108108
// result will be incomplete, and might cause churn in the data plane.
109109
if r.xdsIRReady {
110-
if err := result.XdsIR.Validate(); err != nil {
111-
r.Logger.Error(err, "unable to validate xds ir, skipped sending it")
112-
} else {
113-
r.XdsIR.Store(r.Name(), result.XdsIR)
110+
for key, val := range result.XdsIR {
111+
if err := val.Validate(); err != nil {
112+
r.Logger.Error(err, "unable to validate xds ir, skipped sending it")
113+
} else {
114+
r.XdsIR.Store(key, val)
115+
}
114116
}
115117
}
116118

internal/gatewayapi/runner/runner_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/stretchr/testify/require"
10+
"k8s.io/apimachinery/pkg/types"
1011

1112
"github.com/envoyproxy/gateway/internal/envoygateway/config"
1213
"github.com/envoyproxy/gateway/internal/ir"
@@ -32,21 +33,22 @@ func TestRunner(t *testing.T) {
3233
require.NoError(t, err)
3334

3435
// IR is nil at start
35-
require.Equal(t, (*ir.Xds)(nil), xdsIR.Get())
36-
require.Equal(t, (*ir.Infra)(nil), infraIR.Get())
36+
require.Equal(t, map[string]*ir.Xds{}, xdsIR.LoadAll())
37+
require.Equal(t, map[string]*ir.Infra{}, infraIR.LoadAll())
3738

3839
// TODO: pass valid provider resources
3940

40-
// Reset gatewayclass slice and update with a nil gatewayclass to trigger a delete
41-
pResources.DeleteGatewayClasses()
42-
pResources.GatewayClasses.Store("test", nil)
41+
// Reset gateway slice and update with a nil gateway to trigger a delete.
42+
pResources.DeleteGateways()
43+
key := types.NamespacedName{Namespace: "test", Name: "test"}
44+
pResources.Gateways.Store(key, nil)
4345
require.Eventually(t, func() bool {
44-
out := xdsIR.Get()
46+
out := xdsIR.LoadAll()
4547
if out == nil {
4648
return false
4749
}
4850
// Ensure ir is empty
49-
return (reflect.DeepEqual(*xdsIR.Get(), ir.Xds{})) && (reflect.DeepEqual(*infraIR.Get(), ir.Infra{Proxy: nil}))
51+
return (reflect.DeepEqual(xdsIR.LoadAll(), map[string]*ir.Xds{})) && (reflect.DeepEqual(infraIR.LoadAll(), map[string]*ir.Infra{}))
5052
}, time.Second*1, time.Millisecond*20)
5153

5254
}

internal/gatewayapi/testdata/gateway-allows-same-namespace-with-allowed-httproute.out.yaml

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,33 @@ httpRoutes:
5454
reason: Accepted
5555
message: Route is accepted
5656
xdsIR:
57-
http:
58-
- name: envoy-gateway-gateway-1-http
59-
address: 0.0.0.0
60-
port: 10080
61-
hostnames:
62-
- "*"
63-
routes:
64-
- name: envoy-gateway-httproute-1-rule-0-match-0-*
65-
pathMatch:
66-
prefix: "/"
67-
destinations:
68-
- host: 7.7.7.7
69-
port: 8080
70-
weight: 1
57+
envoy-gateway-gateway-1:
58+
http:
59+
- name: envoy-gateway-gateway-1-http
60+
address: 0.0.0.0
61+
port: 10080
62+
hostnames:
63+
- "*"
64+
routes:
65+
- name: envoy-gateway-httproute-1-rule-0-match-0-*
66+
pathMatch:
67+
prefix: "/"
68+
destinations:
69+
- host: 7.7.7.7
70+
port: 8080
71+
weight: 1
7172
infraIR:
72-
proxy:
73-
metadata:
74-
labels:
75-
gateway.envoyproxy.io/owning-gatewayclass: envoy-gateway-class
76-
name: envoy-gateway-class
77-
image: envoyproxy/envoy:v1.23-latest
78-
listeners:
79-
- address: ""
80-
ports:
81-
- name: envoy-gateway-gateway-1
82-
protocol: "HTTP"
83-
servicePort: 80
84-
containerPort: 10080
73+
envoy-gateway-gateway-1:
74+
proxy:
75+
metadata:
76+
labels:
77+
gateway.envoyproxy.io/owning-gateway: gateway-1
78+
name: envoy-gateway-gateway-1
79+
image: envoyproxy/envoy:v1.23-latest
80+
listeners:
81+
- address: ""
82+
ports:
83+
- name: envoy-gateway-gateway-1
84+
protocol: "HTTP"
85+
servicePort: 80
86+
containerPort: 10080

internal/gatewayapi/testdata/gateway-allows-same-namespace-with-disallowed-httproute.out.yaml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,25 @@ httpRoutes:
5454
reason: NotAllowedByListeners
5555
message: No listeners included by this parent ref allowed this attachment.
5656
xdsIR:
57-
http:
58-
- name: envoy-gateway-gateway-1-http
59-
address: 0.0.0.0
60-
hostnames:
61-
- "*"
62-
port: 10080
57+
envoy-gateway-gateway-1:
58+
http:
59+
- name: envoy-gateway-gateway-1-http
60+
address: 0.0.0.0
61+
hostnames:
62+
- "*"
63+
port: 10080
6364
infraIR:
64-
proxy:
65-
metadata:
66-
labels:
67-
gateway.envoyproxy.io/owning-gatewayclass: envoy-gateway-class
68-
name: envoy-gateway-class
69-
image: envoyproxy/envoy:v1.23-latest
70-
listeners:
71-
- address: ""
72-
ports:
73-
- name: envoy-gateway-gateway-1
74-
protocol: "HTTP"
75-
servicePort: 80
76-
containerPort: 10080
65+
envoy-gateway-gateway-1:
66+
proxy:
67+
metadata:
68+
labels:
69+
gateway.envoyproxy.io/owning-gateway: gateway-1
70+
name: envoy-gateway-gateway-1
71+
image: envoyproxy/envoy:v1.23-latest
72+
listeners:
73+
- address: ""
74+
ports:
75+
- name: envoy-gateway-gateway-1
76+
protocol: "HTTP"
77+
servicePort: 80
78+
containerPort: 10080

internal/gatewayapi/testdata/gateway-with-listener-with-invalid-allowed-namespaces-selector.out.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ httpRoutes:
5959
status: "False"
6060
reason: NoReadyListeners
6161
message: There are no ready listeners for this parent ref
62-
xdsIR: {}
62+
xdsIR:
63+
envoy-gateway-gateway-1: {}
6364
infraIR:
64-
proxy:
65-
metadata:
66-
labels:
67-
gateway.envoyproxy.io/owning-gatewayclass: envoy-gateway-class
68-
name: envoy-gateway-class
69-
image: envoyproxy/envoy:v1.23-latest
70-
listeners:
71-
- address: ""
65+
envoy-gateway-gateway-1:
66+
proxy:
67+
metadata:
68+
labels:
69+
gateway.envoyproxy.io/owning-gateway: gateway-1
70+
name: envoy-gateway-gateway-1
71+
image: envoyproxy/envoy:v1.23-latest
72+
listeners:
73+
- address: ""

internal/gatewayapi/testdata/gateway-with-listener-with-invalid-allowed-routes-group.out.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ httpRoutes:
5757
status: "False"
5858
reason: NoReadyListeners
5959
message: There are no ready listeners for this parent ref
60-
xdsIR: {}
60+
xdsIR:
61+
envoy-gateway-gateway-1: {}
6162
infraIR:
62-
proxy:
63-
metadata:
64-
labels:
65-
gateway.envoyproxy.io/owning-gatewayclass: envoy-gateway-class
66-
name: envoy-gateway-class
67-
image: envoyproxy/envoy:v1.23-latest
68-
listeners:
69-
- address: ""
63+
envoy-gateway-gateway-1:
64+
proxy:
65+
metadata:
66+
labels:
67+
gateway.envoyproxy.io/owning-gateway: gateway-1
68+
name: envoy-gateway-gateway-1
69+
image: envoyproxy/envoy:v1.23-latest
70+
listeners:
71+
- address: ""

0 commit comments

Comments
 (0)