-
Notifications
You must be signed in to change notification settings - Fork 49
feat(sandbox-env): opt-in HPA, PDB and 502-retry EnvoyFilter for the preview gateway #4285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicacioliveira
wants to merge
2
commits into
main
Choose a base branch
from
feat/preview-gateway-resilience
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
deploy/helm/sandbox-env/templates/sandbox-preview-hpa.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| {{- if and .Values.previewGateway.enabled .Values.previewGateway.autoscaling.enabled }} | ||
| {{- $previewName := include "sandbox-env.previewName" . }} | ||
| # HPA over the Deployment that Istio's gateway controller generates for the | ||
| # preview Gateway (`<previewName>-istio`). This is the Istio-documented way | ||
| # to scale an auto-deployed Gateway API gateway: the controller never writes | ||
| # `spec.replicas` after creation, so the HPA owns replica count without | ||
| # conflict. Scoped by namespace + target name — it cannot reach any other | ||
| # gateway (the sites gateway lives in istio-system under a different name). | ||
| apiVersion: autoscaling/v2 | ||
| kind: HorizontalPodAutoscaler | ||
| metadata: | ||
| name: {{ $previewName }}-istio | ||
| namespace: {{ .Values.previewGateway.namespace }} | ||
| labels: | ||
| {{- include "sandbox-env.sandboxPreviewLabels" . | nindent 4 }} | ||
| spec: | ||
| scaleTargetRef: | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| name: {{ $previewName }}-istio | ||
| minReplicas: {{ .Values.previewGateway.autoscaling.minReplicas }} | ||
| maxReplicas: {{ .Values.previewGateway.autoscaling.maxReplicas }} | ||
| metrics: | ||
| - type: Resource | ||
| resource: | ||
| name: cpu | ||
| target: | ||
| type: Utilization | ||
| averageUtilization: {{ .Values.previewGateway.autoscaling.targetCPUUtilizationPercentage }} | ||
| {{- end }} | ||
22 changes: 22 additions & 0 deletions
22
deploy/helm/sandbox-env/templates/sandbox-preview-pdb.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| {{- if and .Values.previewGateway.enabled .Values.previewGateway.pdb.enabled }} | ||
| {{- $previewName := include "sandbox-env.previewName" . }} | ||
| # PDB over the pods of the Istio-generated preview gateway Deployment, | ||
| # selected by the `gateway-name` label the controller stamps on them. With | ||
| # minAvailable 1 and a single replica, voluntary evictions (Karpenter | ||
| # consolidation/drift, node drains) are blocked outright — the gateway is | ||
| # the only ingress for every preview URL, so an eviction is a full preview | ||
| # outage. Spot interruptions and node failures are NOT covered by a PDB; | ||
| # raise previewGateway.autoscaling.minReplicas to 2 for that. | ||
| apiVersion: policy/v1 | ||
| kind: PodDisruptionBudget | ||
| metadata: | ||
| name: {{ $previewName }}-istio | ||
| namespace: {{ .Values.previewGateway.namespace }} | ||
| labels: | ||
| {{- include "sandbox-env.sandboxPreviewLabels" . | nindent 4 }} | ||
| spec: | ||
| minAvailable: {{ .Values.previewGateway.pdb.minAvailable }} | ||
| selector: | ||
| matchLabels: | ||
| gateway.networking.k8s.io/gateway-name: {{ $previewName }} | ||
| {{- end }} |
60 changes: 60 additions & 0 deletions
60
deploy/helm/sandbox-env/templates/sandbox-preview-retry.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| {{- if and .Values.previewGateway.enabled .Values.previewGateway.retries.enabled }} | ||
| {{- $previewName := include "sandbox-env.previewName" . }} | ||
| {{- $retries := .Values.previewGateway.retries }} | ||
| # Retry policy for the preview data path. Istio's built-in default retry | ||
| # policy covers connection-level failures only — an upstream that ANSWERS | ||
| # 502 is returned to the client as-is. On this path that 502 is the sandbox | ||
| # daemon reporting "dev server (port 3000) not up yet" during boot/restart, | ||
| # so a short, spaced retry budget absorbs the blip instead of surfacing it. | ||
| # | ||
| # Scope: the workloadSelector below is HARD-CODED to this gateway's | ||
| # `gateway-name` label and the resource lands in the gateway's namespace — | ||
| # double barrier (namespace + label), so this filter can never apply to any | ||
| # other Envoy in the mesh. validations.yaml rejects rendering it into | ||
| # istio-system, where root-namespace EnvoyFilter semantics would make the | ||
| # label selector match cluster-wide. | ||
| # | ||
| # Safety properties of the policy: | ||
| # - GET-only (`retriable_request_headers` on :method): no request-body | ||
| # buffering, no replayed mutations. | ||
| # - 503 is intentionally not retried: the daemon's 503 is the | ||
| # auto-refreshing "Connecting…" page — a response the user should see | ||
| # immediately, not after a retry budget. | ||
| # | ||
| # EnvoyFilter is v1alpha3 and coupled to Envoy internals — smoke-test on | ||
| # stg after every Istio upgrade (see PR notes / values.yaml). | ||
| apiVersion: networking.istio.io/v1alpha3 | ||
| kind: EnvoyFilter | ||
| metadata: | ||
| name: {{ $previewName }}-retry | ||
| namespace: {{ .Values.previewGateway.namespace }} | ||
| labels: | ||
| {{- include "sandbox-env.sandboxPreviewLabels" . | nindent 4 }} | ||
| spec: | ||
| workloadSelector: | ||
| labels: | ||
| gateway.networking.k8s.io/gateway-name: {{ $previewName }} | ||
| configPatches: | ||
| - applyTo: HTTP_ROUTE | ||
| match: | ||
| context: GATEWAY | ||
| patch: | ||
| operation: MERGE | ||
| value: | ||
| route: | ||
| retry_policy: | ||
| retry_on: {{ $retries.retryOn | quote }} | ||
| retriable_status_codes: | ||
| {{- range $retries.retriableStatusCodes }} | ||
| - {{ . }} | ||
| {{- end }} | ||
| num_retries: {{ $retries.attempts }} | ||
| per_try_timeout: {{ $retries.perTryTimeout }} | ||
| retry_back_off: | ||
| base_interval: {{ $retries.backoffBaseInterval }} | ||
| max_interval: {{ $retries.backoffMaxInterval }} | ||
| retriable_request_headers: | ||
| - name: ":method" | ||
| string_match: | ||
| exact: "GET" | ||
| {{- end }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Autoscaling can silently be ineffective when
previewGateway.gatewayClassNameis notistio, because the HPA target Deployment name is fixed to-istio. Consider gatingpreviewGateway.autoscaling.enabledto Istio (validation) or deriving the target from the selected gateway controller instead of hard-coding the suffix.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed — extended the existing retries-only validation to all three knobs:
autoscaling/pdb/retries.enabled=true each fail at template time whengatewayClassName != istio. PDB had the same issue (thegateway.networking.k8s.io/gateway-namepod label is also Istio's controller convention), so it's gated too. Deriving the generated Deployment name per controller isn't worth it here — every other controller has different generated-workload conventions, and the chart's data path (per-claim HTTPRoutes minted by mesh) is only exercised against Istio anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks — the Istio-specific boundary is clear, and the PDB/gateway-name detail is useful. The original autoscaling point still stands, but the broader contract is that these preview-gateway resilience knobs should be gated together to Istio-only conventions.
Thanks for the feedback! I've saved this as a new learning to improve future reviews.