Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into ext-auth-e2e-grpc-s…
Browse files Browse the repository at this point in the history
…ervice
  • Loading branch information
zhaohuabing committed Mar 10, 2024
2 parents 5722fb9 + 67079b7 commit eee8c59
Show file tree
Hide file tree
Showing 19 changed files with 642 additions and 42 deletions.
5 changes: 3 additions & 2 deletions internal/infrastructure/kubernetes/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ func ExpectedServiceSpec(service *egv1a1.KubernetesServiceSpec) corev1.ServiceSp
return serviceSpec
}

// CompareSvc compare entire Svc.Spec but ignored the ports[*].nodePort, ClusterIP and ClusterIPs in case user have modified for some scene.
// CompareSvc compares the Service resource and ignores specific fields that may have been modified by other actors.
func CompareSvc(currentSvc, originalSvc *corev1.Service) bool {
return cmp.Equal(currentSvc.Spec, originalSvc.Spec,
cmpopts.IgnoreFields(corev1.ServicePort{}, "NodePort"),
cmpopts.IgnoreFields(corev1.ServiceSpec{}, "ClusterIP", "ClusterIPs"))
cmpopts.IgnoreFields(corev1.ServiceSpec{}, "ClusterIP", "ClusterIPs"),
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "Finalizers"))
}

// ExpectedContainerEnv returns expected container envs.
Expand Down
42 changes: 42 additions & 0 deletions internal/infrastructure/kubernetes/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,48 @@ func TestCompareSvc(t *testing.T) {
Type: "ClusterIP",
},
},
}, {
// Finalizers field differs
ExpectRet: true,
NewSvc: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "my-service",
Namespace: "default",
Finalizers: []string{"service.k8s.aws/resources"},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Name: "http",
Port: 80,
TargetPort: intstr.FromInt(8080),
},
},
Selector: map[string]string{
"app": "my-app",
},
Type: "ClusterIP",
},
},
OriginalSvc: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "my-service",
Namespace: "default",
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Name: "http",
Port: 80,
TargetPort: intstr.FromInt(8080),
},
},
Selector: map[string]string{
"app": "my-app",
},
Type: "ClusterIP",
},
},
},
}

Expand Down
38 changes: 38 additions & 0 deletions internal/xds/translator/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/envoyproxy/go-control-plane/pkg/wellknown"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/wrapperspb"
"k8s.io/utils/ptr"

Expand Down Expand Up @@ -93,6 +94,29 @@ func buildXdsCluster(args *xdsClusterArgs) *clusterv3.Cluster {
cluster.TransportSocket = args.tSocket
}

for i, ds := range args.settings {
if ds.TLS != nil {
socket, err := buildXdsUpstreamTLSSocketWthCert(ds.TLS)
if err != nil {
// TODO: Log something here
return nil
}
if args.proxyProtocol != nil {
socket = buildProxyProtocolSocket(args.proxyProtocol, socket)
}
matchName := fmt.Sprintf("%s/tls/%d", args.name, i)
cluster.TransportSocketMatches = append(cluster.TransportSocketMatches, &clusterv3.Cluster_TransportSocketMatch{
Name: matchName,
Match: &structpb.Struct{
Fields: map[string]*structpb.Value{
"name": structpb.NewStringValue(matchName),
},
},
TransportSocket: socket,
})
}
}

