Skip to content

Commit

Permalink
Merge branch 'main' into ctp-for-tcp
Browse files Browse the repository at this point in the history
Signed-off-by: Dingkang Li <dingkang1743@gmail.com>
  • Loading branch information
aoledk committed May 11, 2024
2 parents 95b9a6e + c30d09f commit 77e4573
Show file tree
Hide file tree
Showing 54 changed files with 495 additions and 111 deletions.
3 changes: 1 addition & 2 deletions api/v1alpha1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ const (
//
// +kubebuilder:validation:XValidation:rule="self.type == 'Header' ? has(self.header) : !has(self.header)",message="If consistent hash type is header, the header field must be set."
type ConsistentHash struct {
// Valid Type values are "SourceIP".
// ConsistentHashType defines the type of input to hash on. Valid Type values are "SourceIP" or "Header".
//
// +unionDiscriminator
Type ConsistentHashType `json:"type"`

// Header configures the header hash policy when the consistent hash type is set to Header.
//
// +optional
// +notImplementedHide
Header *Header `json:"header,omitempty"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ spec:
- name
type: object
type:
description: Valid Type values are "SourceIP".
description: ConsistentHashType defines the type of input
to hash on. Valid Type values are "SourceIP" or "Header".
enum:
- SourceIP
- Header
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/envoyproxy/gateway

go 1.22.2
go 1.22.3

require (
fortio.org/fortio v1.63.7
Expand Down
10 changes: 9 additions & 1 deletion internal/cmd/egctl/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (

supportedXPolicyTypes = []string{
gatewayapi.KindBackendTLSPolicy, gatewayapi.KindBackendTrafficPolicy, gatewayapi.KindClientTrafficPolicy,
gatewayapi.KindSecurityPolicy, gatewayapi.KindEnvoyPatchPolicy,
gatewayapi.KindSecurityPolicy, gatewayapi.KindEnvoyPatchPolicy, gatewayapi.KindEnvoyExtensionPolicy,
}

supportedAllTypes = []string{
Expand Down Expand Up @@ -238,6 +238,14 @@ func runStatus(ctx context.Context, cli client.Client, inputResourceType, namesp
resourcesList = &epp
resourceKind = gatewayapi.KindEnvoyPatchPolicy

case "eep", "envoyextensionpolicy":
eep := egv1a1.EnvoyExtensionPolicyList{}
if err := cli.List(ctx, &eep, client.InNamespace(namespace)); err != nil {
return err
}
resourcesList = &eep
resourceKind = gatewayapi.KindEnvoyExtensionPolicy

case "sp", "securitypolicy":
sp := egv1a1.SecurityPolicyList{}
if err := cli.List(ctx, &sp, client.InNamespace(namespace)); err != nil {
Expand Down
23 changes: 18 additions & 5 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,11 +764,7 @@ func (t *Translator) buildLoadBalancer(policy *egv1a1.BackendTrafficPolicy) *ir.
switch policy.Spec.LoadBalancer.Type {
case egv1a1.ConsistentHashLoadBalancerType:
lb = &ir.LoadBalancer{
ConsistentHash: &ir.ConsistentHash{},
}
if policy.Spec.LoadBalancer.ConsistentHash != nil &&
policy.Spec.LoadBalancer.ConsistentHash.Type == egv1a1.SourceIPConsistentHashType {
lb.ConsistentHash.SourceIP = ptr.To(true)
ConsistentHash: t.buildConsistentHashLoadBalancer(policy),
}
case egv1a1.LeastRequestLoadBalancerType:
lb = &ir.LoadBalancer{}
Expand Down Expand Up @@ -805,6 +801,23 @@ func (t *Translator) buildLoadBalancer(policy *egv1a1.BackendTrafficPolicy) *ir.
return lb
}

func (t *Translator) buildConsistentHashLoadBalancer(policy *egv1a1.BackendTrafficPolicy) *ir.ConsistentHash {
switch policy.Spec.LoadBalancer.ConsistentHash.Type {
case egv1a1.SourceIPConsistentHashType:
return &ir.ConsistentHash{
SourceIP: ptr.To(true),
}
case egv1a1.HeaderConsistentHashType:
return &ir.ConsistentHash{
Header: &ir.Header{
Name: policy.Spec.LoadBalancer.ConsistentHash.Header.Name,
},
}
default:
return &ir.ConsistentHash{}
}
}

func (t *Translator) buildProxyProtocol(policy *egv1a1.BackendTrafficPolicy) *ir.ProxyProtocol {
var pp *ir.ProxyProtocol
switch policy.Spec.ProxyProtocol.Version {
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR XdsIRMap
// Infra IR proxy ports must be unique.
foundPorts := make(map[string][]*protocolPort)
t.validateConflictedLayer7Listeners(gateways)
t.validateConflictedLayer4Listeners(gateways, gwapiv1.TCPProtocolType, gwapiv1.TLSProtocolType)
t.validateConflictedLayer4Listeners(gateways, gwapiv1.TCPProtocolType)
t.validateConflictedLayer4Listeners(gateways, gwapiv1.UDPProtocolType)
if t.MergeGateways {
t.validateConflictedMergedListeners(gateways)
Expand Down
8 changes: 7 additions & 1 deletion internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ func (t *Translator) processTLSRouteParentRefs(tlsRoute *TLSRouteContext, resour
if irListener != nil {
irRoute := &ir.TCPRoute{
Name: irTCPRouteName(tlsRoute),
TLS: &ir.TLS{Passthrough: &ir.TLSInspectorConfig{
TLS: &ir.TLS{TLSInspectorConfig: &ir.TLSInspectorConfig{
SNIs: hosts,
}},
Destination: &ir.RouteDestination{
Expand Down Expand Up @@ -1095,6 +1095,12 @@ func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resour

if irListener.TLS != nil {
irRoute.TLS = &ir.TLS{Terminate: irListener.TLS}

if listener.Hostname != nil {
irRoute.TLS.TLSInspectorConfig = &ir.TLSInspectorConfig{
SNIs: []string{string(*listener.Hostname)},
}
}
}

irListener.Routes = append(irListener.Routes, irRoute)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,6 @@ xdsIR:
weight: 1
name: tlsroute/default/tlsroute-1
tls:
passthrough:
inspector:
snis:
- foo.bar.com
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ gateways:
kind: TCPRoute
- attachedRoutes: 1
conditions:
- lastTransitionTime: null
message: Only one TCP/TLS listener is allowed in a given port
reason: ProtocolConflict
status: "True"
type: Conflicted
- lastTransitionTime: null
message: Listener must have TLS set when protocol is TLS.
reason: Invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ gateways:
allowedRoutes:
namespaces:
from: All
- name: tls-hostname
hostname: "foo.bar.com"
protocol: TLS
port: 90
tls:
certificateRefs:
- group: ""
kind: Secret
name: tls-secret-1
mode: Terminate
allowedRoutes:
namespaces:
from: All
tcpRoutes:
- apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TCPRoute
Expand All @@ -29,10 +42,25 @@ tcpRoutes:
parentRefs:
- namespace: envoy-gateway
name: gateway-1
sectionName: tls
rules:
- backendRefs:
- name: service-1
port: 8080
- apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TCPRoute
metadata:
namespace: default
name: tcproute-2
spec:
parentRefs:
- namespace: envoy-gateway
name: gateway-1
sectionName: tls-hostname
rules:
- backendRefs:
- name: service-2
port: 8080

secrets:
- apiVersion: v1
Expand Down
Loading

0 comments on commit 77e4573

Please sign in to comment.