Skip to content

Commit d521feb

Browse files
committed
update gateway translator tests
1 parent 3065648 commit d521feb

9 files changed

+708
-36
lines changed

projects/gateway2/api/applyconfiguration/api/v1alpha1/accessloggingservice.go

-28
This file was deleted.

projects/gateway2/extensions2/plugins/httplistenerpolicy/access_logging_converter.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import (
2929
)
3030

3131
// Helper function to convert AccessLogConfig to Envoy AccessLog
32-
func convertAccessLogConfig(ctx context.Context, config *v1alpha1.AccessLoggingConfig) []*v33.AccessLog {
32+
func convertAccessLogConfig(ctx context.Context, config *v1alpha1.AccessLoggingConfig) ([]*v33.AccessLog, error) {
3333
if config == nil || len(config.AccessLog) == 0 {
34-
return nil
34+
return nil, nil
3535
}
3636

3737
logger := contextutils.LoggerFrom(ctx).Desugar()
@@ -40,12 +40,20 @@ func convertAccessLogConfig(ctx context.Context, config *v1alpha1.AccessLoggingC
4040
for _, log := range config.AccessLog {
4141
var accessLogCfg v33.AccessLog
4242

43+
if log.FileSink != nil && log.GrpcService != nil {
44+
return nil, eris.New("access log config cannot have both file sink and grpc service")
45+
}
46+
4347
// Convert FileSink
4448
if log.FileSink != nil {
4549
fileCfg := &envoyalfile.FileAccessLog{
4650
Path: log.FileSink.Path,
4751
}
4852

53+
if log.FileSink.StringFormat != "" && log.FileSink.JsonFormat != nil {
54+
return nil, eris.New("access log config cannot have both string format and json format")
55+
}
56+
4957
// Handle output format
5058
if log.FileSink.StringFormat != "" {
5159
formatterExtensions, err := getFormatterExtensions()
@@ -80,17 +88,20 @@ func convertAccessLogConfig(ctx context.Context, config *v1alpha1.AccessLoggingC
8088
accessLogCfg, err = NewAccessLogWithConfig(wellknown.FileAccessLog, fileCfg)
8189
if err != nil {
8290
logger.Error(fmt.Sprintf("error creating file access log config: %s", err.Error()))
91+
return nil, err
8392
}
8493
} else if log.GrpcService != nil {
8594
// Convert GrpcService
8695
var cfg envoygrpc.HttpGrpcAccessLogConfig
8796
err = copyGrpcSettings(&cfg, log.GrpcService)
8897
if err != nil {
8998
logger.Error(fmt.Sprintf("error converting grpc access log config: %s", err.Error()))
99+
return nil, err
90100
}
91101
accessLogCfg, err = NewAccessLogWithConfig(wellknown.HTTPGRPCAccessLog, &cfg)
92102
if err != nil {
93103
logger.Error(fmt.Sprintf("error creating grpc access log config: %s", err.Error()))
104+
return nil, err
94105
}
95106
}
96107

@@ -127,7 +138,7 @@ func convertAccessLogConfig(ctx context.Context, config *v1alpha1.AccessLoggingC
127138
results = append(results, &accessLogCfg)
128139
}
129140

130-
return results
141+
return results, nil
131142
}
132143

133144
func translateFilter(logger *zap.Logger, filter *v1alpha1.FilterType) *v33.AccessLogFilter {

projects/gateway2/extensions2/plugins/httplistenerpolicy/httplistener_plugin.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ func (p *httpListenerOptsPluginGwPass) ApplyHCM(
105105

106106
// translate access logging configuration
107107
if policy.spec.AccessLoggingConfig != nil {
108-
accessLog := convertAccessLogConfig(ctx, policy.spec.AccessLoggingConfig)
108+
accessLog, err := convertAccessLogConfig(ctx, policy.spec.AccessLoggingConfig)
109+
if err != nil {
110+
return eris.Errorf("failed to convert access log config: %v", err)
111+
}
109112
if accessLog != nil {
110113
out.AccessLog = append(out.GetAccessLog(), accessLog...)
111114
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
clusters:
2+
- connectTimeout: 5s
3+
edsClusterConfig:
4+
edsConfig:
5+
ads: {}
6+
resourceApiVersion: V3
7+
metadata: {}
8+
name: kube_default_kubernetes_443
9+
transportSocketMatches:
10+
- match:
11+
tlsMode: istio
12+
name: tlsMode-istio
13+
transportSocket:
14+
name: envoy.transport_sockets.tls
15+
typedConfig:
16+
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
17+
commonTlsContext:
18+
alpnProtocols:
19+
- istio
20+
tlsCertificateSdsSecretConfigs:
21+
- name: istio_server_cert
22+
sdsConfig:
23+
apiConfigSource:
24+
apiType: GRPC
25+
grpcServices:
26+
- envoyGrpc:
27+
clusterName: gateway_proxy_sds
28+
setNodeOnFirstMessageOnly: true
29+
transportApiVersion: V3
30+
resourceApiVersion: V3
31+
tlsParams: {}
32+
validationContextSdsSecretConfig:
33+
name: istio_validation_context
34+
sdsConfig:
35+
apiConfigSource:
36+
apiType: GRPC
37+
grpcServices:
38+
- envoyGrpc:
39+
clusterName: gateway_proxy_sds
40+
setNodeOnFirstMessageOnly: true
41+
transportApiVersion: V3
42+
resourceApiVersion: V3
43+
sni: outbound_.443_._.kubernetes.default.svc.cluster.local
44+
- match: {}
45+
name: tlsMode-disabled
46+
transportSocket:
47+
name: envoy.transport_sockets.raw_buffer
48+
typedConfig:
49+
'@type': type.googleapis.com/envoy.extensions.transport_sockets.raw_buffer.v3.RawBuffer
50+
type: EDS
51+
- connectTimeout: 5s
52+
edsClusterConfig:
53+
edsConfig:
54+
ads: {}
55+
resourceApiVersion: V3
56+
metadata: {}
57+
name: kube_gwtest_reviews_8080
58+
transportSocketMatches:
59+
- match:
60+
tlsMode: istio
61+
name: tlsMode-istio
62+
transportSocket:
63+
name: envoy.transport_sockets.tls
64+
typedConfig:
65+
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
66+
commonTlsContext:
67+
alpnProtocols:
68+
- istio
69+
tlsCertificateSdsSecretConfigs:
70+
- name: istio_server_cert
71+
sdsConfig:
72+
apiConfigSource:
73+
apiType: GRPC
74+
grpcServices:
75+
- envoyGrpc:
76+
clusterName: gateway_proxy_sds
77+
setNodeOnFirstMessageOnly: true
78+
transportApiVersion: V3
79+
resourceApiVersion: V3
80+
tlsParams: {}
81+
validationContextSdsSecretConfig:
82+
name: istio_validation_context
83+
sdsConfig:
84+
apiConfigSource:
85+
apiType: GRPC
86+
grpcServices:
87+
- envoyGrpc:
88+
clusterName: gateway_proxy_sds
89+
setNodeOnFirstMessageOnly: true
90+
transportApiVersion: V3
91+
resourceApiVersion: V3
92+
sni: outbound_.8080_._.reviews.gwtest.svc.cluster.local
93+
- match: {}
94+
name: tlsMode-disabled
95+
transportSocket:
96+
name: envoy.transport_sockets.raw_buffer
97+
typedConfig:
98+
'@type': type.googleapis.com/envoy.extensions.transport_sockets.raw_buffer.v3.RawBuffer
99+
type: EDS
100+
endpoints:
101+
- clusterName: kube_gwtest_reviews_8080
102+
endpoints:
103+
- lbEndpoints:
104+
- endpoint:
105+
address:
106+
socketAddress:
107+
address: 10.244.1.11
108+
portValue: 8080
109+
loadBalancingWeight: 1
110+
loadBalancingWeight: 1
111+
listeners:
112+
- address:
113+
socketAddress:
114+
address: '::'
115+
ipv4Compat: true
116+
portValue: 8080
117+
filterChains:
118+
- filters:
119+
- name: envoy.filters.network.http_connection_manager
120+
typedConfig:
121+
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
122+
accessLog:
123+
- filter:
124+
extensionFilter:
125+
name: envoy.access_loggers.extension_filters.cel
126+
typedConfig:
127+
'@type': type.googleapis.com/envoy.extensions.access_loggers.filters.cel.v3.ExpressionFilter
128+
expression: request.headers['test'].contains('cool-beans')
129+
name: envoy.access_loggers.http_grpc
130+
typedConfig:
131+
'@type': type.googleapis.com/envoy.extensions.access_loggers.grpc.v3.HttpGrpcAccessLogConfig
132+
commonConfig:
133+
grpcService:
134+
envoyGrpc:
135+
clusterName: test-accesslog-service
136+
logName: test-accesslog-service
137+
transportApiVersion: V3
138+
- filter:
139+
extensionFilter:
140+
name: envoy.access_loggers.extension_filters.cel
141+
typedConfig:
142+
'@type': type.googleapis.com/envoy.extensions.access_loggers.filters.cel.v3.ExpressionFilter
143+
expression: request.headers['test'].contains('cool-beans')
144+
name: envoy.access_loggers.http_grpc
145+
typedConfig:
146+
'@type': type.googleapis.com/envoy.extensions.access_loggers.grpc.v3.HttpGrpcAccessLogConfig
147+
commonConfig:
148+
grpcService:
149+
envoyGrpc:
150+
clusterName: test-accesslog-service
151+
logName: test-accesslog-service
152+
transportApiVersion: V3
153+
httpFilters:
154+
- name: envoy.filters.http.router
155+
typedConfig:
156+
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
157+
mergeSlashes: true
158+
normalizePath: true
159+
rds:
160+
configSource:
161+
ads: {}
162+
resourceApiVersion: V3
163+
routeConfigName: http
164+
statPrefix: http
165+
name: http
166+
name: http
167+
- address:
168+
socketAddress:
169+
address: '::'
170+
ipv4Compat: true
171+
portValue: 8081
172+
filterChains:
173+
- filters:
174+
- name: envoy.filters.network.http_connection_manager
175+
typedConfig:
176+
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
177+
accessLog:
178+
- filter:
179+
extensionFilter:
180+
name: envoy.access_loggers.extension_filters.cel
181+
typedConfig:
182+
'@type': type.googleapis.com/envoy.extensions.access_loggers.filters.cel.v3.ExpressionFilter
183+
expression: request.headers['test'].contains('cool-beans')
184+
name: envoy.access_loggers.http_grpc
185+
typedConfig:
186+
'@type': type.googleapis.com/envoy.extensions.access_loggers.grpc.v3.HttpGrpcAccessLogConfig
187+
commonConfig:
188+
grpcService:
189+
envoyGrpc:
190+
clusterName: test-accesslog-service
191+
logName: test-accesslog-service
192+
transportApiVersion: V3
193+
- filter:
194+
extensionFilter:
195+
name: envoy.access_loggers.extension_filters.cel
196+
typedConfig:
197+
'@type': type.googleapis.com/envoy.extensions.access_loggers.filters.cel.v3.ExpressionFilter
198+
expression: request.headers['test'].contains('cool-beans')
199+
name: envoy.access_loggers.http_grpc
200+
typedConfig:
201+
'@type': type.googleapis.com/envoy.extensions.access_loggers.grpc.v3.HttpGrpcAccessLogConfig
202+
commonConfig:
203+
grpcService:
204+
envoyGrpc:
205+
clusterName: test-accesslog-service
206+
logName: test-accesslog-service
207+
transportApiVersion: V3
208+
httpFilters:
209+
- name: envoy.filters.http.router
210+
typedConfig:
211+
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
212+
mergeSlashes: true
213+
normalizePath: true
214+
rds:
215+
configSource:
216+
ads: {}
217+
resourceApiVersion: V3
218+
routeConfigName: other
219+
statPrefix: http
220+
name: other
221+
name: other
222+
routes:
223+
- ignorePortInHostMatching: true
224+
name: http
225+
virtualHosts:
226+
- domains:
227+
- www.example.com
228+
name: http~www_example_com
229+
routes:
230+
- match:
231+
prefix: /
232+
name: http~www_example_com-route-0-httproute-reviews-gwtest-0-0-matcher-0
233+
route:
234+
cluster: kube_gwtest_reviews_8080
235+
clusterNotFoundResponseCode: INTERNAL_SERVER_ERROR
236+
- ignorePortInHostMatching: true
237+
name: other
238+
virtualHosts:
239+
- domains:
240+
- www.example.com
241+
name: other~www_example_com
242+
routes:
243+
- match:
244+
prefix: /
245+
name: other~www_example_com-route-0-httproute-reviews-gwtest-0-0-matcher-0
246+
route:
247+
cluster: kube_gwtest_reviews_8080
248+
clusterNotFoundResponseCode: INTERNAL_SERVER_ERROR

0 commit comments

Comments
 (0)