if args.endpointType == EndpointTypeStatic {
cluster.ClusterDiscoveryType = &clusterv3.Cluster_Type{Type: clusterv3.Cluster_EDS}
cluster.EdsClusterConfig = &clusterv3.Cluster_EdsClusterConfig{
Expand Down Expand Up @@ -336,8 +360,22 @@ func buildXdsClusterLoadAssignment(clusterName string, destSettings []*ir.Destin

endpoints := make([]*endpointv3.LbEndpoint, 0, len(ds.Endpoints))

var metadata *corev3.Metadata
if ds.TLS != nil {
metadata = &corev3.Metadata{
FilterMetadata: map[string]*structpb.Struct{
"envoy.transport_socket_match": {
Fields: map[string]*structpb.Value{
"name": structpb.NewStringValue(fmt.Sprintf("%s/tls/%d", clusterName, i)),
},
},
},
}
}

for _, irEp := range ds.Endpoints {
lbEndpoint := &endpointv3.LbEndpoint{
Metadata: metadata,
HostIdentifier: &endpointv3.LbEndpoint_Endpoint{
Endpoint: &endpointv3.Endpoint{
Address: &corev3.Address{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
http:
- address: 0.0.0.0
hostnames:
- '*'
isHTTP2: false
name: envoy-gateway/gateway-btls/http
path:
escapedSlashesAction: UnescapeAndRedirect
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
name: httproute/envoy-gateway/httproute-btls/rule/0
settings:
- addressType: IP
endpoints:
- host: 10.244.0.12
port: 8080
protocol: HTTPS
tls:
caCertificate:
certificate: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURKekNDQWcrZ0F3SUJBZ0lVQWw2VUtJdUttenRlODFjbGx6NVBmZE4ySWxJd0RRWUpLb1pJaHZjTkFRRUwKQlFBd0l6RVFNQTRHQTFVRUF3d0hiWGxqYVdWdWRERVBNQTBHQTFVRUNnd0dhM1ZpWldSaU1CNFhEVEl6TVRBdwpNakExTkRFMU4xb1hEVEkwTVRBd01UQTFOREUxTjFvd0l6RVFNQTRHQTFVRUF3d0hiWGxqYVdWdWRERVBNQTBHCkExVUVDZ3dHYTNWaVpXUmlNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQXdTVGMKMXlqOEhXNjJueW5rRmJYbzRWWEt2MmpDMFBNN2RQVmt5ODdGd2VaY1RLTG9XUVZQUUUycDJrTERLNk9Fc3ptTQp5eXIreHhXdHlpdmVyZW1yV3FuS2tOVFloTGZZUGhnUWtjemliN2VVYWxtRmpVYmhXZEx2SGFrYkVnQ29kbjNiCmt6NTdtSW5YMlZwaURPS2c0a3lIZml1WFdwaUJxckN4MEtOTHB4bzNERVFjRmNzUVRlVEh6aDQ3NTJHVjA0UlUK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VaTlrYVlqd2RWaURSRUdTams3SlcxN3ZsNTc2SGpEa2RmUndpNEUyOFN5ZFJJblpmNkoKaThIWmNaN2NhSDZEeFIzMzVmZ0hWekxpNU5pVGNlL09qTkJRelEyTUpYVkRkOERCbUc1ZnlhdEppT0pRNGJXRQpBN0ZsUDBSZFAzQ08zR1dFME01aVhPQjJtMXFXa0UyZXlPNFVIdndUcU5RTGRyZEFYZ0RRbGJhbTllNEJHM0dnCmQvNnRoQWtXRGJ0L1FOVCtFSkhEQ3ZoRFJLaDFSdUdIeWcrWSsvbmViVFdXckZXc2t0UnJiT29IQ1ppQ3BYSTEKM2VYRTZudDBZa2d0RHhHMjJLcW5ocEFnOWdVU3MyaGxob3h5dmt6eUYwbXU2TmhQbHdBZ25xNysvUT09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
name: policy-btls/policies-ca
sni: example.com
weight: 1
hostname: '*'
name: httproute/envoy-gateway/httproute-btls/rule/0/match/0/*
pathMatch:
distinct: false
exact: /exact
name: ""
- address: 0.0.0.0
hostnames:
- 'example.com'
isHTTP2: false
name: envoy-gateway/gateway-btls-2/http
path:
escapedSlashesAction: UnescapeAndRedirect
mergeSlashes: true
port: 10081
routes:
- backendWeights:
invalid: 0
valid: 0
proxyProtocol:
version: "V2"
destination:
name: httproute/envoy-gateway/httproute-btls-2/rule/0
settings:
- addressType: IP
endpoints:
- host: 10.244.0.12
port: 8080
protocol: HTTP
weight: 1
- addressType: IP
endpoints:
- host: 10.244.0.11
port: 8080
protocol: HTTPS
tls:
caCertificate:
certificate: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURKekNDQWcrZ0F3SUJBZ0lVQWw2VUtJdUttenRlODFjbGx6NVBmZE4ySWxJd0RRWUpLb1pJaHZjTkFRRUwKQlFBd0l6RVFNQTRHQTFVRUF3d0hiWGxqYVdWdWRERVBNQTBHQTFVRUNnd0dhM1ZpWldSaU1CNFhEVEl6TVRBdwpNakExTkRFMU4xb1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1dFME01aVhPQjJtMXFXa0UyZXlPNFVIdndUcU5RTGRyZEFYZ0RRbGJhbTllNEJHM0dnCmQvNnRoQWtXRGJ0L1FOVCtFSkhEQ3ZoRFJLaDFSdUdIeWcrWSsvbmViVFdXckZXc2t0UnJiT29IQ1ppQ3BYSTEKM2VYRTZudDBZa2d0RHhHMjJLcW5ocEFnOWdVU3MyaGxob3h5dmt6eUYwbXU2TmhQbHdBZ25xNysvUT09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
name: policy-btls-2/policies-ca
sni: example.com
weight: 1
hostname: '*'
name: httproute/envoy-gateway/httproute-btls-2/rule/0/match/0/*
pathMatch:
distinct: false
exact: /exact
name: ""
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
name: httproute/envoy-gateway/httproute-btls/rule/0
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
transportSocket:
name: envoy.transport_sockets.tls
typedConfig:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
commonTlsContext:
validationContext:
trustedCa:
filename: /etc/ssl/certs/ca-certificates.crt
sni: example.com
transportSocketMatches:
- match:
name: httproute/envoy-gateway/httproute-btls/rule/0/tls/0
name: httproute/envoy-gateway/httproute-btls/rule/0/tls/0
transportSocket:
name: envoy.transport_sockets.tls
typedConfig:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
commonTlsContext:
validationContext:
trustedCa:
filename: /etc/ssl/certs/ca-certificates.crt
sni: example.com
type: EDS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
address: 10.244.0.11
portValue: 8080
loadBalancingWeight: 1
metadata:
filterMetadata:
envoy.transport_socket_match:
name: httproute/envoy-gateway/httproute-btls/rule/0/tls/0
loadBalancingWeight: 1
locality:
region: httproute/envoy-gateway/httproute-btls/rule/0/backend/0
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
- circuitBreakers:
thresholds:
- maxRetries: 1024
commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
serviceName: httproute/envoy-gateway/httproute-btls/rule/0
lbPolicy: LEAST_REQUEST
name: httproute/envoy-gateway/httproute-btls/rule/0
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
transportSocketMatches:
- match:
name: httproute/envoy-gateway/httproute-btls/rule/0/tls/0
name: httproute/envoy-gateway/httproute-btls/rule/0/tls/0
transportSocket:
name: envoy.transport_sockets.tls
typedConfig:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
commonTlsContext:
validationContextSdsSecretConfig:
name: policy-btls/policies-ca2
sdsConfig:
ads: {}
resourceApiVersion: V3
sni: bar.example.com
- match:
name: httproute/envoy-gateway/httproute-btls/rule/0/tls/1
name: httproute/envoy-gateway/httproute-btls/rule/0/tls/1
transportSocket:
name: envoy.transport_sockets.tls
typedConfig:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
commonTlsContext:
validationContextSdsSecretConfig:
name: policy-btls/policies-ca
sdsConfig:
ads: {}
resourceApiVersion: V3
sni: example.com
type: EDS
- circuitBreakers:
thresholds:
- maxRetries: 1024
commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
serviceName: httproute/envoy-gateway/httproute-btls-2/rule/0
lbPolicy: LEAST_REQUEST
name: httproute/envoy-gateway/httproute-btls-2/rule/0
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
transportSocket:
name: envoy.transport_sockets.upstream_proxy_protocol
typedConfig:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.proxy_protocol.v3.ProxyProtocolUpstreamTransport
config:
version: V2
transportSocket:
name: envoy.transport_sockets.raw_buffer
typedConfig:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.raw_buffer.v3.RawBuffer
transportSocketMatches:
- match:
name: httproute/envoy-gateway/httproute-btls-2/rule/0/tls/1
name: httproute/envoy-gateway/httproute-btls-2/rule/0/tls/1
transportSocket:
name: envoy.transport_sockets.upstream_proxy_protocol
typedConfig:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.proxy_protocol.v3.ProxyProtocolUpstreamTransport
config:
version: V2
transportSocket:
name: envoy.transport_sockets.tls
typedConfig:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
commonTlsContext:
validationContextSdsSecretConfig:
name: policy-btls-2/policies-ca
sdsConfig:
ads: {}
resourceApiVersion: V3
sni: example.com
type: EDS
Loading

0 comments on commit eee8c59

Please sign in to comment.