Skip to content

Conversation

@sheidkamp
Copy link
Contributor

@sheidkamp sheidkamp commented Aug 7, 2025

Description

We support setting nodeSelector, affinity, antiAffinity, and tolerations on the gateways via Gateway Parameters.

This PR adds support for topologySpreadConstraints as well.

Fixes: #11917

Change Type

/kind new_feature

Changelog

Adds `topologySpreadConstraints` to the Pod struct used in GatewayParameters in order to set the corresponding [topologySpreadConstrains](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/#topologyspreadconstraints-field) field in the gateway-proxy pod.

Notes

To set the topology constraints on a gateway pod, for example as:

  topologySpreadConstraints:
  - maxSkew: 25
    topologyKey: myTopologyKey
    whenUnsatisfiable: ScheduleAnyway

The following resources could be applied:

k apply -f - <<EOF
kind: GatewayParameters
apiVersion: gateway.kgateway.dev/v1alpha1
metadata:
  name: gloo-test
spec:
  kube:
    podTemplate:
      topologySpreadConstraints:
        - maxSkew: 25
          topologyKey: myTopologyKey
          whenUnsatisfiable: ScheduleAnyway

---
kind: GatewayClass
apiVersion: gateway.networking.k8s.io/v1
metadata:
  name: gloo-test
spec:
  controllerName: kgateway.dev/kgateway
  parametersRef:
    group: gateway.kgateway.dev
    kind: GatewayParameters
    name: gloo-test
    namespace: default
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: transformation-test-gateway
spec:
  gatewayClassName: gloo-test
  listeners:
    - name: http
      port: 8080
      protocol: HTTP
      allowedRoutes:
        namespaces:
          from: All
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: transformation-test-route
spec:
  parentRefs:
    - name: transformation-test-gateway
  hostnames:
    - "www.example.com"
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: httpbin
          port: 8000
EOF

Copilot AI review requested due to automatic review settings August 7, 2025 15:01
@sheidkamp sheidkamp added the work in progress Indicates that a PR should not merge because it is a work in progress label Aug 7, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for TopologySpreadConstraints to Pod specifications in the kgateway system. TopologySpreadConstraints allow users to control how pods are distributed across topology domains (like zones or nodes) for better availability and performance.

  • Adds TopologySpreadConstraints field to Pod kube_types
  • Implements merge logic for combining TopologySpreadConstraints from different sources
  • Updates Helm templates and deployer logic to support the new field

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
api/v1alpha1/kube_types.go Adds TopologySpreadConstraints field and getter method to Pod struct
pkg/deployer/values.go Adds TopologySpreadConstraints field to HelmGateway struct
pkg/deployer/merge.go Implements merge logic for TopologySpreadConstraints
pkg/deployer/deployer_test.go Adds test coverage for TopologySpreadConstraints
internal/kgateway/helm/kgateway/templates/gateway/proxy-deployment.yaml Updates Helm template to render TopologySpreadConstraints
internal/kgateway/deployer/gateway_parameters.go Wires TopologySpreadConstraints from pod config to gateway values
install/helm/kgateway-crds/templates/gateway.kgateway.dev_gatewayparameters.yaml Adds CRD schema for TopologySpreadConstraints
api/v1alpha1/zz_generated.deepcopy.go Generated deepcopy implementation for TopologySpreadConstraints
api/applyconfiguration/internal/internal.go Updates schema YAML for apply configurations
api/applyconfiguration/api/v1alpha1/pod.go Adds apply configuration support for TopologySpreadConstraints
Comments suppressed due to low confidence (1)

@github-actions github-actions bot added do-not-merge/kind-invalid Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/release-note-invalid Indicates that a PR should not merge because it's missing one of the release note labels. labels Aug 7, 2025
@sheidkamp sheidkamp removed the work in progress Indicates that a PR should not merge because it is a work in progress label Aug 7, 2025
@github-actions github-actions bot added kind/feature Categorizes issue or PR as related to a new feature. release-note and removed do-not-merge/kind-invalid Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/release-note-invalid Indicates that a PR should not merge because it's missing one of the release note labels. labels Aug 7, 2025
@timflannagan
Copy link
Member

@sheidkamp Looks like there's merge conflicts. I'd also use Fixes #11917 in the PR description to auto-close the issue, but we can also manually link it up.

@sheidkamp sheidkamp closed this Aug 8, 2025
@sheidkamp sheidkamp reopened this Aug 8, 2025
@sheidkamp sheidkamp enabled auto-merge August 8, 2025 16:06
@sheidkamp sheidkamp added this pull request to the merge queue Aug 8, 2025
Merged via the queue into kgateway-dev:main with commit 432f599 Aug 8, 2025
23 checks passed
@sheidkamp sheidkamp deleted the add-topology-spread-constraint branch August 8, 2025 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support TopologySpreadConstraints in gateway parameters

3 participants