Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/app_charts/base/cloud/gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ spec:
# backends as "<namespace>/<name>|<namespace>/<name>|...".
clusterStatName: "%ROUTE_KIND%/%ROUTE_NAMESPACE%/%ROUTE_NAME%/rule/%ROUTE_RULE_NUMBER%/%BACKEND_REFS%"
---
# Keep at least one Envoy Gateway controller replica available during voluntary
# disruptions (e.g. node drains and upgrades).
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: envoy-gateway
namespace: envoy-gateway-system
spec:
maxUnavailable: 1
selector:
matchLabels:
control-plane: envoy-gateway
app.kubernetes.io/name: gateway-helm
app.kubernetes.io/instance: eg
---
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
Expand Down
18 changes: 17 additions & 1 deletion third_party/envoy-gateway/envoy-gateway-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ metadata:
app.kubernetes.io/version: "latest"
app.kubernetes.io/managed-by: Helm
spec:
replicas: 1
replicas: 2
selector:
matchLabels:
control-plane: envoy-gateway
Expand All @@ -508,6 +508,22 @@ spec:
app.kubernetes.io/name: gateway-helm
app.kubernetes.io/instance: eg
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
control-plane: envoy-gateway
topologyKey: kubernetes.io/hostname
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
control-plane: envoy-gateway
automountServiceAccountToken: true
securityContext:
fsGroup: 65532
Expand Down
67 changes: 67 additions & 0 deletions third_party/envoy-gateway/process_envoy_gateway_manifest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python3
"""Helper script for third_party/envoy-gateway/update.sh to process Envoy Gateway manifests."""

import re
import sys
from typing import Any

import yaml

Expand All @@ -20,6 +22,66 @@

_EG_SYSTEM_FOOTER = "\n{{- end }}\n"

_EG_CONTROLLER_SCHEDULING_PATCH = """ affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
control-plane: envoy-gateway
topologyKey: kubernetes.io/hostname
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
control-plane: envoy-gateway
"""


def _patch_controller_deployment(doc_str: str, doc_obj: dict[str, Any]) -> str:
"""Patches Deployment/envoy-gateway for multi-replica HA scheduling."""
spec = doc_obj.get("spec") or {}
pod_spec = (spec.get("template") or {}).get("spec") or {}
if "affinity" in pod_spec or "topologySpreadConstraints" in pod_spec:
raise ValueError(
"Deployment/envoy-gateway already defines affinity or"
" topologySpreadConstraints; review upstream manifest before patching"
)

patched, count = re.subn(r"(?m)^ replicas:\s*\d+$", " replicas: 2", doc_str)
if count != 1:
raise ValueError(
f"Expected 1 replicas field in Deployment/envoy-gateway, found {count}"
)

pod_spec_marker = "\n spec:\n"
if patched.count(pod_spec_marker) != 1:
raise ValueError(
"Expected 1 pod template spec block in Deployment/envoy-gateway"
)
patched = patched.replace(
pod_spec_marker,
f"{pod_spec_marker}{_EG_CONTROLLER_SCHEDULING_PATCH}",
1,
)

patched_obj = yaml.safe_load(patched)
patched_spec = patched_obj.get("spec") or {}
patched_pod_spec = (patched_spec.get("template") or {}).get("spec") or {}
if patched_spec.get("replicas") != 2:
raise ValueError("Failed to set Deployment/envoy-gateway replicas to 2")
if (
"affinity" not in patched_pod_spec
or "topologySpreadConstraints" not in patched_pod_spec
):
raise ValueError(
"Failed to inject scheduling constraints into Deployment/envoy-gateway"
)
return patched


def _parse_manifests(install_file: str) -> tuple[list[str], list[str]]:
"""Parses the upstream install.yaml and splits into CRDs and system docs.
Expand Down Expand Up @@ -71,6 +133,11 @@ def _parse_manifests(install_file: str) -> tuple[list[str], list[str]]:
"extensionApis: {}",
"extensionApis:\n enableBackend: true",
)
elif (
kind == "Deployment"
and doc_obj.get("metadata", {}).get("name") == "envoy-gateway"
):
cleaned = _patch_controller_deployment(cleaned, doc_obj)
system_docs.append(cleaned)

return eg_crds, system_docs
Expand Down
Loading