Skip to content

Commit 6f7173b

Browse files
committed
Allow setting service topology aware routing mode
1 parent 59c4401 commit 6f7173b

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,22 @@ spec:
202202
egress.monzo.com/gateway: egress-gateway-name
203203
```
204204
205-
| Variable name | Default | Description |
206-
|------------------------------------|-------------------------------------------|----------------------------------------------------|
207-
| ENVOY_IMAGE | `envoyproxy/envoy-alpine:v1.16.5` | Name of the Envoy Proxy image to use |
208-
| TAINT_TOLERATION_KEY | Empty, no tolerations applied | Toleration key to apply to gateway pods |
209-
| TAINT_TOLERATION_VALUE | Empty, no tolerations applied | Toleration value to apply to gateway pods |
210-
| NODE_SELECTOR_KEY | Empty, no node selector added | Node selector label key to apply to gateway pods |
211-
| NODE_SELECTOR_VALUE | Empty, no node selector added | Node selector label value to apply to gateway pods |
212-
| POD_TOPOLOGY_ZONE_MAX_SKEW_KEY | `topology.kubernetes.io/zone` | Topology key for the zone constraint |
213-
| POD_TOPOLOGY_ZONE_MAX_SKEW | Empty, won't inject a zone constraint | Value of maxSkew for the zone constraint |
214-
| POD_TOPOLOGY_HOSTNAME_MAX_SKEW_KEY | `kubernetes.io/hostname` | Topology key for the hostname constraint |
215-
| POD_TOPOLOGY_HOSTNAME_MAX_SKEW | Empty, won't inject a hostname constraint | Value of maxSkew for the hostname constraint |
216-
205+
You can also setup services to have their endpoints aware of network topologies with [topology aware routing](https://kubernetes.io/docs/concepts/services-networking/topology-aware-routing/).
206+
207+
If you set the environment variable `ENABLE_SERVICE_TOPOLOGY_MODE="true"` this will enable setting the annotations `service.kubernetes.io/topology-mode="auto"`.
208+
209+
If you turn this on you can also set `spec.serviceTopologyMode` to any value if you want to disable this for particular egress'. For example
210+
if you set `spec.serviceTopologyMode: "None"` this will disable topology aware routing for your ExternalService.
211+
212+
| Variable name | Default | Description |
213+
|------------------------------------|-------------------------------------------|-----------------------------------------------------------|
214+
| ENVOY_IMAGE | `envoyproxy/envoy-alpine:v1.16.5` | Name of the Envoy Proxy image to use |
215+
| TAINT_TOLERATION_KEY | Empty, no tolerations applied | Toleration key to apply to gateway pods |
216+
| TAINT_TOLERATION_VALUE | Empty, no tolerations applied | Toleration value to apply to gateway pods |
217+
| NODE_SELECTOR_KEY | Empty, no node selector added | Node selector label key to apply to gateway pods |
218+
| NODE_SELECTOR_VALUE | Empty, no node selector added | Node selector label value to apply to gateway pods |
219+
| POD_TOPOLOGY_ZONE_MAX_SKEW_KEY | `topology.kubernetes.io/zone` | Topology key for the zone constraint |
220+
| POD_TOPOLOGY_ZONE_MAX_SKEW | Empty, won't inject a zone constraint | Value of maxSkew for the zone constraint |
221+
| POD_TOPOLOGY_HOSTNAME_MAX_SKEW_KEY | `kubernetes.io/hostname` | Topology key for the hostname constraint |
222+
| POD_TOPOLOGY_HOSTNAME_MAX_SKEW | Empty, won't inject a hostname constraint | Value of maxSkew for the hostname constraint |
223+
| ENABLE_SERVICE_TOPOLOGY_MODE | Empty, won't add the annotation | Set to 'true' to add the topology mode service annotation |

api/v1/externalservice_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ type ExternalServiceSpec struct {
6262
// If this circuit breaker overflows the upstream_cx_overflow counter for the cluster will increment.
6363
// +optional
6464
EnvoyClusterMaxConnections *uint32 `json:"envoyClusterMaxConnections,omitempty"`
65+
66+
// Provides a way to override the global default
67+
// +optional
68+
ServiceTopologyMode string `json:"serviceTopologyMode,omitempty"`
6569
}
6670

6771
type ExternalServicePort struct {

controllers/externalservice_controller.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ package controllers
1818
import (
1919
"bytes"
2020
"context"
21+
"os"
2122

2223
"github.com/go-logr/logr"
23-
egressv1 "github.com/monzo/egress-operator/api/v1"
2424
appsv1 "k8s.io/api/apps/v1"
2525
autoscalingv1 "k8s.io/api/autoscaling/v1"
2626
corev1 "k8s.io/api/core/v1"
@@ -29,6 +29,8 @@ import (
2929
"k8s.io/apimachinery/pkg/runtime"
3030
ctrl "sigs.k8s.io/controller-runtime"
3131
"sigs.k8s.io/controller-runtime/pkg/client"
32+
33+
egressv1 "github.com/monzo/egress-operator/api/v1"
3234
)
3335

3436
const namespace = "egress-operator-system"
@@ -106,9 +108,19 @@ func labels(es *egressv1.ExternalService) map[string]string {
106108
}
107109

108110
func annotations(es *egressv1.ExternalService) map[string]string {
109-
return map[string]string{
111+
annotations := map[string]string{
110112
"egress.monzo.com/dns-name": es.Spec.DnsName,
111113
}
114+
// Allow setting the topology aware routing annotation
115+
value, ok := os.LookupEnv("ENABLE_SERVICE_TOPOLOGY_MODE")
116+
if ok && value == "true" {
117+
if es.Spec.ServiceTopologyMode != "" {
118+
annotations["service.kubernetes.io/topology-mode"] = es.Spec.ServiceTopologyMode
119+
} else {
120+
annotations["service.kubernetes.io/topology-mode"] = "Auto"
121+
}
122+
}
123+
return annotations
112124
}
113125

114126
func labelsToSelect(es *egressv1.ExternalService) map[string]string {

0 commit comments

Comments
 (0)