Skip to content

Commit

Permalink
fix: listener on IPv6 first cluster
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <[email protected]>
  • Loading branch information
zirain committed Oct 30, 2024
1 parent 20a4622 commit 082e472
Show file tree
Hide file tree
Showing 83 changed files with 622 additions and 88 deletions.
4 changes: 4 additions & 0 deletions charts/gateway-helm/templates/envoy-gateway-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ spec:
- server
- --config-path=/config/envoy-gateway.yaml
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ envoyProxyForGatewayClass:
- name: envoy-gateway-proxy-ready-0.0.0.0-19001
address:
socket_address:
address: 0.0.0.0
address: '0.0.0.0'
port_value: 19001
protocol: TCP
filter_chains:
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/envoy/shutdown_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ func Shutdown(drainTimeout time.Duration, minDrainDuration time.Duration, exitAt

// postEnvoyAdminAPI sends a POST request to the Envoy admin API
func postEnvoyAdminAPI(path string) error {
// TODO: change bootstrap.AdminAddress() to localhost because there're in the same pod?

Check warning on line 173 in internal/cmd/envoy/shutdown_manager.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/envoy/shutdown_manager.go#L173

Added line #L173 was not covered by tests
if resp, err := http.Post(fmt.Sprintf("http://%s:%d/%s",
bootstrap.EnvoyAdminAddress, bootstrap.EnvoyAdminPort, path), "application/json", nil); err != nil {
bootstrap.AdminAddress(), bootstrap.EnvoyAdminPort, path), "application/json", nil); err != nil {

Check warning on line 175 in internal/cmd/envoy/shutdown_manager.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/envoy/shutdown_manager.go#L175

Added line #L175 was not covered by tests
return err
} else {
defer resp.Body.Close()
Expand All @@ -187,7 +188,7 @@ func postEnvoyAdminAPI(path string) error {
func getTotalConnections() (*int, error) {
// Send request to Envoy admin API to retrieve server.total_connections stat
if resp, err := http.Get(fmt.Sprintf("http://%s:%d//stats?filter=^server\\.total_connections$&format=json",
bootstrap.EnvoyAdminAddress, bootstrap.EnvoyAdminPort)); err != nil {
bootstrap.AdminAddress(), bootstrap.EnvoyAdminPort)); err != nil {

Check warning on line 191 in internal/cmd/envoy/shutdown_manager.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/envoy/shutdown_manager.go#L191

Added line #L191 was not covered by tests
return nil, err
} else {
defer resp.Body.Close()
Expand Down
18 changes: 15 additions & 3 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import (
"github.com/envoyproxy/gateway/internal/ir"
"github.com/envoyproxy/gateway/internal/utils"
"github.com/envoyproxy/gateway/internal/utils/naming"
"github.com/envoyproxy/gateway/internal/utils/net"
)

const (
ipv4ListenerAddress = "0.0.0.0"
ipv6ListenerAddress = "::1"
)

var _ ListenersTranslator = (*Translator)(nil)
Expand Down Expand Up @@ -99,6 +105,12 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
if !isReady {
continue
}

// TODO: find a better way to this, maybe detect in the beginning of the process
address := ipv4ListenerAddress
if net.IsIPv6Pod() {
address = ipv6ListenerAddress
}

Check warning on line 113 in internal/gatewayapi/listener.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/listener.go#L112-L113

Added lines #L112 - L113 were not covered by tests
// Add the listener to the Xds IR
servicePort := &protocolPort{protocol: listener.Protocol, port: int32(listener.Port)}
containerPort := servicePortToContainerPort(int32(listener.Port), gateway.envoyProxy)
Expand All @@ -107,7 +119,7 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
irListener := &ir.HTTPListener{
CoreListenerDetails: ir.CoreListenerDetails{
Name: irListenerName(listener),
Address: "0.0.0.0",
Address: address,
Port: uint32(containerPort),
Metadata: buildListenerMetadata(listener, gateway),
IPFamily: getIPFamily(gateway.envoyProxy),
Expand All @@ -134,7 +146,7 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
irListener := &ir.TCPListener{
CoreListenerDetails: ir.CoreListenerDetails{
Name: irListenerName(listener),
Address: "0.0.0.0",
Address: address,
Port: uint32(containerPort),
IPFamily: getIPFamily(gateway.envoyProxy),
},
Expand All @@ -150,7 +162,7 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
irListener := &ir.UDPListener{
CoreListenerDetails: ir.CoreListenerDetails{
Name: irListenerName(listener),
Address: "0.0.0.0",
Address: address,
Port: uint32(containerPort),
},
}
Expand Down
8 changes: 8 additions & 0 deletions internal/infrastructure/kubernetes/proxy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,14 @@ func expectedVolumes(name string, pod *egv1a1.KubernetesPodSpec) []corev1.Volume
// expectedContainerEnv returns expected proxy container envs.
func expectedContainerEnv(containerSpec *egv1a1.KubernetesContainerSpec) []corev1.EnvVar {
env := []corev1.EnvVar{
{
Name: "POD_IP",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "status.podIP",
},
},
},
{
Name: envoyNsEnvVar,
ValueFrom: &corev1.EnvVarSource{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ spec:
command:
- envoy
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down Expand Up @@ -122,6 +126,10 @@ spec:
command:
- envoy-gateway
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ spec:
- name: envoy-gateway-proxy-ready-0.0.0.0-19001
address:
socket_address:
address: 0.0.0.0
address: '0.0.0.0'
port_value: 19001
protocol: TCP
filter_chains:
Expand Down Expand Up @@ -229,6 +229,10 @@ spec:
command:
- envoy
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down Expand Up @@ -299,6 +303,10 @@ spec:
command:
- envoy-gateway
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ spec:
- name: envoy-gateway-proxy-ready-0.0.0.0-19001
address:
socket_address:
address: 0.0.0.0
address: '0.0.0.0'
port_value: 19001
protocol: TCP
filter_chains:
Expand Down Expand Up @@ -228,6 +228,10 @@ spec:
command:
- envoy
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down Expand Up @@ -298,6 +302,10 @@ spec:
command:
- envoy-gateway
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ spec:
- name: envoy-gateway-proxy-ready-0.0.0.0-19001
address:
socket_address:
address: 0.0.0.0
address: '0.0.0.0'
port_value: 19001
protocol: TCP
filter_chains:
Expand Down Expand Up @@ -213,6 +213,10 @@ spec:
command:
- envoy
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down Expand Up @@ -289,6 +293,10 @@ spec:
command:
- envoy-gateway
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ spec:
- name: envoy-gateway-proxy-ready-0.0.0.0-19001
address:
socket_address:
address: 0.0.0.0
address: '0.0.0.0'
port_value: 19001
protocol: TCP
filter_chains:
Expand Down Expand Up @@ -187,6 +187,10 @@ spec:
command:
- envoy
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down Expand Up @@ -260,6 +264,10 @@ spec:
command:
- envoy-gateway
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ spec:
- name: envoy-gateway-proxy-ready-0.0.0.0-19001
address:
socket_address:
address: 0.0.0.0
address: '0.0.0.0'
port_value: 19001
protocol: TCP
filter_chains:
Expand Down Expand Up @@ -228,6 +228,10 @@ spec:
command:
- envoy
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down Expand Up @@ -302,6 +306,10 @@ spec:
command:
- envoy-gateway
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ spec:
- name: envoy-gateway-proxy-ready-0.0.0.0-19001
address:
socket_address:
address: 0.0.0.0
address: '0.0.0.0'
port_value: 19001
protocol: TCP
filter_chains:
Expand Down Expand Up @@ -222,6 +222,10 @@ spec:
command:
- envoy
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down Expand Up @@ -298,6 +302,10 @@ spec:
command:
- envoy-gateway
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ spec:
- name: envoy-gateway-proxy-ready-0.0.0.0-19001
address:
socket_address:
address: 0.0.0.0
address: '0.0.0.0'
port_value: 19001
protocol: TCP
filter_chains:
Expand Down Expand Up @@ -213,6 +213,10 @@ spec:
command:
- envoy
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down Expand Up @@ -289,6 +293,10 @@ spec:
command:
- envoy-gateway
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ spec:
- name: envoy-gateway-proxy-ready-0.0.0.0-19001
address:
socket_address:
address: 0.0.0.0
address: '0.0.0.0'
port_value: 19001
protocol: TCP
filter_chains:
Expand Down Expand Up @@ -213,6 +213,10 @@ spec:
command:
- envoy
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down Expand Up @@ -294,6 +298,10 @@ spec:
value: env_a_value
- name: env_b
value: env_b_value
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENVOY_GATEWAY_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Loading

0 comments on commit 082e472

Please sign in to comment.