Skip to content

Commit 45ae657

Browse files
committed
Allow rolling update maxSurge maxUnavailable to be configurable
1 parent 5c2183d commit 45ae657

2 files changed

Lines changed: 36 additions & 15 deletions

File tree

README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# egress-operator
2+
23
An operator to produce egress gateway pods and control access to them with network policies, and a coredns plugin to route egress traffic to these pods.
34

45
The idea is that instead of authorizing egress traffic with protocol inspection,
56
you instead create a internal clusterIP for every external service you use, lock
67
it down to only a few pods via a network policy, and then set up your dns server
78
to resolve the external service to that clusterIP.
89

9-
Built with kubebuilder: https://book.kubebuilder.io/
10+
Built with kubebuilder: <https://book.kubebuilder.io/>
1011

1112
The operator accepts ExternalService objects, which aren't namespaced, which define a dns name and ports for an external service.
1213
In the `egress-operator-system` namespace, it creates:
14+
1315
- An envoy configmap for a TCP/UDP proxy to that service (UDP not working until the next envoy release that enables it)
1416
- A deployment for some envoy pods with that config
1517
- A horizontal pod autoscaler to keep the deployment correctly sized
@@ -31,24 +33,28 @@ In the `egress-operator-system` namespace, it creates:
3133
```bash
3234
make run
3335
```
36+
3437
This creates an ExternalService object to see the controller-manager creating managed resources in the remote cluster.
3538

3639
### Setting up CoreDNS plugin
3740

3841
The CoreDNS plugin rewrites responses for external service hostnames managed by egress-operator.
3942

4043
Build a CoreDNS image which contains the plugin:
44+
4145
```bash
4246
cd coredns-plugin
4347
make docker-build docker-push IMG=yourrepo/egress-operator-coredns:latest
4448
```
4549

4650
You'll need to swap out the image of your coredns kubedns Deployment for `yourrepo/egress-operator-coredns:latest`:
51+
4752
```bash
4853
kubectl edit deploy coredns -n kube-system # Your Deployment name may vary
4954
```
5055

5156
And edit the coredns Corefile in ConfigMap to put in `egressoperator egress-operator-system cluster.local`:
57+
5258
```bash
5359
kubectl edit configmap coredns-config -n kube-system # Your ConfigMap name may vary
5460
```
@@ -202,15 +208,16 @@ spec:
202208
egress.monzo.com/gateway: egress-gateway-name
203209
```
204210
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-
211+
| Variable name | Default | Description |
212+
| ---------------------------------- | ----------------------------------------- | ------------------------------------------------------- |
213+
| ENVOY_IMAGE | `envoyproxy/envoy-alpine:v1.16.5` | Name of the Envoy Proxy image to use |
214+
| TAINT_TOLERATION_KEY | Empty, no tolerations applied | Toleration key to apply to gateway pods |
215+
| TAINT_TOLERATION_VALUE | Empty, no tolerations applied | Toleration value to apply to gateway pods |
216+
| NODE_SELECTOR_KEY | Empty, no node selector added | Node selector label key to apply to gateway pods |
217+
| NODE_SELECTOR_VALUE | Empty, no node selector added | Node selector label value to apply to gateway pods |
218+
| POD_TOPOLOGY_ZONE_MAX_SKEW_KEY | `topology.kubernetes.io/zone` | Topology key for the zone constraint |
219+
| POD_TOPOLOGY_ZONE_MAX_SKEW | Empty, won't inject a zone constraint | Value of maxSkew for the zone constraint |
220+
| POD_TOPOLOGY_HOSTNAME_MAX_SKEW_KEY | `kubernetes.io/hostname` | Topology key for the hostname constraint |
221+
| POD_TOPOLOGY_HOSTNAME_MAX_SKEW | Empty, won't inject a hostname constraint | Value of maxSkew for the hostname constraint |
222+
| ROLLING_UPDATE_MAX_UNAVAILABLE | 25% | Rolling Update max unavailable to apply to gateway pods |
223+
| ROLLING_UPDATE_MAX_SURGE | 25% | Rolling Update max surge to apply to gateway pods |

controllers/deployment.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ func deployment(es *egressv1.ExternalService, configHash string) *appsv1.Deploym
134134
}
135135
}
136136

137+
maxUnavailableStr := lookupEnvOr("ROLLING_UPDATE_MAX_UNAVAILABLE", "25%")
138+
maxSurgeStr := lookupEnvOr("ROLLING_UPDATE_MAX_SURGE", "25%")
139+
137140
var resources corev1.ResourceRequirements
138141
if es.Spec.Resources != nil {
139142
resources = *es.Spec.Resources
@@ -150,6 +153,9 @@ func deployment(es *egressv1.ExternalService, configHash string) *appsv1.Deploym
150153
}
151154
}
152155

156+
maxUnavailable := intstr.FromString(maxUnavailableStr)
157+
maxSurge := intstr.FromString(maxSurgeStr)
158+
153159
return &appsv1.Deployment{
154160
ObjectMeta: metav1.ObjectMeta{
155161
Name: es.Name,
@@ -163,8 +169,8 @@ func deployment(es *egressv1.ExternalService, configHash string) *appsv1.Deploym
163169
Strategy: appsv1.DeploymentStrategy{
164170
Type: appsv1.RollingUpdateDeploymentStrategyType,
165171
RollingUpdate: &appsv1.RollingUpdateDeployment{
166-
MaxUnavailable: intstr.ValueOrDefault(nil, intstr.FromString("25%")),
167-
MaxSurge: intstr.ValueOrDefault(nil, intstr.FromString("25%")),
172+
MaxUnavailable: &maxUnavailable,
173+
MaxSurge: &maxSurge,
168174
},
169175
},
170176
Selector: labelSelector,
@@ -245,3 +251,11 @@ func deployment(es *egressv1.ExternalService, configHash string) *appsv1.Deploym
245251
},
246252
}
247253
}
254+
255+
func lookupEnvOr(envKey, envDefaultValue string) string {
256+
valueStr, isSet := os.LookupEnv(envKey)
257+
if !isSet || len(valueStr) == 0 {
258+
return envDefaultValue
259+
}
260+
return valueStr
261+
}

0 commit comments

Comments
 (0)