Compare commits

..

5 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
856ab6c721 Address code review feedback: optimize theme provider
Co-authored-by: howardjohn <623453+howardjohn@users.noreply.github.com>
2026-02-16 00:52:40 +00:00
copilot-swe-agent[bot]
3ba3520502 Fix linting errors and build successfully
Co-authored-by: howardjohn <623453+howardjohn@users.noreply.github.com>
2026-02-16 00:51:34 +00:00
copilot-swe-agent[bot]
6c708133e2 Clean up Next.js configuration files
Co-authored-by: howardjohn <623453+howardjohn@users.noreply.github.com>
2026-02-16 00:49:35 +00:00
copilot-swe-agent[bot]
845d103d78 Replace Next.js with Vite + React Router
Co-authored-by: howardjohn <623453+howardjohn@users.noreply.github.com>
2026-02-16 00:48:34 +00:00
copilot-swe-agent[bot]
e32afeda5d Initial plan 2026-02-16 00:39:29 +00:00
1035 changed files with 81738 additions and 93628 deletions

8
.gitattributes vendored
View File

@ -1,5 +1,3 @@
controller/api/applyconfiguration/** linguist-generated=true
controller/pkg/client/** linguist-generated=true
controller/pkg/generated/** linguist-generated=true
crates/agentgateway/src/llm/tests/** text eol=lf
crates/agentgateway/src/llm/tests/**/*.bin -text
api/applyconfiguration/** linguist-generated=true
pkg/client/** linguist-generated=true
pkg/generated/** linguist-generated=true

View File

@ -1,83 +0,0 @@
version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
time: "05:00"
timezone: "America/Los_Angeles"
groups:
cargo-weekly:
patterns:
- "*"
ignore:
- dependency-name: "nom"
- dependency-name: "criterion"
open-pull-requests-limit: 1
# Disable regular version updates while still allowing Dependabot security PRs.
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
time: "09:00"
timezone: "America/Los_Angeles"
open-pull-requests-limit: 0
- package-ecosystem: "gomod"
directory: "/api"
schedule:
interval: "daily"
time: "09:00"
timezone: "America/Los_Angeles"
open-pull-requests-limit: 0
- package-ecosystem: "gomod"
directory: "/tools"
schedule:
interval: "daily"
time: "09:00"
timezone: "America/Los_Angeles"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/ui"
schedule:
interval: "daily"
time: "09:00"
timezone: "America/Los_Angeles"
open-pull-requests-limit: 0
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
time: "09:00"
timezone: "America/Los_Angeles"
open-pull-requests-limit: 0
- package-ecosystem: "docker"
directory: "/controller/hack/testbox"
schedule:
interval: "daily"
time: "09:00"
timezone: "America/Los_Angeles"
open-pull-requests-limit: 0
- package-ecosystem: "uv"
directory: "/examples/a2a/strands-agents"
schedule:
interval: "daily"
time: "09:00"
timezone: "America/Los_Angeles"
open-pull-requests-limit: 0
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
time: "09:00"
timezone: "America/Los_Angeles"
open-pull-requests-limit: 0

View File

@ -15,10 +15,10 @@ on:
type: string
jobs:
cache-upload:
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
uses: actions/checkout@v4
- name: Restore cache
uses: Andrej730/cache/restore@e294f7d180f76c94062d0251c60fe7362ce6667d
@ -28,7 +28,7 @@ jobs:
key: ${{ github.event.inputs.cache_key }}
- name: Upload cached folder as artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
uses: actions/upload-artifact@v4
with:
name: cache-artifact
path: |

View File

@ -1,56 +0,0 @@
name: Nightly Release
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch: {}
permissions:
contents: write
packages: write
id-token: write
jobs:
prepare:
if: github.repository == 'agentgateway/agentgateway'
runs-on: ubuntu-24.04
outputs:
has_commits: ${{ steps.check.outputs.has_commits }}
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 1
- name: Check for commits in the last 24 hours
id: check
run: |
LAST_COMMIT=$(git log -1 --format="%ct")
NOW=$(date +%s)
DIFF=$((NOW - LAST_COMMIT))
# 86400 = seconds in one day
if [ "$DIFF" -lt 86400 ]; then
echo "has_commits=true" >> $GITHUB_OUTPUT
echo "Recent commit found (${DIFF}s ago)"
else
echo "has_commits=false" >> $GITHUB_OUTPUT
echo "No recent commits (last commit was ${DIFF}s ago), skipping nightly release"
fi
- name: Compute nightly version
id: version
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
echo "version=0.0.0-alpha.${SHORT_SHA}" >> $GITHUB_OUTPUT
echo "Nightly version: 0.0.0-alpha.${SHORT_SHA}"
release:
needs: prepare
if: ${{ needs.prepare.outputs.has_commits == 'true' || github.event_name == 'workflow_dispatch' }}
uses: ./.github/workflows/release.yml
with:
version: ${{ needs.prepare.outputs.version }}
extra_tag: latest-dev
# Helm is special and requires a semver.
extra_helm_tag: 0.0.0-latest-dev
secrets: inherit

View File

@ -2,11 +2,9 @@ name: Branch
on:
push:
branches:
- "main"
branches: [ "main" ]
pull_request:
branches:
- "main"
branches: [ "main" ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
@ -16,61 +14,54 @@ env:
CARGO_TERM_COLOR: always
CI: true
RUST_VERSION: "1.93.1"
GO_VERSION: "1.26.2"
GO_VERSION: "1.25.7"
jobs:
#### Proxy jobs ####
proxy-test:
test:
strategy:
matrix:
include:
- os: blacksmith-4vcpu-ubuntu-2404
name: "Proxy Test"
- os: windows-2025
name: "Proxy Test (Windows)"
- os: macos-15
name: "Proxy Test (Mac)"
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
name: ${{ matrix.name }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # master
uses: dtolnay/rust-toolchain@master
with:
toolchain: "${{ env.RUST_VERSION }}"
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
- uses: Swatinem/rust-cache@v2
# Github cache is too tiny to handle the full matrix :-(
if: ${{ startsWith(matrix.os, 'blacksmith-') }}
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
# Github cache will restore from 'main' OR the current branch.
# If we cache PR branches, we may evict the 'main' cache and end up with no cache hits at all.
# Ideally, we would have main be 'high priority' and not be evicted but I don't think thats possible.
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Start validation dependencies
if: ${{ startsWith(matrix.os, 'blacksmith-') }}
run: tools/manage-validation-deps.sh start
- name: Test
run: make test
env:
KEYCLOAK_AVAILABLE: ${{ startsWith(matrix.os, 'blacksmith-') && '1' || '' }}
- name: Stop validation dependencies
if: ${{ always() && startsWith(matrix.os, 'blacksmith-') }}
run: tools/manage-validation-deps.sh stop
- name: Validate
if: ${{ matrix.os == 'ubuntu-latest' }}
run: make validate
proxy-lint:
runs-on: blacksmith-4vcpu-ubuntu-2404
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: 23
- name: Install Rust
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # master
uses: dtolnay/rust-toolchain@master
with:
toolchain: "${{ env.RUST_VERSION }}"
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
- uses: Swatinem/rust-cache@v2
with:
# Github cache will restore from 'main' OR the current branch.
# If we cache PR branches, we may evict the 'main' cache and end up with no cache hits at all.
# Ideally, we would have main be 'high priority' and not be evicted but I don't think thats possible.
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Add Go bin to PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- name: Generation
run: make generate-schema check-clean-repo
- name: Lint
@ -78,15 +69,15 @@ jobs:
#### UI jobs ####
ui-lint:
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
defaults:
run:
working-directory: ui
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: 24
node-version: 23
- name: Lint
run: |
npm ci
@ -94,10 +85,10 @@ jobs:
#### Controller jobs ####
controller-test:
runs-on: blacksmith-4vcpu-ubuntu-2404
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: "${{ env.GO_VERSION }}"
cache-dependency-path: |
@ -107,10 +98,10 @@ jobs:
run: go test -race ./...
controller-lint:
runs-on: blacksmith-4vcpu-ubuntu-2404
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: "${{ env.GO_VERSION }}"
cache-dependency-path: |
@ -118,35 +109,25 @@ jobs:
.github/workflows/cache-test
- name: Lint
run: make -C controller analyze
- name: go mod tidy
run: |
go mod tidy
git diff --exit-code go.mod go.sum
- name: Gen
# TODO: the rest of codegen
run: make generate-apis check-clean-repo
controller-e2e:
runs-on: blacksmith-4vcpu-ubuntu-2404
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Check Runner Info
run: |
cat /sys/fs/cgroup/cpu.stat || true
cat /proc/pressure/cpu || true
lscpu || true
openssl speed -seconds 1 -bytes 256 sha256 || rtue
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # master
uses: dtolnay/rust-toolchain@master
with:
toolchain: "${{ env.RUST_VERSION }}"
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
- uses: Swatinem/rust-cache@v2
with:
# Github cache will restore from 'main' OR the current branch.
# If we cache PR branches, we may evict the 'main' cache and end up with no cache hits at all.
# Ideally, we would have main be 'high priority' and not be evicted but I don't think thats possible.
save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6
- uses: actions/setup-go@v6
with:
go-version: "${{ env.GO_VERSION }}"
cache-dependency-path: |
@ -162,13 +143,13 @@ jobs:
CGO_ENABLED=0 PERSIST_INSTALL=true go test -tags=e2e -v ./controller/test/e2e/tests -run '^TestAgentgatewayIntegration'
- name: Archive bug report directory on failure
if: ${{ failure() }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
uses: actions/upload-artifact@v4
with:
name: bug-report
path: ./controller/_test/bug_report/kind
retention-days: 2
- name: Upload cargo timings
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
uses: actions/upload-artifact@v4
with:
name: cargo-timings-e2e
path: target/cargo-timings/cargo-timing*.html
@ -179,19 +160,19 @@ jobs:
cat controller/_test/ci-step-timings.log >> $GITHUB_STEP_SUMMARY
controller-conformance:
runs-on: blacksmith-4vcpu-ubuntu-2404
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # master
uses: dtolnay/rust-toolchain@master
with:
toolchain: "${{ env.RUST_VERSION }}"
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
- uses: Swatinem/rust-cache@v2
with:
# We only read the cache from 'E2E' job, since they should have identical cache.
save-if: "false"
shared-key: "controller-e2e" # Pull E2E job's cache
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6
- uses: actions/setup-go@v6
with:
go-version: "${{ env.GO_VERSION }}"
cache-dependency-path: |
@ -205,14 +186,8 @@ jobs:
- name: Conformance
run: |
make -C controller all-conformance
- name: Debug Info
if: ${{ failure() }}
run: |
kubectl describe deployment -n agentgateway-system
kubectl get pods -n agentgateway-system
kubectl logs -n agentgateway-system -l app.kubernetes.io/name=agentgateway
- name: Upload cargo timings
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
uses: actions/upload-artifact@v4
with:
name: cargo-timings-conformance
path: target/cargo-timings/cargo-timing*.html
@ -222,12 +197,12 @@ jobs:
cat-yamls () {
local files=("$@")
local count=$#
for ((i=0; i<count-1; i++)); do
cat "${files[i]}"
echo -e "\n---"
done
if [ $count -gt 0 ]; then
cat "${files[count-1]}"
fi

View File

@ -13,53 +13,23 @@ on:
required: false
default: false
type: boolean
extra_helm_tag:
description: 'Additional Helm chart version to push (e.g. 0.0.0-latest-dev)'
required: false
default: ''
type: string
workflow_call:
inputs:
version:
description: 'Version number (without v prefix)'
required: true
type: string
extra_tag:
description: 'Additional Docker image tag to push (e.g. latest-dev)'
required: false
default: ''
type: string
extra_helm_tag:
description: 'Additional Helm chart version to push (e.g. 0.0.0-latest-dev)'
required: false
default: ''
type: string
env:
CARGO_TERM_COLOR: always
CI: true
RUST_VERSION: "1.93.1"
GO_VERSION: "1.26.2"
REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/agentgateway
CONTROLLER_REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/controller
# Note: /charts is added to this
CHART_REGISTRY_IMAGE_BASE: ghcr.io/${{ github.repository_owner }}
REGISTRY_IMAGE: ghcr.io/${{ github.repository }}
CONTROLLER_REGISTRY_IMAGE: ghcr.io/${{ github.repository }}-controller
jobs:
setup:
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
# Help debug what exact was input for this since Github doesn't expose it.
- name: Output Inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- name: Set canonical VERSION
id: version
run: |
# Determine version source
if [ -n "${{ inputs.version }}" ]; then
VERSION="${{ inputs.version }}"
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION="${{ github.ref_name }}"
fi
@ -80,9 +50,9 @@ jobs:
matrix:
include:
- platform: linux/amd64
os: blacksmith-4vcpu-ubuntu-2404
os: ubuntu-latest
- platform: linux/arm64
os: blacksmith-4vcpu-ubuntu-2404-arm
os: ubuntu-22.04-arm
env:
VERSION: ${{ needs.setup.outputs.version }}
steps:
@ -93,23 +63,23 @@ jobs:
- name: Docker meta
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Login to GitHub Container Registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
uses: docker/setup-buildx-action@v3
- name: Build and push by digest
id: build
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
uses: docker/build-push-action@v6
with:
build-args: |
VERSION=${{ env.VERSION }}
@ -128,7 +98,7 @@ jobs:
touch "${{ runner.temp }}/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
@ -136,7 +106,7 @@ jobs:
retention-days: 1
push-image:
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
@ -148,33 +118,32 @@ jobs:
VERSION: ${{ needs.setup.outputs.version }}
steps:
- name: Install cosign
uses: sigstore/cosign-installer@398d4b0eeef1380460a10c8013a76f728fb906ac # v3
uses: sigstore/cosign-installer@v3.9.2
- name: Download digests
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-linux-*
merge-multiple: true
- name: Login to GitHub Container Registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=raw,value=v${{ env.VERSION }}
type=raw,value=${{ inputs.extra_tag }},enable=${{ inputs.extra_tag != '' }}
type=semver,pattern={{version}},value=${{ env.VERSION }}
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
@ -183,15 +152,11 @@ jobs:
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Sign the container image
run: cosign sign --yes ${{ env.REGISTRY_IMAGE }}:v${{ env.VERSION }}
- name: Sign the extra tag
if: ${{ inputs.extra_tag != '' }}
run: cosign sign --yes ${{ env.REGISTRY_IMAGE }}:${{ inputs.extra_tag }}
run: cosign sign --yes ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:v${{ env.VERSION }}
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
musl-build-image:
runs-on: ${{ matrix.os }}
@ -205,9 +170,9 @@ jobs:
matrix:
include:
- platform: linux/amd64
os: blacksmith-4vcpu-ubuntu-2404
os: ubuntu-latest
- platform: linux/arm64
os: blacksmith-4vcpu-ubuntu-2404-arm
os: ubuntu-22.04-arm
env:
VERSION: ${{ needs.setup.outputs.version }}
steps:
@ -218,24 +183,24 @@ jobs:
- name: Docker meta
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}-musl
- name: Login to GitHub Container Registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
uses: docker/setup-buildx-action@v3
- name: Build and push by digest
id: build
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
@ -255,7 +220,7 @@ jobs:
touch "${{ runner.temp }}/digests-musl/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
uses: actions/upload-artifact@v4
with:
name: digests-musl-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests-musl/*
@ -263,7 +228,7 @@ jobs:
retention-days: 1
musl-push-image:
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
@ -275,33 +240,32 @@ jobs:
VERSION: ${{ needs.setup.outputs.version }}
steps:
- name: Install cosign
uses: sigstore/cosign-installer@398d4b0eeef1380460a10c8013a76f728fb906ac # v3
uses: sigstore/cosign-installer@v3.9.2
- name: Download digests
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests-musl
pattern: digests-musl*
merge-multiple: true
- name: Login to GitHub Container Registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=raw,value=v${{ env.VERSION }}
type=raw,value=${{ inputs.extra_tag }},enable=${{ inputs.extra_tag != '' }}
type=semver,pattern={{version}},value=${{ env.VERSION }}
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests-musl
@ -310,15 +274,11 @@ jobs:
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Sign the container image
run: cosign sign --yes ${{ env.REGISTRY_IMAGE }}:v${{ env.VERSION }}-musl
- name: Sign the extra tag
if: ${{ inputs.extra_tag != '' }}
run: cosign sign --yes ${{ env.REGISTRY_IMAGE }}:${{ inputs.extra_tag }}-musl
run: cosign sign --yes ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}-musl
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:v${{ env.VERSION }}-musl
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}-musl
build-controller-image:
runs-on: ${{ matrix.os }}
@ -332,10 +292,10 @@ jobs:
matrix:
include:
- platform: linux/amd64
os: ubuntu-24.04
os: ubuntu-latest
goarch: amd64
- platform: linux/arm64
os: blacksmith-4vcpu-ubuntu-2404-arm
os: ubuntu-22.04-arm
goarch: arm64
defaults:
run:
@ -349,19 +309,19 @@ jobs:
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
working-directory: .
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6
uses: actions/setup-go@v5
with:
go-version: "${{ env.GO_VERSION }}"
go-version: '1.25.7'
cache-dependency-path: |
**/*.sum
@ -377,16 +337,16 @@ jobs:
- name: Docker meta
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5
uses: docker/metadata-action@v5
with:
images: ${{ env.CONTROLLER_REGISTRY_IMAGE }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
uses: docker/setup-buildx-action@v3
- name: Build and push by digest
id: build
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
uses: docker/build-push-action@v6
with:
context: controller/_output/pkg/agentgateway
file: controller/_output/pkg/agentgateway/Dockerfile.agentgateway
@ -406,7 +366,7 @@ jobs:
touch "${{ runner.temp }}/controller-digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
uses: actions/upload-artifact@v4
with:
name: controller-digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/controller-digests/*
@ -414,7 +374,7 @@ jobs:
retention-days: 1
push-controller-image:
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
@ -426,10 +386,10 @@ jobs:
VERSION: ${{ needs.setup.outputs.version }}
steps:
- name: Install cosign
uses: sigstore/cosign-installer@398d4b0eeef1380460a10c8013a76f728fb906ac # v3
uses: sigstore/cosign-installer@v3.9.2
- name: Download digests
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/controller-digests
pattern: controller-digests-*
@ -443,23 +403,22 @@ jobs:
find . -type f
- name: Login to GitHub Container Registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5
uses: docker/metadata-action@v5
with:
images: ${{ env.CONTROLLER_REGISTRY_IMAGE }}
tags: |
type=raw,value=v${{ env.VERSION }}
type=raw,value=${{ inputs.extra_tag }},enable=${{ inputs.extra_tag != '' }}
type=semver,pattern={{version}},value=${{ env.VERSION }}
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/controller-digests
@ -468,79 +427,48 @@ jobs:
$(find . -type f -exec sh -c 'printf "${{ env.CONTROLLER_REGISTRY_IMAGE }}@sha256:%s " "$(basename "$1")"' _ {} \;)
- name: Sign the container image
run: cosign sign --yes ${{ env.CONTROLLER_REGISTRY_IMAGE }}:v${{ env.VERSION }}
- name: Sign the extra tag
if: ${{ inputs.extra_tag != '' }}
run: cosign sign --yes ${{ env.CONTROLLER_REGISTRY_IMAGE }}:${{ inputs.extra_tag }}
run: cosign sign --yes ${{ env.CONTROLLER_REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.CONTROLLER_REGISTRY_IMAGE }}:v${{ env.VERSION }}
push-helm-charts:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
needs:
- setup
- push-controller-image
env:
VERSION: ${{ needs.setup.outputs.version }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Helm login to ${{ env.CHART_REGISTRY_IMAGE_BASE }}
run: echo "${{ secrets.GITHUB_TOKEN }}" | ./tools/helm registry login ghcr.io -u ${{ github.repository_owner }} --password-stdin
- name: Push helm charts
run: make -C controller release-charts
env:
IMAGE_REGISTRY: ${{ env.CHART_REGISTRY_IMAGE_BASE }}
EXTRA_HELM_TAG: ${{ inputs.extra_helm_tag }}
docker buildx imagetools inspect ${{ env.CONTROLLER_REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
build:
if: ${{ github.event_name != 'workflow_call' && (github.event_name == 'push' || ! github.event.inputs.skip_gh_release) }}
if: ${{ github.event_name == 'push' || ! github.event.inputs.skip_gh_release }}
needs:
- setup
runs-on: ${{ matrix.os }}
permissions:
contents: read
env:
VERSION: ${{ needs.setup.outputs.version }}
strategy:
matrix:
include:
- os: blacksmith-4vcpu-ubuntu-2404
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
# Performance is horrendous on musl without jemalloc
features: jemalloc
name: linux
- os: blacksmith-4vcpu-ubuntu-2404-arm
- os: ubuntu-22.04-arm
target: aarch64-unknown-linux-musl
# TODO: arm64 build fails with jemalloc for some reason? https://github.com/tikv/jemallocator/issues/146
# TODO: arm64 build fails with jemalloc for some reason?
features: default
name: linux-arm
- os: macos-26
- os: macos-latest
target: aarch64-apple-darwin
features: default
name: mac
- os: windows-2025
- os: macos-15-intel
target: x86_64-apple-darwin
features: default
- os: windows-latest
target: x86_64-pc-windows-msvc
features: default
name: windows
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
node-version: 23
- name: Install Rust
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # master
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "${{ env.RUST_VERSION }}"
targets: ${{ matrix.target }}
# TODO: build this in a separate job and just copy it over
- name: Build UI
@ -548,8 +476,8 @@ jobs:
cd ui
npm install
npm run build
- name: Prepare Linux target
if: ${{ matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'aarch64-unknown-linux-musl' }}
- name: Install musl-tools
if: ${{ matrix.os == 'ubuntu-22.04-arm' || matrix.os == 'ubuntu-latest' }}
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
@ -562,30 +490,26 @@ jobs:
run: |
git status
- name: Upload Artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
uses: actions/upload-artifact@v4
with:
name: release-binary-${{ matrix.name }}
name: release-binary-${{ matrix.os }}
path: |
target/${{ matrix.target }}/release/agentgateway
target/${{ matrix.target }}/release/agentgateway.exe
release:
if: ${{ github.event_name != 'workflow_call' && (github.event_name == 'push' || ! github.event.inputs.skip_gh_release) }}
if: ${{ github.event_name == 'push' || ! github.event.inputs.skip_gh_release }}
needs:
- setup
- push-image
- musl-push-image
- push-controller-image
- push-helm-charts
- build
runs-on: blacksmith-4vcpu-ubuntu-2404
runs-on: ubuntu-latest
permissions:
contents: write
env:
VERSION: ${{ needs.setup.outputs.version }}
steps:
- name: Download Artifacts
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
uses: actions/download-artifact@v4
with:
pattern: release-binary-*
@ -593,38 +517,22 @@ jobs:
run: |
ls -R
mkdir outputs
mv release-binary-mac/agentgateway outputs/agentgateway-darwin-arm64
mv release-binary-macos-latest/agentgateway outputs/agentgateway-darwin-arm64
sha256sum outputs/agentgateway-darwin-arm64 > outputs/agentgateway-darwin-arm64.sha256
mv release-binary-linux/agentgateway outputs/agentgateway-linux-amd64
mv release-binary-macos-15-intel/agentgateway outputs/agentgateway-darwin-amd64
sha256sum outputs/agentgateway-darwin-amd64 > outputs/agentgateway-darwin-amd64.sha256
mv release-binary-ubuntu-latest/agentgateway outputs/agentgateway-linux-amd64
sha256sum outputs/agentgateway-linux-amd64 > outputs/agentgateway-linux-amd64.sha256
mv release-binary-linux-arm/agentgateway outputs/agentgateway-linux-arm64
mv release-binary-ubuntu-22.04-arm/agentgateway outputs/agentgateway-linux-arm64
sha256sum outputs/agentgateway-linux-arm64 > outputs/agentgateway-linux-arm64.sha256
mv release-binary-windows/agentgateway.exe outputs/agentgateway-windows-amd64.exe
mv release-binary-windows-latest/agentgateway.exe outputs/agentgateway-windows-amd64.exe
sha256sum outputs/agentgateway-windows-amd64.exe > outputs/agentgateway-windows-amd64.exe.sha256
- name: Create GitHub Release
uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # v2
uses: softprops/action-gh-release@v2
with:
files: outputs/agentgateway-*
tag_name: ${{ github.ref_name }}
generate_release_notes: true
body: |
🎉 Welcome to the ${{ env.VERSION }} release of the agentgateway project!
## Artifacts
**Docker images** are available:
* `cr.agentgateway.dev/agentgateway:v${{ env.VERSION }}`
* `cr.agentgateway.dev/controller:v${{ env.VERSION }}`
**Helm charts** are available:
* `cr.agentgateway.dev/charts/agentgateway:v${{ env.VERSION }}`
* `cr.agentgateway.dev/charts/agentgateway-crds:v${{ env.VERSION }}`
**Binaries** are available below.
## Quick Start
Follow the [Kubernetes](https://agentgateway.dev/docs/kubernetes/latest/quickstart/) or [Standalone](https://agentgateway.dev/docs/standalone/latest/quickstart/) quick start guide to get started!
body: "Automated release of ${{ github.ref_name }}."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(github.ref, 'refs/tags/')

2
.gitignore vendored
View File

@ -1,8 +1,6 @@
.cursor
/target
.vscode
.idea
.run
.DS_Store
.venv
*.local

222
.goreleaser.yaml Normal file
View File

@ -0,0 +1,222 @@
version: 2
before:
hooks:
- go mod tidy
- go mod download
builds:
- id: controller
main: ./cmd/agentgateway
binary: agentgateway-linux-{{ .Arch }}
gcflags: "{{ .Env.GCFLAGS }}"
ldflags: "{{ .Env.LDFLAGS }}"
env:
- CGO_ENABLED=0
- GO111MODULE=on
- GOARCH={{ .Arch }}
- GOOS={{ .Os }}
mod_timestamp: "{{ .CommitTimestamp }}"
goos:
- linux
goarch:
- amd64
- arm64
- id: sds
main: ./cmd/sds
binary: sds-linux-{{ .Arch }}
gcflags: "{{ .Env.GCFLAGS }}"
ldflags: "{{ .Env.LDFLAGS }}"
env:
- CGO_ENABLED=0
- GO111MODULE=on
- GOARCH={{ .Arch }}
- GOOS={{ .Os }}
goos:
- linux
goarch:
- amd64
- arm64
- id: envoyinit
main: ./cmd/envoyinit
binary: envoyinit-linux-{{ .Arch }}
gcflags: "{{ .Env.GCFLAGS }}"
ldflags: "{{ .Env.LDFLAGS }}"
env:
- CGO_ENABLED=0
- GO111MODULE=on
- GOARCH={{ .Arch }}
- GOOS={{ .Os }}
goos:
- linux
goarch:
- amd64
- arm64
dockers:
- image_templates:
- &controller_arm_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.CONTROLLER_IMAGE_REPO }}:{{ .Env.VERSION }}-arm64"
use: buildx
dockerfile: &controller_dockerfile cmd/agentgateway/Dockerfile
goos: linux
goarch: arm64
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--build-arg=GOARCH=arm64"
- "--build-arg=ENVOY_IMAGE={{ .Env.ENVOY_IMAGE_ARM64 }}"
- image_templates:
- &controller_amd_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.CONTROLLER_IMAGE_REPO }}:{{ .Env.VERSION }}-amd64"
use: buildx
dockerfile: *controller_dockerfile
goos: linux
goarch: amd64
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- "--build-arg=GOARCH=amd64"
- "--build-arg=ENVOY_IMAGE={{ .Env.ENVOY_IMAGE_AMD64 }}"
- image_templates:
- &agentgateway_arm_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.AGENTGATEWAY_IMAGE_REPO }}:{{ .Env.VERSION }}-arm64"
use: buildx
dockerfile: &agentgateway_dockerfile cmd/agentgateway/Dockerfile.agentgateway
goos: linux
goarch: arm64
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--build-arg=GOARCH=arm64"
- image_templates:
- &agentgateway_amd_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.AGENTGATEWAY_IMAGE_REPO }}:{{ .Env.VERSION }}-amd64"
use: buildx
dockerfile: *agentgateway_dockerfile
goos: linux
goarch: amd64
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- "--build-arg=GOARCH=amd64"
- image_templates:
- &sds_arm_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.SDS_IMAGE_REPO }}:{{ .Env.VERSION }}-arm64"
use: buildx
dockerfile: &sds_dockerfile cmd/sds/Dockerfile
goos: linux
goarch: arm64
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--build-arg=GOARCH=arm64"
- "--build-arg=BASE_IMAGE={{ .Env.ALPINE_BASE_IMAGE }}"
- image_templates:
- &sds_amd_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.SDS_IMAGE_REPO }}:{{ .Env.VERSION }}-amd64"
use: buildx
dockerfile: *sds_dockerfile
goos: linux
goarch: amd64
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- "--build-arg=GOARCH=amd64"
- "--build-arg=BASE_IMAGE={{ .Env.ALPINE_BASE_IMAGE }}"
- image_templates:
- &envoyinit_arm_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.ENVOYINIT_IMAGE_REPO }}:{{ .Env.VERSION }}-arm64"
use: buildx
dockerfile: &envoyinit_dockerfile cmd/envoyinit/Dockerfile
goos: linux
goarch: arm64
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--build-arg=GOARCH=arm64"
- "--build-arg=ENTRYPOINT_SCRIPT=/cmd/envoyinit/docker-entrypoint.sh"
- "--build-arg=ENVOY_IMAGE={{ .Env.ENVOY_IMAGE_ARM64 }}"
- "--build-arg=RUST_BUILD_ARCH=aarch64"
- "--build-arg=RUSTFORMATIONS_DIR=/internal/envoyinit"
- "--cache-from=type=registry,ref={{ .Env.IMAGE_REGISTRY }}/envoy-wrapper-cache:arm64"
- "--cache-to=type=registry,ref={{ .Env.IMAGE_REGISTRY }}/envoy-wrapper-cache:arm64,mode=max,ignore-error=true"
extra_files:
- cmd/envoyinit/docker-entrypoint.sh
- internal/envoyinit
- image_templates:
- &envoyinit_amd_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.ENVOYINIT_IMAGE_REPO }}:{{ .Env.VERSION }}-amd64"
use: buildx
dockerfile: *envoyinit_dockerfile
goos: linux
goarch: amd64
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- "--build-arg=GOARCH=amd64"
- "--build-arg=ENTRYPOINT_SCRIPT=/cmd/envoyinit/docker-entrypoint.sh"
- "--build-arg=ENVOY_IMAGE={{ .Env.ENVOY_IMAGE_AMD64 }}"
- "--build-arg=RUSTFORMATIONS_DIR=/internal/envoyinit"
- "--cache-from=type=registry,ref={{ .Env.IMAGE_REGISTRY }}/envoy-wrapper-cache:amd64"
- "--cache-to=type=registry,ref={{ .Env.IMAGE_REGISTRY }}/envoy-wrapper-cache:amd64,mode=max,ignore-error=true"
extra_files:
- cmd/envoyinit/docker-entrypoint.sh
- internal/envoyinit
docker_manifests:
- name_template: "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.CONTROLLER_IMAGE_REPO }}:{{ .Env.VERSION }}"
image_templates:
- *controller_arm_image
- *controller_amd_image
- name_template: "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.AGENTGATEWAY_IMAGE_REPO }}:{{ .Env.VERSION }}"
image_templates:
- *agentgateway_arm_image
- *agentgateway_amd_image
- name_template: "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.SDS_IMAGE_REPO }}:{{ .Env.VERSION }}"
image_templates:
- *sds_arm_image
- *sds_amd_image
- name_template: "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.ENVOYINIT_IMAGE_REPO }}:{{ .Env.VERSION }}"
image_templates:
- *envoyinit_arm_image
- *envoyinit_amd_image
changelog:
# Disable auto-generated changelog from git commits.
# For real releases, we use --release-notes flag with our custom script output.
# For main branch builds, we skip changelog entirely (same as release).
disable: '{{ if isEnvSet "GORELEASER_DISABLE_RELEASE" }}{{ .Env.GORELEASER_DISABLE_RELEASE }}{{ else }}false{{ end }}'
release:
disable: '{{ if isEnvSet "GORELEASER_DISABLE_RELEASE" }}{{ .Env.GORELEASER_DISABLE_RELEASE }}{{ else }}false{{ end }}'
prerelease: "auto"
mode: "replace"
replace_existing_artifacts: true
target_commitish: "{{ .FullCommit }}"
header: |
{{ if eq .Env.VERSION "v2.3.0-main" }}
🚀 Rolling main build of kgateway!
---
It includes the latest changes but may be unstable. Use it for testing and providing feedback.
{{ else }}
🎉 Welcome to the {{ .Env.VERSION }} release of the kgateway project!
---
{{ end }}
footer: |
## Installation
The kgateway project is available as a Helm chart and docker images.
### Helm Charts
The Helm charts are available at:
* [{{ .Env.VANITY_REGISTRY }}/charts/kgateway]({{ .Env.VANITY_REGISTRY }}/charts/kgateway).
* [{{ .Env.AGW_VANITY_REGISTRY }}/charts/agentgateway]({{ .Env.AGW_VANITY_REGISTRY }}/charts/agentgateway).
### Docker Images
The docker images are available at:
- {{ .Env.VANITY_REGISTRY }}/{{ .Env.CONTROLLER_IMAGE_REPO }}:{{ .Env.VERSION }}
- {{ .Env.VANITY_REGISTRY }}/{{ .Env.SDS_IMAGE_REPO }}:{{ .Env.VERSION }}
- {{ .Env.VANITY_REGISTRY }}/{{ .Env.ENVOYINIT_IMAGE_REPO }}:{{ .Env.VERSION }}
- {{ .Env.AGW_VANITY_REGISTRY }}/{{ .Env.AGENTGATEWAY_IMAGE_REPO }}:{{ .Env.VERSION }}
## Quickstart
Try installing this release:
```
helm install kgateway-crds oci://{{ .Env.VANITY_REGISTRY }}/charts/kgateway-crds --version {{ .Env.VERSION }} --namespace kgateway-system --create-namespace
helm install kgateway oci://{{ .Env.VANITY_REGISTRY }}/charts/kgateway --version {{ .Env.VERSION }} --namespace kgateway-system --create-namespace
helm install agentgateway-crds oci://{{ .Env.AGW_VANITY_REGISTRY }}/charts/agentgateway-crds --version {{ .Env.VERSION }} --namespace agentgateway-system --create-namespace
helm install agentgateway oci://{{ .Env.AGW_VANITY_REGISTRY }}/charts/agentgateway --version {{ .Env.VERSION }} --namespace agentgateway-system --create-namespace
```
For detailed installation instructions and next steps, please visit our [quickstart guide](https://kgateway.dev/docs/quickstart/).

View File

@ -104,7 +104,7 @@ Only project maintainers can create releases. The process is:
### Community
- Join our [Discord server](https://discord.gg/y9efgEmppm) for discussions
- Participate in our [agentgateway community calls](https://calendar.google.com/calendar/u/0?cid=Y18zZTAzNGE0OTFiMGUyYzU2OWI1Y2ZlOWNmOWM4NjYyZTljNTNjYzVlOTdmMjdkY2I5ZTZmNmM5ZDZhYzRkM2ZmQGdyb3VwLmNhbGVuZGFyLmdvb2dsZS5jb20)
- Participate in [our All Things AI Agents community calls](https://github.com/kagent-dev/community?tab=readme-ov-file#community-meetings)
- Help answer questions in GitHub issues
- Review pull requests from other contributors
@ -114,4 +114,4 @@ By contributing to this project, you agree that your contributions will be licen
## Questions?
If you have any questions about contributing, please open an issue or reach out to the maintainers.
If you have any questions about contributing, please open an issue or reach out to the maintainers.

1567
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@ wiremock = { git = "https://github.com/howardjohn/wiremock-rs", rev = "e55f5b960
[workspace]
resolver = "2"
members = [
"crates/a2a-sdk",
"crates/agentgateway",
"crates/agentgateway-app",
"crates/cel-fork/cel",
@ -13,11 +14,11 @@ members = [
"crates/celx",
"crates/core",
"crates/hbone",
"crates/protos",
"crates/xds",
"crates/xtask",
]
default-members = [
"crates/a2a-sdk",
"crates/agentgateway",
"crates/agentgateway-app",
"crates/cel-fork/cel",
@ -25,18 +26,18 @@ default-members = [
"crates/celx",
"crates/core",
"crates/hbone",
"crates/protos",
"crates/xds",
]
[workspace.package]
version = "0.0.0" # We do not use this version
version = "0.7.0"
edition = "2024"
rust-version = "1.90"
license = "Apache-2.0"
publish = false
[workspace.dependencies]
a2a-sdk = { version = "0.7.0", path = "crates/a2a-sdk" }
agent-core = { path = "crates/core" }
agent-celx = { path = "crates/celx" }
agent-hbone = { path = "crates/hbone" }
@ -44,52 +45,45 @@ agent-xds = { path = "crates/xds" }
agentgateway = { path = "crates/agentgateway" }
cel = { path = "crates/cel-fork/cel" }
cel-derive = { path = "crates/cel-fork/cel-derive" }
protos = { path = "crates/protos" }
atomic_float = { version = "1.1.0", features = ["serde"] }
anyhow = "1.0"
arc-swap = "1.9"
arc-swap = "1.7.1"
arcstr = { version = "1.2", features = ["serde"] }
assert_matches = "1.5.0"
async-openai = { version = "0.34", default-features = false, features = ["chat-completion-types", "moderation-types", "response-types", "realtime-types"] }
async-openai = { version = "0.32.2", default-features = false, features = ["chat-completion-types", "embedding-types", "moderation-types", "response-types", "realtime-types"] }
async-stream = "0.3"
async-trait = "0.1"
aws-config = { version = "1.8", default-features = false, features = ["default-https-client", "rt-tokio"] }
aws-config = "1.8"
aws-credential-types = "1.2"
aws-sigv4 = "1.3"
aws-smithy-eventstream = "0.60"
aws-smithy-types = "1.3"
aws-lc-rs = "1.16"
aws-lc-rs = "1.15"
axum = { version = "0.8", features = ["macros"] }
axum-core = "0.5"
axum-extra = { version = "0.12", features = ["json-lines", "typed-header"] }
# Disable default features to avoid pulling in native-tls and requiring openssl
# TODO: allow default features if we ever add an openssl feature
azure_identity = { version = "0.33", default-features = false }
azure_core = { version = "0.33", default-features = false }
typespec_client_core = { default-features = false, version = "0.12" }
azure_identity = { version = "0.31", default-features = false }
azure_core = { version = "0.31", default-features = false }
typespec_client_core = { default-features = false, version = "0.10" }
base64 = "0.22"
cookie = { version = "0.18", default-features = false }
bcrypt = "0.19"
bytes = { version = "1.11", features = ["serde"] }
bcrypt = "0.18"
bytes = { version = "1.10", features = ["serde"] }
chrono = { version = "0.4", features = ["serde"] }
clap = { version = "4.6", features = ["derive"] }
clocksource = "1.0"
clap = { version = "4.5", features = ["derive"] }
clocksource = "0.8"
crossbeam = "0.8"
divan = "0.1"
durationfmt = "0.1"
go-parse-duration = "0.1"
flurry = "0.5.2"
fs-err = { version = "3.3", features = ["tokio"] }
fs-err = { version = "3.1", features = ["tokio"] }
futures = "0.3"
futures-channel = "0.3"
futures-core = "0.3"
futures-util = "0.3"
google-cloud-auth = { version = "1.8", default-features = false, features = [
"idtoken",
# They use AWS-LC which is what we want so its fine. If they changed we would need to switch
# To installing a global default which is annoying so prefer to do it this way.
"default-rustls-provider",
] }
google-cloud-auth = { git = "https://github.com/googleapis/google-cloud-rust", rev = "18f8434cb598ae9f9835b7d77b2a8774fec1d2ea", default-features = false, features = ["idtoken"] }
hashbrown = "0.16"
h2 = "0.4"
headers = "0.4"
@ -97,37 +91,37 @@ hex = "0.4"
hickory-resolver = { version = "0.25", features = ["serde"] }
htpasswd-verify-fork = { path = "crates/htpasswd-verify-fork" }
httpdate = "1.0"
http = "1.4"
http = "1.3"
http-body = "1"
http-body-util = "0.1.3"
hyper = { version = "1.8", features = ["full"] }
hyper = { version = "1.6", features = ["full"] }
hyper-rustls = "0.27"
hyper-util = { version = "0.1", features = ["full"] }
hyper-util-fork = { path = "crates/hyper-util-fork" }
hyper-util-fork = { path = "crates/hyper-util-fork", features = ["full"] }
include_dir = "0.7"
indexmap = { version = "2.13", features = ["serde"] }
insta = { version = "1.47", features = ["json", "redactions", "filters", "yaml"] }
ipnet = { version = "2.12", features = ["serde"] }
indexmap = { version = "2.9", features = ["serde"] }
insta = { version = "1.38", features = ["json", "redactions", "filters"] }
ipnet = { version = "2.11", features = ["serde"] }
itertools = "0.14"
jsonwebtoken = { version = "10.3", features = ["aws_lc_rs"] }
lazy_static = "1.5"
lazy_static = "1.4"
libc = "0.2"
notify = "8.2"
notify = "8.0"
notify-debouncer-full = "0.7"
md-5 = "0.11"
md-5 = "0.10"
num_cpus = "1.17"
once_cell = "1.21"
openapiv3 = "2.2"
opentelemetry = "0.31"
opentelemetry-http = "0.31"
opentelemetry-otlp = { version = "0.31", default-features = false, features = ["http-proto", "internal-logs", "trace", "grpc-tonic", "logs"] }
opentelemetry-proto = { version = "0.31", features = ["gen-tonic", "logs"] }
opentelemetry_sdk = { version = "0.31", features = ["rt-tokio", "logs"] }
opentelemetry-otlp = { version = "0.31", features = ["grpc-tonic"] }
opentelemetry-proto = { version = "0.31", features = ["gen-tonic"] }
opentelemetry_sdk = { version = "0.31", features = ["rt-tokio"] }
parking_lot = "0.12"
percent-encoding = "2.3"
phonenumber = "0.3"
pin-project-lite = "0.2"
pingora-pool = "0.8"
pingora-pool = "0.7"
ppp = "2.3"
pprof = { version = "0.15", features = [
"protobuf",
@ -139,22 +133,24 @@ prometheus-client = "0.24"
prost = "0.14"
prost-build = "0.14"
prost-types = "0.14"
prost-wkt-types = { version = "0.7", features = ["vendored-protox"] }
prost-wkt-build = "0.7"
prost-wkt-types = { version = "0.7.0", features = ["vendored-protox"] }
prost-wkt-build = "0.7.0"
pwhash = "1"
rand = "0.10"
rcgen = { version = "0.14", default-features = false, features = ["pem", "x509-parser", "aws_lc_rs"] }
regex = "1.12"
reqwest = { version = "0.13", default-features = false, features = [
rcgen = { version = "0.14", features = ["pem", "x509-parser"] }
regex = "1.11"
reqwest = { version = "0.12", default-features = false, features = [
"http2",
"charset",
"rustls",
"macos-system-configuration",
"rustls-tls",
] }
rstest = "0.26"
rustc_version = "0.4"
rustls = { version = "0.23", default-features = false, features = ["tls12", "aws_lc_rs"] }
rustls = { version = "0.23", features = ["tls12", "ring"] }
rustls-native-certs = "0.8"
rustls-pki-types = "1.14"
rustls-pemfile = "2.2"
rustls-pki-types = "1.12"
schemars = { version = "=1.0.4", git = "https://github.com/howardjohn/schemars", rev = "4364354fa41897a0c2001d891c0a9a38eafedb82", features = [
#schemars = { version = "1.0", features = [
"bytes1",
@ -170,18 +166,17 @@ serde-untagged = "0.1"
serde_json_path_to_error = "0.1"
serde_regex = "1.1"
serde_yaml = "0.9"
sha1 = "0.11"
sha2 = "0.11"
sha1 = "0.10"
shellexpand = "3.1"
socket2 = "0.6"
split-iter = "0.1"
sse-stream = "0.2"
stacker = "0.1"
tempfile = "3.27"
tempfile = "3.20"
thiserror = "2.0"
tiktoken-rs = "0.9"
tokio = { version = "1.50", features = ["full", "macros", "sync"] }
tokio-rustls = { version = "0.26", default-features = false, features = ["aws_lc_rs"] }
tokio = { version = "1.48", features = ["full", "macros", "sync"] }
tokio-rustls = { version = "0.26", default-features = false }
tokio-stream = { version = "0.1", features = ["net", "sync"] }
tokio-test = "0.4"
tokio-util = { version = "0.7", features = ["codec", "io"] }
@ -204,7 +199,7 @@ tracing-subscriber = { version = "0.3", features = [
"json",
] }
url = "2.5"
uuid = { version = "1.23", features = ["v4"] }
uuid = { version = "1.11", features = ["v4"] }
wiremock = { version = "0.6", features = ["tls"] }
x509-parser = { version = "0.18", default-features = false, features = ["verify-aws"] }
which = "8.0"
@ -215,12 +210,12 @@ crossbeam-channel = "0.5"
http-serde = "2.1"
itoa = "1.0"
serde_urlencoded = "0.7"
serde_with = { version = "3.17", features = [
serde_with = { version = "3.14", features = [
"schemars_1",
"macros",
"alloc",
], default-features = false }
value-bag = { version = "1.12", features = ["serde", "value-bag-serde1"] }
value-bag = { version = "1.11", features = ["serde", "value-bag-serde1"] }
time = "0.3"
tikv-jemallocator = { version = "0.6", features = [
"profiling",
@ -228,17 +223,17 @@ tikv-jemallocator = { version = "0.6", features = [
] }
jemalloc_pprof = { version = "0.8", features = ["symbolize"] }
protox = "0.9"
async-compression = { version = "0.4", features = [
async-compression = { version = "0.4.27", features = [
"brotli",
"zlib",
"gzip",
"zstd",
"tokio",
] }
core_affinity = "0.8"
frozen-collections = "0.9"
core_affinity = "0.8.3"
frozen-collections = "0.8.0"
heck = "0.5"
macro_rules_attribute = "0.2"
macro_rules_attribute = "0.2.2"
# Release optimized but without as many dependencies, suitable for incremental development
[profile.quick-release]

View File

@ -1,4 +1,3 @@
# syntax=docker/dockerfile:1.11
ARG BUILDER=base
FROM docker.io/library/node:23.11.0-bookworm AS node

View File

@ -19,14 +19,6 @@ else
$(DOCKER_BUILDER) build $(DOCKER_BUILD_ARGS) -t $(IMAGE_FULL_NAME) . --progress=plain
endif
.PHONY: docker-ci
docker-ci:
ifeq ($(OS),Windows_NT)
$(DOCKER_BUILDER) build $(DOCKER_BUILD_ARGS) --build-arg PROFILE=ci -f Dockerfile.windows -t $(IMAGE_FULL_NAME) .
else
$(DOCKER_BUILDER) build $(DOCKER_BUILD_ARGS) --build-arg PROFILE=ci -t $(IMAGE_FULL_NAME) . --progress=plain
endif
.PHONY: docker-musl
docker-musl:
$(DOCKER_BUILDER) build $(DOCKER_BUILD_ARGS) -t $(IMAGE_FULL_NAME)-musl --build-arg=BUILDER=musl . --progress=plain
@ -82,7 +74,7 @@ generate-schema:
# Code generation for xds apis
.PHONY: generate-apis
generate-apis:
@PATH="./common/tools:$(PATH)" buf generate --path crates/protos/proto/resource.proto
@PATH="./common/tools:$(PATH)" buf generate --path crates/agentgateway/proto/resource.proto
.PHONY: run-validation-deps
run-validation-deps:

View File

@ -29,7 +29,7 @@
---
**Agentgateway** is an open source proxy built on AI-native protocols ([MCP](https://modelcontextprotocol.io/introduction) & [A2A](https://developers.googleblog.com/en/a2a-a-new-era-of-agent-interoperability/)) that provides drop-in security, observability, and governance for agent-to-LLM, agent-to-tool, and agent-to-agent communication across any framework and environment.
**Agentgateway** is an open source data plane optimized for agentic AI connectivity within or across any agent framework or environment. Agentgateway provides drop-in security, observability, and governance for agent-to-agent and agent-to-tool communication and supports leading interoperable protocols, including [Agent2Agent (A2A)](https://developers.googleblog.com/en/a2a-a-new-era-of-agent-interoperability/) and [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction).
<br>
<div align="center">
@ -37,42 +37,33 @@
</div>
<br>
> [!TIP]
> Want to use agentgateway in Kubernetes? Check out the [kgateway.dev/docs/agentgateway](https://kgateway.dev/docs/agentgateway/) docs. Agentgateway is a supported data plane for the kgateway project, which provides a control plane to dynamically provision and manage agentgateway with the Kubernetes Gateway API.
## Intro to Agentgateway Video
[![Agentgateway Intro Video](https://img.youtube.com/vi/SomP92JWPmE/hqdefault.jpg)](https://youtu.be/SomP92JWPmE)
## Key Features
## Key Features:
- **LLM Gateway**<br>
Route traffic to major LLM providers (OpenAI, Anthropic, Gemini, Bedrock, and more) through a unified OpenAI-compatible API with budget and spend controls, prompt enrichment, load balancing, and failover.
- **MCP Gateway**<br>
Connect LLMs to tools and external data sources via MCP with tool federation, stdio/HTTP/SSE/Streamable HTTP transports, OpenAPI integration, and OAuth authentication.
- **A2A Gateway**<br>
Enable secure agent-to-agent communication using A2A, with capability discovery, modality negotiation, and task collaboration.
- **Inference Routing**<br>
Intelligent routing to self-hosted models using Kubernetes Inference Gateway extensions, with decisions based on GPU utilization, KV cache, LoRA adapters, and queue depth.
- **Guardrails**<br>
Multi-layered content filtering with regex, OpenAI moderation, AWS Bedrock Guardrails, Google Model Armor, and custom webhooks.
- **Security & Observability**<br>
Auth (JWT, API keys, OAuth), fine-grained RBAC with CEL policy engine, rate limiting, TLS, and OpenTelemetry metrics/logs/tracing.
- [x] **Highly performant:** agentgateway is written in rust, and is designed from the ground up to handle any scale you can throw at it.
- [x] **Security First:** agentgateway includes a robust MCP/A2A focused RBAC system.
- [x] **Multi Tenant:** agentgateway supports multiple tenants, each with their own set of resources and users.
- [x] **Dynamic:** agentgateway supports dynamic configuration updates via xDS, without any downtime.
- [x] **Run Anywhere:** agentgateway can run anywhere with any agent framework, from a single machine to a large scale multi-tenant deployment.
- [x] **Legacy API Support:** agentgateway can transform legacy APIs into MCP resources. Currently supports OpenAPI. (gRPC coming soon)
<br>
## Getting Started
## Getting Started
- [Standalone Quickstart](https://agentgateway.dev/docs/quickstart) — Get started with agentgateway in minutes.
- [Kubernetes Quickstart](https://agentgateway.dev/docs/kubernetes/latest) — Deploy on Kubernetes using the built-in controller and Gateway API.
To get started with agentgateway, please check out the [Getting Started Guide](https://agentgateway.dev/docs/quickstart).
## Documentation
Depending on your deployment environment, check out the following docs:
- [agentgateway.dev/docs](https://agentgateway.dev/docs/): For standalone deployments such as local or on-prem. These docs are for this upstream `agentgateway/agentgateway` GitHub project.
- [agentgateway.dev/docs/kubernetes/latest](https://agentgateway.dev/docs/kubernetes/latest): For Kubernetes-based deployments using the built-in Kubernetes controller and Gateway API support.
- [kgateway.dev/docs/agentgateway](https://kgateway.dev/docs/agentgateway/): For Kubernetes-based deployments. These docs are for the agentgateway data plane that is supported by the [`kgateway-dev/kgateway` GitHub project](https://github.com/kgateway-dev/kgateway). Kgateway provides a control plane to dynamically provision and manage agentgateway with the Kubernetes Gateway API.
Agentgateway has a built-in UI for you to explore agentgateway connecting agent-to-agent or agent-to-tool:
@ -80,23 +71,6 @@ Agentgateway has a built-in UI for you to explore agentgateway connecting agent-
<img alt="agentgateway UI" src="img/UI-homepage.png">
</div>
## Sponsors
<table>
<tr>
<td align="center" width="33.3%">
<a href="https://blacksmith.sh/">
<picture>
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/agentgateway/agentgateway/main/img/blacksmith-light.svg">
<img src="https://raw.githubusercontent.com/agentgateway/agentgateway/main/img/blacksmith.svg" alt="Blacksmith" height="48">
</picture>
</a>
</td>
</tr>
</table>
Thank you to our sponsors for helping to fund the development of agentgateway!
## Contributing
For instructions on how to contribute to the agentgateway project, see the [CONTRIBUTION.md](CONTRIBUTION.md) file.
@ -108,7 +82,7 @@ Recordings of the community meetings will be published on our [google drive](htt
## Roadmap
`agentgateway` is currently in active development. If you'd like a feature that's missing, open an issue in our [GitHub repo](https://github.com/agentgateway/agentgateway/issues).
`agentgateway` is currently in active development. If you want a feature missing, open an issue in our [Github repo](https://github.com/agentgateway/agentgateway/issues).
## Contributors

177
Tiltfile
View File

@ -1,177 +0,0 @@
# Tiltfile for AgentGateway development
# This deploys both control plane (Go) and data plane (Rust) to Kind with live updates
load('ext://restart_process', 'docker_build_with_restart')
load('ext://helm_resource', 'helm_resource', 'helm_repo')
# Configuration
version = 'v1.0.1-dev'
cluster_name = 'kind'
install_namespace = k8s_namespace()
image_registry = 'localhost:5000'
# Ensure Kind cluster exists
allow_k8s_contexts('kind-' + cluster_name)
# Helper to run Make targets
def run_make(target, cwd='.'):
return local('make -C ' + cwd + ' ' + target)
def run_controller_make(target):
return run_make(target, cwd='./controller')
# =============================================================================
# Setup: Ensure cluster is ready
# =============================================================================
# Check if kind cluster exists, create if not
if str(local('kind get clusters 2>/dev/null | grep -c "^' + cluster_name + '$" || true')).strip() == '0':
print('No kind cluster! create one and restart tilt after doing so. You can use this command:')
print('ctlptl create cluster kind --name kind-' + cluster_name + ' --registry=ctlptl-registry')
fail("started kind cluster. Create one and run tilt again")
print('Installing Gateway API CRDs...')
run_controller_make('gw-api-crds')
run_controller_make('gie-crds')
# Install CRDs
print('Installing AgentGateway CRDs...')
helm_resource(
'agentgateway-crds',
'controller/install/helm/agentgateway-crds',
namespace=install_namespace,
flags=['--set=version=' + version],
)
# =============================================================================
# Control Plane (Go-based controller)
# =============================================================================
local_resource(
'go-compile-controller',
'make -C ./controller VERSION=' + version + ' GCFLAGS=all="-N -l" agentgateway-controller && mv ./controller/_output/pkg/agentgateway/agentgateway-linux-$(go env GOARCH) ./tools/tilt/agentgateway-controller',
deps=['./controller/'],
ignore=['./controller/_output/'],
)
# Build control plane Docker image
docker_build_with_restart(
image_registry + '/agentgateway-controller',
context='./tools/tilt/',
entrypoint='/usr/local/bin/agentgateway-controller',
dockerfile_contents="""
FROM ubuntu:24.04
COPY agentgateway-controller /usr/local/bin/agentgateway-controller
ENTRYPOINT /usr/local/bin/agentgateway-controller
""",
# Live update: sync Go binaries
live_update=[
# Sync Go code changes
sync('./tools/tilt/agentgateway-controller', '/usr/local/bin/agentgateway-controller'),
],
only=[
'./agentgateway-controller',
],
)
# =============================================================================
# Deploy via Helm
# =============================================================================
# Deploy AgentGateway via Helm
k8s_yaml(helm(
'controller/install/helm/agentgateway',
name='agentgateway',
namespace=install_namespace,
set=[
'image.registry=' + image_registry,
'image.tag=' + version,
'image.pullPolicy=IfNotPresent',
'controller.image.repository=agentgateway-controller',
'controller.image.tag=' + version,
'controller.replicaCount=1',
'controller.logLevel=debug',
'proxy.image.repository=agentgateway',
'proxy.image.tag=' + version,
],
values=[config.main_dir + '/controller/hack/helm/dev.yaml'] if os.path.exists(config.main_dir + '/controller/hack/helm/dev.yaml') else [],
))
k8s_resource('agentgateway',
resource_deps=['go-compile-controller'])
# =============================================================================
# Data Plane (Rust-based proxy)
# =============================================================================
local_resource(
'rust-compile-dataplane',
'cargo build && if [ -f "./tools/tilt/agentgateway" ]; then rm "./tools/tilt/agentgateway"; fi && mv ./target/debug/agentgateway ./tools/tilt/agentgateway',
deps=['./crates',
'./Cargo.toml',
'./Cargo.lock',
'./.cargo'])
#
# Build data plane Docker image
docker_build(
'agentgateway',
context='./tools/tilt/',
dockerfile_contents="""
FROM ubuntu:24.04
COPY start.sh /scripts/start.sh
COPY restart.sh /scripts/restart.sh
COPY agentgateway /usr/local/bin/
ENTRYPOINT ["/scripts/start.sh", "/usr/local/bin/agentgateway"]
""",
live_update=[
sync('./tools/tilt/agentgateway', '/usr/local/bin/agentgateway'),
run('/scripts/restart.sh'),
],
only=[
'./agentgateway',
'./start.sh',
'./restart.sh',
],
)
k8s_kind('AgentgatewayParameters', image_object={'json_path': '{.spec.image}', 'repo_field': 'repository', 'tag_field': 'tag'})
k8s_kind('Gateway', pod_readiness='wait')
k8s_yaml(blob("""
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayParameters
metadata:
name: dataplane-dev-gwparams
spec:
image:
registry: "" # tilt will fill in the registry in the repository field, so leave it blank here (othewise it will be duplicated)
repository: agentgateway
tag: """ + version + """
deployment:
spec:
template:
spec:
containers:
# Delete container-level securityContext so that Tilt can apply live updates
# (need root user, and file system to be writable for live updates)
- name: agentgateway
securityContext:
$patch: delete
---
kind: Gateway
apiVersion: gateway.networking.k8s.io/v1
metadata:
name: tilt-gw
spec:
gatewayClassName: agentgateway
infrastructure:
parametersRef:
group: agentgateway.dev
kind: AgentgatewayParameters
name: dataplane-dev-gwparams
listeners:
- name: http
protocol: HTTP
port: 8080
"""))
k8s_resource(workload='dataplane-dev-gwparams', extra_pod_selectors={"gateway.networking.k8s.io/gateway-name":"tilt-gw"},
resource_deps=['rust-compile-dataplane'])

File diff suppressed because it is too large Load Diff

View File

@ -336,17 +336,6 @@ func (this *AzureDeveloperImplicit) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for AzureImplicit
func (this *AzureImplicit) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
return []byte(str), err
}
// UnmarshalJSON is a custom unmarshaler for AzureImplicit
func (this *AzureImplicit) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for RouteMatch
func (this *RouteMatch) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
@ -611,17 +600,6 @@ func (this *FrontendPolicySpec_TCP) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for FrontendPolicySpec_NetworkAuthorization
func (this *FrontendPolicySpec_NetworkAuthorization) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
return []byte(str), err
}
// UnmarshalJSON is a custom unmarshaler for FrontendPolicySpec_NetworkAuthorization
func (this *FrontendPolicySpec_NetworkAuthorization) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for FrontendPolicySpec_Logging
func (this *FrontendPolicySpec_Logging) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
@ -655,17 +633,6 @@ func (this *FrontendPolicySpec_Logging_Fields) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for FrontendPolicySpec_Logging_OtlpAccessLog
func (this *FrontendPolicySpec_Logging_OtlpAccessLog) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
return []byte(str), err
}
// UnmarshalJSON is a custom unmarshaler for FrontendPolicySpec_Logging_OtlpAccessLog
func (this *FrontendPolicySpec_Logging_OtlpAccessLog) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for FrontendPolicySpec_Tracing
func (this *FrontendPolicySpec_Tracing) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
@ -688,17 +655,6 @@ func (this *FrontendPolicySpec_TracingAttribute) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for JWTValidationOptions
func (this *JWTValidationOptions) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
return []byte(str), err
}
// UnmarshalJSON is a custom unmarshaler for JWTValidationOptions
func (this *JWTValidationOptions) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for TrafficPolicySpec
func (this *TrafficPolicySpec) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
@ -831,17 +787,6 @@ func (this *TrafficPolicySpec_JWT) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for TrafficPolicySpec_JWT_MCP
func (this *TrafficPolicySpec_JWT_MCP) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
return []byte(str), err
}
// UnmarshalJSON is a custom unmarshaler for TrafficPolicySpec_JWT_MCP
func (this *TrafficPolicySpec_JWT_MCP) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for TrafficPolicySpec_BasicAuthentication
func (this *TrafficPolicySpec_BasicAuthentication) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
@ -1150,28 +1095,6 @@ func (this *BackendPolicySpec_InferenceRouting) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for BackendPolicySpec_Eviction
func (this *BackendPolicySpec_Eviction) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
return []byte(str), err
}
// UnmarshalJSON is a custom unmarshaler for BackendPolicySpec_Eviction
func (this *BackendPolicySpec_Eviction) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for BackendPolicySpec_Health
func (this *BackendPolicySpec_Health) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
return []byte(str), err
}
// UnmarshalJSON is a custom unmarshaler for BackendPolicySpec_Health
func (this *BackendPolicySpec_Health) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for BackendPolicySpec_BackendTLS
func (this *BackendPolicySpec_BackendTLS) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
@ -1194,17 +1117,6 @@ func (this *BackendPolicySpec_BackendHTTP) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for BackendPolicySpec_BackendTunnel
func (this *BackendPolicySpec_BackendTunnel) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
return []byte(str), err
}
// UnmarshalJSON is a custom unmarshaler for BackendPolicySpec_BackendTunnel
func (this *BackendPolicySpec_BackendTunnel) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for BackendPolicySpec_BackendTCP
func (this *BackendPolicySpec_BackendTCP) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
@ -1271,28 +1183,6 @@ func (this *DynamicForwardProxy) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for AwsBackend
func (this *AwsBackend) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
return []byte(str), err
}
// UnmarshalJSON is a custom unmarshaler for AwsBackend
func (this *AwsBackend) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for AwsAgentCoreBackend
func (this *AwsAgentCoreBackend) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)
return []byte(str), err
}
// UnmarshalJSON is a custom unmarshaler for AwsAgentCoreBackend
func (this *AwsAgentCoreBackend) UnmarshalJSON(b []byte) error {
return ResourceUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}
// MarshalJSON is a custom marshaler for AIBackend
func (this *AIBackend) MarshalJSON() ([]byte, error) {
str, err := ResourceMarshaler.MarshalToString(this)

View File

@ -5,10 +5,6 @@ CEL is an expression language that can evaluate user-defined (at runtime) expres
A simple example of an expression that could be used for MCP authorization: `jwt.sub == "test-user" && mcp.tool.name == "add"`.
For post-request logging, tracing, and metrics CEL, MCP tool calls also expose payload fields such as
`mcp.methodName`, `mcp.sessionId`, `mcp.tool.arguments`, `mcp.tool.result`, and `mcp.tool.error`.
Request-time authorization keeps the `mcp` context identity-only, so those payload fields are absent during RBAC evaluation.
While CEL is not as powerful as alternatives like Lua or WASM, it is pretty fast and good enough for many use cases.
Agentgateway currently uses CEL for:

View File

@ -1,4 +1,4 @@
version: v1beta1
build:
roots:
- crates/protos/proto
- crates/agentgateway/proto

View File

@ -104,6 +104,10 @@ linters:
alias: gwv1a2
- pkg: sigs.k8s.io/gateway-api/apis/v1beta1
alias: gwv1b1
- pkg: github.com/envoyproxy/go-control-plane/envoy/config/(\w+)/(v[\w\d]+)
alias: envoy$1$2
- pkg: github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3
alias: envoytlsv3
- pkg: github.com/agentgateway/agentgateway/controller/api/annotations
alias: apiannotations
- pkg: github.com/agentgateway/agentgateway/controller/api/settings
@ -161,6 +165,7 @@ linters:
- third_party$
- builtin$
- examples$
- hack/dummy-idp
rules:
# Forbid t.Cleanup only in e2e tests (exclude the rule from non-e2e paths)
- path-except: test/e2e/

View File

@ -117,6 +117,7 @@ mod-download: ## Download the dependencies
.PHONY: mod-tidy-nested
mod-tidy-nested: ## Tidy go mod files in nested modules
@echo "Tidying tools..." && cd ../tools && go mod tidy
@echo "Tidying test/e2e/defaults/extproc..." && cd test/e2e/defaults/extproc && go mod tidy
.PHONY: mod-tidy
mod-tidy: mod-download mod-tidy-nested ## Tidy the go mod file
@ -174,7 +175,7 @@ test: ## Run all tests with ginkgo, or only run the test package at {TEST_PKG} i
# will still have e2e tests run by Github Actions once they publish a pull
# request.
.PHONY: e2e-test
e2e-test: testbox-docker kind-load-testbox
e2e-test: extproc-server-docker kind-load-extproc-server
e2e-test: go-test
e2e-test: TEST_TAG = e2e
e2e-test: GO_TEST_ARGS = $(E2E_GO_TEST_ARGS)
@ -426,42 +427,67 @@ agentgateway-controller-docker-local: agentgateway-controller $(CONTROLLER_OUTPU
-t localhost:5000/$(AGENTGATEWAY_IMAGE_REPO):$(TAG)
#----------------------------------------------------------------------------------
# testbox (used in e2e tests)
# dummy idp (used in e2e tests)
#----------------------------------------------------------------------------------
TESTBOX_DIR=hack/testbox
TESTBOX_OUTPUT_DIR=$(OUTPUT_DIR)/$(TESTBOX_DIR)
export TESTBOX_IMAGE_REPO ?= testbox
TESTBOX_VERSION=0.0.1
DUMMY_IDP_DIR=hack/dummy-idp
DUMMY_IDP_OUTPUT_DIR=$(OUTPUT_DIR)/$(DUMMY_IDP_DIR)
export DUMMY_IDP_IMAGE_REPO ?= dummy-idp
DUMMY_IDP_VERSION=0.0.1
.PHONY: testbox
testbox:
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $(TESTBOX_OUTPUT_DIR)/testbox-linux-$(GOARCH) ./hack/testbox...
.PHONY: dummy-idp
dummy-idp:
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $(DUMMY_IDP_OUTPUT_DIR)/dummy-idp-linux-$(GOARCH) ./hack/dummy-idp...
$(TESTBOX_OUTPUT_DIR)/Dockerfile.testbox: ./hack/testbox/Dockerfile
$(DUMMY_IDP_OUTPUT_DIR)/Dockerfile.dummy-idp: ./hack/dummy-idp/Dockerfile
cp $< $@
.PHONY: testbox-docker
testbox-docker: testbox $(TESTBOX_OUTPUT_DIR)/Dockerfile.testbox
$(BUILDX_BUILD) --load $(PLATFORM) $(TESTBOX_OUTPUT_DIR) -f $(TESTBOX_OUTPUT_DIR)/Dockerfile.testbox \
.PHONY: dummy-idp-docker
dummy-idp-docker: dummy-idp $(DUMMY_IDP_OUTPUT_DIR)/Dockerfile.dummy-idp
$(BUILDX_BUILD) --load $(PLATFORM) $(DUMMY_IDP_OUTPUT_DIR) -f $(DUMMY_IDP_OUTPUT_DIR)/Dockerfile.dummy-idp \
--build-arg GOARCH=$(GOARCH) \
-t $(IMAGE_REGISTRY)/$(TESTBOX_IMAGE_REPO):$(TESTBOX_VERSION)
--build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
-t $(IMAGE_REGISTRY)/$(DUMMY_IDP_IMAGE_REPO):$(DUMMY_IDP_VERSION)
.PHONY: kind-load-testbox
kind-load-testbox:
kind load docker-image $(IMAGE_REGISTRY)/$(TESTBOX_IMAGE_REPO):$(TESTBOX_VERSION) --name $(CLUSTER_NAME)
.PHONY: kind-load-dummy-idp
kind-load-dummy-idp:
kind load docker-image $(IMAGE_REGISTRY)/$(DUMMY_IDP_IMAGE_REPO):$(DUMMY_IDP_VERSION) --name $(CLUSTER_NAME)
#----------------------------------------------------------------------------------
# extproc-server (used in e2e tests)
#----------------------------------------------------------------------------------
EXTPROC_SERVER_DIR=test/e2e/defaults/extproc
EXTPROC_SERVER_OUTPUT_DIR=$(OUTPUT_DIR)/$(EXTPROC_SERVER_DIR)
export EXTPROC_SERVER_IMAGE_REPO ?= extproc-server
EXTPROC_SERVER_VERSION=0.0.1
$(EXTPROC_SERVER_OUTPUT_DIR)/.docker-stamp-$(EXTPROC_SERVER_VERSION)-$(GOARCH): $(shell find $(EXTPROC_SERVER_DIR) -name '*.go') $(EXTPROC_SERVER_DIR)/Dockerfile
$(BUILDX_BUILD) --load $(PLATFORM) $(EXTPROC_SERVER_DIR) -f $(EXTPROC_SERVER_DIR)/Dockerfile \
-t $(IMAGE_REGISTRY)/$(EXTPROC_SERVER_IMAGE_REPO):$(EXTPROC_SERVER_VERSION)
@mkdir -p $(dir $@)
@touch $@
.PHONY: extproc-server-docker
extproc-server-docker: $(EXTPROC_SERVER_OUTPUT_DIR)/.docker-stamp-$(EXTPROC_SERVER_VERSION)-$(GOARCH)
.PHONY: kind-load-extproc-server
kind-load-extproc-server:
kind load docker-image $(IMAGE_REGISTRY)/$(EXTPROC_SERVER_IMAGE_REPO):$(EXTPROC_SERVER_VERSION) --name $(CLUSTER_NAME)
#----------------------------------------------------------------------------------
# Helm
#----------------------------------------------------------------------------------
HELM ?= helm
# Publish charts with both semver variants to preserve compatibility.
# Keep VERSION as-is for image tags and other release identifiers.
HELM_CHART_VERSION_NO_V ?= $(patsubst v%,%,$(VERSION))
HELM_CHART_VERSION_V ?= v$(HELM_CHART_VERSION_NO_V)
HELM_PACKAGE_ARGS ?= --version $(HELM_CHART_VERSION_NO_V) --app-version $(HELM_CHART_VERSION_NO_V)
EXTRA_HELM_TAG ?=
# It would be nice to use actual semver '--version', as Helm docs clearly state
# is intended (and yet is not enforced by 'helm lint'). Here we say '--version
# v2.0.0', not '--version 2.0.0', e.g. To do it cleanly, you'd probably
# repackage all published versions' charts and republish as vA.B.C and A.B.C
# both. Users would be surprised if their installation recipes had to change on
# some patch or minor version release. ('--app-version v2.0.0' is acceptable
# and in fact preferred since it matches our git tags and OCI image tags.)
HELM_PACKAGE_ARGS ?= --version $(VERSION) --app-version $(VERSION)
HELM_CHART_DIR_AGW=install/helm/agentgateway
HELM_CHART_DIR_AGW_CRD=install/helm/agentgateway-crds
HELM_ADDITIONAL_VALUES ?= hack/helm/dev.yaml
@ -481,39 +507,26 @@ package-agentgateway-crd-chart: ## Package the agentgateway crd chart
$(HELM) package $(HELM_PACKAGE_ARGS) --destination $(TEST_ASSET_DIR) $(HELM_CHART_DIR_AGW_CRD); \
$(HELM) repo index $(TEST_ASSET_DIR);
# VERSION_NO_V strips the leading 'v' from VERSION (e.g., v2.0.0 -> 2.0.0)
VERSION_NO_V := $(patsubst v%,%,$(VERSION))
CHART_NAMES := agentgateway agentgateway-crds
.PHONY: release-charts
release-charts: package-agentgateway-charts
mkdir -p $(TEST_ASSET_DIR); \
$(HELM) package --version $(HELM_CHART_VERSION_V) --app-version $(HELM_CHART_VERSION_V) --destination $(TEST_ASSET_DIR) $(HELM_CHART_DIR_AGW); \
$(HELM) repo index $(TEST_ASSET_DIR);
mkdir -p $(TEST_ASSET_DIR); \
$(HELM) package --version $(HELM_CHART_VERSION_V) --app-version $(HELM_CHART_VERSION_V) --destination $(TEST_ASSET_DIR) $(HELM_CHART_DIR_AGW_CRD); \
$(HELM) repo index $(TEST_ASSET_DIR);
@if [ -n "$(EXTRA_HELM_TAG)" ]; then \
mkdir -p $(TEST_ASSET_DIR); \
$(HELM) package --version $(EXTRA_HELM_TAG) --app-version $(VERSION) --destination $(TEST_ASSET_DIR) $(HELM_CHART_DIR_AGW); \
$(HELM) repo index $(TEST_ASSET_DIR); \
mkdir -p $(TEST_ASSET_DIR); \
$(HELM) package --version $(EXTRA_HELM_TAG) --app-version $(VERSION) --destination $(TEST_ASSET_DIR) $(HELM_CHART_DIR_AGW_CRD); \
$(HELM) repo index $(TEST_ASSET_DIR); \
fi
@for chart in $(CHART_NAMES); do \
$(HELM) push $(TEST_ASSET_DIR)/$$chart-$(HELM_CHART_VERSION_NO_V).tgz oci://$(IMAGE_REGISTRY)/charts; \
$(HELM) push $(TEST_ASSET_DIR)/$$chart-$(HELM_CHART_VERSION_V).tgz oci://$(IMAGE_REGISTRY)/charts; \
if [ -n "$(EXTRA_HELM_TAG)" ]; then \
$(HELM) push $(TEST_ASSET_DIR)/$$chart-$(EXTRA_HELM_TAG).tgz oci://$(IMAGE_REGISTRY)/charts; \
fi; \
done;
release-charts: ## Release the agentgateway charts (publishes both vX.Y.Z and X.Y.Z tags)
@for v in $(VERSION) $(VERSION_NO_V); do \
$(MAKE) package-agentgateway-charts VERSION=$$v; \
for chart in $(CHART_NAMES); do \
$(HELM) push $(TEST_ASSET_DIR)/$$chart-$$v.tgz oci://$(IMAGE_REGISTRY)/charts; \
done; \
done
.PHONY: deploy-agentgateway-crd-chart
deploy-agentgateway-crd-chart: ## Deploy the agentgateway crd chart
$(HELM) upgrade --install agentgateway-crds $(TEST_ASSET_DIR)/agentgateway-crds-$(HELM_CHART_VERSION_NO_V).tgz --namespace $(INSTALL_NAMESPACE) --create-namespace
$(HELM) upgrade --install agentgateway-crds $(TEST_ASSET_DIR)/agentgateway-crds-$(VERSION).tgz --namespace $(INSTALL_NAMESPACE) --create-namespace
.PHONY: deploy-agentgateway-chart
deploy-agentgateway-chart: ## Deploy the agentgateway chart
$(HELM) upgrade --install agentgateway $(TEST_ASSET_DIR)/agentgateway-$(HELM_CHART_VERSION_NO_V).tgz \
$(HELM) upgrade --install agentgateway $(TEST_ASSET_DIR)/agentgateway-$(VERSION).tgz \
--namespace $(INSTALL_NAMESPACE) --create-namespace \
--set image.registry=$(IMAGE_REGISTRY) \
--set image.tag=$(VERSION) \
@ -529,6 +542,13 @@ lint-charts: ## Lint the agentgateway charts
# Release
#----------------------------------------------------------------------------------
GORELEASER_ARGS ?= --snapshot --clean
GORELEASER_TIMEOUT ?= 60m
GORELEASER_CURRENT_TAG ?= $(VERSION)
.PHONY: release
release: ## Create a release using goreleaser
GORELEASER_CURRENT_TAG=$(GORELEASER_CURRENT_TAG) goreleaser release $(GORELEASER_ARGS) --timeout $(GORELEASER_TIMEOUT)
.PHONY: release-notes
release-notes: ## Generate release notes (PREVIOUS_TAG required, CURRENT_TAG optional)
./hack/generate-release-notes.sh -p $(PREVIOUS_TAG) -c $(or $(CURRENT_TAG),HEAD)
@ -549,7 +569,7 @@ kind-create: ## Create a KinD cluster
kind get clusters | grep $(CLUSTER_NAME) || kind create cluster --name $(CLUSTER_NAME) --image kindest/node:$(CLUSTER_NODE_VERSION)
CONFORMANCE_CHANNEL ?= experimental
CONFORMANCE_VERSION ?= $(shell go list -m -f '{{.Version}}' sigs.k8s.io/gateway-api)
CONFORMANCE_VERSION ?= v1.4.1
.PHONY: gw-api-crds
gw-api-crds: ## Install the Gateway API CRDs. HACK: Use SSA to avoid the issue with the CRD annotations being too long.
ifeq ($(shell echo $(CONFORMANCE_VERSION) | grep -q '^v[0-9]' && echo yes),yes)
@ -563,7 +583,10 @@ endif
endif
# The version of the k8s gateway api inference extension CRDs to install.
GIE_CRD_VERSION ?= $(shell go list -m -f '{{.Version}}' sigs.k8s.io/gateway-api-inference-extension)
# Managed by `make bump-gie`.
GIE_CRD_VERSION ?= v1.3.0
# When we are back on a release version instead of `main`, we can do this
#GIE_CRD_VERSION ?= $(shell go list -m -f '{{.Version}}' sigs.k8s.io/gateway-api-inference-extension)
.PHONY: gie-crds
gie-crds: ## Install the Gateway API Inference Extension CRDs
@ -573,11 +596,9 @@ else
kubectl apply --kustomize "https://github.com/kubernetes-sigs/gateway-api-inference-extension/config/crd?ref=$(GIE_CRD_VERSION)"
endif
.PHONY: metallb
.PHONY: kind-metallb
metallb: ## Install the MetalLB load balancer
kubectl apply -f ./test/setup/metallb.yaml
kubectl rollout status -n metallb-system deployment/controller --timeout=120s
kubectl rollout status -n metallb-system daemonset/speaker --timeout=120s
./hack/kind/setup-metalllb-on-kind.sh
.PHONY: deploy-agentgateway
deploy-agentgateway: package-agentgateway-charts deploy-agentgateway-crd-chart deploy-agentgateway-chart ## Deploy the agentgateway chart and CRDs
@ -588,7 +609,7 @@ setup-base: kind-create gw-api-crds gie-crds metallb ## Setup the base infrastru
# Creates a functional kind cluster, builds and loads all images, and packages charts
# Does NOT deploy anything to the cluster
.PHONY: setup
setup: setup-base kind-build-and-load package-agentgateway-charts ## Setup base infra, build/load images, and package charts (without deployment)
setup: setup-base kind-build-and-load package-agentgateway-charts dummy-idp-docker kind-load-dummy-idp ## Setup the complete infrastructure (base setup plus images and charts)
.PHONY: run
run: setup deploy-agentgateway ## Set up complete development environment
@ -605,6 +626,7 @@ kind-load-%:
# Build an image and load it into the KinD cluster
# Depends on: IMAGE_REGISTRY, VERSION, CLUSTER_NAME
# Envoy image may be specified via ENVOY_IMAGE on the command line or at the top of this file
kind-build-and-load-%: %-docker kind-load-% ; ## Use to build specified image and load it into kind
# Update the docker image used by a deployment
@ -624,15 +646,16 @@ kind-set-image-%:
# You can reload an image, which means it will be rebuilt and reloaded into the kind cluster, and the deployment
# will be updated to reference it
# Depends on: IMAGE_REGISTRY, VERSION, INSTALL_NAMESPACE , CLUSTER_NAME
# Envoy image may be specified via ENVOY_IMAGE on the command line or at the top of this file
kind-reload-%: kind-build-and-load-% kind-set-image-% ; ## Use to build specified image, load it into kind, and restart its deployment
.PHONY: kind-build-and-load ## Use to build all images and load them into kind
kind-build-and-load: kind-build-and-load-agentgateway-controller
kind-build-and-load: kind-build-and-load-testbox
kind-build-and-load: kind-build-and-load-dummy-idp
.PHONY: kind-load ## Use to load all images into kind
kind-load: kind-load-agentgateway-controller
kind-load: kind-load-testbox
kind-load: kind-load-dummy-idp
#----------------------------------------------------------------------------------
# Targets for running Agent Gateway conformance tests

View File

@ -1,6 +1,6 @@
# APIs for Agentgateway Controller
# APIs for kgateway
This directory contains Go types for Agentgateway Controller APIs & custom resources.
This directory contains Go types for kgateway APIs & custom resources.
## Adding a new API / CRD
@ -9,14 +9,14 @@ These are the steps required to add a new CRD to be used in the Kubernetes Gatew
1. If creating a new API version (e.g. `v1`, `v2alpha1`), create a new directory for the version and create a `doc.go` file with the `// +kubebuilder:object:generate=true` annotation, so that Go types in that directory will be converted into CRDs when codegen is run.
- The `groupName` marker specifies the API group name for the generated CRD.
- RBAC rules are defined via the `+kubebuilder:rbac` annotation (note: this annotation should not belong to the type, but rather the file or package).
2. Create a `_types.go` file in the API version directory. Following [agentgateway_parameters_types.go](/controller/api/v1alpha1/agentgateway/agentgateway_parameters_types.go) as an example:
2. Create a `_types.go` file in the API version directory. Following [gateway_parameters_types.go](/api/v1alpha1/kgateway/gateway_parameters_types.go) as an example:
- Define a struct for the resource (containing the metadata fields, `Spec`, and `Status`). Follow the [API guidelines](#api-guidelines) below.
- Define a struct for the resource list (containing the metadata fields and `Items`)
3. Run codegen via `make generated-code -B`. This will invoke the `controller-gen` command specified in [generate.go](/controller/hack/generate.go), which should result in the following:
3. Run codegen via `make generated-code -B`. This will invoke the `controller-gen` command specified in [generate.go](/hack/generate.go), which should result in the following:
- A `zz_generated.deepcopy.go` file is created in the same directory as the Go types.
- A `zz_generated.register.go` file is created in the same directory as the Go types, to help with registering the Go types with the scheme.
- CRDs are generated in the CRD helm chart template dir: [install/helm/agentgateway-crds/templates](/controller/install/helm/agentgateway-crds/templates)
- RBAC roles are generated in [controller/install/helm/templates/role.yaml](/agentgateway/install/helm/agentgateway/templates/role.yaml)
- CRDs are generated in the CRD helm chart template dir: [install/helm/kgateway-crds/templates](/install/helm/kgateway-crds/templates)
- RBAC roles are generated in [install/helm/kgateway/templates/role.yaml](/install/helm/kgateway/templates/role.yaml)
- Updates the [api/applyconfiguration](/api/applyconfiguration), [pkg/generated](/pkg/generated) and [pkg/client](/pkg/client) folders with kube clients. These are used in plugin initialization and the fake client is used in tests.
## API guidelines
@ -32,27 +32,10 @@ These are the steps required to add a new CRD to be used in the Kubernetes Gatew
- Avoid using slices with pointers (e.g. use `[]string` instead of `[]*string`). See: https://github.com/kubernetes/code-generator/issues/166
- For time duration fields, use the `metav1.Duration` type and use CEL validation rules to ensure it is within the correct range.
### Custom validation markers
The CRD generation pipeline supports custom kubebuilder validation markers, implemented in
`controller/hack/crdgen`.
- `+kubebuilder:validation:AtLeastOneFieldSet` requires at least one field on the struct to be set.
- `+kubebuilder:validation:ExactlyOneFieldSet` requires exactly one field on the struct to be set.
- `+kubebuilder:validation:IfThenOnlyFields:if="...",fields=a;b;c,message="..."` requires that, when `if` is true,
only the listed fields may be set.
Optional arguments for `AtLeastOneFieldSet` and `ExactlyOneFieldSet`:
- `fields=a;b;c` to explicitly pick fields to count.
- `exclude=a;b` to drop fields from the counted set.
- `message="..."` to override the generated validation message.
These markers are intended for struct/type comments (`markers.DescribesType`).
### Replicating Gateway API policies in TrafficPolicy API
Gateway API policies may be replicated as a part of the TrafficPolicy API to enable policy attachment at different levels in the config hierarchy, such as at the Gateway, Gateway's listener, or route level. The following guidelines should be considered when doing so:
- When the Gateway API types are considered sufficient to meet the requirements, they can be embedded as is in the TrafficPolicy API. TrafficPolicy's `cors` is an example where the Gateway API type `HTTPCORSFilter` is embedded directly.
- When embedding the Gateway API type, it is important to consider whether the type is marked as `<gateway:experimental>`, as experimental types may introduce breaking changes and should be noted similarly in the TrafficPolicy API. It is discouraged to embed experimental types in the TrafficPolicy API. However, if there is a breaking change in the Gateway API type, it is recommended to replicate the previous version of that type into the TrafficPolicy API and not propagate the breaking change to the TrafficPolicy API.
- When the Gateway API types are not sufficient and a more advanced API is required, a new type should be created in the TrafficPolicy API instead of embedding the Gateway API type. TrafficPolicy's `retry` and `timeouts` are examples that define new types instead of reusing the `HTTPRouteRetry` and `HTTPRouteTimeouts` types from the Gateway API.

View File

@ -1,7 +1,4 @@
package annotations
// LegacyMCPServiceHTTPPath is the legacy annotation used to specify the HTTP path for the MCP service. Users should switch to MCPServiceHTTPPath.
const LegacyMCPServiceHTTPPath = "kgateway.dev/mcp-path"
// MCPServiceHTTPPath is the annotation used to specify the HTTP path for the MCP service
const MCPServiceHTTPPath = "agentgateway.dev/mcp-path"
const MCPServiceHTTPPath = "kgateway.dev/mcp-path"

View File

@ -9,6 +9,37 @@ import (
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
)
// ValidationMode determines how invalid routes and policies are handled during translation.
// Higher levels increase safety guarantees, but may have performance implications.
type ValidationMode string
const (
// ValidationStandard rewrites invalid routes to direct responses
// (typically HTTP 500), preserving a valid config while isolating failures.
// This limits the blast radius of misconfigured routes or policies without
// affecting unrelated tenants.
ValidationStandard ValidationMode = "STANDARD"
// ValidationStrict builds on standard by running targeted validation
// (e.g. RDS, CDS, and security-related policies). Routes that fail these
// checks are also replaced with direct responses, and helps prevent unsafe
// config from reaching Envoy.
// Strict Validation is not supported with Rustformation yet,
// see docs/guides/transformation.md for details
ValidationStrict ValidationMode = "STRICT"
)
// Decode implements envconfig.Decoder.
func (v *ValidationMode) Decode(value string) error {
level := ValidationMode(strings.ToUpper(value))
switch level {
case ValidationStandard, ValidationStrict:
*v = level
return nil
default:
return fmt.Errorf("invalid validation mode: %q", value)
}
}
// DnsLookupFamily controls the DNS lookup family for all static clusters created via Backend resources.
type DnsLookupFamily string
@ -127,19 +158,19 @@ type Settings struct {
// Defaults to "istio-system".
IstioNamespace string `split_words:"true" default:"istio-system"`
// IstioRevision is the Istio revision of the Istio control plane.
// Defaults to "default".
IstioRevision string `split_words:"true" default:"default"`
// XdsServiceHost is the host that serves xDS config.
// It overrides xdsServiceName if set.
XdsServiceHost string `split_words:"true"`
// XdsServiceName is the name of the Kubernetes Service that serves xDS config.
// It is assumed to be in the agentgateway install namespace.
// It is assumed to be in the kgateway install namespace.
// Ignored if XdsServiceHost is set.
XdsServiceName string `split_words:"true" default:"agentgateway"`
// XdsServicePort is the port of the Kubernetes Service that serves xDS config.
// This corresponds to the value of the `grpc-xds` port in the service.
XdsServicePort uint32 `split_words:"true" default:"9977"`
// XdsAuth enables or disables xDS authentication between the data-plane and control-plane.
// By default, this is enabled.
XdsAuth bool `split_words:"true" default:"true"`
@ -152,10 +183,6 @@ type Settings struct {
// This corresponds to the value of the `grpc-xds-agw` port in the service.
AgentgatewayXdsServicePort uint32 `split_words:"true" default:"9978"`
// NoListenersDummyPort is the port exposed on the generated Service when a Gateway has no listeners.
// This keeps the LoadBalancer provisioned and address stable across transitions to zero listeners.
NoListenersDummyPort uint16 `split_words:"true" default:"443"`
// EnableInferExt defines whether to enable/disable support for Gateway API inference extension.
// If enabled, EnableAgentgateway should also be set to true. Enabling inference extension without agentgateway
// is deprecated in v2.1 and will not be supported in v2.2.
@ -172,23 +199,14 @@ type Settings struct {
// Defaults to "info" if not set.
LogLevel string `split_words:"true" default:"info"`
// JSON representation of list of metav1.LabelSelector to select namespaces considered for resource discovery.
// Defaults to an empty list which selects all namespaces.
// E.g., [{"matchExpressions":[{"key":"kubernetes.io/metadata.name","operator":"In","values":["infra"]}]},{"matchLabels":{"app":"a"}}]
DiscoveryNamespaceSelectors string `split_words:"true" default:"[]"`
// EnableBuiltinDefaultMetrics enables the default builtin controller-runtime metrics and go runtime metrics.
// Since these metrics can be numerous, it is disabled by default.
EnableBuiltinDefaultMetrics bool `split_words:"true" default:"false"`
// GlobalPolicyNamespace is the namespace where policies that can attach to resources
// in any namespace are defined.
GlobalPolicyNamespace string `split_words:"true"`
// Controls if leader election is disabled. Defaults to false.
DisableLeaderElection bool `split_words:"true" default:"false"`
// EnableExperimentalGatewayAPIFeatures enables support for experimental features and APIs
// EnableExperimentalGatewayAPIFeatures enables kgateway to support experimental features and APIs
EnableExperimentalGatewayAPIFeatures bool `split_words:"true" default:"true"`
// GatewayClassParametersRefs configures the GatewayParameters references to set on the default GatewayClasses.

View File

@ -21,16 +21,13 @@ func allEnvVarsSet() map[string]string {
"AGW_DNS_LOOKUP_FAMILY": string(DnsLookupFamilyV4Only),
"AGW_LISTENER_BIND_IPV6": "false",
"AGW_ISTIO_NAMESPACE": "my-istio-namespace",
"AGW_ISTIO_REVISION": "my-istio-revision",
"AGW_XDS_SERVICE_HOST": "my-xds-host",
"AGW_XDS_SERVICE_NAME": "custom-svc",
"AGW_XDS_SERVICE_PORT": "1234",
"AGW_AGENTGATEWAY_XDS_SERVICE_PORT": "5678",
"AGW_NO_LISTENERS_DUMMY_PORT": "8443",
"AGW_ENABLE_INFER_EXT": "true",
"AGW_LOG_LEVEL": "debug",
"AGW_DISCOVERY_NAMESPACE_SELECTORS": `[{"matchLabels":{"app":"test"}}]`,
"AGW_ENABLE_BUILTIN_DEFAULT_METRICS": "true",
"AGW_GLOBAL_POLICY_NAMESPACE": "policy-ns",
"AGW_DISABLE_LEADER_ELECTION": "true",
"AGW_GATEWAY_CLASS_PARAMETERS_REFS": `{"kgateway":{"name":"custom-gwp","namespace":"infra"},"agentgateway":{"name":"custom-gwp-agw","namespace":"infra"}}`,
"AGW_XDS_AUTH": "false",
@ -65,16 +62,13 @@ func TestSettings(t *testing.T) {
DnsLookupFamily: DnsLookupFamilyV4Preferred,
ListenerBindIpv6: true,
IstioNamespace: "istio-system",
IstioRevision: "default",
XdsServiceHost: "",
XdsServiceName: "agentgateway",
XdsServicePort: 9977,
AgentgatewayXdsServicePort: 9978,
NoListenersDummyPort: 443,
EnableInferExt: false,
LogLevel: "info",
DiscoveryNamespaceSelectors: "[]",
EnableBuiltinDefaultMetrics: false,
GlobalPolicyNamespace: "",
DisableLeaderElection: false,
XdsAuth: true,
XdsTLS: false,
@ -93,16 +87,13 @@ func TestSettings(t *testing.T) {
DnsLookupFamily: DnsLookupFamilyV4Only,
ListenerBindIpv6: false,
IstioNamespace: "my-istio-namespace",
IstioRevision: "my-istio-revision",
XdsServiceHost: "my-xds-host",
XdsServiceName: "custom-svc",
XdsServicePort: 1234,
AgentgatewayXdsServicePort: 5678,
NoListenersDummyPort: 8443,
EnableInferExt: true,
LogLevel: "debug",
DiscoveryNamespaceSelectors: `[{"matchLabels":{"app":"test"}}]`,
EnableBuiltinDefaultMetrics: true,
GlobalPolicyNamespace: "policy-ns",
DisableLeaderElection: true,
XdsAuth: false,
XdsTLS: true,
@ -130,9 +121,9 @@ func TestSettings(t *testing.T) {
expectedErrorStr: "invalid syntax",
},
{
name: "errors on invalid bool",
name: "errors on invalid port",
envVars: map[string]string{
"AGW_LISTENER_BIND_IPV6": "true123",
"AGW_XDS_SERVICE_PORT": "a123",
},
expectedErrorStr: "invalid syntax",
},
@ -175,16 +166,10 @@ func TestSettings(t *testing.T) {
DnsLookupFamily: DnsLookupFamilyV4Preferred,
ListenerBindIpv6: true,
IstioNamespace: "istio-system",
IstioRevision: "default",
XdsServiceName: "agentgateway",
XdsServicePort: 9977,
AgentgatewayXdsServicePort: 9978,
EnableInferExt: false,
NoListenersDummyPort: 443,
LogLevel: "info",
DiscoveryNamespaceSelectors: "[]",
EnableBuiltinDefaultMetrics: false,
GlobalPolicyNamespace: "",
DisableLeaderElection: false,
XdsAuth: true,
XdsTLS: false,
EnableExperimentalGatewayAPIFeatures: true,

View File

@ -86,7 +86,7 @@ spec:
{{end}}
{{.policy|nindent 2}}
`
v := NewAgentgatewayValidator(t)
v := NewKgatewayValidator(t)
for _, tt := range cases {
for _, ref := range []bool{true, false} {
sn := "ref"

View File

@ -34,7 +34,7 @@ type TestExpectation struct {
}
func TestCRDs(t *testing.T) {
v := NewAgentgatewayValidator(t)
v := NewKgatewayValidator(t)
base := "testdata"
d, err := os.ReadDir(base)
if err != nil {

View File

@ -41,51 +41,6 @@ spec:
matchExpressions:
- 'true'
---
_err: unknown fields
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
name: mcp-static-target-authentication
spec:
mcp:
targets:
- name: target
static:
host: example.com
port: 443
policies:
mcp:
authentication:
issuer: https://issuer.example.com/
jwks:
backendRef:
name: jwks
port: 443
jwksPath: /.well-known/jwks.json
---
_err: path and pathPrefix are mutually exclusive
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
name: path-and-pathprefix
spec:
ai:
provider:
openai: {}
path: /custom/path
pathPrefix: /custom
---
_err: pathPrefix requires host to be set
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
name: pathprefix-without-host
spec:
ai:
provider:
openai: {}
pathPrefix: /custom
---
_err: both host and port must be set together
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
@ -95,47 +50,4 @@ spec:
ai:
provider:
openai: {}
host: example.com
---
_err: exactly one of the fields in [host backendRef] must be set
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
name: mcp-backend-ref-missing-port
spec:
mcp:
targets:
- name: bad-ref
static:
host: mcp.example.com
backendRef:
name: mcp-service
port: 8080
---
_err: exactly one of the fields in [host backendRef] must be set
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
name: mcp-backend-ref-no-target
spec:
mcp:
targets:
- name: bad-ref
static:
port: 8080
---
_err: mcp target policies may not be used with backendRef
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
name: mcp-backend-ref-with-policies
spec:
mcp:
targets:
- name: bad-ref
static:
backendRef:
name: mcp-service
port: 8080
policies:
tls: {}
host: example.com

View File

@ -63,20 +63,6 @@ kind: AgentgatewayBackend
metadata:
name: mcp-full
spec:
policies:
mcp:
authorization:
action: Deny
policy:
matchExpressions:
- 'mcp.tool.name == "hello"'
authentication:
issuer: https://issuer.example.com/
jwks:
backendRef:
name: jwks
port: 443
jwksPath: /.well-known/jwks.json
mcp:
targets:
- name: everything
@ -85,6 +71,12 @@ spec:
port: 443
policies:
tls: {}
mcp:
authorization:
action: Deny
policy:
matchExpressions:
- 'mcp.tool.name == "hello"'
- name: k8s
selector:
namespaces:
@ -132,36 +124,4 @@ spec:
model: ollama
host: localhost
port: 8443
path: /custom
---
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
name: mcp-require
spec:
mcp:
targets:
- name: everything
static:
host: example.com
port: 443
policies:
mcp:
authorization:
action: Require
policy:
matchExpressions:
- 'mcp.tool.name == "hello"'
---
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
name: mcp-backend-ref
spec:
mcp:
targets:
- name: local-svc
static:
backendRef:
name: mcp-service
port: 8080
path: /custom

View File

@ -247,39 +247,6 @@ spec:
expression: 'request.headers["x-user"]'
unit: Minutes
---
_err: 'failureMode: Unsupported value'
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: traffic-extauth-invalid-failure-mode
spec:
traffic:
extAuth:
backendRef:
name: auth-server
kind: Service
failureMode: IgnoreErrors
grpc: {}
---
_err: 'failureMode: Unsupported value'
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: traffic-ratelimit-global-invalid-failure-mode
spec:
traffic:
rateLimit:
global:
backendRef:
name: ratelimit-service
kind: Service
failureMode: IgnoreErrors
domain: example.com
descriptors:
- entries:
- name: user
expression: 'request.headers["x-user"]'
---
_err: 'phase: Unsupported value'
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
@ -294,21 +261,6 @@ spec:
- name: X-Test
value: '"test"'
---
_err: 'jwtAuthentication.mcp requires mode Strict'
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: traffic-jwt-mcp-nonstrict
spec:
traffic:
jwtAuthentication:
mode: Optional
providers:
- issuer: https://example.com
jwks:
inline: '{"keys":[]}'
mcp: {}
---
_err: 'pseudo-headers must be one of'
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
@ -335,30 +287,14 @@ spec:
kind: Service
protocol: TCP
---
_err: 'path is only valid with protocol HTTP'
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: traffic-tracing-path-with-grpc
spec:
frontend:
tracing:
backendRef:
name: otel-collector
kind: Service
port: 4317
protocol: GRPC
path: /v1/traces
---
_err: 'spec.traffic.hostRewrite.mode: Unsupported value'
_err: 'hostRewrite: Unsupported value'
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: traffic-hostrewrite-invalid
spec:
traffic:
hostRewrite:
mode: Custom
hostRewrite: Custom
---
_err: ' exactly one of the fields in [targetRefs targetSelectors] must be set'
apiVersion: agentgateway.dev/v1alpha1
@ -434,28 +370,6 @@ spec:
- field: a
value: b
---
_err: 'traffic.jwtAuthentication may not be used with backend.mcp.authentication in the same policy'
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: jwt-and-mcp-authentication
spec:
traffic:
jwtAuthentication:
providers:
- issuer: https://example.com
jwks:
inline: '{"keys":[]}'
backend:
mcp:
authentication:
issuer: https://example.com
jwks:
backendRef:
kind: Service
name: jwks
jwksPath: /.well-known/jwks.json
---
_err: "targetRefs may only"
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
@ -467,7 +381,7 @@ spec:
kind: Backend
name: dummy
---
_err: "the 'traffic.phase=PreRouting' field can only target a Gateway or ListenerSet"
_err: "the 'traffic.phase=PreRouting' field can only target a Gateway or XListenerSet"
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
@ -500,4 +414,4 @@ spec:
rateLimit:
local:
- requests: 100
unit: Minutes
unit: Minutes

View File

@ -308,7 +308,6 @@ spec:
name: auth-server
kind: AgentgatewayBackend
group: agentgateway.dev
failureMode: FailOpen
forwardBody:
maxSize: 1048576
---
@ -359,7 +358,6 @@ spec:
name: ratelimit-service
kind: Service
port: 8080
failureMode: FailOpen
domain: example.com
descriptors:
- entries:
@ -458,26 +456,6 @@ spec:
expression: 'request.headers["x-custom"]'
remove:
- http.method
---
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: traffic-tracing-http-path
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: dummy
frontend:
tracing:
backendRef:
name: otel-collector
kind: Service
port: 4318
protocol: HTTP
path: /custom/v1/traces
randomSampling: '0.1'
clientSampling: '1.0'
#---
#apiVersion: agentgateway.dev/v1alpha1
#kind: AgentgatewayPolicy
@ -660,4 +638,4 @@ spec:
unit: Minutes
- requests: 10
unit: Seconds
burst: 5
burst: 5

View File

@ -7,38 +7,16 @@ import (
"testing"
"istio.io/istio/pkg/config/crd"
"istio.io/istio/pkg/lazy"
"istio.io/istio/pkg/test/util/assert"
"github.com/agentgateway/agentgateway/controller/pkg/utils/fsutils"
)
var validator = lazy.New(func() (*crd.Validator, error) {
return newAgentgatewayValidator(false)
})
var validatorSkipMissing = lazy.New(func() (*crd.Validator, error) {
return newAgentgatewayValidator(true)
})
func NewAgentgatewayValidator(t *testing.T) *crd.Validator {
v, err := validator.Get()
assert.NoError(t, err)
return v
}
func NewAgentgatewayValidatorSkipMissing(t *testing.T) *crd.Validator {
v, err := validatorSkipMissing.Get()
assert.NoError(t, err)
return v
}
func newAgentgatewayValidator(skipMissing bool) (*crd.Validator, error) {
func NewKgatewayValidator(t *testing.T) *crd.Validator {
root := fsutils.GetModuleRoot()
dirs := []string{}
agentgatewayDir, err := os.ReadDir(filepath.Join(root, "controller/install/helm/agentgateway-crds/templates/"))
if err != nil {
return nil, err
}
assert.NoError(t, err)
for _, d := range agentgatewayDir {
if strings.HasSuffix(d.Name(), ".yaml") {
dirs = append(dirs, filepath.Join(root, "controller/install/helm/agentgateway-crds/templates", d.Name()))
@ -48,8 +26,7 @@ func newAgentgatewayValidator(skipMissing bool) (*crd.Validator, error) {
dirs...,
)
if err != nil {
return nil, err
t.Fatal(err)
}
v.SkipMissing = skipMissing
return v, nil
return v
}

View File

@ -1,7 +1,6 @@
package agentgateway
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
)
@ -14,8 +13,8 @@ import (
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:metadata:labels={app=agentgateway,app.kubernetes.io/name=agentgateway}
// +kubebuilder:resource:categories=agentgateway,shortName=agbe
// +kubebuilder:metadata:labels={app=kgateway,app.kubernetes.io/name=kgateway}
// +kubebuilder:resource:categories=kgateway,shortName=agbe
// +kubebuilder:subresource:status
type AgentgatewayBackend struct {
metav1.TypeMeta `json:",inline"`
@ -52,7 +51,7 @@ type AgentgatewayBackendList struct {
Items []AgentgatewayBackend `json:"items"`
}
// +kubebuilder:validation:ExactlyOneOf=ai;static;dynamicForwardProxy;mcp;aws
// +kubebuilder:validation:ExactlyOneOf=ai;static;dynamicForwardProxy;mcp
// +kubebuilder:validation:XValidation:rule="has(self.policies) && has(self.policies.ai) ? has(self.ai) : true",message="AI policies require AI backend"
// +kubebuilder:validation:XValidation:rule="has(self.policies) && has(self.policies.mcp) ? has(self.mcp) : true",message="MCP policies require MCP backend"
type AgentgatewayBackendSpec struct {
@ -76,10 +75,6 @@ type AgentgatewayBackendSpec struct {
// +optional
DynamicForwardProxy *DynamicForwardProxyBackend `json:"dynamicForwardProxy,omitempty"`
// aws represents an AWS service backend (AgentCore, etc.).
// +optional
Aws *AwsBackend `json:"aws,omitempty"`
// policies controls policies for communicating with this backend. Policies may also be set in AgentgatewayPolicy;
// policies are merged on a field-level basis, with policies on the Backend (this field) taking precedence.
// +optional
@ -89,24 +84,6 @@ type AgentgatewayBackendSpec struct {
type DynamicForwardProxyBackend struct {
}
// AwsBackend configures an AWS service backend.
// +kubebuilder:validation:ExactlyOneOf=agentCore
type AwsBackend struct {
// agentCore configures Amazon Bedrock AgentCore as a backend.
// +optional
AgentCore *AwsAgentCoreBackend `json:"agentCore,omitempty"`
}
// AwsAgentCoreBackend configures Amazon Bedrock AgentCore.
type AwsAgentCoreBackend struct {
// agentRuntimeArn is the ARN of the AgentCore runtime.
// +required
AgentRuntimeArn string `json:"agentRuntimeArn"`
// qualifier optionally specifies the alias or version qualifier.
// +optional
Qualifier *string `json:"qualifier,omitempty"`
}
type StaticBackend struct {
// host to connect to.
// +required
@ -121,37 +98,35 @@ type StaticBackend struct {
// AIBackend specifies the AI backend configuration
// +kubebuilder:validation:ExactlyOneOf=provider;groups
type AIBackend struct {
// `provider` specifies configuration for how to reach the configured LLM
// provider.
// provider specifies configuration for how to reach the configured LLM provider.
// +optional
LLM *LLMProvider `json:"provider,omitempty"`
// `groups` specifies a list of groups in priority order where each group
// defines a set of LLM providers. The priority determines the priority of
// the backend endpoints chosen.
// Note: provider names must be unique across all providers in all priority
// groups. Backend policies may target a specific provider by name using
// `targetRefs[].sectionName`.
// groups specifies a list of groups in priority order where each group defines
// a set of LLM providers. The priority determines the priority of the backend endpoints chosen.
// Note: provider names must be unique across all providers in all priority groups. Backend policies
// may target a specific provider by name using targetRefs[].sectionName.
//
// Example configuration with two priority groups:
//
// groups:
// - providers:
// - azureopenai:
// deploymentName: gpt-4o-mini
// apiVersion: 2024-02-15-preview
// endpoint: ai-gateway.openai.azure.com
// - providers:
// - azureopenai:
// deploymentName: gpt-4o-mini-2
// apiVersion: 2024-02-15-preview
// endpoint: ai-gateway-2.openai.azure.com
// policies:
// auth:
// secretRef:
// name: azure-secret
// ```yaml
// groups:
// - providers:
// - azureopenai:
// deploymentName: gpt-4o-mini
// apiVersion: 2024-02-15-preview
// endpoint: ai-gateway.openai.azure.com
// - providers:
// - azureopenai:
// deploymentName: gpt-4o-mini-2
// apiVersion: 2024-02-15-preview
// endpoint: ai-gateway-2.openai.azure.com
// policies:
// auth:
// secretRef:
// name: azure-secret
// ```
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=8
// +kubebuilder:validation:MaxItems=32
// +optional
// TODO: enable this rule when we don't need to support older k8s versions where this rule breaks // +kubebuilder:validation:XValidation:message="provider names must be unique across groups",rule="self.map(pg, pg.providers.map(pp, pp.name)).map(p, self.map(pg, pg.providers.map(pp, pp.name)).filter(cp, cp != p).exists(cp, p.exists(pn, pn in cp))).exists(p, !p)"
PriorityGroups []PriorityGroup `json:"groups,omitempty"`
@ -162,7 +137,7 @@ type PriorityGroup struct {
// with automatic weighting based on health.
//
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=16
// +kubebuilder:validation:MaxItems=32
// +kubebuilder:validation:XValidation:message="provider names must be unique within a group",rule="self.all(p1, self.exists_one(p2, p1.name == p2.name))"
// +required
Providers []NamedLLMProvider `json:"providers"`
@ -173,11 +148,9 @@ type NamedLLMProvider struct {
// +required
Name gwv1.SectionName `json:"name"`
// `policies` controls policies for communicating with this backend.
// Policies may also be set in `AgentgatewayPolicy`, or in the top-level
// `AgentgatewayBackend`. Policies are merged on a field-level basis, with
// order: `AgentgatewayPolicy` < `AgentgatewayBackend` < `AgentgatewayBackend`
// LLM provider (this field).
// policies controls policies for communicating with this backend. Policies may also be set in AgentgatewayPolicy, or
// in the top level AgentgatewayBackend. policies are merged on a field-level basis, with order: AgentgatewayPolicy <
// AgentgatewayBackend < AgentgatewayBackend LLM provider (this field).
// +optional
Policies *BackendWithAI `json:"policies,omitempty"`
@ -187,8 +160,6 @@ type NamedLLMProvider struct {
// LLMProvider specifies the target large language model provider that the backend should route requests to.
// +kubebuilder:validation:ExactlyOneOf=openai;azureopenai;anthropic;gemini;vertexai;bedrock
// +kubebuilder:validation:XValidation:rule="has(self.host) || has(self.port) ? has(self.host) && has(self.port) : true",message="both host and port must be set together"
// +kubebuilder:validation:XValidation:rule="!(has(self.path) && has(self.pathPrefix))",message="path and pathPrefix are mutually exclusive"
// +kubebuilder:validation:XValidation:rule="has(self.pathPrefix) ? has(self.host) : true",message="pathPrefix requires host to be set"
type LLMProvider struct {
// OpenAI provider
// +optional
@ -231,15 +202,9 @@ type LLMProvider struct {
// If not specified, the default path for the provider is used.
// +optional
Path LongString `json:"path,omitempty"`
// PathPrefix overrides the default base path prefix (e.g. "/v1") for upstream requests.
// Path translation for cross-format requests still applies using this prefix.
// Only supported for OpenAI and Anthropic providers.
// +optional
PathPrefix LongString `json:"pathPrefix,omitempty"`
}
// OpenAIConfig settings for the [OpenAI](https://developers.openai.com/api/docs/guides/streaming-responses) LLM provider.
// OpenAIConfig settings for the [OpenAI](https://platform.openai.com/docs/api-reference/streaming) LLM provider.
type OpenAIConfig struct {
// Optional: Override the model name, such as `gpt-4o-mini`.
// If unset, the model name is taken from the request.
@ -247,7 +212,7 @@ type OpenAIConfig struct {
Model *ShortString `json:"model,omitempty"`
}
// AzureOpenAIConfig settings for the [Azure OpenAI](https://learn.microsoft.com/en-us/azure/ai-foundry/?view=foundry-classic) LLM provider.
// AzureOpenAIConfig settings for the [Azure OpenAI](https://learn.microsoft.com/en-us/azure/ai-services/openai/) LLM provider.
// +kubebuilder:validation:XValidation:message="deploymentName is required for this apiVersion",rule="!has(self.apiVersion) || self.apiVersion == 'v1' ? true : has(self.deploymentName)"
type AzureOpenAIConfig struct {
// The endpoint for the Azure OpenAI API to use, such as `my-endpoint.openai.azure.com`.
@ -256,15 +221,14 @@ type AzureOpenAIConfig struct {
Endpoint ShortString `json:"endpoint"`
// The name of the Azure OpenAI model deployment to use.
// For more information, see the [Azure OpenAI model docs](https://learn.microsoft.com/en-us/azure/ai-foundry/foundry-models/concepts/models-sold-directly-by-azure?view=foundry-classic).
// This is required if `apiVersion` is not `v1`. For `v1`, the model can be
// set in the request.
// For more information, see the [Azure OpenAI model docs](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models).
// This is required if ApiVersion is not 'v1'. For v1, the model can be set in the request.
// +optional
DeploymentName *ShortString `json:"deploymentName,omitempty"`
// The version of the Azure OpenAI API to use.
// For more information, see the [Azure OpenAI API version reference](https://learn.microsoft.com/en-us/azure/ai-foundry/?view=foundry-classicreference#api-specs).
// If unset, defaults to `v1`.
// For more information, see the [Azure OpenAI API version reference](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#api-specs).
// If unset, defaults to "v1"
// +optional
ApiVersion *TinyString `json:"apiVersion,omitempty"`
}
@ -277,7 +241,7 @@ type GeminiConfig struct {
Model *ShortString `json:"model,omitempty"`
}
// VertexAIConfig settings for the [Vertex AI](https://docs.cloud.google.com/vertex-ai/docs) LLM provider.
// VertexAIConfig settings for the [Vertex AI](https://cloud.google.com/vertex-ai/docs) LLM provider.
type VertexAIConfig struct {
// Optional: Override the model name, such as `gpt-4o-mini`.
// If unset, the model name is taken from the request.
@ -289,13 +253,11 @@ type VertexAIConfig struct {
ProjectId TinyString `json:"projectId"`
// The location of the Google Cloud Project that you use for the Vertex AI.
// Defaults to `global` if not specified.
// +optional
// +kubebuilder:default=global
Region TinyString `json:"region,omitempty"`
// +required
Region TinyString `json:"region"`
}
// AnthropicConfig settings for the [Anthropic](https://platform.claude.com/docs/en/release-notes/overview) LLM provider.
// AnthropicConfig settings for the [Anthropic](https://docs.anthropic.com/en/release-notes/api) LLM provider.
type AnthropicConfig struct {
// Optional: Override the model name, such as `gpt-4o-mini`.
// If unset, the model name is taken from the request.
@ -305,7 +267,7 @@ type AnthropicConfig struct {
type BedrockConfig struct {
// Region is the AWS region to use for the backend.
// Defaults to `us-east-1` if not specified.
// Defaults to us-east-1 if not specified.
// +optional
// +kubebuilder:default=us-east-1
// +kubebuilder:validation:MinLength=1
@ -318,8 +280,7 @@ type BedrockConfig struct {
// +optional
Model *ShortString `json:"model,omitempty"`
// `guardrail` configures the Guardrail policy to use for the backend. See
// <https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails.html>.
// Guardrail configures the Guardrail policy to use for the backend. See <https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails.html>
// If not specified, the AWS Guardrail policy will not be used.
// +optional
Guardrail *AWSGuardrailConfig `json:"guardrail,omitempty"`
@ -335,12 +296,11 @@ type AWSGuardrailConfig struct {
GuardrailVersion ShortString `json:"version"`
}
// MCPBackend configures `mcp` backends.
// MCPBackend configures mcp backends
type MCPBackend struct {
// `targets` is a list of MCP targets to use for this backend. Policies
// targeting MCP targets must use `targetRefs[].sectionName` to select
// the target by name.
//
// Targets is a list of MCPBackend targets to use for this backend.
// Policies targeting MCPBackend targets must use targetRefs[].sectionName
// to select the target by name.
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MinItems=1
@ -349,52 +309,32 @@ type MCPBackend struct {
// +required
Targets []McpTargetSelector `json:"targets"`
// `sessionRouting` configures MCP session behavior for requests.
// Defaults to `Stateful` if not set.
// SessionRouting configures MCP session behavior for requests.
// Defaults to Stateful if not set.
// +optional
SessionRouting SessionRouting `json:"sessionRouting,omitempty"`
// `failureMode` controls behavior when MCP targets fail to initialize or
// become unavailable at runtime. `FailOpen` skips failed targets and
// continues serving from healthy ones. `FailClosed` (default) fails the
// entire session if any target fails.
// +optional
FailureMode FailureMode `json:"failureMode,omitempty"`
}
const (
// FailClosed fails the entire MCP session if any target fails.
FailClosed FailureMode = "FailClosed"
// FailOpen skips failed targets and continues serving from healthy ones.
FailOpen FailureMode = "FailOpen"
)
// +kubebuilder:validation:Enum=FailOpen;FailClosed
type FailureMode string
// McpTargetSelector defines the MCPBackend target to use for this backend.
// +kubebuilder:validation:ExactlyOneOf=selector;static
type McpTargetSelector struct {
// Name of the MCP target.
// Name of the MCPBackend target.
// +required
Name gwv1.SectionName `json:"name"`
// `selector` is the label selector used to select `Service` resources.
// If policies are needed on a per-service basis, `AgentgatewayPolicy` can
// target the desired `Service`.
// selector is a label selector is the selector to use to select Services.
// If policies are needed on a per-service basis, AgentgatewayPolicy can target the desired Service.
// +optional
Selector *McpSelector `json:"selector,omitempty"`
// `static` configures a static MCP destination. When connecting to
// in-cluster `Service` resources, it is recommended to use `selector`
// instead.
// static configures a static MCP destination. When connecting to in-cluster Services, it is recommended to use
// 'selector' instead.
// +optional
Static *McpTarget `json:"static,omitempty"`
}
const (
// `Stateful` mode creates an MCP session (via `mcp-session-id`) and
// internally
// Stateful mode creates an MCP session (via mcp-session-id) and internally
// ensures requests for that session are routed to a consistent backend replica.
Stateful SessionRouting = "Stateful"
Stateless SessionRouting = "Stateless"
@ -403,71 +343,55 @@ const (
// +kubebuilder:validation:Enum=Stateful;Stateless
type SessionRouting string
// +kubebuilder:validation:AtLeastOneFieldSet
// +kubebuilder:validation:AtLeastOneOf=namespaces;services
type McpSelector struct {
// `namespace` is the label selector for namespaces that `Service`
// resources should be selected from. If unset, only the namespace of the
// `AgentgatewayBackend` is searched.
// namespace is the label selector in which namespaces Services should be selected from.
// If unset, only the namespace of the AgentgatewayBackend is searched.
// +optional
Namespace *metav1.LabelSelector `json:"namespaces,omitempty"`
// `services` is the label selector for which `Service` resources should be
// selected.
// services is the label selector for which Services should be selected.
// +optional
Service *metav1.LabelSelector `json:"services,omitempty"`
}
// McpTarget defines a single MCPBackend target configuration.
// +kubebuilder:validation:ExactlyOneOf=host;backendRef
// +kubebuilder:validation:XValidation:rule="!has(self.backendRef) || !has(self.policies)",message="mcp target policies may not be used with backendRef"
type McpTarget struct {
// Host is the hostname or IP address of the MCP target.
// +optional
Host *ShortString `json:"host,omitempty"`
// Host is the hostname or IP address of the MCPBackend target.
// +required
Host ShortString `json:"host"`
// `backendRef` references a namespace-local `Service` resource by name.
// When set, this replaces `host` only; `port`, `path`, and `protocol`
// remain configured on this target.
// +optional
BackendRef *corev1.LocalObjectReference `json:"backendRef,omitempty"`
// Port is the port number of the MCP target.
// Port is the port number of the MCPBackend target.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
// +required
Port int32 `json:"port"`
// Path is the URL path of the MCP target endpoint.
// Defaults to `"/sse"` for the `SSE` protocol or `"/mcp"` for the
// `StreamableHTTP` protocol if not specified.
// Path is the URL path of the MCPBackend target endpoint.
// Defaults to "/sse" for SSE protocol or "/mcp" for StreamableHTTP protocol if not specified.
// +optional
Path *LongString `json:"path,omitempty"`
// Protocol is the protocol to use for the connection to the MCP
// target.
// Protocol is the protocol to use for the connection to the MCPBackend target.
// +optional
Protocol *MCPProtocol `json:"protocol,omitempty"`
// `policies` controls policies for communicating with this backend.
// Policies may also be set in `AgentgatewayPolicy`, or in the top-level
// `AgentgatewayBackend`. Policies are merged on a field-level basis, with
// order: `AgentgatewayPolicy` < `AgentgatewayBackend` < `AgentgatewayBackend` MCP (this field).
// This field may only be used with host-based static targets, not
// `backendRef`.
// policies controls policies for communicating with this backend. Policies may also be set in AgentgatewayPolicy, or
// in the top level AgentgatewayBackend. Policies are merged on a field-level basis, with order: AgentgatewayPolicy <
// AgentgatewayBackend < AgentgatewayBackend MCP (this field).
// +optional
Policies *BackendSimple `json:"policies,omitempty"`
Policies *BackendWithMCP `json:"policies,omitempty"`
}
// MCPProtocol defines the protocol to use for the `MCPBackend` target.
// MCPProtocol defines the protocol to use for the MCPBackend target
// +kubebuilder:validation:Enum=StreamableHTTP;SSE
type MCPProtocol string
const (
// MCPProtocolStreamableHTTP specifies that `StreamableHTTP` must be used as
// the protocol.
// MCPProtocolStreamableHTTP specifies Streamable HTTP must be used as the protocol
MCPProtocolStreamableHTTP MCPProtocol = "StreamableHTTP"
// MCPProtocolSSE specifies that Server-Sent Events (`SSE`) must be used as
// the protocol.
// MCPProtocolSSE specifies Server-Sent Events (SSE) must be used as the protocol
MCPProtocolSSE MCPProtocol = "SSE"
)

View File

@ -19,8 +19,8 @@ import (
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:metadata:labels={app=agentgateway,app.kubernetes.io/name=agentgateway}
// +kubebuilder:resource:categories=agentgateway,shortName=agpar,path=agentgatewayparameters
// +kubebuilder:metadata:labels={app=kgateway,app.kubernetes.io/name=kgateway}
// +kubebuilder:resource:categories=kgateway,shortName=agpar,path=agentgatewayparameters
// +kubebuilder:subresource:status
// +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=Direct"
type AgentgatewayParameters struct {
@ -64,9 +64,9 @@ const (
)
type AgentgatewayParametersLogging struct {
// Logging level in standard `RUST_LOG` syntax, for example `info` (the
// default), or a comma-separated per-module setting such as
// `rmcp=warn,hickory_server::server::server_future=off,typespec_client_core::http::policies::logging=warn`.
// Logging level in standard RUST_LOG syntax, e.g. 'info', the default, or
// by module, comma-separated. E.g.,
// "rmcp=warn,hickory_server::server::server_future=off,typespec_client_core::http::policies::logging=warn"
// +optional
Level string `json:"level,omitempty"`
// +optional
@ -74,16 +74,16 @@ type AgentgatewayParametersLogging struct {
}
type AgentgatewayParametersConfigs struct {
// `logging` configuration for Agentgateway. By default, all logs are set to
// `info` level.
// logging configuration for Agentgateway. By default, all logs are set to "info" level.
// +optional
Logging *AgentgatewayParametersLogging `json:"logging,omitempty"`
// `rawConfig` provides an opaque mechanism to configure the `agentgateway`
// config file. The `agentgateway` binary has a `-f` option to specify a
// config file, and this field supplies that file. This will be merged with
// configuration derived from typed fields like `logging.format`, and those
// typed fields will take precedence.
// rawConfig provides an opaque mechanism to configure the agentgateway
// config file (the agentgateway binary has a '-f' option to specify a
// config file, and this is that file). This will be merged with
// configuration derived from typed fields like
// AgentgatewayParametersLogging.Format, and those typed fields will take
// precedence.
//
// Example:
//
@ -95,11 +95,11 @@ type AgentgatewayParametersConfigs struct {
// - policies:
// cors:
// allowOrigins:
// - "*"
// - "*"
// allowHeaders:
// - mcp-protocol-version
// - content-type
// - cache-control
// - mcp-protocol-version
// - content-type
// - cache-control
// backends:
// - mcp:
// targets:
@ -129,17 +129,14 @@ type AgentgatewayParametersConfigs struct {
// The container environment variables. These override any existing
// values. If you want to delete an environment variable entirely, use
// `$patch: delete` with `AgentgatewayParametersOverlays` instead. Note that
// `$patch: delete` with AgentgatewayParametersOverlays instead. Note that
// [variable
// expansion](https://kubernetes.io/docs/tasks/inject-data-application/define-interdependent-environment-variables/)
// does apply, but is highly discouraged -- to set dependent environment
// variables, you can use `$(VAR_NAME)`, but it's highly discouraged.
// `$$(VAR_NAME)` avoids expansion and results in a literal
// variables, you can use $(VAR_NAME), but it's highly
// discouraged. `$$(VAR_NAME)` avoids expansion and results in a literal
// `$(VAR_NAME)`.
//
// If `SESSION_KEY` is specified, it takes precedence over the
// controller-managed per-`Gateway` session key `Secret`.
//
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`
@ -150,11 +147,10 @@ type AgentgatewayParametersConfigs struct {
// +optional
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
// Shutdown delay configuration. How graceful planned or unplanned data
// Shutdown delay configuration. How graceful planned or unplanned data
// plane changes happen is in tension with how quickly rollouts of the data
// plane complete. How long a data plane pod must wait for shutdown to be
// perfectly graceful depends on how you have configured your `Gateway`
// resources.
// perfectly graceful depends on how you have configured your Gateways.
//
// +optional
Shutdown *ShutdownSpec `json:"shutdown,omitempty"`
@ -179,8 +175,8 @@ type IstioSpec struct {
// +kubebuilder:validation:XValidation:rule="self.min <= self.max",message="The 'min' value must be less than or equal to the 'max' value."
type ShutdownSpec struct {
// Minimum time (in seconds) to wait before allowing Agentgateway to
// terminate. Refer to the `CONNECTION_MIN_TERMINATION_DEADLINE`
// environment variable for details.
// terminate. Refer to the CONNECTION_MIN_TERMINATION_DEADLINE environment
// variable for details.
//
// +required
// +kubebuilder:validation:Minimum=0
@ -188,8 +184,8 @@ type ShutdownSpec struct {
Min int64 `json:"min"`
// Maximum time (in seconds) to wait before allowing Agentgateway to
// terminate. Refer to the `TERMINATION_GRACE_PERIOD_SECONDS`
// environment variable for details.
// terminate. Refer to the TERMINATION_GRACE_PERIOD_SECONDS environment
// variable for details.
//
// +required
// +kubebuilder:validation:Minimum=0
@ -198,34 +194,29 @@ type ShutdownSpec struct {
}
type AgentgatewayParametersOverlays struct {
// `deployment` allows specifying overrides for the generated
// `Deployment` resource.
// deployment allows specifying overrides for the generated Deployment resource.
// +optional
Deployment *shared.KubernetesResourceOverlay `json:"deployment,omitempty"`
// `service` allows specifying overrides for the generated `Service`
// resource.
// service allows specifying overrides for the generated Service resource.
// +optional
Service *shared.KubernetesResourceOverlay `json:"service,omitempty"`
// `serviceAccount` allows specifying overrides for the generated
// `ServiceAccount` resource.
// serviceAccount allows specifying overrides for the generated ServiceAccount resource.
// +optional
ServiceAccount *shared.KubernetesResourceOverlay `json:"serviceAccount,omitempty"`
// `podDisruptionBudget` allows creating a `PodDisruptionBudget` for the
// agentgateway proxy. If absent, no PDB is created. If present, a PDB is
// created with its selector automatically configured to target the
// agentgateway proxy `Deployment`. The `metadata` and `spec` fields from
// this overlay are applied to the generated PDB.
// podDisruptionBudget allows creating a PodDisruptionBudget for the agentgateway proxy.
// If absent, no PDB is created. If present, a PDB is created with its selector
// automatically configured to target the agentgateway proxy Deployment.
// The metadata and spec fields from this overlay are applied to the generated PDB.
// +optional
PodDisruptionBudget *shared.KubernetesResourceOverlay `json:"podDisruptionBudget,omitempty"`
// `horizontalPodAutoscaler` allows creating a `HorizontalPodAutoscaler`
// for the agentgateway proxy. If absent, no HPA is created. If present, an
// HPA is created with its `scaleTargetRef` automatically configured to
// target the agentgateway proxy `Deployment`. The `metadata` and `spec`
// fields from this overlay are applied to the generated HPA.
// horizontalPodAutoscaler allows creating a HorizontalPodAutoscaler for the agentgateway proxy.
// If absent, no HPA is created. If present, an HPA is created with its scaleTargetRef
// automatically configured to target the agentgateway proxy Deployment.
// The metadata and spec fields from this overlay are applied to the generated HPA.
// +optional
HorizontalPodAutoscaler *shared.KubernetesResourceOverlay `json:"horizontalPodAutoscaler,omitempty"`
}

View File

@ -3,8 +3,6 @@ package agentgateway
import (
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
"github.com/agentgateway/agentgateway/controller/api/v1alpha1/shared"
)
// AIPromptEnrichment defines the config to enrich requests sent to the LLM provider by appending and prepending system prompts.
@ -12,18 +10,16 @@ import (
// Prompt enrichment allows you to add additional context to the prompt before sending it to the model.
// Unlike RAG or other dynamic context methods, prompt enrichment is static and is applied to every request.
//
// **Note**: Some providers, including Anthropic, do not support `SYSTEM`
// role messages, and instead have a dedicated `system` field in the input
// JSON. In this case, use the [`defaults` setting](#fielddefault) to set the
// `system` field.
// **Note**: Some providers, including Anthropic, do not support SYSTEM role messages, and instead have a dedicated
// system field in the input JSON. In this case, use the [`defaults` setting](#fielddefault) to set the system field.
//
// The following example prepends a system prompt of
// `Answer all questions in French.` and appends
// `Describe the painting as if you were a famous art critic from the 17th century.`
// to each request that is sent to the `openai` `HTTPRoute`.
// The following example prepends a system prompt of `Answer all questions in French.`
// and appends `Describe the painting as if you were a famous art critic from the 17th century.`
// to each request that is sent to the `openai` HTTPRoute.
// ```yaml
//
// name: openai-opt
// namespace: agentgateway-system
// namespace: kgateway-system
//
// spec:
//
@ -39,6 +35,8 @@ import (
// append:
// - role: USER
// content: "Describe the painting as if you were a famous art critic from the 17th century."
//
// ```
type AIPromptEnrichment struct {
// A list of messages to be prepended to the prompt sent by the client.
// +optional
@ -61,7 +59,7 @@ type Message struct {
Content string `json:"content"`
}
// Built-in regex patterns for specific types of strings in prompts.
// BuiltIn regex patterns for specific types of strings in prompts.
// For example, if you specify `CreditCard`, any credit card numbers
// in the request or response are matched.
// +kubebuilder:validation:Enum=Ssn;CreditCard;PhoneNumber;Email;CaSin
@ -85,8 +83,7 @@ const (
)
// Action to take if a regex pattern is matched in a request or response.
// This setting applies only to request matches. `PromptguardResponse`
// matches are always masked by default.
// This setting applies only to request matches. PromptguardResponse matches are always masked by default.
// +kubebuilder:validation:Enum=Mask;Reject
type Action string
@ -111,8 +108,7 @@ type Regex struct {
Builtins []BuiltIn `json:"builtins,omitempty"`
// The action to take if a regex pattern is matched in a request or response.
// This setting applies only to request matches. `PromptguardResponse`
// matches are always masked by default.
// This setting applies only to request matches. PromptguardResponse matches are always masked by default.
// Defaults to `Mask`.
// +kubebuilder:default=Mask
// +optional
@ -138,10 +134,10 @@ type Webhook struct {
// CustomResponse configures a response to return to the client if request content
// is matched against a regex pattern and the action is `REJECT`.
// +kubebuilder:validation:AtLeastOneFieldSet
// +kubebuilder:validation:AtLeastOneOf=message;statusCode
type CustomResponse struct {
// A custom response message to return to the client. If not specified, defaults to
// `The request was rejected due to inappropriate content`.
// "The request was rejected due to inappropriate content".
// +kubebuilder:default="The request was rejected due to inappropriate content"
// +optional
Message string `json:"message,omitempty"`
@ -155,12 +151,11 @@ type CustomResponse struct {
}
type OpenAIModeration struct {
// `model` specifies the moderation model to use. For example,
// `omni-moderation`.
// model specifies the moderation model to use. For example, `omni-moderation`.
// +optional
Model *string `json:"model,omitempty"`
// policies controls policies for communicating with OpenAI.
// +kubebuilder:validation:AtLeastOneFieldSet
// +kubebuilder:validation:AtLeastOneOf=tcp;tls;http;auth
// +optional
Policies *BackendSimple `json:"policies,omitempty"`
}
@ -174,13 +169,12 @@ type BedrockGuardrails struct {
// +required
GuardrailVersion ShortString `json:"version"`
// Region is the AWS region where the guardrail is deployed (for example,
// `us-west-2`).
// Region is the AWS region where the guardrail is deployed (e.g., "us-west-2").
// +required
Region ShortString `json:"region"`
// policies controls policies for communicating with AWS Bedrock Guardrails.
// +kubebuilder:validation:AtLeastOneFieldSet
// +kubebuilder:validation:AtLeastOneOf=tcp;tls;http;auth
// +optional
Policies *BackendSimple `json:"policies,omitempty"`
}
@ -194,14 +188,14 @@ type GoogleModelArmor struct {
// +required
ProjectID ShortString `json:"projectId"`
// Location is the Google Cloud location (for example, `us-central1`).
// Defaults to `us-central1` if not specified.
// Location is the Google Cloud location (e.g., "us-central1").
// Defaults to "us-central1" if not specified.
// +kubebuilder:default="us-central1"
// +optional
Location *ShortString `json:"location,omitempty"`
// policies controls policies for communicating with Google Model Armor.
// +kubebuilder:validation:AtLeastOneFieldSet
// +kubebuilder:validation:AtLeastOneOf=tcp;tls;http;auth
// +optional
Policies *BackendSimple `json:"policies,omitempty"`
}
@ -210,7 +204,7 @@ type GoogleModelArmor struct {
// +kubebuilder:validation:ExactlyOneOf=regex;webhook;openAIModeration;bedrockGuardrails;googleModelArmor
type PromptguardRequest struct {
// A custom response message to return to the client. If not specified, defaults to
// `The request was rejected due to inappropriate content`.
// "The request was rejected due to inappropriate content".
// +optional
CustomResponse *CustomResponse `json:"response,omitempty"`
@ -222,18 +216,16 @@ type PromptguardRequest struct {
// +optional
Webhook *Webhook `json:"webhook,omitempty"`
// `openAIModeration` passes prompt data through the OpenAI Moderations
// endpoint.
// See https://developers.openai.com/api/reference/resources/moderations for more information.
// openAIModeration passes prompt data through the OpenAI Moderations endpoint.
// See https://platform.openai.com/docs/api-reference/moderations for more information.
// +optional
OpenAIModeration *OpenAIModeration `json:"openAIModeration,omitempty"`
// `bedrockGuardrails` configures AWS Bedrock Guardrails for prompt
// guarding.
// bedrockGuardrails configures AWS Bedrock Guardrails for prompt guarding.
// +optional
BedrockGuardrails *BedrockGuardrails `json:"bedrockGuardrails,omitempty"`
// `googleModelArmor` configures Google Model Armor for prompt guarding.
// googleModelArmor configures Google Model Armor for prompt guarding.
// +optional
GoogleModelArmor *GoogleModelArmor `json:"googleModelArmor,omitempty"`
}
@ -242,7 +234,7 @@ type PromptguardRequest struct {
// +kubebuilder:validation:ExactlyOneOf=regex;webhook;bedrockGuardrails;googleModelArmor
type PromptguardResponse struct {
// A custom response message to return to the client. If not specified, defaults to
// `The response was rejected due to inappropriate content`.
// "The response was rejected due to inappropriate content".
// +optional
CustomResponse *CustomResponse `json:"response,omitempty"`
@ -254,12 +246,11 @@ type PromptguardResponse struct {
// +optional
Webhook *Webhook `json:"webhook,omitempty"`
// `bedrockGuardrails` configures AWS Bedrock Guardrails for prompt
// guarding.
// bedrockGuardrails configures AWS Bedrock Guardrails for prompt guarding.
// +optional
BedrockGuardrails *BedrockGuardrails `json:"bedrockGuardrails,omitempty"`
// `googleModelArmor` configures Google Model Armor for prompt guarding.
// googleModelArmor configures Google Model Armor for prompt guarding.
// +optional
GoogleModelArmor *GoogleModelArmor `json:"googleModelArmor,omitempty"`
}
@ -270,23 +261,25 @@ type PromptguardResponse struct {
//
// This example rejects any request prompts that contain
// the string "credit card", and masks any credit card numbers in the response.
// ```yaml
// promptGuard:
//
// promptGuard:
// request:
// - response:
// message: "Rejected due to inappropriate content"
// regex:
// action: REJECT
// matches:
// - pattern: "credit card"
// name: "CC"
// response:
// - regex:
// builtins:
// - CREDIT_CARD
// action: MASK
// request:
// - response:
// message: "Rejected due to inappropriate content"
// regex:
// action: REJECT
// matches:
// - pattern: "credit card"
// name: "CC"
// response:
// - regex:
// builtins:
// - CREDIT_CARD
// action: MASK
//
// +kubebuilder:validation:AtLeastOneFieldSet
// ```
// +kubebuilder:validation:AtLeastOneOf=request;response
type AIPromptGuard struct {
// Prompt guards to apply to requests sent by the client.
// +kubebuilder:validation:MinItems=1
@ -308,29 +301,35 @@ type AIPromptGuard struct {
// Defaults set here do _not_ override those user-provided values unless you explicitly set `override` to `true`.
//
// Example: Setting a default system field for Anthropic, which does not support system role messages:
// ```yaml
// defaults:
// - field: "system"
// value: "answer all questions in French"
//
// defaults:
// - field: "system"
// value: "answer all questions in French"
// ```
//
// Example: Setting a default temperature and overriding `max_tokens`:
// ```yaml
// defaults:
// - field: "temperature"
// value: "0.5"
// - field: "max_tokens"
// value: "100"
// override: true
//
// defaults:
// - field: "temperature"
// value: "0.5"
// - field: "max_tokens"
// value: "100"
// override: true
// ```
//
// Example: Setting custom lists fields:
// ```yaml
// defaults:
// - field: "custom_integer_list"
// value: [1,2,3]
//
// defaults:
// - field: "custom_integer_list"
// value: [1,2,3]
// overrides:
// - field: "custom_string_list"
// value: ["one","two","three"]
//
// overrides:
// - field: "custom_string_list"
// value: ["one","two","three"]
// ```
//
// Note: The `field` values correspond to keys in the JSON request body, not fields in this CRD.
type FieldDefault struct {
@ -345,20 +344,6 @@ type FieldDefault struct {
Value apiextensionsv1.JSON `json:"value"`
}
// FieldTransformation maps a request JSON field to a CEL expression string.
// The expression is evaluated against the current request body and its result
// is assigned to the configured field.
type FieldTransformation struct {
// The name of the field to set.
// +kubebuilder:validation:MinLength=1
// +required
Field ShortString `json:"field"`
// CEL expression used to compute the field value.
// +required
Expression shared.CELExpression `json:"expression"`
}
// PromptCachingConfig configures automatic prompt caching for supported LLM providers.
// Currently only AWS Bedrock supports this feature (Claude 3+ and Nova models).
//
@ -368,9 +353,10 @@ type FieldTransformation struct {
// Example:
//
// promptCaching:
// cacheSystem: true
// cacheMessages: true
// cacheTools: false
// cacheSystem: true # Cache system prompts
// cacheMessages: true # Cache conversation history
// cacheTools: false # Don't cache tool definitions
// minTokens: 1024 # Only cache if ≥1024 tokens
//
// Cost savings example:
// - Without caching: 10,000 tokens × $3/MTok = $0.03
@ -401,13 +387,4 @@ type PromptCachingConfig struct {
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=1024
MinTokens int `json:"minTokens,omitempty"`
// CacheMessageOffset shifts the message cache point further back in the
// conversation. 0 (default) places it at the second-to-last message.
// Higher values move it N additional messages towards the start, clamped
// to bounds.
// +optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=0
CacheMessageOffset int `json:"cacheMessageOffset,omitempty"`
}

View File

@ -3,3 +3,44 @@
// +groupName=agentgateway.dev
// +versionName=v1alpha1
package agentgateway
// Gateway API resources with status management
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses;gateways;httproutes;grpcroutes;tcproutes;tlsroutes;referencegrants;backendtlspolicies,verbs=get;list;watch
// +kubebuilder:rbac:groups=gateway.networking.x-k8s.io,resources=xlistenersets,verbs=get;list;watch
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses/status;gateways/status;httproutes/status;grpcroutes/status;tcproutes/status;tlsroutes/status;backendtlspolicies/status,verbs=patch;update
// +kubebuilder:rbac:groups=gateway.networking.x-k8s.io,resources=xlistenersets/status,verbs=patch;update
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses,verbs=create;patch;update
// Controller resources
// +kubebuilder:rbac:groups="",resources=pods,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=nodes,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=endpoints,verbs=get;list;watch
// jwks store controller that require extra permissions
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch;create;patch;update;delete
// Proxy deployer resources that require extra permissions
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;patch;update;delete
// +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;patch;update;delete
// +kubebuilder:rbac:groups="",resources=secrets;serviceaccounts,verbs=get;list;watch;create;patch;delete
// +kubebuilder:rbac:groups="",resources=serviceaccounts,verbs=get;list;watch;create;patch;delete
// +kubebuilder:rbac:groups=policy,resources=poddisruptionbudgets,verbs=get;list;watch;create;patch;update;delete
// +kubebuilder:rbac:groups=autoscaling,resources=horizontalpodautoscalers,verbs=get;list;watch;create;patch;update;delete
// EDS discovery resources
// +kubebuilder:rbac:groups=discovery.k8s.io,resources=endpointslices,verbs=get;list;watch
// CRD access for scheme registration
// +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get;list;watch
// Istio resources for traffic management
// +kubebuilder:rbac:groups=networking.istio.io,resources=destinationrules,verbs=get;list;watch
// +kubebuilder:rbac:groups=networking.istio.io,resources=serviceentries,verbs=get;list;watch
// +kubebuilder:rbac:groups=networking.istio.io,resources=workloadentries,verbs=get;list;watch
// +kubebuilder:rbac:groups=security.istio.io,resources=authorizationpolicies,verbs=get;list;watch
// Leases for leader election
// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;create;update
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch

View File

@ -147,11 +147,6 @@ func (in *AccessLog) DeepCopyInto(out *AccessLog) {
*out = new(LogTracingAttributes)
(*in).DeepCopyInto(*out)
}
if in.Otlp != nil {
in, out := &in.Otlp, &out.Otlp
*out = new(OtlpAccessLog)
(*in).DeepCopyInto(*out)
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AccessLog.
@ -324,11 +319,6 @@ func (in *AgentgatewayBackendSpec) DeepCopyInto(out *AgentgatewayBackendSpec) {
*out = new(DynamicForwardProxyBackend)
**out = **in
}
if in.Aws != nil {
in, out := &in.Aws, &out.Aws
*out = new(AwsBackend)
(*in).DeepCopyInto(*out)
}
if in.Policies != nil {
in, out := &in.Policies, &out.Policies
*out = new(BackendFull)
@ -704,26 +694,6 @@ func (in *AttributeAdd) DeepCopy() *AttributeAdd {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AwsAgentCoreBackend) DeepCopyInto(out *AwsAgentCoreBackend) {
*out = *in
if in.Qualifier != nil {
in, out := &in.Qualifier, &out.Qualifier
*out = new(string)
**out = **in
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AwsAgentCoreBackend.
func (in *AwsAgentCoreBackend) DeepCopy() *AwsAgentCoreBackend {
if in == nil {
return nil
}
out := new(AwsAgentCoreBackend)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AwsAuth) DeepCopyInto(out *AwsAuth) {
*out = *in
@ -740,62 +710,6 @@ func (in *AwsAuth) DeepCopy() *AwsAuth {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AwsBackend) DeepCopyInto(out *AwsBackend) {
*out = *in
if in.AgentCore != nil {
in, out := &in.AgentCore, &out.AgentCore
*out = new(AwsAgentCoreBackend)
(*in).DeepCopyInto(*out)
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AwsBackend.
func (in *AwsBackend) DeepCopy() *AwsBackend {
if in == nil {
return nil
}
out := new(AwsBackend)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AzureAuth) DeepCopyInto(out *AzureAuth) {
*out = *in
out.SecretRef = in.SecretRef
if in.ManagedIdentity != nil {
in, out := &in.ManagedIdentity, &out.ManagedIdentity
*out = new(AzureManagedIdentity)
**out = **in
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzureAuth.
func (in *AzureAuth) DeepCopy() *AzureAuth {
if in == nil {
return nil
}
out := new(AzureAuth)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AzureManagedIdentity) DeepCopyInto(out *AzureManagedIdentity) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzureManagedIdentity.
func (in *AzureManagedIdentity) DeepCopy() *AzureManagedIdentity {
if in == nil {
return nil
}
out := new(AzureManagedIdentity)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AzureOpenAIConfig) DeepCopyInto(out *AzureOpenAIConfig) {
*out = *in
@ -848,13 +762,6 @@ func (in *BackendAI) DeepCopyInto(out *BackendAI) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.Transformations != nil {
in, out := &in.Transformations, &out.Transformations
*out = make([]FieldTransformation, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.ModelAliases != nil {
in, out := &in.ModelAliases, &out.ModelAliases
*out = make(map[string]string, len(*in))
@ -909,11 +816,6 @@ func (in *BackendAuth) DeepCopyInto(out *BackendAuth) {
*out = new(AwsAuth)
**out = **in
}
if in.Azure != nil {
in, out := &in.Azure, &out.Azure
*out = new(AzureAuth)
(*in).DeepCopyInto(*out)
}
if in.GCP != nil {
in, out := &in.GCP, &out.GCP
*out = new(GcpAuth)
@ -946,41 +848,6 @@ func (in *BackendAuthPassthrough) DeepCopy() *BackendAuthPassthrough {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *BackendEviction) DeepCopyInto(out *BackendEviction) {
*out = *in
if in.Duration != nil {
in, out := &in.Duration, &out.Duration
*out = new(v1.Duration)
**out = **in
}
if in.RestoreHealth != nil {
in, out := &in.RestoreHealth, &out.RestoreHealth
*out = new(int32)
**out = **in
}
if in.ConsecutiveFailures != nil {
in, out := &in.ConsecutiveFailures, &out.ConsecutiveFailures
*out = new(int32)
**out = **in
}
if in.HealthThreshold != nil {
in, out := &in.HealthThreshold, &out.HealthThreshold
*out = new(int32)
**out = **in
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BackendEviction.
func (in *BackendEviction) DeepCopy() *BackendEviction {
if in == nil {
return nil
}
out := new(BackendEviction)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *BackendFull) DeepCopyInto(out *BackendFull) {
*out = *in
@ -1075,26 +942,11 @@ func (in *BackendSimple) DeepCopyInto(out *BackendSimple) {
*out = new(BackendHTTP)
(*in).DeepCopyInto(*out)
}
if in.Tunnel != nil {
in, out := &in.Tunnel, &out.Tunnel
*out = new(BackendTunnel)
(*in).DeepCopyInto(*out)
}
if in.Transformation != nil {
in, out := &in.Transformation, &out.Transformation
*out = new(Transformation)
(*in).DeepCopyInto(*out)
}
if in.Auth != nil {
in, out := &in.Auth, &out.Auth
*out = new(BackendAuth)
(*in).DeepCopyInto(*out)
}
if in.Health != nil {
in, out := &in.Health, &out.Health
*out = new(Health)
(*in).DeepCopyInto(*out)
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BackendSimple.
@ -1181,22 +1033,6 @@ func (in *BackendTLS) DeepCopy() *BackendTLS {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *BackendTunnel) DeepCopyInto(out *BackendTunnel) {
*out = *in
in.BackendRef.DeepCopyInto(&out.BackendRef)
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BackendTunnel.
func (in *BackendTunnel) DeepCopy() *BackendTunnel {
if in == nil {
return nil
}
out := new(BackendTunnel)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *BackendWithAI) DeepCopyInto(out *BackendWithAI) {
*out = *in
@ -1218,6 +1054,27 @@ func (in *BackendWithAI) DeepCopy() *BackendWithAI {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *BackendWithMCP) DeepCopyInto(out *BackendWithMCP) {
*out = *in
in.BackendSimple.DeepCopyInto(&out.BackendSimple)
if in.MCP != nil {
in, out := &in.MCP, &out.MCP
*out = new(BackendMCP)
(*in).DeepCopyInto(*out)
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BackendWithMCP.
func (in *BackendWithMCP) DeepCopy() *BackendWithMCP {
if in == nil {
return nil
}
out := new(BackendWithMCP)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *BasicAuthentication) DeepCopyInto(out *BasicAuthentication) {
*out = *in
@ -1461,21 +1318,6 @@ func (in *FieldDefault) DeepCopy() *FieldDefault {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *FieldTransformation) DeepCopyInto(out *FieldTransformation) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FieldTransformation.
func (in *FieldTransformation) DeepCopy() *FieldTransformation {
if in == nil {
return nil
}
out := new(FieldTransformation)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Frontend) DeepCopyInto(out *Frontend) {
*out = *in
@ -1484,11 +1326,6 @@ func (in *Frontend) DeepCopyInto(out *Frontend) {
*out = new(FrontendTCP)
(*in).DeepCopyInto(*out)
}
if in.NetworkAuthorization != nil {
in, out := &in.NetworkAuthorization, &out.NetworkAuthorization
*out = new(shared.Authorization)
(*in).DeepCopyInto(*out)
}
if in.TLS != nil {
in, out := &in.TLS, &out.TLS
*out = new(FrontendTLS)
@ -1748,31 +1585,6 @@ func (in *HeaderTransformation) DeepCopy() *HeaderTransformation {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Health) DeepCopyInto(out *Health) {
*out = *in
if in.UnhealthyCondition != nil {
in, out := &in.UnhealthyCondition, &out.UnhealthyCondition
*out = new(shared.CELExpression)
**out = **in
}
if in.Eviction != nil {
in, out := &in.Eviction, &out.Eviction
*out = new(BackendEviction)
(*in).DeepCopyInto(*out)
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Health.
func (in *Health) DeepCopy() *Health {
if in == nil {
return nil
}
out := new(Health)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *HostnameRewrite) DeepCopyInto(out *HostnameRewrite) {
*out = *in
@ -1878,11 +1690,6 @@ func (in *JWTAuthentication) DeepCopyInto(out *JWTAuthentication) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.MCP != nil {
in, out := &in.MCP, &out.MCP
*out = new(JWTMCPConfig)
(*in).DeepCopyInto(*out)
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JWTAuthentication.
@ -1895,33 +1702,6 @@ func (in *JWTAuthentication) DeepCopy() *JWTAuthentication {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *JWTMCPConfig) DeepCopyInto(out *JWTMCPConfig) {
*out = *in
if in.ResourceMetadata != nil {
in, out := &in.ResourceMetadata, &out.ResourceMetadata
*out = make(map[string]apiextensionsv1.JSON, len(*in))
for key, val := range *in {
(*out)[key] = *val.DeepCopy()
}
}
if in.Provider != nil {
in, out := &in.Provider, &out.Provider
*out = new(McpIDP)
**out = **in
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JWTMCPConfig.
func (in *JWTMCPConfig) DeepCopy() *JWTMCPConfig {
if in == nil {
return nil
}
out := new(JWTMCPConfig)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *JWTProvider) DeepCopyInto(out *JWTProvider) {
*out = *in
@ -2158,16 +1938,6 @@ func (in *McpSelector) DeepCopy() *McpSelector {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *McpTarget) DeepCopyInto(out *McpTarget) {
*out = *in
if in.Host != nil {
in, out := &in.Host, &out.Host
*out = new(ShortString)
**out = **in
}
if in.BackendRef != nil {
in, out := &in.BackendRef, &out.BackendRef
*out = new(corev1.LocalObjectReference)
**out = **in
}
if in.Path != nil {
in, out := &in.Path, &out.Path
*out = new(LongString)
@ -2180,7 +1950,7 @@ func (in *McpTarget) DeepCopyInto(out *McpTarget) {
}
if in.Policies != nil {
in, out := &in.Policies, &out.Policies
*out = new(BackendSimple)
*out = new(BackendWithMCP)
(*in).DeepCopyInto(*out)
}
}
@ -2301,27 +2071,6 @@ func (in *OpenAIModeration) DeepCopy() *OpenAIModeration {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *OtlpAccessLog) DeepCopyInto(out *OtlpAccessLog) {
*out = *in
in.BackendRef.DeepCopyInto(&out.BackendRef)
if in.Path != nil {
in, out := &in.Path, &out.Path
*out = new(LongString)
**out = **in
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OtlpAccessLog.
func (in *OtlpAccessLog) DeepCopy() *OtlpAccessLog {
if in == nil {
return nil
}
out := new(OtlpAccessLog)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *PriorityGroup) DeepCopyInto(out *PriorityGroup) {
*out = *in
@ -2675,11 +2424,6 @@ func (in *Timeouts) DeepCopy() *Timeouts {
func (in *Tracing) DeepCopyInto(out *Tracing) {
*out = *in
in.BackendRef.DeepCopyInto(&out.BackendRef)
if in.Path != nil {
in, out := &in.Path, &out.Path
*out = new(LongString)
**out = **in
}
if in.Attributes != nil {
in, out := &in.Attributes, &out.Attributes
*out = new(LogTracingAttributes)
@ -2832,13 +2576,6 @@ func (in *Transform) DeepCopyInto(out *Transform) {
*out = new(shared.CELExpression)
**out = **in
}
if in.Metadata != nil {
in, out := &in.Metadata, &out.Metadata
*out = make(map[string]shared.CELExpression, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Transform.

View File

@ -29,36 +29,34 @@ type ObjectMetadata struct {
// Overlays are applied **after** all typed configuration fields have been processed.
// The full merge order is:
//
// 1. `GatewayClass` typed configuration fields, for example replicas or image settings from `parametersRef`
// 2. `Gateway` typed configuration fields from `infrastructure.parametersRef`
// 3. `GatewayClass` overlays are applied
// 4. `Gateway` overlays are applied
// 1. GatewayClass typed configuration fields (e.g., replicas, image settings from parametersRef)
// 2. Gateway typed configuration fields (from infrastructure.parametersRef)
// 3. GatewayClass overlays are applied
// 4. Gateway overlays are applied
//
// This ordering means `Gateway`-level configuration overrides
// `GatewayClass`-level configuration
// This ordering means Gateway-level configuration overrides GatewayClass-level configuration
// at each stage. For example, if both levels set the same label, the Gateway value wins.
type KubernetesResourceOverlay struct {
// `metadata` defines a subset of object metadata to be customized.
// `labels` and `annotations` are merged with existing values. If both
// `GatewayClass` and `Gateway` parameters define the same label or
// annotation key, the `Gateway` value takes precedence (applied second).
// metadata defines a subset of object metadata to be customized.
// Labels and annotations are merged with existing values. If both GatewayClass
// and Gateway parameters define the same label or annotation key, the Gateway
// value takes precedence (applied second).
// +optional
Metadata *ObjectMetadata `json:"metadata,omitempty"`
// `spec` provides an opaque mechanism to configure the resource spec.
// This field accepts a complete or partial Kubernetes resource spec, such
// as `PodSpec` or `ServiceSpec`, and will be merged with the generated
// configuration using **Strategic Merge Patch** semantics.
// Spec provides an opaque mechanism to configure the resource Spec.
// This field accepts a complete or partial Kubernetes resource spec (e.g., PodSpec, ServiceSpec)
// and will be merged with the generated configuration using **Strategic Merge Patch** semantics.
//
// # Application Order
//
// Overlays are applied after all typed configuration fields from both levels.
// The full merge order is:
//
// 1. `GatewayClass` typed configuration fields
// 2. `Gateway` typed configuration fields
// 3. `GatewayClass` overlays
// 4. `Gateway` overlays (can override all previous values)
// 1. GatewayClass typed configuration fields
// 2. Gateway typed configuration fields
// 3. GatewayClass overlays
// 4. Gateway overlays (can override all previous values)
//
// # Strategic Merge Patch & Deletion Guide
//
@ -69,8 +67,7 @@ type KubernetesResourceOverlay struct {
// Simple fields (strings, integers, booleans) in your config will overwrite the generated defaults.
//
// **2. Merging Lists (Append/Merge):**
// Lists with "merge keys", like `containers` which merges on `name`, or
// `tolerations` which merges on `key`,
// Lists with "merge keys" (like `containers` which merges on `name`, or `tolerations` which merges on `key`)
// will append your items to the generated list, or update existing items if keys match.
//
// **3. Deleting Fields or List Items ($patch: delete):**
@ -79,7 +76,6 @@ type KubernetesResourceOverlay struct {
// and is the recommended approach because it works with both client-side
// and server-side apply.
//
//
// spec:
// template:
// spec:
@ -90,12 +86,11 @@ type KubernetesResourceOverlay struct {
// nodeSelector:
// $patch: delete
// containers:
// # Be sure to use the correct proxy name here or you will add a
// # container instead of modifying a container.
// - name: proxy-name
// # Delete container-level securityContext
// securityContext:
// $patch: delete
// # Be sure to use the correct proxy name here or you will add a container instead of modifying a container:
// - name: proxy-name
// # Delete container-level securityContext
// securityContext:
// $patch: delete
//
// **4. Null Values (server-side apply only):**
// Setting a field to `null` can also remove it, but this ONLY works with
@ -104,7 +99,6 @@ type KubernetesResourceOverlay struct {
// the API server, so the deletion won't occur. Prefer `$patch: delete`
// for consistent behavior across both apply modes.
//
//
// spec:
// template:
// spec:
@ -114,7 +108,6 @@ type KubernetesResourceOverlay struct {
// To replace an entire map with your values (instead of merging), use `$patch: replace`.
// This removes all existing keys and replaces them with only your specified keys.
//
//
// spec:
// template:
// spec:
@ -125,19 +118,18 @@ type KubernetesResourceOverlay struct {
// **6. Replacing Lists Entirely ($patch: replace):**
// If you want to strictly define a list and ignore all generated defaults, use `$patch: replace`.
//
//
// service:
// spec:
// ports:
// - $patch: replace
// - name: http
// port: 80
// targetPort: 8080
// protocol: TCP
// - name: https
// port: 443
// targetPort: 8443
// protocol: TCP
// - $patch: replace
// - name: http
// port: 80
// targetPort: 8080
// protocol: TCP
// - name: https
// port: 443
// targetPort: 8443
// protocol: TCP
//
// +optional
// +kubebuilder:validation:Type=object

View File

@ -1,7 +1,7 @@
package shared
// PolicyConditionType is a type of condition for a policy. This type should be
// used with a Policy resource `Status.Conditions` field.
// used with a Policy resource Status.Conditions field.
type PolicyConditionType string
// PolicyConditionReason is a reason for a policy condition.
@ -10,47 +10,44 @@ type PolicyConditionReason string
const (
// PolicyConditionAccepted indicates whether the policy has been accepted or rejected, and why.
//
// Possible reasons for this condition to be `True` are:
// * `Valid`
// Possible reasons for this condition to be True are:
// * Valid
//
// Possible reasons for this condition to be `False` are:
// * `Pending`
// * `Invalid`
// Possible reasons for this condition to be False are:
// * Pending
// * Invalid
//
PolicyConditionAccepted PolicyConditionType = "Accepted"
// PolicyConditionAttached indicates whether the policy has attached to the targeted resources.
//
// Possible reasons for this condition to be `True` are:
// * `Attached`
// * `Merged`
// Possible reasons for this condition to be True are:
// * Attached
// * Merged
//
// Possible reasons for this condition to be `False` are:
// * `Pending`
// * `Overridden`
// Possible reasons for this condition to be False are:
// * Pending
// * Overridden
//
PolicyConditionAttached PolicyConditionType = "Attached"
// PolicyReasonValid is used with the `Accepted` condition when the policy
// PolicyReasonValid is used with the "Accepted" condition when the policy
// has been accepted by the system.
PolicyReasonValid PolicyConditionReason = "Valid"
// PolicyReasonInvalid is used with the `Accepted` or `Attached` condition
// when the policy is syntactically or semantically invalid.
// PolicyReasonInvalid is used with the "Accepted" or "Attached" condition when the policy
// is syntactically or semantically invalid.
PolicyReasonInvalid PolicyConditionReason = "Invalid"
// PolicyReasonAttached is used with the `Attached` condition when the
// PolicyReasonAttached is used with the "Attached" condition when the
// policy has been successfully attached to all the targeted resources.
PolicyReasonAttached PolicyConditionReason = "Attached"
// PolicyReasonPending is used with the `Accepted` or `Attached` condition
// when the policy has been referenced but not yet fully processed by the
// controller.
// PolicyReasonPending is used with the "Accepted" or "Attached" condition when the policy has been referenced but not yet fully processed by the controller.
PolicyReasonPending PolicyConditionReason = "Pending"
// PolicyReasonPartiallyValid is used with the `Accepted` condition when the
// policy has been accepted by the system, but some of the referenced
// resources are not valid.
// PolicyReasonPartiallyValid is used with the "Accepted" condition when the policy has been accepted by the system,
// but some of the referenced resources are not valid.
PolicyReasonPartiallyValid PolicyConditionReason = "PartiallyValid"
)

View File

@ -2,22 +2,14 @@ package shared
// Authorization defines the configuration for role-based access control.
type Authorization struct {
// `policy` specifies the authorization rule to evaluate.
//
// * For `Allow` rules: any policy allows the request.
// * For `Require` rules: all policies must match for the request to be allowed.
// * For `Deny` rules: any matching policy denies the request. Note: a CEL expression that fails to evaluate is not
// considered to match, making this a risky policy; prefer to use `Require`.
//
// The presence of at least one `Allow` rule triggers a deny-by-default policy, requiring at least 1 match to allow.
// With no rules, all requires are allowed.
// Policy specifies the Authorization rule to evaluate.
// A policy matches when **any** of the conditions evaluates to true.
// +required
Policy AuthorizationPolicy `json:"policy"`
// `action` defines whether the rule allows, denies, or requires the request if
// matched. If unspecified, the default is `Allow`.
// Require policies are conjunctive across merged policies: all require policies must match.
// +kubebuilder:validation:Enum=Allow;Deny;Require
// Action defines whether the rule allows or denies the request if matched.
// If unspecified, the default is "Allow".
// +kubebuilder:validation:Enum=Allow;Deny
// +kubebuilder:default=Allow
// +optional
Action AuthorizationPolicyAction `json:"action,omitempty"`
@ -29,11 +21,10 @@ type Authorization struct {
// +k8s:deepcopy-gen=false
type CELExpression string
// AuthorizationPolicy defines a single authorization rule.
// AuthorizationPolicy defines a single Authorization rule.
type AuthorizationPolicy struct {
// MatchExpressions defines a set of conditions that must be satisfied for the rule to match.
// These expressions should be in the form of a Common Expression Language
// (`CEL`) expression.
// These expression should be in the form of a Common Expression Language (CEL) expression.
//
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=256
@ -41,17 +32,12 @@ type AuthorizationPolicy struct {
MatchExpressions []CELExpression `json:"matchExpressions"`
}
// AuthorizationPolicyAction defines the action to take when the
// `RBACPolicies` matches.
// AuthorizationPolicyAction defines the action to take when the RBACPolicies matches.
type AuthorizationPolicyAction string
const (
// AuthorizationPolicyActionAllow defines the action to take when the
// `RBACPolicies` matches.
// AuthorizationPolicyActionAllow defines the action to take when the RBACPolicies matches.
AuthorizationPolicyActionAllow AuthorizationPolicyAction = "Allow"
// AuthorizationPolicyActionDeny denies the action to take when the
// `RBACPolicies` matches.
// AuthorizationPolicyActionDeny denies the action to take when the RBACPolicies matches.
AuthorizationPolicyActionDeny AuthorizationPolicyAction = "Deny"
// AuthorizationPolicyActionRequire requires the action to take when the RBACPolicies matches.
AuthorizationPolicyActionRequire AuthorizationPolicyAction = "Require"
)

View File

@ -8,7 +8,7 @@ import (
// Control-plane Authorization rules not specific to policies:
// +kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create
// Select the object by `name` and `namespace`.
// Select the object by Name and Namespace.
// You can target only one object at a time.
type NamespacedObjectReference struct {
// The name of the target resource.
@ -21,7 +21,7 @@ type NamespacedObjectReference struct {
Namespace *gwv1.Namespace `json:"namespace,omitempty"`
}
// Select the object to attach the policy by `Group`, `Kind`, and `Name`.
// Select the object to attach the policy by Group, Kind, and Name.
// The object must be in the same namespace as the policy.
// You can target only one object at a time.
type LocalPolicyTargetReference struct {
@ -30,7 +30,8 @@ type LocalPolicyTargetReference struct {
// +required
Group gwv1.Group `json:"group"`
// The API kind of the target resource, such as `Gateway` or `HTTPRoute`.
// The API kind of the target resource,
// such as Gateway or HTTPRoute.
// +required
Kind gwv1.Kind `json:"kind"`
@ -39,8 +40,7 @@ type LocalPolicyTargetReference struct {
Name gwv1.ObjectName `json:"name"`
}
// Select the object to attach the policy by `Group`, `Kind`, `Name`, and
// `SectionName`.
// Select the object to attach the policy by Group, Kind, Name and SectionName.
// The object must be in the same namespace as the policy.
// You can target only one object at a time.
type LocalPolicyTargetReferenceWithSectionName struct {
@ -51,17 +51,20 @@ type LocalPolicyTargetReferenceWithSectionName struct {
SectionName *gwv1.SectionName `json:"sectionName,omitempty"`
}
// LocalPolicyTargetSelector selects the object to attach the policy by
// `Group`, `Kind`, and `MatchLabels`.
// LocalPolicyTargetSelector selects the object to attach the policy by Group, Kind, and MatchLabels.
// The object must be in the same namespace as the policy and match the
// specified labels.
// Do not use targetSelectors when reconciliation times are critical, especially if you
// have a large number of policies that target the same resource.
// Instead, use targetRefs to attach the policy.
type LocalPolicyTargetSelector struct {
// The API group of the target resource.
// For Kubernetes Gateway API resources, the group is `gateway.networking.k8s.io`.
// +required
Group gwv1.Group `json:"group"`
// The API kind of the target resource, such as `Gateway` or `HTTPRoute`.
// The API kind of the target resource,
// such as Gateway or HTTPRoute.
// +required
Kind gwv1.Kind `json:"kind"`
@ -70,14 +73,12 @@ type LocalPolicyTargetSelector struct {
MatchLabels map[string]string `json:"matchLabels"`
}
// LocalPolicyTargetSelectorWithSectionName selects the object to attach the
// policy by `Group`, `Kind`, `MatchLabels`, and optionally `SectionName`.
// LocalPolicyTargetSelectorWithSectionName the object to attach the policy by Group, Kind, MatchLabels, and optionally SectionName.
// The object must be in the same namespace as the policy and match the
// specified labels.
// Do not use `targetSelectors` when reconciliation times are critical,
// especially if you
// Do not use targetSelectors when reconciliation times are critical, especially if you
// have a large number of policies that target the same resource.
// Instead, use `targetRefs` to attach the policy.
// Instead, use targetRefs to attach the policy.
type LocalPolicyTargetSelectorWithSectionName struct {
LocalPolicyTargetSelector `json:",inline"`
@ -107,17 +108,17 @@ type PolicyAncestorStatus struct {
// ControllerName is a domain/path string that indicates the name of the
// controller that wrote this status. This corresponds with the
// `controllerName` field on `GatewayClass`.
// controllerName field on GatewayClass.
//
// Example: `example.net/gateway-controller`.
// Example: "example.net/gateway-controller".
//
// The format of this field is `DOMAIN "/" PATH`, where `DOMAIN` and `PATH` are
// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are
// valid Kubernetes names
// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names).
//
// Controllers MUST populate this field when writing status. Controllers
// should ensure that entries in status populated with their `ControllerName`
// are cleaned up when they are no longer necessary.
// Controllers MUST populate this field when writing status. Controllers should ensure that
// entries to status populated with their ControllerName are cleaned up when they are no
// longer necessary.
// +required
ControllerName string `json:"controllerName"`
@ -135,24 +136,24 @@ type PolicyAncestorStatus struct {
// +kubebuilder:validation:ExactlyOneOf=exact;prefix;suffix;contains;safeRegex
type StringMatcher struct {
// The input string must match exactly the string specified here.
// Example: `abc` matches the value `abc`.
// Example: abc matches the value abc
// +optional
Exact *string `json:"exact,omitempty"`
// The input string must have the prefix specified here.
// Note: empty prefix is not allowed, please use regex instead.
// Example: `abc` matches the value `abc.xyz`.
// Example: abc matches the value abc.xyz
// +optional
Prefix *string `json:"prefix,omitempty"`
// The input string must have the suffix specified here.
// Note: empty prefix is not allowed, please use regex instead.
// Example: `abc` matches the value `xyz.abc`.
// Example: abc matches the value xyz.abc
// +optional
Suffix *string `json:"suffix,omitempty"`
// The input string must contain the substring specified here.
// Example: `abc` matches the value `xyz.abc.def`.
// Example: abc matches the value xyz.abc.def
// +optional
Contains *string `json:"contains,omitempty"`
@ -170,7 +171,7 @@ type StringMatcher struct {
}
// HeaderModifiers can be used to define the policy to modify request and response headers.
// +kubebuilder:validation:AtLeastOneFieldSet
// +kubebuilder:validation:AtLeastOneOf=request;response
type HeaderModifiers struct {
// Request modifies request headers.
// +optional

View File

@ -4,19 +4,17 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
type Timeouts struct {
// Request specifies a timeout for an individual request from the gateway to a backend.
// This spans between the point at which the entire downstream request
// (i.e. end-of-stream) has been
// This spans between the point at which the entire downstream request (i.e. end-of-stream) has been
// processed and when the backend response has been completely processed.
// A value of `0` effectively disables the timeout.
// It is specified as a sequence of decimal numbers, each with optional
// fraction and a unit suffix, such as `1s` or `500ms`.
// A value of 0 effectively disables the timeout.
// It is specified as a sequence of decimal numbers, each with optional fraction and a unit suffix, such as "1s" or "500ms".
// +optional
//
// +kubebuilder:validation:XValidation:rule="matches(self, '^([0-9]{1,5}(h|m|s|ms)){1,4}$')",message="invalid duration value"
Request *metav1.Duration `json:"request,omitempty"`
// StreamIdle specifies a timeout for a requests' idle streams.
// A value of `0` effectively disables the timeout.
// A value of 0 effectively disables the timeout.
// +optional
//
// +kubebuilder:validation:XValidation:rule="matches(self, '^([0-9]{1,5}(h|m|s|ms)){1,4}$')",message="invalid duration value"

View File

@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
"github.com/agentgateway/agentgateway/controller/pkg/setup"
"github.com/agentgateway/agentgateway/controller/pkg/kgateway/setup"
"github.com/agentgateway/agentgateway/controller/pkg/version"
)
@ -20,7 +20,7 @@ func main() {
fmt.Println(version.String())
return nil
}
s, err := setup.New(setup.Options{})
s, err := setup.New()
if err != nil {
return fmt.Errorf("error setting up agentgateway: %w", err)
}

View File

@ -1,9 +1,341 @@
#!/usr/bin/env bash
set -euo pipefail
[ $# -eq 2 ] || { echo "usage: $0 {gie|gtw} REF" >&2; exit 2; }
cd "$(dirname "${BASH_SOURCE[0]}")/.."
case "$1" in
gtw) kubectl kustomize "https://github.com/kubernetes-sigs/gateway-api/config/crd/experimental?ref=$2" > pkg/kgateway/crds/gateway-crds.yaml ;;
gie) kubectl kustomize "https://github.com/kubernetes-sigs/gateway-api-inference-extension/config/crd?ref=$2" > pkg/kgateway/crds/inference-crds.yaml ;;
*) echo "usage: $0 {gie|gtw} REF" >&2; exit 2 ;;
set -o pipefail
set -o nounset
set -o errexit
# The GIE EPP used in e2e tests
EPP_YAML_PATH="test/e2e/features/inferenceextension/testdata/epp.yaml"
# The base URLs for fetching CRDs
GIE_CRD_BASE="https://raw.githubusercontent.com/kubernetes-sigs/gateway-api-inference-extension"
GATEWAY_CRD_BASE="https://raw.githubusercontent.com/kubernetes-sigs/gateway-api"
# The Gateway API channel (experimental or stable)
CONFORMANCE_CHANNEL="${CONFORMANCE_CHANNEL:-experimental}"
if [ $# -ne 2 ]; then
echo "Usage: $0 {gie|gtw} REF"
echo " REF can be a tag (e.g. v1.3.0) or a commit SHA."
exit 2
fi
kind="$1"; shift
ref="$1"; shift
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
echo "Bumping $kind to ref: $ref ..."
# Check the current module version
case "$kind" in
gie) module="sigs.k8s.io/gateway-api-inference-extension";;
gtw) module="sigs.k8s.io/gateway-api";;
*) echo "Unknown kind: $kind" >&2; exit 1;;
esac
current_version="$(go list -m -f '{{.Version}}' "$module" 2>/dev/null || true)"
# Resolve desired ref to a module version (pseudo-version if ref is non-tag)
resolved_version="$(
go list -m -json "${module}@${ref}" 2>/dev/null \
| sed -n 's/.*"Version": *"\([^"]*\)".*/\1/p'
)"
if [ -z "${resolved_version}" ]; then
echo "ERROR: Could not resolve ${module}@${ref} to a module version."
echo " Verify the ref exists in the upstream repo."
exit 1
fi
echo "Current version: ${current_version:-<none>}"
echo "Desired version (resolved): ${resolved_version}"
# If already at the desired version, skip go get/mod tidy but still refresh CRDs.
skip_get=0
if [ -n "$current_version" ] && [ "$current_version" = "$resolved_version" ]; then
echo "Already at ${resolved_version} - skipping dependency bump, refreshing CRDs..."
skip_get=1
fi
if [ $skip_get -eq 0 ]; then
# Bump the module deps
echo "Running: go get ${module}@${ref}"
go get "${module}@${ref}"
echo "Running: go mod tidy"
go mod tidy
fi
# Update GIE_CRD_VERSION in files (for GIE bumps only) to the exact ref passed in.
update_gie_crd_version_line() {
# $1 = file path, $2 = mode ("mk" for Makefile-style, "sh" for shell)
local file="$1"
local mode="$2"
if [ ! -f "$file" ]; then
echo "WARN: $file not found, skipping"
return 0
fi
echo "Setting GIE_CRD_VERSION to '${ref}' in $file"
if [ "$mode" = "mk" ]; then
# If the var exists, replace its RHS (supports '=', '?=', '=').
if grep -Eq '^[[:space:]]*GIE_CRD_VERSION[[:space:]]*([?:]?=)' "$file"; then
sed -i.bak -E \
-e 's|^([[:space:]]*GIE_CRD_VERSION[[:space:]]*[?:]?=)[[:space:]]*.*$|\1 '"$ref"'|g' \
"$file"
rm -f "$file.bak"
else
# Append a sane default form if not present.
printf '\nGIE_CRD_VERSION ?= %s\n' "$ref" >> "$file"
fi
else
# Shell-style assignment; replace the whole line if present, else append.
if grep -Eq '^[[:space:]]*GIE_CRD_VERSION=' "$file"; then
sed -i.bak -E \
-e 's|^[[:space:]]*GIE_CRD_VERSION=.*$|GIE_CRD_VERSION="'"$ref"'"|g' \
"$file"
rm -f "$file.bak"
else
printf '\nGIE_CRD_VERSION="%s"\n' "$ref" >> "$file"
fi
fi
}
# Helper: derive image tag from module version.
# - For pseudo-versions that end with '...-YYYYMMDDHHMMSS-<sha>', produce 'vYYYYMMDD-<sha7>'
# - Otherwise (e.g., semver tag), use the version itself as the image tag.
derive_image_tag() {
local ver="$1"
# Match the trailing timestamp + sha anywhere at the end (robust for different pseudo-version bases)
if [[ "$ver" =~ ([0-9]{14})-([0-9a-f]{7,40})$ ]]; then
local ts="${BASH_REMATCH[1]}"
local sha="${BASH_REMATCH[2]}"
# Use YYYYMMDD and first 7 chars of sha
echo "v${ts:0:8}-${sha:0:7}"
else
# Fall back to the version string itself (for true tags like v1.0.0 or v1.0.0-rc.2)
echo "$ver"
fi
}
# Update e2e EPP image tag (GIE only)
if [ "$kind" = gie ]; then
img_tag="$(derive_image_tag "$resolved_version")"
echo "Updating EPP image tag in $EPP_YAML_PATH to ${img_tag} (from module version: ${resolved_version})"
# macOS/BSD-safe inline edit
sed -i.bak -E \
-e "s|(gateway-api-inference-extension/epp:)[^[:space:]\"]+|\1${img_tag}|g" \
"$root/$EPP_YAML_PATH"
rm -f "$root/$EPP_YAML_PATH.bak"
# Also update GIE_CRD_VERSION to the ref we were given (tag or SHA).
update_gie_crd_version_line "$root/Makefile" "mk"
if [ -f "$root/hack/kind/setup-kind.sh" ]; then
update_gie_crd_version_line "$root/hack/kind/setup-kind.sh" "sh"
elif [ -f "$root/kind/setup-kind.sh" ]; then
update_gie_crd_version_line "$root/kind/setup-kind.sh" "sh"
else
echo "WARN: No setup-kind.sh found under hack/kind or kind/, skipping"
fi
fi
update_make_var_line() {
local file="$1"
local var="$2"
local val="$3"
if [ ! -f "$file" ]; then
echo "WARN: $file not found, skipping"
return 0
fi
echo "Setting ${var} to '${val}' in ${file}"
if grep -Eq "^[[:space:]]*${var}[[:space:]]*([?:]?=)" "$file"; then
sed -i.bak -E \
-e "s|^([[:space:]]*${var}[[:space:]]*[?:]?=)[[:space:]]*.*$|\1 ${val}|g" \
"$file"
rm -f "$file.bak"
else
printf '\n%s ?= %s\n' "$var" "$val" >> "$file"
fi
}
update_nightly_gateway_api_matrix_versions() {
local file="$1"
local old="$2"
local new="$3"
if [ ! -f "$file" ]; then
echo "WARN: $file not found, skipping"
return 0
fi
# Escape dots for ERE (good enough for vX.Y.Z / -rc.N)
local old_esc="${old//./\\.}"
echo "Updating nightly-tests gateway-api matrix: ${old} -> ${new} in ${file}"
sed -i.bak -E \
-e "s|(version:[[:space:]]*')${old_esc}(')|\1${new}\2|g" \
"$file"
rm -f "$file.bak"
}
# Fetch and store the CRDs
crd_dir="$root/pkg/kgateway/crds"
mkdir -p "$crd_dir"
if [ "$kind" = gie ]; then
# Build a single all-in-one CRD file.
outfile="${crd_dir}/inference-crds.yaml"
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
# Known CRDs/sources
declare -a SOURCES=(
"${GIE_CRD_BASE}/${ref}/config/crd/bases/inference.networking.k8s.io_inferencepools.yaml"
"${GIE_CRD_BASE}/${ref}/config/crd/bases/inference.networking.x-k8s.io_inferenceobjectives.yaml"
)
tmpout="$(mktemp)"
: > "$tmpout"
for url in "${SOURCES[@]}"; do
fname="$tmpdir/$(basename "$url")"
echo "Fetching $url"
curl -fsS "$url" -o "$fname"
{
echo "# Source: $url"
cat "$fname"
echo "---"
} >> "$tmpout"
done
# Remove the trailing '---' and any trailing blank lines
# shellcheck disable=SC2016
awk '{
lines[NR]=$0
} END {
# drop trailing separators/blank lines
i=NR
while (i>0 && (lines[i] ~ /^---[[:space:]]*$/ || lines[i] ~ /^[[:space:]]*$/)) { i-- }
for (j=1; j<=i; j++) print lines[j]
}' "$tmpout" > "${tmpout}.trim"
mv -f "${tmpout}.trim" "$outfile"
rm -f "$tmpout"
echo "Wrote GIE all-in-one CRDs to $outfile"
elif [ "$kind" = gtw ]; then
# Gateway API CRDs
# Use release assets when ref resolves to a non-pseudo version (tags incl. -rc.*),
# otherwise iterate files from the repo for pseudo-versions (timestamps/SHAs).
out_all="${crd_dir}/gateway-crds.yaml"
is_pseudo=0
if [[ "$resolved_version" =~ ([0-9]{14})-([0-9a-f]{7,40})$ ]]; then
is_pseudo=1
fi
# Read current pinned conformance version from the Makefile (so we only replace “latest”)
current_conf="$(
sed -nE 's/^[[:space:]]*CONFORMANCE_VERSION[[:space:]]*[?:]?=[[:space:]]*([^[:space:]#]+).*$/\1/p' \
"$root/Makefile" | head -n1
)"
if [ $is_pseudo -eq 0 ]; then
# Update Makefile pin
update_make_var_line "$root/Makefile" "CONFORMANCE_VERSION" "$resolved_version"
# Update nightly-tests “latest” entries (the ones matching current_conf)
if [ -n "${current_conf:-}" ]; then
update_nightly_gateway_api_matrix_versions \
"$root/.github/workflows/nightly-tests.yaml" \
"$current_conf" \
"$resolved_version"
else
echo "WARN: Could not parse current CONFORMANCE_VERSION from Makefile; skipping workflow update"
fi
else
echo "WARN: Gateway API resolved to pseudo-version (${resolved_version}); leaving CONFORMANCE_VERSION and nightly matrix unchanged"
fi
if [ $is_pseudo -eq 0 ]; then
# Try to download prebuilt install manifest from the GitHub release
if [ "${CONFORMANCE_CHANNEL}" = "experimental" ]; then
asset="experimental-install.yaml"
else
asset="standard-install.yaml"
fi
release_url="https://github.com/kubernetes-sigs/gateway-api/releases/download/${resolved_version}/${asset}"
echo "Attempting to fetch Gateway API release asset: ${release_url}"
tmp_release="$(mktemp)"
if curl -fLSs "${release_url}" -o "${tmp_release}"; then
# Extra safety: ensure non-empty before replacing
if [ -s "${tmp_release}" ]; then
mv -f "${tmp_release}" "${out_all}"
echo "Wrote Gateway (${CONFORMANCE_CHANNEL}) CRDs to ${out_all} from release asset"
else
echo "Release asset downloaded but empty; falling back to repo iteration for ${ref}"
rm -f "${tmp_release}"
is_pseudo=1
fi
else
echo "Release asset not available (or download failed); falling back to repo iteration for ${ref}"
rm -f "${tmp_release}"
is_pseudo=1
fi
fi
if [ $is_pseudo -eq 1 ]; then
# Fallback for pseudo-versions (or when release asset unavailable):
# fetch all YAMLs under config/crd/${CONFORMANCE_CHANNEL} and concatenate.
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
archive_url="https://codeload.github.com/kubernetes-sigs/gateway-api/tar.gz/${ref}"
echo "Downloading Gateway API archive: $archive_url"
curl -fsSL "$archive_url" -o "$tmpdir/gtw.tar.gz"
echo "Extracting archive..."
tar -xzf "$tmpdir/gtw.tar.gz" -C "$tmpdir"
srcdir="$(echo "$tmpdir"/gateway-api-*/config/crd/${CONFORMANCE_CHANNEL})"
if [ ! -d "$srcdir" ]; then
echo "ERROR: Could not find extracted CRD directory: $srcdir"
exit 1
fi
tmp_all="$(mktemp)"
: > "$tmp_all"
echo "Building all-in-one CRD file at ${out_all} from ${srcdir}"
# Concatenate in a stable order and include both x-k8s.io and k8s.io groups.
for f in $(ls "$srcdir"/*.yaml | sort); do
base="$(basename "$f")"
echo "# Source: ${GATEWAY_CRD_BASE}/${ref}/config/crd/${CONFORMANCE_CHANNEL}/${base}" >> "$tmp_all"
cat "$f" >> "$tmp_all"
echo "---" >> "$tmp_all"
done
# Trim trailing separators/blank lines
awk '{
lines[NR]=$0
} END {
i=NR
while (i>0 && (lines[i] ~ /^---[[:space:]]*$/ || lines[i] ~ /^[[:space:]]*$/)) { i-- }
for (j=1; j<=i; j++) print lines[j]
}' "$tmp_all" > "${out_all}"
rm -f "$tmp_all"
echo "Wrote Gateway (${CONFORMANCE_CHANNEL}) all-in-one CRDs to $out_all"
fi
# Final sanity: if ${out_all} exists but is empty, fail loudly
if [ -e "${out_all}" ] && [ ! -s "${out_all}" ]; then
echo "ERROR: ${out_all} is empty after CRD refresh. Please check the logs above."
exit 1
fi
fi
echo "$kind bumped to ${resolved_version} (ref: ${ref}) successfully!"

View File

@ -1,882 +0,0 @@
package main
import (
"bytes"
"errors"
"flag"
"fmt"
"go/ast"
"go/types"
"os"
"path/filepath"
"reflect"
"slices"
"sort"
"strings"
"golang.org/x/tools/go/packages"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-tools/pkg/crd"
crdmarkers "sigs.k8s.io/controller-tools/pkg/crd/markers"
"sigs.k8s.io/controller-tools/pkg/loader"
"sigs.k8s.io/controller-tools/pkg/markers"
"sigs.k8s.io/yaml"
)
const (
atLeastOneFieldSetMarker = "kubebuilder:validation:AtLeastOneFieldSet"
ifThenOnlyFieldsMarker = "kubebuilder:validation:IfThenOnlyFields"
overrideXValidationMarker = "kubebuilder:validation:OverrideXValidation"
controllerGenVersion = "v0.20.0"
)
type pathList []string
func (p *pathList) String() string {
return strings.Join(*p, ",")
}
func (p *pathList) Set(value string) error {
for part := range strings.SplitSeq(value, ",") {
part = strings.TrimSpace(part)
if part == "" {
continue
}
*p = append(*p, part)
}
return nil
}
// +controllertools:marker:generateHelp:category="CRD validation"
type AtLeastOneFieldSet struct {
Fields []string `marker:",optional"`
Exclude []string `marker:",optional"`
Message string `marker:",optional"`
}
// +controllertools:marker:generateHelp:category="CRD validation"
type IfThenOnlyFields struct {
If string
Fields []string
Message string `marker:",optional"`
}
// +controllertools:marker:generateHelp:category="CRD validation"
type OverrideXValidation struct {
MessageContains string `marker:"messageContains"`
Rule string `marker:",optional"`
Message string `marker:",optional"`
MessageExpression string `marker:"messageExpression,optional"`
Reason string `marker:"reason,optional"`
FieldPath string `marker:"fieldPath,optional"`
OptionalOldSelf *bool `marker:"optionalOldSelf,optional"`
}
func (m AtLeastOneFieldSet) ApplyToSchema(schema *apiextensionsv1.JSONSchemaProps) error {
allFields := sortedPropertyNames(schema)
if len(m.Fields) > 0 {
allFields = dedupeAndSort(append(allFields, m.Fields...))
}
if len(m.Exclude) > 0 {
allFields = dedupeAndSort(append(allFields, m.Exclude...))
}
return applyAtLeastOneFieldSet(schema, allFields, m)
}
func (AtLeastOneFieldSet) ApplyPriority() crdmarkers.ApplyPriority {
return crdmarkers.AtLeastOneOf{}.ApplyPriority() + 1
}
func main() {
var paths pathList
outputDir := flag.String("output-dir", "", "directory to write CRD YAMLs")
maxDescLen := flag.Int("max-desc-len", 0, "maximum description length (0 disables descriptions)")
crdVersion := flag.String("crd-version", apiextensionsv1.SchemeGroupVersion.Version, "CRD API version")
flag.Var(&paths, "path", "Go package path root to load (repeatable or comma-separated)")
flag.Parse()
if *outputDir == "" {
exitWithErr(fmt.Errorf("--output-dir is required"))
}
if len(paths) == 0 {
exitWithErr(fmt.Errorf("at least one --path is required"))
}
if err := os.MkdirAll(*outputDir, 0o755); err != nil {
exitWithErr(fmt.Errorf("create output dir %q: %w", *outputDir, err))
}
if err := generateCRDs(paths, *outputDir, *maxDescLen, *crdVersion); err != nil {
exitWithErr(err)
}
}
func exitWithErr(err error) {
_, _ = fmt.Fprintf(os.Stderr, "custom CRD generation failed: %v\n", err)
os.Exit(1)
}
func generateCRDs(paths []string, outputDir string, maxDescLen int, crdVersion string) error {
roots, err := loader.LoadRoots(paths...)
if err != nil {
return fmt.Errorf("load roots: %w", err)
}
generator := &crd.Generator{}
parser := &crd.Parser{
Collector: &markers.Collector{Registry: &markers.Registry{}},
Checker: &loader.TypeChecker{
NodeFilters: []loader.NodeFilter{generator.CheckFilter()},
},
}
if err := generator.RegisterMarkers(parser.Collector.Registry); err != nil {
return fmt.Errorf("register builtin markers: %w", err)
}
if err := registerCustomMarkers(parser.Collector.Registry); err != nil {
return fmt.Errorf("register custom markers: %w", err)
}
crd.AddKnownTypes(parser)
for _, root := range roots {
parser.NeedPackage(root)
}
if err := populateInferredMarkerFields(parser); err != nil {
return fmt.Errorf("populate inferred marker fields: %w", err)
}
metav1Pkg := crd.FindMetav1(roots)
if metav1Pkg == nil {
return fmt.Errorf("no objects in roots (nothing imported metav1)")
}
kubeKinds := crd.FindKubeKinds(parser, metav1Pkg)
if len(kubeKinds) == 0 {
return fmt.Errorf("found zero Kubernetes kinds for paths: %s", strings.Join(paths, ", "))
}
for _, groupKind := range kubeKinds {
parser.NeedCRDFor(groupKind, &maxDescLen)
crdRaw := parser.CustomResourceDefinitions[groupKind]
if err := applyPostSchemaMarkersToCRD(parser, &crdRaw, groupKind); err != nil {
return fmt.Errorf("apply post-schema markers to CRD %s/%s: %w", groupKind.Group, groupKind.Kind, err)
}
addAttribution(&crdRaw)
crd.FixTopLevelMetadata(crdRaw)
converted, err := crd.AsVersion(crdRaw, schema.GroupVersion{Group: apiextensionsv1.SchemeGroupVersion.Group, Version: crdVersion})
if err != nil {
return fmt.Errorf("convert CRD %s/%s: %w", groupKind.Group, groupKind.Kind, err)
}
crdV1, ok := converted.(*apiextensionsv1.CustomResourceDefinition)
if !ok {
return fmt.Errorf("unexpected converted type %T", converted)
}
removeDescriptionFromMetadata(crdV1)
out, err := marshalCRD(crdV1)
if err != nil {
return fmt.Errorf("marshal CRD %s/%s: %w", groupKind.Group, groupKind.Kind, err)
}
fileName := fmt.Sprintf("%s_%s.yaml", crdRaw.Spec.Group, crdRaw.Spec.Names.Plural)
filePath := filepath.Join(outputDir, fileName)
// nolint:gosec // G306: not relevant here
if err := os.WriteFile(filePath, out, 0o644); err != nil {
return fmt.Errorf("write CRD %q: %w", filePath, err)
}
}
if loader.PrintErrors(roots, packages.TypeError) {
return fmt.Errorf("not all generators ran successfully")
}
return nil
}
func registerCustomMarkers(registry *markers.Registry) error {
defs := []*markers.Definition{
markers.Must(markers.MakeDefinition(atLeastOneFieldSetMarker, markers.DescribesType, AtLeastOneFieldSet{})),
markers.Must(markers.MakeDefinition(ifThenOnlyFieldsMarker, markers.DescribesType, IfThenOnlyFields{})),
markers.Must(markers.MakeDefinition(overrideXValidationMarker, markers.DescribesType, OverrideXValidation{})),
}
for _, def := range defs {
if err := registry.Register(def); err != nil {
return err
}
}
return nil
}
func populateInferredMarkerFields(parser *crd.Parser) error {
fieldCache := make(map[crd.TypeIdent][]string)
inProgress := make(map[crd.TypeIdent]bool)
for typ, info := range parser.Types {
needInferredFields := false
for _, raw := range info.Markers[atLeastOneFieldSetMarker] {
marker, err := asAtLeastOneFieldSet(raw)
if err != nil {
return fmt.Errorf("%s: %w", typ, err)
}
if len(marker.Fields) == 0 {
needInferredFields = true
break
}
}
if !needInferredFields {
continue
}
inferredFields, err := allJSONFieldNamesForType(parser, typ, info, fieldCache, inProgress)
if err != nil {
return fmt.Errorf("%s: %w", typ, err)
}
if markerVals, ok := info.Markers[atLeastOneFieldSetMarker]; ok {
for i, raw := range markerVals {
marker, err := asAtLeastOneFieldSet(raw)
if err != nil {
return fmt.Errorf("%s: %w", typ, err)
}
if len(marker.Fields) == 0 {
marker.Fields = append([]string(nil), inferredFields...)
markerVals[i] = marker
}
}
info.Markers[atLeastOneFieldSetMarker] = markerVals
}
}
return nil
}
func asAtLeastOneFieldSet(raw any) (AtLeastOneFieldSet, error) {
switch marker := raw.(type) {
case AtLeastOneFieldSet:
return marker, nil
case *AtLeastOneFieldSet:
if marker == nil {
return AtLeastOneFieldSet{}, fmt.Errorf("unexpected nil marker for %s", atLeastOneFieldSetMarker)
}
return *marker, nil
default:
return AtLeastOneFieldSet{}, fmt.Errorf("unexpected marker value %T for %s", raw, atLeastOneFieldSetMarker)
}
}
func asOverrideXValidation(raw any) (OverrideXValidation, error) {
switch marker := raw.(type) {
case OverrideXValidation:
return marker, nil
case *OverrideXValidation:
if marker == nil {
return OverrideXValidation{}, fmt.Errorf("unexpected nil marker for %s", overrideXValidationMarker)
}
return *marker, nil
default:
return OverrideXValidation{}, fmt.Errorf("unexpected marker value %T for %s", raw, overrideXValidationMarker)
}
}
func asIfThenOnlyFields(raw any) (IfThenOnlyFields, error) {
switch marker := raw.(type) {
case IfThenOnlyFields:
return marker, nil
case *IfThenOnlyFields:
if marker == nil {
return IfThenOnlyFields{}, fmt.Errorf("unexpected nil marker for %s", ifThenOnlyFieldsMarker)
}
return *marker, nil
default:
return IfThenOnlyFields{}, fmt.Errorf("unexpected marker value %T for %s", raw, ifThenOnlyFieldsMarker)
}
}
func applyAtLeastOneFieldSet(schema *apiextensionsv1.JSONSchemaProps, allFields []string, marker AtLeastOneFieldSet) error {
fields, err := resolveFields(allFields, marker.Fields, marker.Exclude)
if err != nil {
return err
}
if len(fields) == 0 {
return errors.New("AtLeastOneFieldSet resolved to zero fields")
}
message := marker.Message
if message == "" {
message = fmt.Sprintf("at least one of the fields in %v must be set", fields)
}
return crdmarkers.XValidation{
Rule: fmt.Sprintf("%s >= 1", fieldsToOneOfCelRuleStr(fields)),
Message: message,
}.ApplyToSchema(schema)
}
func applyIfThenOnlyFields(schema *apiextensionsv1.JSONSchemaProps, allFields []string, marker IfThenOnlyFields) error {
if strings.TrimSpace(marker.If) == "" {
return errors.New("IfThenOnlyFields requires 'if'")
}
if len(marker.Fields) == 0 {
return errors.New("IfThenOnlyFields requires at least one field")
}
allowedFields, err := validateFieldList(allFields, dedupeAndSort(marker.Fields), "fields")
if err != nil {
return err
}
allowed := make(map[string]struct{}, len(allowedFields))
for _, field := range allowedFields {
allowed[field] = struct{}{}
}
disallowedFields := make([]string, 0, len(allFields))
for _, field := range allFields {
if _, ok := allowed[field]; !ok {
disallowedFields = append(disallowedFields, field)
}
}
if len(disallowedFields) == 0 {
return nil
}
message := marker.Message
if message == "" {
message = fmt.Sprintf("only fields in %v may be set when %s", allowedFields, marker.If)
}
return crdmarkers.XValidation{
Rule: fmt.Sprintf("%s ? %s == 0 : true", marker.If, fieldsToOneOfCelRuleStr(disallowedFields)),
Message: message,
}.ApplyToSchema(schema)
}
func applyOverrideXValidation(schema *apiextensionsv1.JSONSchemaProps, override OverrideXValidation) error {
if strings.TrimSpace(override.MessageContains) == "" {
return errors.New("OverrideXValidation requires messageContains")
}
matches := make([]int, 0, 1)
for i, validation := range schema.XValidations {
if strings.Contains(validation.Message, override.MessageContains) {
matches = append(matches, i)
}
}
if len(matches) != 1 {
return fmt.Errorf("OverrideXValidation matched %d rules for messageContains %q, expected exactly 1", len(matches), override.MessageContains)
}
if strings.TrimSpace(override.Rule) == "" {
schema.XValidations = append(schema.XValidations[:matches[0]], schema.XValidations[matches[0]+1:]...)
return nil
}
replaced, err := overrideValidationRule(schema.XValidations[matches[0]], override)
if err != nil {
return err
}
schema.XValidations[matches[0]] = replaced
return nil
}
func applyPostSchemaMarkersToCRD(parser *crd.Parser, crdObj *apiextensionsv1.CustomResourceDefinition, groupKind schema.GroupKind) error {
for i := range crdObj.Spec.Versions {
versionSpec := &crdObj.Spec.Versions[i]
if versionSpec.Schema == nil || versionSpec.Schema.OpenAPIV3Schema == nil {
continue
}
rootType, ok := rootTypeForCRDVersion(parser, groupKind, versionSpec.Name)
if !ok {
continue
}
inProgress := map[crd.TypeIdent]bool{}
if err := applyPostSchemaMarkersForType(parser, rootType, versionSpec.Schema.OpenAPIV3Schema, inProgress); err != nil {
return fmt.Errorf("%s: %w", rootType, err)
}
}
return nil
}
func rootTypeForCRDVersion(parser *crd.Parser, groupKind schema.GroupKind, version string) (crd.TypeIdent, bool) {
for pkg, gv := range parser.GroupVersions {
if gv.Group != groupKind.Group || gv.Version != version {
continue
}
typ := crd.TypeIdent{
Package: pkg,
Name: groupKind.Kind,
}
if parser.LookupType(pkg, groupKind.Kind) != nil {
return typ, true
}
}
return crd.TypeIdent{}, false
}
func applyPostSchemaMarkersForType(
parser *crd.Parser,
typ crd.TypeIdent,
schema *apiextensionsv1.JSONSchemaProps,
inProgress map[crd.TypeIdent]bool,
) error {
if schema == nil {
return nil
}
if inProgress[typ] {
return nil
}
info := parser.LookupType(typ.Package, typ.Name)
if info == nil {
return nil
}
inProgress[typ] = true
defer delete(inProgress, typ)
for _, field := range info.Fields {
fieldName, inline, include := jsonFieldInfo(field.Tag)
if !include {
continue
}
fieldType, ok := typeIdentForExpr(parser, typ.Package, field.RawField.Type)
if !ok {
continue
}
if inline {
if err := applyPostSchemaMarkersForType(parser, fieldType, schema, inProgress); err != nil {
return err
}
continue
}
fieldSchema, ok := schema.Properties[fieldName]
if !ok {
continue
}
if err := applyPostSchemaMarkersForType(parser, fieldType, &fieldSchema, inProgress); err != nil {
return err
}
schema.Properties[fieldName] = fieldSchema
}
if rawMarkers, ok := info.Markers[overrideXValidationMarker]; ok {
for _, raw := range rawMarkers {
marker, err := asOverrideXValidation(raw)
if err != nil {
return err
}
if err := applyOverrideXValidation(schema, marker); err != nil {
return err
}
}
}
if rawMarkers, ok := info.Markers[ifThenOnlyFieldsMarker]; ok {
allFields := sortedPropertyNames(schema)
for _, raw := range rawMarkers {
marker, err := asIfThenOnlyFields(raw)
if err != nil {
return err
}
if err := applyIfThenOnlyFields(schema, allFields, marker); err != nil {
return err
}
}
}
return nil
}
func resolveFields(allFields, includes, excludes []string) ([]string, error) {
var err error
includes, err = normalizeFieldList(includes, "fields")
if err != nil {
return nil, err
}
excludes, err = normalizeFieldList(excludes, "exclude")
if err != nil {
return nil, err
}
if len(includes) > 0 {
includes, err = validateFieldList(allFields, includes, "fields")
if err != nil {
return nil, err
}
}
if len(excludes) > 0 {
excludes, err = validateFieldList(allFields, excludes, "exclude")
if err != nil {
return nil, err
}
}
if len(includes) == 0 {
includes = append([]string(nil), allFields...)
}
excluded := make(map[string]struct{}, len(excludes))
for _, field := range excludes {
excluded[field] = struct{}{}
}
result := make([]string, 0, len(includes))
for _, field := range includes {
if _, ok := excluded[field]; !ok {
result = append(result, field)
}
}
return result, nil
}
func normalizeFieldList(fields []string, listName string) ([]string, error) {
fields = dedupeAndSort(fields)
for _, field := range fields {
if strings.Contains(field, ".") {
return nil, fmt.Errorf("%s: cannot reference nested fields: %s", listName, strings.Join(fields, ","))
}
}
return fields, nil
}
func validateFieldList(allFields []string, fields []string, listName string) ([]string, error) {
fields, err := normalizeFieldList(fields, listName)
if err != nil {
return nil, err
}
if len(fields) == 0 {
return fields, nil
}
all := make(map[string]struct{}, len(allFields))
for _, name := range allFields {
all[name] = struct{}{}
}
for _, field := range fields {
if _, ok := all[field]; !ok {
return nil, fmt.Errorf("%s: unknown field %q", listName, field)
}
}
return fields, nil
}
func dedupeAndSort(in []string) []string {
if len(in) == 0 {
return nil
}
seen := make(map[string]struct{}, len(in))
out := make([]string, 0, len(in))
for _, v := range in {
v = strings.TrimSpace(v)
if v == "" {
continue
}
if _, ok := seen[v]; ok {
continue
}
seen[v] = struct{}{}
out = append(out, v)
}
sort.Strings(out)
return out
}
func sortedPropertyNames(schema *apiextensionsv1.JSONSchemaProps) []string {
namesSet := map[string]struct{}{}
for name := range schema.Properties {
namesSet[name] = struct{}{}
}
var collect func(items []apiextensionsv1.JSONSchemaProps)
collect = func(items []apiextensionsv1.JSONSchemaProps) {
for _, item := range items {
for name := range item.Properties {
namesSet[name] = struct{}{}
}
if len(item.AllOf) > 0 {
collect(item.AllOf)
}
}
}
collect(schema.AllOf)
names := make([]string, 0, len(namesSet))
for name := range namesSet {
names = append(names, name)
}
sort.Strings(names)
return names
}
func allJSONFieldNamesForType(
parser *crd.Parser,
typ crd.TypeIdent,
info *markers.TypeInfo,
fieldCache map[crd.TypeIdent][]string,
inProgress map[crd.TypeIdent]bool,
) ([]string, error) {
if cached, ok := fieldCache[typ]; ok {
return append([]string(nil), cached...), nil
}
if inProgress[typ] {
return nil, fmt.Errorf("%s: recursive inline embedding detected", typ)
}
if _, isStruct := info.RawSpec.Type.(*ast.StructType); !isStruct {
return nil, fmt.Errorf("%s marker is only supported on struct types", typ)
}
inProgress[typ] = true
defer delete(inProgress, typ)
fieldSet := map[string]struct{}{}
for _, field := range info.Fields {
fieldName, inline, include := jsonFieldInfo(field.Tag)
if !include {
continue
}
if inline {
embeddedType, ok := typeIdentForExpr(parser, typ.Package, field.RawField.Type)
if !ok {
continue
}
parser.NeedPackage(embeddedType.Package)
embeddedInfo := parser.LookupType(embeddedType.Package, embeddedType.Name)
if embeddedInfo == nil {
continue
}
embeddedFields, err := allJSONFieldNamesForType(parser, embeddedType, embeddedInfo, fieldCache, inProgress)
if err != nil {
return nil, err
}
for _, embeddedField := range embeddedFields {
fieldSet[embeddedField] = struct{}{}
}
continue
}
fieldSet[fieldName] = struct{}{}
}
fields := make([]string, 0, len(fieldSet))
for field := range fieldSet {
fields = append(fields, field)
}
sort.Strings(fields)
fieldCache[typ] = fields
return append([]string(nil), fields...), nil
}
func jsonFieldInfo(tag reflect.StructTag) (name string, inline bool, include bool) {
jsonTag, hasTag := tag.Lookup("json")
if !hasTag {
return "", false, false
}
jsonOpts := strings.Split(jsonTag, ",")
if len(jsonOpts) == 1 && jsonOpts[0] == "-" {
return "", false, false
}
if slices.Contains(jsonOpts[1:], "inline") {
inline = true
}
name = jsonOpts[0]
inline = inline || name == ""
if inline {
return "", true, true
}
return name, false, true
}
func typeIdentForExpr(parser *crd.Parser, contextPkg *loader.Package, expr ast.Expr) (crd.TypeIdent, bool) {
if contextPkg == nil {
return crd.TypeIdent{}, false
}
contextPkg.NeedTypesInfo()
goType := contextPkg.TypesInfo.TypeOf(expr)
if goType == nil {
return crd.TypeIdent{}, false
}
for {
goType = types.Unalias(goType)
switch typed := goType.(type) {
case *types.Pointer:
goType = typed.Elem()
case *types.Named:
obj := typed.Obj()
if obj == nil || obj.Pkg() == nil {
return crd.TypeIdent{}, false
}
typePkg := packageForPath(parser, contextPkg, obj.Pkg().Path())
if typePkg == nil {
return crd.TypeIdent{}, false
}
return crd.TypeIdent{
Package: typePkg,
Name: obj.Name(),
}, true
default:
return crd.TypeIdent{}, false
}
}
}
func packageForPath(parser *crd.Parser, contextPkg *loader.Package, pkgPath string) *loader.Package {
targetPath := loader.NonVendorPath(pkgPath)
if loader.NonVendorPath(contextPkg.PkgPath) == targetPath {
return contextPkg
}
if imported := contextPkg.Imports()[targetPath]; imported != nil {
return imported
}
for _, imported := range contextPkg.Imports() {
if loader.NonVendorPath(imported.PkgPath) == targetPath {
return imported
}
}
for typ := range parser.Types {
if loader.NonVendorPath(typ.Package.PkgPath) == targetPath {
return typ.Package
}
}
return nil
}
func fieldsToOneOfCelRuleStr(fields []string) string {
var builder strings.Builder
builder.WriteString("[")
for i, field := range fields {
if i > 0 {
builder.WriteString(",")
}
builder.WriteString("has(self.")
builder.WriteString(field)
builder.WriteString(")")
}
builder.WriteString("].filter(x,x==true).size()")
return builder.String()
}
func overrideValidationRule(existing apiextensionsv1.ValidationRule, override OverrideXValidation) (apiextensionsv1.ValidationRule, error) {
result := existing
result.Rule = override.Rule
if override.Message != "" {
result.Message = override.Message
}
if override.MessageExpression != "" {
result.MessageExpression = override.MessageExpression
}
if override.Reason != "" {
switch override.Reason {
case string(apiextensionsv1.FieldValueRequired), string(apiextensionsv1.FieldValueInvalid), string(apiextensionsv1.FieldValueForbidden), string(apiextensionsv1.FieldValueDuplicate):
reason := apiextensionsv1.FieldValueErrorReason(override.Reason)
result.Reason = &reason
default:
return apiextensionsv1.ValidationRule{}, fmt.Errorf("invalid reason %s, valid values are %s, %s, %s and %s", override.Reason, apiextensionsv1.FieldValueRequired, apiextensionsv1.FieldValueInvalid, apiextensionsv1.FieldValueForbidden, apiextensionsv1.FieldValueDuplicate)
}
}
if override.FieldPath != "" {
result.FieldPath = override.FieldPath
}
if override.OptionalOldSelf != nil {
result.OptionalOldSelf = override.OptionalOldSelf
}
return result, nil
}
func addAttribution(crd *apiextensionsv1.CustomResourceDefinition) {
if crd.ObjectMeta.Annotations == nil {
crd.ObjectMeta.Annotations = map[string]string{}
}
crd.ObjectMeta.Annotations["controller-gen.kubebuilder.io/version"] = controllerGenVersion
}
func removeDescriptionFromMetadata(crd *apiextensionsv1.CustomResourceDefinition) {
for _, versionSpec := range crd.Spec.Versions {
if versionSpec.Schema != nil {
removeDescriptionFromMetadataProps(versionSpec.Schema.OpenAPIV3Schema)
}
}
}
func removeDescriptionFromMetadataProps(schema *apiextensionsv1.JSONSchemaProps) {
metadataSchema, ok := schema.Properties["metadata"]
if !ok {
return
}
if metadataSchema.Description == "" {
return
}
metadataSchema.Description = ""
schema.Properties["metadata"] = metadataSchema
}
func marshalCRD(crd *apiextensionsv1.CustomResourceDefinition) ([]byte, error) {
type output struct {
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Metadata map[string]any `json:"metadata,omitempty"`
Spec apiextensionsv1.CustomResourceDefinitionSpec `json:"spec"`
}
metadataBytes, err := yaml.Marshal(crd.ObjectMeta)
if err != nil {
return nil, err
}
metadata := map[string]any{}
if err := yaml.Unmarshal(metadataBytes, &metadata); err != nil {
return nil, err
}
delete(metadata, "creationTimestamp")
out, err := yaml.Marshal(output{
APIVersion: crd.APIVersion,
Kind: crd.Kind,
Metadata: metadata,
Spec: crd.Spec,
})
if err != nil {
return nil, err
}
if bytes.HasPrefix(out, []byte("---\n")) {
return out, nil
}
return append([]byte("---\n"), out...), nil
}

View File

@ -1,188 +0,0 @@
package main
import (
"testing"
"github.com/stretchr/testify/require"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"sigs.k8s.io/controller-tools/pkg/crd"
"sigs.k8s.io/controller-tools/pkg/loader"
"sigs.k8s.io/controller-tools/pkg/markers"
)
func newTestParser(t *testing.T, rootPath string) ([]*loader.Package, *crd.Parser) {
t.Helper()
roots, err := loader.LoadRoots(rootPath)
require.NoError(t, err)
require.Len(t, roots, 1)
generator := &crd.Generator{}
parser := &crd.Parser{
Collector: &markers.Collector{Registry: &markers.Registry{}},
Checker: &loader.TypeChecker{
NodeFilters: []loader.NodeFilter{generator.CheckFilter()},
},
}
require.NoError(t, generator.RegisterMarkers(parser.Collector.Registry))
require.NoError(t, registerCustomMarkers(parser.Collector.Registry))
crd.AddKnownTypes(parser)
parser.NeedPackage(roots[0])
return roots, parser
}
func TestAllJSONFieldNamesForTypeIncludesImportedInlineFields(t *testing.T) {
const rootPath = "github.com/agentgateway/agentgateway/controller/hack/crdgen/testdata/root"
roots, parser := newTestParser(t, rootPath)
typ := crd.TypeIdent{
Package: roots[0],
Name: "Wrapper",
}
info := parser.LookupType(typ.Package, typ.Name)
require.NotNil(t, info)
fields, err := allJSONFieldNamesForType(parser, typ, info, map[crd.TypeIdent][]string{}, map[crd.TypeIdent]bool{})
require.NoError(t, err)
require.Equal(t, []string{"bar", "baz", "foo"}, fields)
}
func TestOverrideXValidationReplacesExactlyOneMatch(t *testing.T) {
schema := &apiextensionsv1.JSONSchemaProps{
XValidations: []apiextensionsv1.ValidationRule{
{
Rule: "old-rule",
Message: "phase PreRouting only supports extAuth",
},
{
Rule: "keep-rule",
Message: "some other validation",
},
},
}
err := applyOverrideXValidation(schema, OverrideXValidation{
MessageContains: "phase PreRouting only",
Rule: "new-rule",
})
require.NoError(t, err)
require.Equal(t, apiextensionsv1.ValidationRules{
{
Rule: "new-rule",
Message: "phase PreRouting only supports extAuth",
},
{
Rule: "keep-rule",
Message: "some other validation",
},
}, schema.XValidations)
}
func TestOverrideXValidationRemovesMatchWhenRuleEmpty(t *testing.T) {
schema := &apiextensionsv1.JSONSchemaProps{
XValidations: []apiextensionsv1.ValidationRule{
{
Rule: "old-rule",
Message: "phase PreRouting only supports extAuth",
},
{
Rule: "keep-rule",
Message: "some other validation",
},
},
}
err := applyOverrideXValidation(schema, OverrideXValidation{
MessageContains: "phase PreRouting only",
})
require.NoError(t, err)
require.Equal(t, apiextensionsv1.ValidationRules{
{
Rule: "keep-rule",
Message: "some other validation",
},
}, schema.XValidations)
}
func TestOverrideXValidationErrorsWithoutExactSingleMatch(t *testing.T) {
t.Run("no matches", func(t *testing.T) {
schema := &apiextensionsv1.JSONSchemaProps{
XValidations: []apiextensionsv1.ValidationRule{
{Rule: "keep-rule", Message: "some other validation"},
},
}
err := applyOverrideXValidation(schema, OverrideXValidation{
MessageContains: "phase PreRouting only",
Rule: "new-rule",
})
require.EqualError(t, err, "OverrideXValidation matched 0 rules for messageContains \"phase PreRouting only\", expected exactly 1")
})
t.Run("multiple matches", func(t *testing.T) {
schema := &apiextensionsv1.JSONSchemaProps{
XValidations: []apiextensionsv1.ValidationRule{
{Rule: "old-rule-1", Message: "phase PreRouting only supports extAuth"},
{Rule: "old-rule-2", Message: "phase PreRouting only supports rateLimit"},
},
}
err := applyOverrideXValidation(schema, OverrideXValidation{
MessageContains: "phase PreRouting only",
Rule: "new-rule",
})
require.EqualError(t, err, "OverrideXValidation matched 2 rules for messageContains \"phase PreRouting only\", expected exactly 1")
})
}
func TestApplyIfThenOnlyFieldsUsesVisibleSchemaFields(t *testing.T) {
schema := &apiextensionsv1.JSONSchemaProps{
Properties: map[string]apiextensionsv1.JSONSchemaProps{
"foo": {},
"bar": {},
"baz": {},
},
}
err := applyIfThenOnlyFields(schema, sortedPropertyNames(schema), IfThenOnlyFields{
If: "has(self.baz)",
Fields: []string{"foo", "baz"},
})
require.NoError(t, err)
require.Len(t, schema.XValidations, 1)
require.Equal(t, "has(self.baz) ? [has(self.bar)].filter(x,x==true).size() == 0 : true", schema.XValidations[0].Rule)
require.Equal(t, "only fields in [baz foo] may be set when has(self.baz)", schema.XValidations[0].Message)
}
func TestApplyPostSchemaMarkersToCRDIfThenOnlyFieldsIncludesImportedInlineFields(t *testing.T) {
const rootPath = "github.com/agentgateway/agentgateway/controller/hack/crdgen/testdata/ifthenembedded/api/v1"
roots, parser := newTestParser(t, rootPath)
metav1Pkg := crd.FindMetav1(roots)
require.NotNil(t, metav1Pkg)
kubeKinds := crd.FindKubeKinds(parser, metav1Pkg)
require.Len(t, kubeKinds, 1)
groupKind := kubeKinds[0]
maxDescLen := 0
parser.NeedCRDFor(groupKind, &maxDescLen)
crdObj := parser.CustomResourceDefinitions[groupKind]
require.NoError(t, applyPostSchemaMarkersToCRD(parser, &crdObj, groupKind))
require.Len(t, crdObj.Spec.Versions, 1)
rootSchema := crdObj.Spec.Versions[0].Schema.OpenAPIV3Schema
require.NotNil(t, rootSchema)
specSchema, ok := rootSchema.Properties["spec"]
require.True(t, ok)
trafficSchema, ok := specSchema.Properties["traffic"]
require.True(t, ok)
require.Len(t, trafficSchema.XValidations, 1)
require.Equal(t, "when baz is set only foo and baz may be set", trafficSchema.XValidations[0].Message)
require.Equal(t, "has(self.baz) ? [has(self.bar)].filter(x,x==true).size() == 0 : true", trafficSchema.XValidations[0].Rule)
}

View File

@ -1,6 +0,0 @@
package embedded
type InlineFields struct {
Foo *string `json:"foo,omitempty"`
Bar *string `json:"bar,omitempty"`
}

View File

@ -1,2 +0,0 @@
// +groupName=testdata.agentgateway.dev
package v1

View File

@ -1,26 +0,0 @@
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/agentgateway/agentgateway/controller/hack/crdgen/testdata/ifthenembedded/embedded"
)
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=widgets,scope=Namespaced
type Widget struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec WidgetSpec `json:"spec,omitempty"`
}
type WidgetSpec struct {
Traffic Traffic `json:"traffic,omitempty"`
}
// +kubebuilder:validation:IfThenOnlyFields:if="has(self.baz)",fields=foo;baz,message="when baz is set only foo and baz may be set"
type Traffic struct {
embedded.InlineFields `json:",inline"`
Baz *string `json:"baz,omitempty"`
}

View File

@ -1,6 +0,0 @@
package embedded
type InlineFields struct {
Foo *string `json:"foo,omitempty"`
Bar *string `json:"bar,omitempty"`
}

View File

@ -1,9 +0,0 @@
package root
import "github.com/agentgateway/agentgateway/controller/hack/crdgen/testdata/embedded"
// +kubebuilder:validation:AtLeastOneFieldSet
type Wrapper struct {
embedded.InlineFields `json:",inline"`
Baz *string `json:"baz,omitempty"`
}

View File

@ -0,0 +1,13 @@
ARG BASE_IMAGE
FROM $BASE_IMAGE
ARG GOARCH=amd64
RUN apk -U upgrade
COPY dummy-idp-linux-$GOARCH /usr/local/bin/dummy-idp
USER 10101
ENTRYPOINT ["/usr/local/bin/dummy-idp"]

View File

@ -0,0 +1,185 @@
Based on agentgateway auth0 example: https://github.com/agentgateway/agentgateway/tree/485a299d2199cf7f792a8f7e55677f1a4898013b/examples/mcp-authentication
## Building and Deploying
1. Build docker with the Make target
```shell
VERSION=<version> make kind-build-and-load-dummy-idp
```
2. Apply the mock IDP deployment
```shell
kubectl apply -f test/e2e/features/agentgateway/mcp/testdata/auth0-mock-server.yaml
```
## Running Locally
### Option 1: Using Docker (without Kubernetes)
Build and run the Docker container locally:
```shell
# Build the Go binary and Docker image (will rebuild if source changed)
make dummy-idp-docker
# Run the container
docker run -p 8443:8443 ghcr.io/agentgateway/dummy-idp:0.0.1
```
**Note:** If you see "Nothing to be done for 'dummy-idp'", that's normal - it means the binary is already built and up to date. The `dummy-idp-docker` target will automatically rebuild the binary if source files have changed.
**Alternative: Build with a custom tag**
```shell
# Build the binary first (or force rebuild by deleting _output/hack/dummy-idp/dummy-idp-linux-amd64)
make dummy-idp
# Build Docker image with custom tag (from the output directory)
docker build -f _output/hack/dummy-idp/Dockerfile.dummy-idp \
--build-arg BASE_IMAGE=alpine:3.17.6 \
--build-arg GOARCH=amd64 \
-t dummy-idp:local \
_output/hack/dummy-idp
# Run the container
docker run -p 8443:8443 dummy-idp:local
```
**Force a rebuild:** If you've made code changes and want to force a rebuild:
```shell
# Remove the binary to force rebuild
rm -f _output/hack/dummy-idp/dummy-idp-linux-<arch>
make dummy-idp-docker
```
**Quick run command:**
```shell
docker run -p 8443:8443 ghcr.io/agentgateway/dummy-idp:0.0.1
```
The server will be available at `https://localhost:8443`.
### Option 2: Using Kubernetes Port-Forward
To test the dummy-idp server locally via Kubernetes, port-forward the service:
```shell
kubectl port-forward svc/auth0-mock 8443:8443
```
The server runs on HTTPS port 8443 with a self-signed certificate. When using `curl`, use the `-k` flag to skip certificate verification.
## Testing Endpoints
### OAuth2 Discovery Endpoint
Get the OAuth2 discovery document:
```shell
curl -k https://localhost:8443/.well-known/oauth-authorization-server
```
### JWKS Endpoint
Get the JSON Web Key Set:
```shell
curl -k https://localhost:8443/.well-known/jwks.json
```
### Client Registration
Register a new OAuth2 client:
```shell
curl -k -X POST https://localhost:8443/register \
-H "Content-Type: application/json"
```
### Authorization Endpoint
Request authorization (returns redirect URL with code):
```shell
curl -k "https://localhost:8443/authorize?client_id=mcp_gi3APARn2_uHv2oxfJJqq2yZBDV4OyNo&redirect_uri=http://localhost:8081/callback"
```
### Token Endpoint
Exchange authorization code for access token:
```shell
curl -k -X POST https://localhost:8443/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "client_id=mcp_gi3APARn2_uHv2oxfJJqq2yZBDV4OyNo" \
-d "code=fixed_auth_code_123" \
-d "redirect_uri=http://localhost:8081/callback"
```
Or use Basic authentication:
```shell
curl -k -X POST https://localhost:8443/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-u "mcp_gi3APARn2_uHv2oxfJJqq2yZBDV4OyNo:secret_2nGx_bjvo9z72Aw3-hKTWMusEo2-yTfH" \
-d "grant_type=authorization_code" \
-d "code=fixed_auth_code_123" \
-d "redirect_uri=http://localhost:8081/callback"
```
### Refresh Token
A request to "refresh" an access token will return the same token since this is a mock IDP server for testing. You can try the following request to refresh the token:
```shell
curl -k -X POST https://localhost:8443/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-u "mcp_gi3APARn2_uHv2oxfJJqq2yZBDV4OyNo:secret_2nGx_bjvo9z72Aw3-hKTWMusEo2-yTfH" \
-d "grant_type=refresh_token" \
-d "refresh_token=fixed_refresh_token_123"
```
### Organization-specific Endpoints
Get JWKS for different organizations:
```shell
curl -k https://localhost:8443/org-one/keys
curl -k https://localhost:8443/org-two/keys
curl -k https://localhost:8443/org-three/keys
```
Get JWT tokens for different organizations:
```shell
curl -k https://localhost:8443/org-one/jwt
curl -k https://localhost:8443/org-two/jwt
curl -k https://localhost:8443/org-three/jwt
```
## Hardcoded Values for MCP Auth Flow
The mock server will always return the same JWT token and key pair, which has a 10-year expiration date set. The values for
the token returned are:
```json
{
"iss": "https://kgateway.dev",
"sub": "ignore@kgateway.dev",
"exp": 2071163407,
"nbf": 1763579407,
"iat": 1763579407
}
```
**Hardcoded OAuth2 values:**
- Client ID: `mcp_gi3APARn2_uHv2oxfJJqq2yZBDV4OyNo`
- Client Secret: `secret_2nGx_bjvo9z72Aw3-hKTWMusEo2-yTfH`
- Authorization Code: `fixed_auth_code_123`
- Refresh Token: `fixed_refresh_token_123`
- Redirect URI: `http://localhost:8081/callback`
The mock IDP provider will use a hard coded code `fixed_auth_code_123` for the `handle_authorize` endpoint. The mock
server also sets the redirect url to `http://localhost:8081/callback`, so when testing the MCP Inspector locally,
make sure to expose this through the gateway and route configuration.

View File

@ -6,6 +6,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"log"
"net/http"
"strings"
"time"
@ -19,15 +20,15 @@ var cert []byte
//go:embed dummy-idp.key
var key []byte
func startDummyIDP() (shutdownFunc, error) {
func main() {
roots := x509.NewCertPool()
if !roots.AppendCertsFromPEM(cert) {
return nil, fmt.Errorf("failed to append Cert from PEM")
log.Fatal("failed to append Cert from PEM")
}
cert, err := tls.X509KeyPair(cert, key)
if err != nil {
return nil, err
log.Panic(err)
}
mux := http.NewServeMux()
@ -81,14 +82,12 @@ func startDummyIDP() (shutdownFunc, error) {
mux.ServeHTTP(w, r)
})
// nolint: gosec // Test code only
cfg := &tls.Config{
RootCAs: roots,
Certificates: []tls.Certificate{cert},
NextProtos: []string{"http/1.1"},
}
// nolint: gosec // Test code only
srv := &http.Server{
Addr: "0.0.0.0:8443",
Handler: muxWithCORS,
@ -96,23 +95,20 @@ func startDummyIDP() (shutdownFunc, error) {
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0),
}
return serveHTTP("dummy-idp", srv, func() error {
return srv.ListenAndServeTLS("", "")
}), nil
log.Fatal(srv.ListenAndServeTLS("", ""))
}
// OAuth2/OIDC constants
const (
hardcodedClientID = "mcp_gi3APARn2_uHv2oxfJJqq2yZBDV4OyNo"
hardcodedCode = "fixed_auth_code_123"
// nolint: gosec // Test code only
hardcodedClientID = "mcp_gi3APARn2_uHv2oxfJJqq2yZBDV4OyNo"
hardcodedCode = "fixed_auth_code_123"
hardcodedClientSecret = "secret_2nGx_bjvo9z72Aw3-hKTWMusEo2-yTfH"
hardcodedRefreshToken = "fixed_refresh_token_123"
redirectURI = "http://localhost:8081/callback"
)
// sendJSONResponse sends a JSON response with CORS headers
func sendJSONResponse(w http.ResponseWriter, r *http.Request, data any, statusCode int) {
func sendJSONResponse(w http.ResponseWriter, r *http.Request, data interface{}, statusCode int) {
w.Header().Set("Content-Type", "application/json")
origin := r.Header.Get("Origin")
if origin == "" {
@ -137,7 +133,7 @@ func handleRegister(w http.ResponseWriter, r *http.Request) {
return
}
registration := map[string]any{
registration := map[string]interface{}{
"client_id": hardcodedClientID,
"client_secret": hardcodedClientSecret,
"client_name": "Test Client",
@ -206,7 +202,7 @@ func handleToken(w http.ResponseWriter, r *http.Request) {
// Be lenient for generic MCP inspectors/SPAs using PKCE:
// - Do not require client_secret (public client)
// - Accept any code/redirect_uri/code_verifier
response := map[string]any{
response := map[string]interface{}{
"access_token": string(orgOneJwt),
"refresh_token": hardcodedRefreshToken,
"token_type": "bearer",
@ -221,7 +217,7 @@ func handleToken(w http.ResponseWriter, r *http.Request) {
return
}
// Accept any refresh_token for testing purposes
response := map[string]any{
response := map[string]interface{}{
"access_token": string(orgOneJwt),
"refresh_token": hardcodedRefreshToken,
"token_type": "bearer",
@ -271,7 +267,7 @@ func handleDiscovery(w http.ResponseWriter, r *http.Request) {
}
baseURL := fmt.Sprintf("%s://%s", scheme, host)
discovery := map[string]any{
discovery := map[string]interface{}{
"issuer": "https://kgateway.dev",
"authorization_endpoint": fmt.Sprintf("%s/authorize", baseURL),
"token_endpoint": fmt.Sprintf("%s/token", baseURL),

View File

@ -50,15 +50,23 @@ for VERSION in "${VERSIONS[@]}"; do
rm -f "${ROOT_DIR}/api/${VERSION}/agentgateway/zz_generated.register.go.bak"
done
# Generate objects and RBAC with stock controller-gen.
(cd "${REPO_ROOT}" && controller-gen object paths="${APIS_PKG}/api/${VERSION}/agentgateway" paths="${APIS_PKG}/api/${VERSION}/shared")
# Generate agentgateway CRDs and RBAC
(cd "${REPO_ROOT}" && controller-gen crd:maxDescLen=50000 object rbac:roleName=agentgateway paths="${APIS_PKG}/api/${VERSION}/agentgateway" paths="${APIS_PKG}/api/${VERSION}/shared" \
output:crd:artifacts:config=${ROOT_DIR}/${AGENTGATEWAY_CRD_DIR} output:rbac:artifacts:config=${ROOT_DIR}/${AGENTGATEWAY_MANIFESTS_DIR})
# Template the ClusterRole name to include the namespace
if [[ "$OSTYPE" == "darwin"* ]]; then
# On macOS, prefer gsed (GNU sed) if available
if command -v gsed &> /dev/null; then
gsed -i 's/name: agentgateway/name: agentgateway-{{ .Release.Namespace }}/g' "${ROOT_DIR}/${AGENTGATEWAY_MANIFESTS_DIR}/role.yaml"
else
# Fallback to macOS's native sed
sed -i '' 's/name: agentgateway/name: agentgateway-{{ .Release.Namespace }}/g' "${ROOT_DIR}/${AGENTGATEWAY_MANIFESTS_DIR}/role.yaml"
fi
else
# For other OSes like Linux
sed -i 's/name: agentgateway/name: agentgateway-{{ .Release.Namespace }}/g' "${ROOT_DIR}/${AGENTGATEWAY_MANIFESTS_DIR}/role.yaml"
fi
# Generate CRDs with custom kubebuilder validation markers.
(cd "${REPO_ROOT}" && go run ./controller/hack/crdgen \
--max-desc-len 50000 \
--output-dir "${ROOT_DIR}/${AGENTGATEWAY_CRD_DIR}" \
--path "${APIS_PKG}/api/${VERSION}/agentgateway" \
--path "${APIS_PKG}/api/${VERSION}/shared")
# throw away
new_report="$(mktemp -t "$(basename "$0").api_violations.XXXXXX")"
@ -72,3 +80,4 @@ new_report="$(mktemp -t "$(basename "$0").api_violations.XXXXXX")"
--plural-exceptions "AgentgatewayParameters:AgentgatewayParameters")
go generate ${ROOT_DIR}/pkg/...

View File

@ -1,9 +0,0 @@
FROM cgr.dev/chainguard/static
ARG GOARCH=amd64
COPY testbox-linux-$GOARCH /usr/local/bin/testbox
USER nonroot:nonroot
ENTRYPOINT ["/usr/local/bin/testbox"]

View File

@ -1,17 +0,0 @@
# testbox
Single e2e helper image used by multiple tests.
Ports:
- `80/443/7070/9090`: Istio echo app server (`backend` service)
- `8443`: dummy-idp/auth0-mock
- `18080`: ext-proc gRPC server
- `9000`: ext-authz gRPC server
- `8000`: mcp-website-fetcher
- `3001`: mcp-admin-server
- `9999`: a2a-helloworld
Build/load:
```bash
make -C controller testbox-docker kind-load-testbox
```

View File

@ -1,115 +0,0 @@
package main
import (
"encoding/json"
"io"
"net/http"
"strings"
"time"
)
type a2aRequest struct {
JSONRPC string `json:"jsonrpc"`
ID json.RawMessage `json:"id,omitempty"`
Method string `json:"method"`
Params struct {
ID string `json:"id"`
Message struct {
Parts []struct {
Text string `json:"text"`
} `json:"parts"`
} `json:"message"`
} `json:"params"`
}
func startA2AServer() (shutdownFunc, error) {
mux := http.NewServeMux()
mux.HandleFunc("/agent-card", handleAgentCard)
mux.HandleFunc("/", handleA2ARequest)
// nolint: gosec // Test code only
httpServer := &http.Server{
Addr: ":9999",
Handler: mux,
}
return serveHTTP("a2a", httpServer, httpServer.ListenAndServe), nil
}
func handleAgentCard(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]any{
"name": "Example A2A Agent",
"version": "1.0.0",
"description": "An example A2A agent using the a2a-protocol crate",
"skills": []map[string]any{
{
"id": "echo",
"name": "Echo Skill",
"description": "Echoes back the user's message",
},
},
})
}
func handleA2ARequest(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
body, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
var req a2aRequest
if err := json.Unmarshal(body, &req); err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
if req.Method != "tasks/send" {
w.WriteHeader(http.StatusBadRequest)
return
}
userText := ""
if len(req.Params.Message.Parts) > 0 {
userText = req.Params.Message.Parts[0].Text
}
if userText == "" {
userText = "hello"
}
agentMessage := map[string]any{
"kind": "message",
"messageId": "agent-reply-1",
"role": "agent",
"parts": []map[string]any{
{"kind": "text", "text": "Echo: " + strings.TrimSpace(userText)},
},
}
result := map[string]any{
"contextId": "ctx-1",
"history": []any{agentMessage},
"id": req.Params.ID,
"kind": "task",
"status": map[string]any{
"message": agentMessage,
"state": "working",
"timestamp": time.Now().UTC().Format(time.RFC3339Nano),
},
}
resp := map[string]any{
"jsonrpc": "2.0",
"id": req.ID,
"result": result,
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(resp)
}

View File

@ -1,48 +0,0 @@
package main
import (
"context"
"log"
"os"
"istio.io/istio/pkg/config/protocol"
"istio.io/istio/pkg/test/echo/common"
echoserver "istio.io/istio/pkg/test/echo/server"
)
func startEchoAppServer() (shutdownFunc, error) {
ports := common.PortList{
&common.Port{Name: "http-0", Protocol: protocol.HTTP, Port: 80},
&common.Port{Name: "tcp-0", Protocol: protocol.TCP, Port: 9090},
&common.Port{Name: "grpc-0", Protocol: protocol.GRPC, Port: 7070},
}
cfg := echoserver.Config{
Ports: ports,
Namespace: os.Getenv("NAMESPACE"),
ReportRequest: func() {
},
}
if fileExists("/tls/tls.crt") && fileExists("/tls/tls.key") {
cfg.TLSCert = "/tls/tls.crt"
cfg.TLSKey = "/tls/tls.key"
cfg.Ports = append(cfg.Ports, &common.Port{Name: "https", Protocol: protocol.HTTP, Port: 443, TLS: true})
} else {
log.Println("app TLS certs are not mounted; skipping echo TLS")
}
s := echoserver.New(cfg)
if err := s.Start(); err != nil {
return nil, err
}
return func(_ context.Context) error {
return s.Close()
}, nil
}
func fileExists(path string) bool {
_, err := os.Stat(path)
return err == nil
}

View File

@ -1,120 +0,0 @@
package main
import (
"context"
"log"
"net"
"strings"
envoycorev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
authv3 "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
typev3 "github.com/envoyproxy/go-control-plane/envoy/type/v3"
"google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)
const (
extAuthzCheckHeader = "x-ext-authz"
extAuthzAllowedValue = "allow"
extAuthzResultHeader = "x-ext-authz-check-result"
extAuthzReceivedHeader = "x-ext-authz-check-received"
extAuthzOverrideHeader = "x-ext-authz-additional-header-override"
extAuthzOverrideGRPCValue = "grpc-additional-header-override-value"
extAuthzResultAllowed = "allowed"
extAuthzResultDenied = "denied"
extAuthzAllowedServiceAccount = "a"
)
var extAuthzDenyBody = "denied by ext_authz for not found header `x-ext-authz: allow` in the request"
type extAuthzServerV3 struct{}
func startExtAuthzServer() (shutdownFunc, error) {
// nolint: gosec // Test code only
listener, err := net.Listen("tcp", ":9000")
if err != nil {
return nil, err
}
grpcServer := grpc.NewServer()
authv3.RegisterAuthorizationServer(grpcServer, &extAuthzServerV3{})
return serveGRPC("ext-authz", listener, grpcServer), nil
}
func (s *extAuthzServerV3) Check(_ context.Context, request *authv3.CheckRequest) (*authv3.CheckResponse, error) {
attrs := request.GetAttributes()
allow := false
checkHeaderValue, contains := attrs.GetRequest().GetHttp().GetHeaders()[extAuthzCheckHeader]
if contains {
allow = checkHeaderValue == extAuthzAllowedValue
} else {
allow = attrs.Source != nil && strings.HasSuffix(attrs.Source.Principal, "/sa/"+extAuthzAllowedServiceAccount)
}
if allow {
return s.allow(request), nil
}
return s.deny(request), nil
}
func (s *extAuthzServerV3) allow(request *authv3.CheckRequest) *authv3.CheckResponse {
s.logRequest("allowed", request)
return &authv3.CheckResponse{
HttpResponse: &authv3.CheckResponse_OkResponse{
OkResponse: &authv3.OkHttpResponse{
Headers: []*envoycorev3.HeaderValueOption{
{
Header: &envoycorev3.HeaderValue{Key: extAuthzResultHeader, Value: extAuthzResultAllowed},
},
{
Header: &envoycorev3.HeaderValue{Key: extAuthzReceivedHeader, Value: returnIfNotTooLong(request.GetAttributes().String())},
},
{
Header: &envoycorev3.HeaderValue{Key: extAuthzOverrideHeader, Value: extAuthzOverrideGRPCValue},
},
},
},
},
Status: &status.Status{Code: int32(codes.OK)},
}
}
func (s *extAuthzServerV3) deny(request *authv3.CheckRequest) *authv3.CheckResponse {
s.logRequest("denied", request)
return &authv3.CheckResponse{
HttpResponse: &authv3.CheckResponse_DeniedResponse{
DeniedResponse: &authv3.DeniedHttpResponse{
Status: &typev3.HttpStatus{Code: typev3.StatusCode_Forbidden},
Body: extAuthzDenyBody,
Headers: []*envoycorev3.HeaderValueOption{
{
Header: &envoycorev3.HeaderValue{Key: extAuthzResultHeader, Value: extAuthzResultDenied},
},
{
Header: &envoycorev3.HeaderValue{Key: extAuthzReceivedHeader, Value: returnIfNotTooLong(request.GetAttributes().String())},
},
{
Header: &envoycorev3.HeaderValue{Key: extAuthzOverrideHeader, Value: extAuthzOverrideGRPCValue},
},
},
},
},
Status: &status.Status{Code: int32(codes.PermissionDenied)},
}
}
func (s *extAuthzServerV3) logRequest(state string, request *authv3.CheckRequest) {
httpAttrs := request.GetAttributes().GetRequest().GetHttp()
log.Printf("[ext-authz][%s] %s%s", state, httpAttrs.GetHost(), httpAttrs.GetPath())
}
func returnIfNotTooLong(body string) string {
if len(body) > 60000 {
return "<too-long>"
}
return body
}

View File

@ -1,51 +0,0 @@
package main
import (
"context"
"log"
"os/signal"
"syscall"
"time"
)
type shutdownFunc func(context.Context) error
func main() {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
shutdowns := make([]shutdownFunc, 0, 7)
start := func(name string, fn func() (shutdownFunc, error)) {
shutdown, err := fn()
if err != nil {
log.Fatalf("failed to start %s: %v", name, err)
}
if shutdown != nil {
shutdowns = append(shutdowns, shutdown)
}
log.Printf("started %s", name)
}
start("dummy-idp", startDummyIDP)
start("extproc", startExtProcServer)
start("ext-authz", startExtAuthzServer)
start("mcp-website-fetcher", startMCPWebsiteServer)
start("mcp-admin-server", startMCPAdminServer)
start("test-a2a-server", startA2AServer)
start("app", startEchoAppServer)
<-ctx.Done()
log.Printf("received shutdown signal")
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
for i := len(shutdowns) - 1; i >= 0; i-- {
if err := shutdowns[i](shutdownCtx); err != nil {
log.Printf("shutdown error: %v", err)
}
}
log.Printf("testbox stopped")
}

View File

@ -1,91 +0,0 @@
package main
import (
"context"
"fmt"
"net/http"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func startMCPWebsiteServer() (shutdownFunc, error) {
return startMCPServer(":8000", "mcp-website-fetcher", newMCPWebsiteServer())
}
func startMCPAdminServer() (shutdownFunc, error) {
return startMCPServer(":3001", "mcp-admin-server", newMCPAdminServer())
}
func startMCPServer(addr, name string, server *mcp.Server) (shutdownFunc, error) {
mux := http.NewServeMux()
mux.Handle("/mcp", mcp.NewStreamableHTTPHandler(func(*http.Request) *mcp.Server {
return server
}, nil))
mux.Handle("/", mcp.NewSSEHandler(func(*http.Request) *mcp.Server {
return server
}, nil))
// nolint: gosec // Test code only
httpServer := &http.Server{
Addr: addr,
Handler: mux,
}
return serveHTTP(name, httpServer, httpServer.ListenAndServe), nil
}
func newMCPWebsiteServer() *mcp.Server {
s := mcp.NewServer(&mcp.Implementation{
Name: "mcp-website-fetcher",
Version: "1.0.0",
}, &mcp.ServerOptions{})
mcp.AddTool(s, &mcp.Tool{
Name: "fetch",
Description: "Fetch a URL and return extracted content.",
}, fetchTool)
return s
}
func newMCPAdminServer() *mcp.Server {
s := mcp.NewServer(&mcp.Implementation{
Name: "mcp-admin-server",
Version: "1.0.0",
}, &mcp.ServerOptions{})
mcp.AddTool(s, &mcp.Tool{
Name: "fetch",
Description: "Fetch a URL and return extracted content.",
}, fetchTool)
mcp.AddTool(s, &mcp.Tool{
Name: "admin_status",
Description: "Return admin diagnostics.",
}, adminStatusTool)
return s
}
type fetchArgs struct {
URL string `json:"url" jsonschema:"The URL to fetch"`
}
func fetchTool(_ context.Context, _ *mcp.CallToolRequest, args fetchArgs) (*mcp.CallToolResult, any, error) {
if args.URL == "" {
return nil, nil, fmt.Errorf("missing url")
}
return &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{Text: "fetched: " + args.URL},
},
}, nil, nil
}
func adminStatusTool(_ context.Context, _ *mcp.CallToolRequest, _ struct{}) (*mcp.CallToolResult, any, error) {
return &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{Text: "ok"},
},
}, nil, nil
}

View File

@ -1,47 +0,0 @@
package main
import (
"context"
"errors"
"log"
"net"
"net/http"
"google.golang.org/grpc"
)
func serveHTTP(name string, srv *http.Server, listen func() error) shutdownFunc {
go func() {
if err := listen(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("%s exited: %v", name, err)
}
}()
return func(ctx context.Context) error {
return srv.Shutdown(ctx)
}
}
func serveGRPC(name string, listener net.Listener, server *grpc.Server) shutdownFunc {
go func() {
if err := server.Serve(listener); err != nil && !errors.Is(err, grpc.ErrServerStopped) {
log.Fatalf("%s exited: %v", name, err)
}
}()
return func(ctx context.Context) error {
done := make(chan struct{})
go func() {
server.GracefulStop()
close(done)
}()
select {
case <-done:
return nil
case <-ctx.Done():
server.Stop()
return ctx.Err()
}
}
}

View File

@ -1,55 +1,49 @@
Name|Version|License
---|---|---
[semver/v3](https://github.com/Masterminds/semver)|v3.4.0|MIT License
[anthropics/anthropic-sdk-go](https://github.com/anthropics/anthropic-sdk-go)|v1.27.1|MIT License
[anthropics/anthropic-sdk-go](https://github.com/anthropics/anthropic-sdk-go)|v1.19.0|MIT License
[retry-go/v4](https://github.com/avast/retry-go)|v4.7.0|MIT License
[xds/go](https://github.com/cncf/xds)|v0.0.0-20260202195803-dba9d589def2|Apache License 2.0
[go-control-plane/envoy](https://github.com/envoyproxy/go-control-plane)|v1.37.1-0.20260402053555-4e9843ddb8d0|Apache License 2.0
[xds/go](https://github.com/cncf/xds)|v0.0.0-20251110193048-8bfbf64dc13e|Apache License 2.0
[go-control-plane/envoy](https://github.com/envoyproxy/go-control-plane)|v1.36.1-0.20251120180717-7c66c7f1d0b2|Apache License 2.0
[ghodss/yaml](https://github.com/ghodss/yaml)|v1.0.1-0.20190212211648-25d852aebe32|MIT License
[go-jose/v4](https://github.com/go-jose/go-jose)|v4.1.3|Apache License 2.0
[go-logr/logr](https://github.com/go-logr/logr)|v1.4.3|Apache License 2.0
[jwt/v5](https://github.com/golang-jwt/jwt)|v5.3.1|MIT License
[google/cel-go](https://github.com/google/cel-go)|v0.27.0|Apache License 2.0
[jwt/v5](https://github.com/golang-jwt/jwt)|v5.3.0|MIT License
[golang/protobuf](https://github.com/golang/protobuf)|v1.5.4|BSD 3-clause "New" or "Revised" License
[google/cel-go](https://github.com/google/cel-go)|v0.26.1|Apache License 2.0
[google/go-cmp](https://github.com/google/go-cmp)|v0.7.0|BSD 3-clause "New" or "Revised" License
[google/uuid](https://github.com/google/uuid)|v1.6.0|BSD 3-clause "New" or "Revised" License
[grpc-ecosystem/go-grpc-middleware](https://github.com/grpc-ecosystem/go-grpc-middleware)|v1.4.0|Apache License 2.0
[kagent-dev/mockllm](https://github.com/kagent-dev/mockllm)|v0.0.5|Apache License 2.0
[kagent-dev/mockllm](https://github.com/kagent-dev/mockllm)|v0.0.2-0.20251008144831-c6105837f767|Apache License 2.0
[kelseyhightower/envconfig](https://github.com/kelseyhightower/envconfig)|v1.4.0|MIT License
[modelcontextprotocol/go-sdk](https://github.com/modelcontextprotocol/go-sdk)|v1.4.1|Apache License 2.0
[ginkgo/v2](https://github.com/onsi/ginkgo)|v2.28.1|MIT License
[onsi/gomega](https://github.com/onsi/gomega)|v1.39.1|MIT License
[openai-go/v3](https://github.com/openai/openai-go)|v3.29.0|Apache License 2.0
[ginkgo/v2](https://github.com/onsi/ginkgo)|v2.27.2|MIT License
[onsi/gomega](https://github.com/onsi/gomega)|v1.38.2|MIT License
[openai/openai-go](https://github.com/openai/openai-go)|v1.12.0|Apache License 2.0
[prometheus/client_golang](https://github.com/prometheus/client_golang)|v1.23.2|Apache License 2.0
[prometheus/client_model](https://github.com/prometheus/client_model)|v0.6.2|Apache License 2.0
[prometheus/common](https://github.com/prometheus/common)|v0.67.5|Apache License 2.0
[prometheus/common](https://github.com/prometheus/common)|v0.67.1|Apache License 2.0
[spf13/cobra](https://github.com/spf13/cobra)|v1.10.2|Apache License 2.0
[stretchr/testify](https://github.com/stretchr/testify)|v1.11.1|MIT License
[go.opencensus.io](https://go.opencensus.io)|v0.24.0|Apache License 2.0
[go.uber.org/atomic](https://go.uber.org/atomic)|v1.11.0|MIT License
[go.uber.org/zap](https://go.uber.org/zap)|v1.27.1|MIT License
[x/net](https://golang.org/x/net)|v0.52.0|BSD 3-clause "New" or "Revised" License
[x/sync](https://golang.org/x/sync)|v0.20.0|BSD 3-clause "New" or "Revised" License
[x/time](https://golang.org/x/time)|v0.15.0|BSD 3-clause "New" or "Revised" License
[x/tools](https://golang.org/x/tools)|v0.43.0|BSD 3-clause "New" or "Revised" License
[googleapis/rpc](https://google.golang.org/genproto/googleapis/rpc)|v0.0.0-20260319201613-d00831a3d3e7|Apache License 2.0
[google.golang.org/grpc](https://google.golang.org/grpc)|v1.79.3|Apache License 2.0
[x/net](https://golang.org/x/net)|v0.48.0|BSD 3-clause "New" or "Revised" License
[x/time](https://golang.org/x/time)|v0.14.0|BSD 3-clause "New" or "Revised" License
[google.golang.org/grpc](https://google.golang.org/grpc)|v1.77.0|Apache License 2.0
[google.golang.org/protobuf](https://google.golang.org/protobuf)|v1.36.11|BSD 3-clause "New" or "Revised" License
[helm/v3](https://helm.sh/helm/v3)|v3.20.1|Apache License 2.0
[istio.io/api](https://istio.io/api)|v1.29.0-alpha.0.0.20260315093121-ce7e56c13e1d|Apache License 2.0
[istio.io/client-go](https://istio.io/client-go)|v1.29.0-alpha.0.0.20260315093321-a99807642da7|Apache License 2.0
[istio.io/istio](https://istio.io/istio)|v0.0.0-20260407051556-b9f70d130eb6|Apache License 2.0
[k8s.io/api](https://k8s.io/api)|v0.35.3|Apache License 2.0
[k8s.io/apiextensions-apiserver](https://k8s.io/apiextensions-apiserver)|v0.35.3|Apache License 2.0
[k8s.io/apimachinery](https://k8s.io/apimachinery)|v0.35.3|Apache License 2.0
[k8s.io/client-go](https://k8s.io/client-go)|v0.35.3|Apache License 2.0
[klog/v2](https://k8s.io/klog/v2)|v2.140.0|Apache License 2.0
[k8s.io/utils](https://k8s.io/utils)|v0.0.0-20260319190234-28399d86e0b5|Apache License 2.0
[sigs.k8s.io/controller-runtime](https://sigs.k8s.io/controller-runtime)|v0.23.3|Apache License 2.0
[sigs.k8s.io/controller-tools](https://sigs.k8s.io/controller-tools)|v0.20.1|Apache License 2.0
[sigs.k8s.io/gateway-api](https://sigs.k8s.io/gateway-api)|v1.5.1|Apache License 2.0
[sigs.k8s.io/gateway-api-inference-extension](https://sigs.k8s.io/gateway-api-inference-extension)|v1.4.0|Apache License 2.0
[gateway-api-inference-extension/conformance](https://sigs.k8s.io/gateway-api-inference-extension/conformance)|v0.0.0-20260319184001-6e787dd396f0|Apache License 2.0
[gateway-api/conformance](https://sigs.k8s.io/gateway-api/conformance)|v1.5.1|Apache License 2.0
[helm/v3](https://helm.sh/helm/v3)|v3.19.2|Apache License 2.0
[istio.io/api](https://istio.io/api)|v1.28.0-alpha.0.0.20251210001900-ce7b5802387c|Apache License 2.0
[istio.io/client-go](https://istio.io/client-go)|v1.28.0-alpha.0.0.20251210002059-b67694478a4b|Apache License 2.0
[istio.io/istio](https://istio.io/istio)|v0.0.0-20251218162427-600ea84d2996|Apache License 2.0
[k8s.io/api](https://k8s.io/api)|v0.34.1|Apache License 2.0
[k8s.io/apiextensions-apiserver](https://k8s.io/apiextensions-apiserver)|v0.34.1|Apache License 2.0
[k8s.io/apimachinery](https://k8s.io/apimachinery)|v0.34.3|Apache License 2.0
[k8s.io/client-go](https://k8s.io/client-go)|v0.34.1|Apache License 2.0
[klog/v2](https://k8s.io/klog/v2)|v2.130.1|Apache License 2.0
[k8s.io/utils](https://k8s.io/utils)|v0.0.0-20251002143259-bc988d571ff4|Apache License 2.0
[sigs.k8s.io/controller-runtime](https://sigs.k8s.io/controller-runtime)|v0.22.3|Apache License 2.0
[sigs.k8s.io/gateway-api](https://sigs.k8s.io/gateway-api)|v1.4.1|Apache License 2.0
[sigs.k8s.io/gateway-api-inference-extension](https://sigs.k8s.io/gateway-api-inference-extension)|v1.1.0|Apache License 2.0
[sigs.k8s.io/yaml](https://sigs.k8s.io/yaml)|v1.6.0|MIT License
[cmd/goimports](https://golang.org/x/tools/cmd/goimports)|latest|MIT License
[gogo/protobuf](https://github.com/gogo/protobuf)|latest|MIT License

View File

@ -5,15 +5,15 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.20.0
labels:
app: agentgateway
app.kubernetes.io/name: agentgateway
app: kgateway
app.kubernetes.io/name: kgateway
gateway.networking.k8s.io/policy: Direct
name: agentgatewayparameters.agentgateway.dev
spec:
group: agentgateway.dev
names:
categories:
- agentgateway
- kgateway
kind: AgentgatewayParameters
listKind: AgentgatewayParametersList
plural: agentgatewayparameters
@ -56,16 +56,15 @@ spec:
description: spec defines the desired state of AgentgatewayParameters.
properties:
deployment:
description: |-
`deployment` allows specifying overrides for the generated
`Deployment` resource.
description: deployment allows specifying overrides for the generated
Deployment resource.
properties:
metadata:
description: |-
`metadata` defines a subset of object metadata to be customized.
`labels` and `annotations` are merged with existing values. If both
`GatewayClass` and `Gateway` parameters define the same label or
annotation key, the `Gateway` value takes precedence (applied second).
metadata defines a subset of object metadata to be customized.
Labels and annotations are merged with existing values. If both GatewayClass
and Gateway parameters define the same label or annotation key, the Gateway
value takes precedence (applied second).
properties:
annotations:
additionalProperties:
@ -87,56 +86,55 @@ spec:
type: object
type: object
spec:
description: "`spec` provides an opaque mechanism to configure
the resource spec.\nThis field accepts a complete or partial
Kubernetes resource spec, such\nas `PodSpec` or `ServiceSpec`,
and will be merged with the generated\nconfiguration using **Strategic
Merge Patch** semantics.\n\n# Application Order\n\nOverlays
are applied after all typed configuration fields from both levels.\nThe
full merge order is:\n\n 1. `GatewayClass` typed configuration
fields\n 2. `Gateway` typed configuration fields\n 3. `GatewayClass`
overlays\n 4. `Gateway` overlays (can override all previous
values)\n\n# Strategic Merge Patch & Deletion Guide\n\nThis
merge strategy allows you to override individual fields, merge
lists, or delete items\nwithout needing to provide the entire
resource definition.\n\n**1. Replacing Values (Scalars):**\nSimple
fields (strings, integers, booleans) in your config will overwrite
the generated defaults.\n\n**2. Merging Lists (Append/Merge):**\nLists
with \"merge keys\", like `containers` which merges on `name`,
or\n`tolerations` which merges on `key`,\nwill append your items
to the generated list, or update existing items if keys match.\n\n**3.
Deleting Fields or List Items ($patch: delete):**\nTo remove
a field or list item from the generated resource, use the\n`$patch:
delete` directive. This works for both map fields and list items,\nand
description: "Spec provides an opaque mechanism to configure the
resource Spec.\nThis field accepts a complete or partial Kubernetes
resource spec (e.g., PodSpec, ServiceSpec)\nand will be merged
with the generated configuration using **Strategic Merge Patch**
semantics.\n\n# Application Order\n\nOverlays are applied after
all typed configuration fields from both levels.\nThe full merge
order is:\n\n 1. GatewayClass typed configuration fields\n 2.
Gateway typed configuration fields\n 3. GatewayClass overlays\n
4. Gateway overlays (can override all previous values)\n\n#
Strategic Merge Patch & Deletion Guide\n\nThis merge strategy
allows you to override individual fields, merge lists, or delete
items\nwithout needing to provide the entire resource definition.\n\n**1.
Replacing Values (Scalars):**\nSimple fields (strings, integers,
booleans) in your config will overwrite the generated defaults.\n\n**2.
Merging Lists (Append/Merge):**\nLists with \"merge keys\" (like
`containers` which merges on `name`, or `tolerations` which
merges on `key`)\nwill append your items to the generated list,
or update existing items if keys match.\n\n**3. Deleting Fields
or List Items ($patch: delete):**\nTo remove a field or list
item from the generated resource, use the\n`$patch: delete`
directive. This works for both map fields and list items,\nand
is the recommended approach because it works with both client-side\nand
server-side apply.\n\n\tspec:\n\t template:\n\t spec:\n\t
\ # Delete pod-level securityContext\n\t securityContext:\n\t
\ $patch: delete\n\t # Delete nodeSelector\n\t nodeSelector:\n\t
\ $patch: delete\n\t containers:\n\t # Be sure
to use the correct proxy name here or you will add a\n\t #
container instead of modifying a container.\n\t - name:
proxy-name\n\t # Delete container-level securityContext\n\t
\ securityContext:\n\t $patch: delete\n\n**4.
Null Values (server-side apply only):**\nSetting a field to
`null` can also remove it, but this ONLY works with\n`kubectl
apply --server-side` or equivalent. With regular client-side\n`kubectl
apply`, null values are stripped by kubectl before reaching\nthe
API server, so the deletion won't occur. Prefer `$patch: delete`\nfor
consistent behavior across both apply modes.\n\n\tspec:\n\t
\ template:\n\t spec:\n\t nodeSelector: null # Removes
nodeSelector (server-side apply only!)\n\n**5. Replacing Maps
Entirely ($patch: replace):**\nTo replace an entire map with
your values (instead of merging), use `$patch: replace`.\nThis
removes all existing keys and replaces them with only your specified
keys.\n\n\tspec:\n\t template:\n\t spec:\n\t nodeSelector:\n\t
\ $patch: replace\n\t custom-key: custom-value\n\n**6.
Replacing Lists Entirely ($patch: replace):**\nIf you want to
strictly define a list and ignore all generated defaults, use
`$patch: replace`.\n\n\tservice:\n\t spec:\n\t ports:\n\t
\ - $patch: replace\n\t - name: http\n\t port: 80\n\t
\ targetPort: 8080\n\t protocol: TCP\n\t - name:
https\n\t port: 443\n\t targetPort: 8443\n\t protocol:
TCP"
\ $patch: delete\n\t containers:\n\t # Be
sure to use the correct proxy name here or you will add a container
instead of modifying a container:\n\t - name: proxy-name\n\t
\ # Delete container-level securityContext\n\t securityContext:\n\t
\ $patch: delete\n\n**4. Null Values (server-side
apply only):**\nSetting a field to `null` can also remove it,
but this ONLY works with\n`kubectl apply --server-side` or equivalent.
With regular client-side\n`kubectl apply`, null values are stripped
by kubectl before reaching\nthe API server, so the deletion
won't occur. Prefer `$patch: delete`\nfor consistent behavior
across both apply modes.\n\n\tspec:\n\t template:\n\t spec:\n\t
\ nodeSelector: null # Removes nodeSelector (server-side
apply only!)\n\n**5. Replacing Maps Entirely ($patch: replace):**\nTo
replace an entire map with your values (instead of merging),
use `$patch: replace`.\nThis removes all existing keys and replaces
them with only your specified keys.\n\n\tspec:\n\t template:\n\t
\ spec:\n\t nodeSelector:\n\t $patch: replace\n\t
\ custom-key: custom-value\n\n**6. Replacing Lists Entirely
($patch: replace):**\nIf you want to strictly define a list
and ignore all generated defaults, use `$patch: replace`.\n\n\tservice:\n\t
\ spec:\n\t ports:\n\t - $patch: replace\n\t -
name: http\n\t port: 80\n\t targetPort: 8080\n\t
\ protocol: TCP\n\t - name: https\n\t port:
443\n\t targetPort: 8443\n\t protocol: TCP"
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
@ -144,16 +142,13 @@ spec:
description: |-
The container environment variables. These override any existing
values. If you want to delete an environment variable entirely, use
`$patch: delete` with `AgentgatewayParametersOverlays` instead. Note that
`$patch: delete` with AgentgatewayParametersOverlays instead. Note that
[variable
expansion](https://kubernetes.io/docs/tasks/inject-data-application/define-interdependent-environment-variables/)
does apply, but is highly discouraged -- to set dependent environment
variables, you can use `$(VAR_NAME)`, but it's highly discouraged.
`$$(VAR_NAME)` avoids expansion and results in a literal
variables, you can use $(VAR_NAME), but it's highly
discouraged. `$$(VAR_NAME)` avoids expansion and results in a literal
`$(VAR_NAME)`.
If `SESSION_KEY` is specified, it takes precedence over the
controller-managed per-`Gateway` session key `Secret`.
items:
description: EnvVar represents an environment variable present in
a Container.
@ -311,18 +306,17 @@ spec:
type: array
horizontalPodAutoscaler:
description: |-
`horizontalPodAutoscaler` allows creating a `HorizontalPodAutoscaler`
for the agentgateway proxy. If absent, no HPA is created. If present, an
HPA is created with its `scaleTargetRef` automatically configured to
target the agentgateway proxy `Deployment`. The `metadata` and `spec`
fields from this overlay are applied to the generated HPA.
horizontalPodAutoscaler allows creating a HorizontalPodAutoscaler for the agentgateway proxy.
If absent, no HPA is created. If present, an HPA is created with its scaleTargetRef
automatically configured to target the agentgateway proxy Deployment.
The metadata and spec fields from this overlay are applied to the generated HPA.
properties:
metadata:
description: |-
`metadata` defines a subset of object metadata to be customized.
`labels` and `annotations` are merged with existing values. If both
`GatewayClass` and `Gateway` parameters define the same label or
annotation key, the `Gateway` value takes precedence (applied second).
metadata defines a subset of object metadata to be customized.
Labels and annotations are merged with existing values. If both GatewayClass
and Gateway parameters define the same label or annotation key, the Gateway
value takes precedence (applied second).
properties:
annotations:
additionalProperties:
@ -344,56 +338,55 @@ spec:
type: object
type: object
spec:
description: "`spec` provides an opaque mechanism to configure
the resource spec.\nThis field accepts a complete or partial
Kubernetes resource spec, such\nas `PodSpec` or `ServiceSpec`,
and will be merged with the generated\nconfiguration using **Strategic
Merge Patch** semantics.\n\n# Application Order\n\nOverlays
are applied after all typed configuration fields from both levels.\nThe
full merge order is:\n\n 1. `GatewayClass` typed configuration
fields\n 2. `Gateway` typed configuration fields\n 3. `GatewayClass`
overlays\n 4. `Gateway` overlays (can override all previous
values)\n\n# Strategic Merge Patch & Deletion Guide\n\nThis
merge strategy allows you to override individual fields, merge
lists, or delete items\nwithout needing to provide the entire
resource definition.\n\n**1. Replacing Values (Scalars):**\nSimple
fields (strings, integers, booleans) in your config will overwrite
the generated defaults.\n\n**2. Merging Lists (Append/Merge):**\nLists
with \"merge keys\", like `containers` which merges on `name`,
or\n`tolerations` which merges on `key`,\nwill append your items
to the generated list, or update existing items if keys match.\n\n**3.
Deleting Fields or List Items ($patch: delete):**\nTo remove
a field or list item from the generated resource, use the\n`$patch:
delete` directive. This works for both map fields and list items,\nand
description: "Spec provides an opaque mechanism to configure the
resource Spec.\nThis field accepts a complete or partial Kubernetes
resource spec (e.g., PodSpec, ServiceSpec)\nand will be merged
with the generated configuration using **Strategic Merge Patch**
semantics.\n\n# Application Order\n\nOverlays are applied after
all typed configuration fields from both levels.\nThe full merge
order is:\n\n 1. GatewayClass typed configuration fields\n 2.
Gateway typed configuration fields\n 3. GatewayClass overlays\n
4. Gateway overlays (can override all previous values)\n\n#
Strategic Merge Patch & Deletion Guide\n\nThis merge strategy
allows you to override individual fields, merge lists, or delete
items\nwithout needing to provide the entire resource definition.\n\n**1.
Replacing Values (Scalars):**\nSimple fields (strings, integers,
booleans) in your config will overwrite the generated defaults.\n\n**2.
Merging Lists (Append/Merge):**\nLists with \"merge keys\" (like
`containers` which merges on `name`, or `tolerations` which
merges on `key`)\nwill append your items to the generated list,
or update existing items if keys match.\n\n**3. Deleting Fields
or List Items ($patch: delete):**\nTo remove a field or list
item from the generated resource, use the\n`$patch: delete`
directive. This works for both map fields and list items,\nand
is the recommended approach because it works with both client-side\nand
server-side apply.\n\n\tspec:\n\t template:\n\t spec:\n\t
\ # Delete pod-level securityContext\n\t securityContext:\n\t
\ $patch: delete\n\t # Delete nodeSelector\n\t nodeSelector:\n\t
\ $patch: delete\n\t containers:\n\t # Be sure
to use the correct proxy name here or you will add a\n\t #
container instead of modifying a container.\n\t - name:
proxy-name\n\t # Delete container-level securityContext\n\t
\ securityContext:\n\t $patch: delete\n\n**4.
Null Values (server-side apply only):**\nSetting a field to
`null` can also remove it, but this ONLY works with\n`kubectl
apply --server-side` or equivalent. With regular client-side\n`kubectl
apply`, null values are stripped by kubectl before reaching\nthe
API server, so the deletion won't occur. Prefer `$patch: delete`\nfor
consistent behavior across both apply modes.\n\n\tspec:\n\t
\ template:\n\t spec:\n\t nodeSelector: null # Removes
nodeSelector (server-side apply only!)\n\n**5. Replacing Maps
Entirely ($patch: replace):**\nTo replace an entire map with
your values (instead of merging), use `$patch: replace`.\nThis
removes all existing keys and replaces them with only your specified
keys.\n\n\tspec:\n\t template:\n\t spec:\n\t nodeSelector:\n\t
\ $patch: replace\n\t custom-key: custom-value\n\n**6.
Replacing Lists Entirely ($patch: replace):**\nIf you want to
strictly define a list and ignore all generated defaults, use
`$patch: replace`.\n\n\tservice:\n\t spec:\n\t ports:\n\t
\ - $patch: replace\n\t - name: http\n\t port: 80\n\t
\ targetPort: 8080\n\t protocol: TCP\n\t - name:
https\n\t port: 443\n\t targetPort: 8443\n\t protocol:
TCP"
\ $patch: delete\n\t containers:\n\t # Be
sure to use the correct proxy name here or you will add a container
instead of modifying a container:\n\t - name: proxy-name\n\t
\ # Delete container-level securityContext\n\t securityContext:\n\t
\ $patch: delete\n\n**4. Null Values (server-side
apply only):**\nSetting a field to `null` can also remove it,
but this ONLY works with\n`kubectl apply --server-side` or equivalent.
With regular client-side\n`kubectl apply`, null values are stripped
by kubectl before reaching\nthe API server, so the deletion
won't occur. Prefer `$patch: delete`\nfor consistent behavior
across both apply modes.\n\n\tspec:\n\t template:\n\t spec:\n\t
\ nodeSelector: null # Removes nodeSelector (server-side
apply only!)\n\n**5. Replacing Maps Entirely ($patch: replace):**\nTo
replace an entire map with your values (instead of merging),
use `$patch: replace`.\nThis removes all existing keys and replaces
them with only your specified keys.\n\n\tspec:\n\t template:\n\t
\ spec:\n\t nodeSelector:\n\t $patch: replace\n\t
\ custom-key: custom-value\n\n**6. Replacing Lists Entirely
($patch: replace):**\nIf you want to strictly define a list
and ignore all generated defaults, use `$patch: replace`.\n\n\tservice:\n\t
\ spec:\n\t ports:\n\t - $patch: replace\n\t -
name: http\n\t port: 80\n\t targetPort: 8080\n\t
\ protocol: TCP\n\t - name: https\n\t port:
443\n\t targetPort: 8443\n\t protocol: TCP"
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
@ -436,9 +429,8 @@ spec:
type: string
type: object
logging:
description: |-
`logging` configuration for Agentgateway. By default, all logs are set to
`info` level.
description: logging configuration for Agentgateway. By default, all
logs are set to "info" level.
properties:
format:
description: The default logging format is text.
@ -448,25 +440,24 @@ spec:
type: string
level:
description: |-
Logging level in standard `RUST_LOG` syntax, for example `info` (the
default), or a comma-separated per-module setting such as
`rmcp=warn,hickory_server::server::server_future=off,typespec_client_core::http::policies::logging=warn`.
Logging level in standard RUST_LOG syntax, e.g. 'info', the default, or
by module, comma-separated. E.g.,
"rmcp=warn,hickory_server::server::server_future=off,typespec_client_core::http::policies::logging=warn"
type: string
type: object
podDisruptionBudget:
description: |-
`podDisruptionBudget` allows creating a `PodDisruptionBudget` for the
agentgateway proxy. If absent, no PDB is created. If present, a PDB is
created with its selector automatically configured to target the
agentgateway proxy `Deployment`. The `metadata` and `spec` fields from
this overlay are applied to the generated PDB.
podDisruptionBudget allows creating a PodDisruptionBudget for the agentgateway proxy.
If absent, no PDB is created. If present, a PDB is created with its selector
automatically configured to target the agentgateway proxy Deployment.
The metadata and spec fields from this overlay are applied to the generated PDB.
properties:
metadata:
description: |-
`metadata` defines a subset of object metadata to be customized.
`labels` and `annotations` are merged with existing values. If both
`GatewayClass` and `Gateway` parameters define the same label or
annotation key, the `Gateway` value takes precedence (applied second).
metadata defines a subset of object metadata to be customized.
Labels and annotations are merged with existing values. If both GatewayClass
and Gateway parameters define the same label or annotation key, the Gateway
value takes precedence (applied second).
properties:
annotations:
additionalProperties:
@ -488,73 +479,71 @@ spec:
type: object
type: object
spec:
description: "`spec` provides an opaque mechanism to configure
the resource spec.\nThis field accepts a complete or partial
Kubernetes resource spec, such\nas `PodSpec` or `ServiceSpec`,
and will be merged with the generated\nconfiguration using **Strategic
Merge Patch** semantics.\n\n# Application Order\n\nOverlays
are applied after all typed configuration fields from both levels.\nThe
full merge order is:\n\n 1. `GatewayClass` typed configuration
fields\n 2. `Gateway` typed configuration fields\n 3. `GatewayClass`
overlays\n 4. `Gateway` overlays (can override all previous
values)\n\n# Strategic Merge Patch & Deletion Guide\n\nThis
merge strategy allows you to override individual fields, merge
lists, or delete items\nwithout needing to provide the entire
resource definition.\n\n**1. Replacing Values (Scalars):**\nSimple
fields (strings, integers, booleans) in your config will overwrite
the generated defaults.\n\n**2. Merging Lists (Append/Merge):**\nLists
with \"merge keys\", like `containers` which merges on `name`,
or\n`tolerations` which merges on `key`,\nwill append your items
to the generated list, or update existing items if keys match.\n\n**3.
Deleting Fields or List Items ($patch: delete):**\nTo remove
a field or list item from the generated resource, use the\n`$patch:
delete` directive. This works for both map fields and list items,\nand
description: "Spec provides an opaque mechanism to configure the
resource Spec.\nThis field accepts a complete or partial Kubernetes
resource spec (e.g., PodSpec, ServiceSpec)\nand will be merged
with the generated configuration using **Strategic Merge Patch**
semantics.\n\n# Application Order\n\nOverlays are applied after
all typed configuration fields from both levels.\nThe full merge
order is:\n\n 1. GatewayClass typed configuration fields\n 2.
Gateway typed configuration fields\n 3. GatewayClass overlays\n
4. Gateway overlays (can override all previous values)\n\n#
Strategic Merge Patch & Deletion Guide\n\nThis merge strategy
allows you to override individual fields, merge lists, or delete
items\nwithout needing to provide the entire resource definition.\n\n**1.
Replacing Values (Scalars):**\nSimple fields (strings, integers,
booleans) in your config will overwrite the generated defaults.\n\n**2.
Merging Lists (Append/Merge):**\nLists with \"merge keys\" (like
`containers` which merges on `name`, or `tolerations` which
merges on `key`)\nwill append your items to the generated list,
or update existing items if keys match.\n\n**3. Deleting Fields
or List Items ($patch: delete):**\nTo remove a field or list
item from the generated resource, use the\n`$patch: delete`
directive. This works for both map fields and list items,\nand
is the recommended approach because it works with both client-side\nand
server-side apply.\n\n\tspec:\n\t template:\n\t spec:\n\t
\ # Delete pod-level securityContext\n\t securityContext:\n\t
\ $patch: delete\n\t # Delete nodeSelector\n\t nodeSelector:\n\t
\ $patch: delete\n\t containers:\n\t # Be sure
to use the correct proxy name here or you will add a\n\t #
container instead of modifying a container.\n\t - name:
proxy-name\n\t # Delete container-level securityContext\n\t
\ securityContext:\n\t $patch: delete\n\n**4.
Null Values (server-side apply only):**\nSetting a field to
`null` can also remove it, but this ONLY works with\n`kubectl
apply --server-side` or equivalent. With regular client-side\n`kubectl
apply`, null values are stripped by kubectl before reaching\nthe
API server, so the deletion won't occur. Prefer `$patch: delete`\nfor
consistent behavior across both apply modes.\n\n\tspec:\n\t
\ template:\n\t spec:\n\t nodeSelector: null # Removes
nodeSelector (server-side apply only!)\n\n**5. Replacing Maps
Entirely ($patch: replace):**\nTo replace an entire map with
your values (instead of merging), use `$patch: replace`.\nThis
removes all existing keys and replaces them with only your specified
keys.\n\n\tspec:\n\t template:\n\t spec:\n\t nodeSelector:\n\t
\ $patch: replace\n\t custom-key: custom-value\n\n**6.
Replacing Lists Entirely ($patch: replace):**\nIf you want to
strictly define a list and ignore all generated defaults, use
`$patch: replace`.\n\n\tservice:\n\t spec:\n\t ports:\n\t
\ - $patch: replace\n\t - name: http\n\t port: 80\n\t
\ targetPort: 8080\n\t protocol: TCP\n\t - name:
https\n\t port: 443\n\t targetPort: 8443\n\t protocol:
TCP"
\ $patch: delete\n\t containers:\n\t # Be
sure to use the correct proxy name here or you will add a container
instead of modifying a container:\n\t - name: proxy-name\n\t
\ # Delete container-level securityContext\n\t securityContext:\n\t
\ $patch: delete\n\n**4. Null Values (server-side
apply only):**\nSetting a field to `null` can also remove it,
but this ONLY works with\n`kubectl apply --server-side` or equivalent.
With regular client-side\n`kubectl apply`, null values are stripped
by kubectl before reaching\nthe API server, so the deletion
won't occur. Prefer `$patch: delete`\nfor consistent behavior
across both apply modes.\n\n\tspec:\n\t template:\n\t spec:\n\t
\ nodeSelector: null # Removes nodeSelector (server-side
apply only!)\n\n**5. Replacing Maps Entirely ($patch: replace):**\nTo
replace an entire map with your values (instead of merging),
use `$patch: replace`.\nThis removes all existing keys and replaces
them with only your specified keys.\n\n\tspec:\n\t template:\n\t
\ spec:\n\t nodeSelector:\n\t $patch: replace\n\t
\ custom-key: custom-value\n\n**6. Replacing Lists Entirely
($patch: replace):**\nIf you want to strictly define a list
and ignore all generated defaults, use `$patch: replace`.\n\n\tservice:\n\t
\ spec:\n\t ports:\n\t - $patch: replace\n\t -
name: http\n\t port: 80\n\t targetPort: 8080\n\t
\ protocol: TCP\n\t - name: https\n\t port:
443\n\t targetPort: 8443\n\t protocol: TCP"
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
rawConfig:
description: "`rawConfig` provides an opaque mechanism to configure
the `agentgateway`\nconfig file. The `agentgateway` binary has a
`-f` option to specify a\nconfig file, and this field supplies that
file. This will be merged with\nconfiguration derived from typed
fields like `logging.format`, and those\ntyped fields will take
precedence.\n\nExample:\n\n\trawConfig:\n\t binds:\n\t - port:
3000\n\t listeners:\n\t - routes:\n\t - policies:\n\t
\ cors:\n\t allowOrigins:\n\t - \"*\"\n\t
\ allowHeaders:\n\t - mcp-protocol-version\n\t
\ - content-type\n\t - cache-control\n\t backends:\n\t
\ - mcp:\n\t targets:\n\t - name: everything\n\t
\ stdio:\n\t cmd: npx\n\t args:
[\"@modelcontextprotocol/server-everything\"]"
description: "rawConfig provides an opaque mechanism to configure
the agentgateway\nconfig file (the agentgateway binary has a '-f'
option to specify a\nconfig file, and this is that file). This
will be merged with\nconfiguration derived from typed fields like\nAgentgatewayParametersLogging.Format,
and those typed fields will take\nprecedence.\n\nExample:\n\n\trawConfig:\n\t
\ binds:\n\t - port: 3000\n\t listeners:\n\t - routes:\n\t
\ - policies:\n\t cors:\n\t allowOrigins:\n\t
\ - \"*\"\n\t allowHeaders:\n\t -
mcp-protocol-version\n\t - content-type\n\t -
cache-control\n\t backends:\n\t - mcp:\n\t targets:\n\t
\ - name: everything\n\t stdio:\n\t cmd:
npx\n\t args: [\"@modelcontextprotocol/server-everything\"]"
type: object
x-kubernetes-preserve-unknown-fields: true
resources:
@ -620,16 +609,15 @@ spec:
type: object
type: object
service:
description: |-
`service` allows specifying overrides for the generated `Service`
resource.
description: service allows specifying overrides for the generated
Service resource.
properties:
metadata:
description: |-
`metadata` defines a subset of object metadata to be customized.
`labels` and `annotations` are merged with existing values. If both
`GatewayClass` and `Gateway` parameters define the same label or
annotation key, the `Gateway` value takes precedence (applied second).
metadata defines a subset of object metadata to be customized.
Labels and annotations are merged with existing values. If both GatewayClass
and Gateway parameters define the same label or annotation key, the Gateway
value takes precedence (applied second).
properties:
annotations:
additionalProperties:
@ -651,70 +639,68 @@ spec:
type: object
type: object
spec:
description: "`spec` provides an opaque mechanism to configure
the resource spec.\nThis field accepts a complete or partial
Kubernetes resource spec, such\nas `PodSpec` or `ServiceSpec`,
and will be merged with the generated\nconfiguration using **Strategic
Merge Patch** semantics.\n\n# Application Order\n\nOverlays
are applied after all typed configuration fields from both levels.\nThe
full merge order is:\n\n 1. `GatewayClass` typed configuration
fields\n 2. `Gateway` typed configuration fields\n 3. `GatewayClass`
overlays\n 4. `Gateway` overlays (can override all previous
values)\n\n# Strategic Merge Patch & Deletion Guide\n\nThis
merge strategy allows you to override individual fields, merge
lists, or delete items\nwithout needing to provide the entire
resource definition.\n\n**1. Replacing Values (Scalars):**\nSimple
fields (strings, integers, booleans) in your config will overwrite
the generated defaults.\n\n**2. Merging Lists (Append/Merge):**\nLists
with \"merge keys\", like `containers` which merges on `name`,
or\n`tolerations` which merges on `key`,\nwill append your items
to the generated list, or update existing items if keys match.\n\n**3.
Deleting Fields or List Items ($patch: delete):**\nTo remove
a field or list item from the generated resource, use the\n`$patch:
delete` directive. This works for both map fields and list items,\nand
description: "Spec provides an opaque mechanism to configure the
resource Spec.\nThis field accepts a complete or partial Kubernetes
resource spec (e.g., PodSpec, ServiceSpec)\nand will be merged
with the generated configuration using **Strategic Merge Patch**
semantics.\n\n# Application Order\n\nOverlays are applied after
all typed configuration fields from both levels.\nThe full merge
order is:\n\n 1. GatewayClass typed configuration fields\n 2.
Gateway typed configuration fields\n 3. GatewayClass overlays\n
4. Gateway overlays (can override all previous values)\n\n#
Strategic Merge Patch & Deletion Guide\n\nThis merge strategy
allows you to override individual fields, merge lists, or delete
items\nwithout needing to provide the entire resource definition.\n\n**1.
Replacing Values (Scalars):**\nSimple fields (strings, integers,
booleans) in your config will overwrite the generated defaults.\n\n**2.
Merging Lists (Append/Merge):**\nLists with \"merge keys\" (like
`containers` which merges on `name`, or `tolerations` which
merges on `key`)\nwill append your items to the generated list,
or update existing items if keys match.\n\n**3. Deleting Fields
or List Items ($patch: delete):**\nTo remove a field or list
item from the generated resource, use the\n`$patch: delete`
directive. This works for both map fields and list items,\nand
is the recommended approach because it works with both client-side\nand
server-side apply.\n\n\tspec:\n\t template:\n\t spec:\n\t
\ # Delete pod-level securityContext\n\t securityContext:\n\t
\ $patch: delete\n\t # Delete nodeSelector\n\t nodeSelector:\n\t
\ $patch: delete\n\t containers:\n\t # Be sure
to use the correct proxy name here or you will add a\n\t #
container instead of modifying a container.\n\t - name:
proxy-name\n\t # Delete container-level securityContext\n\t
\ securityContext:\n\t $patch: delete\n\n**4.
Null Values (server-side apply only):**\nSetting a field to
`null` can also remove it, but this ONLY works with\n`kubectl
apply --server-side` or equivalent. With regular client-side\n`kubectl
apply`, null values are stripped by kubectl before reaching\nthe
API server, so the deletion won't occur. Prefer `$patch: delete`\nfor
consistent behavior across both apply modes.\n\n\tspec:\n\t
\ template:\n\t spec:\n\t nodeSelector: null # Removes
nodeSelector (server-side apply only!)\n\n**5. Replacing Maps
Entirely ($patch: replace):**\nTo replace an entire map with
your values (instead of merging), use `$patch: replace`.\nThis
removes all existing keys and replaces them with only your specified
keys.\n\n\tspec:\n\t template:\n\t spec:\n\t nodeSelector:\n\t
\ $patch: replace\n\t custom-key: custom-value\n\n**6.
Replacing Lists Entirely ($patch: replace):**\nIf you want to
strictly define a list and ignore all generated defaults, use
`$patch: replace`.\n\n\tservice:\n\t spec:\n\t ports:\n\t
\ - $patch: replace\n\t - name: http\n\t port: 80\n\t
\ targetPort: 8080\n\t protocol: TCP\n\t - name:
https\n\t port: 443\n\t targetPort: 8443\n\t protocol:
TCP"
\ $patch: delete\n\t containers:\n\t # Be
sure to use the correct proxy name here or you will add a container
instead of modifying a container:\n\t - name: proxy-name\n\t
\ # Delete container-level securityContext\n\t securityContext:\n\t
\ $patch: delete\n\n**4. Null Values (server-side
apply only):**\nSetting a field to `null` can also remove it,
but this ONLY works with\n`kubectl apply --server-side` or equivalent.
With regular client-side\n`kubectl apply`, null values are stripped
by kubectl before reaching\nthe API server, so the deletion
won't occur. Prefer `$patch: delete`\nfor consistent behavior
across both apply modes.\n\n\tspec:\n\t template:\n\t spec:\n\t
\ nodeSelector: null # Removes nodeSelector (server-side
apply only!)\n\n**5. Replacing Maps Entirely ($patch: replace):**\nTo
replace an entire map with your values (instead of merging),
use `$patch: replace`.\nThis removes all existing keys and replaces
them with only your specified keys.\n\n\tspec:\n\t template:\n\t
\ spec:\n\t nodeSelector:\n\t $patch: replace\n\t
\ custom-key: custom-value\n\n**6. Replacing Lists Entirely
($patch: replace):**\nIf you want to strictly define a list
and ignore all generated defaults, use `$patch: replace`.\n\n\tservice:\n\t
\ spec:\n\t ports:\n\t - $patch: replace\n\t -
name: http\n\t port: 80\n\t targetPort: 8080\n\t
\ protocol: TCP\n\t - name: https\n\t port:
443\n\t targetPort: 8443\n\t protocol: TCP"
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
serviceAccount:
description: |-
`serviceAccount` allows specifying overrides for the generated
`ServiceAccount` resource.
description: serviceAccount allows specifying overrides for the generated
ServiceAccount resource.
properties:
metadata:
description: |-
`metadata` defines a subset of object metadata to be customized.
`labels` and `annotations` are merged with existing values. If both
`GatewayClass` and `Gateway` parameters define the same label or
annotation key, the `Gateway` value takes precedence (applied second).
metadata defines a subset of object metadata to be customized.
Labels and annotations are merged with existing values. If both GatewayClass
and Gateway parameters define the same label or annotation key, the Gateway
value takes precedence (applied second).
properties:
annotations:
additionalProperties:
@ -736,72 +722,70 @@ spec:
type: object
type: object
spec:
description: "`spec` provides an opaque mechanism to configure
the resource spec.\nThis field accepts a complete or partial
Kubernetes resource spec, such\nas `PodSpec` or `ServiceSpec`,
and will be merged with the generated\nconfiguration using **Strategic
Merge Patch** semantics.\n\n# Application Order\n\nOverlays
are applied after all typed configuration fields from both levels.\nThe
full merge order is:\n\n 1. `GatewayClass` typed configuration
fields\n 2. `Gateway` typed configuration fields\n 3. `GatewayClass`
overlays\n 4. `Gateway` overlays (can override all previous
values)\n\n# Strategic Merge Patch & Deletion Guide\n\nThis
merge strategy allows you to override individual fields, merge
lists, or delete items\nwithout needing to provide the entire
resource definition.\n\n**1. Replacing Values (Scalars):**\nSimple
fields (strings, integers, booleans) in your config will overwrite
the generated defaults.\n\n**2. Merging Lists (Append/Merge):**\nLists
with \"merge keys\", like `containers` which merges on `name`,
or\n`tolerations` which merges on `key`,\nwill append your items
to the generated list, or update existing items if keys match.\n\n**3.
Deleting Fields or List Items ($patch: delete):**\nTo remove
a field or list item from the generated resource, use the\n`$patch:
delete` directive. This works for both map fields and list items,\nand
description: "Spec provides an opaque mechanism to configure the
resource Spec.\nThis field accepts a complete or partial Kubernetes
resource spec (e.g., PodSpec, ServiceSpec)\nand will be merged
with the generated configuration using **Strategic Merge Patch**
semantics.\n\n# Application Order\n\nOverlays are applied after
all typed configuration fields from both levels.\nThe full merge
order is:\n\n 1. GatewayClass typed configuration fields\n 2.
Gateway typed configuration fields\n 3. GatewayClass overlays\n
4. Gateway overlays (can override all previous values)\n\n#
Strategic Merge Patch & Deletion Guide\n\nThis merge strategy
allows you to override individual fields, merge lists, or delete
items\nwithout needing to provide the entire resource definition.\n\n**1.
Replacing Values (Scalars):**\nSimple fields (strings, integers,
booleans) in your config will overwrite the generated defaults.\n\n**2.
Merging Lists (Append/Merge):**\nLists with \"merge keys\" (like
`containers` which merges on `name`, or `tolerations` which
merges on `key`)\nwill append your items to the generated list,
or update existing items if keys match.\n\n**3. Deleting Fields
or List Items ($patch: delete):**\nTo remove a field or list
item from the generated resource, use the\n`$patch: delete`
directive. This works for both map fields and list items,\nand
is the recommended approach because it works with both client-side\nand
server-side apply.\n\n\tspec:\n\t template:\n\t spec:\n\t
\ # Delete pod-level securityContext\n\t securityContext:\n\t
\ $patch: delete\n\t # Delete nodeSelector\n\t nodeSelector:\n\t
\ $patch: delete\n\t containers:\n\t # Be sure
to use the correct proxy name here or you will add a\n\t #
container instead of modifying a container.\n\t - name:
proxy-name\n\t # Delete container-level securityContext\n\t
\ securityContext:\n\t $patch: delete\n\n**4.
Null Values (server-side apply only):**\nSetting a field to
`null` can also remove it, but this ONLY works with\n`kubectl
apply --server-side` or equivalent. With regular client-side\n`kubectl
apply`, null values are stripped by kubectl before reaching\nthe
API server, so the deletion won't occur. Prefer `$patch: delete`\nfor
consistent behavior across both apply modes.\n\n\tspec:\n\t
\ template:\n\t spec:\n\t nodeSelector: null # Removes
nodeSelector (server-side apply only!)\n\n**5. Replacing Maps
Entirely ($patch: replace):**\nTo replace an entire map with
your values (instead of merging), use `$patch: replace`.\nThis
removes all existing keys and replaces them with only your specified
keys.\n\n\tspec:\n\t template:\n\t spec:\n\t nodeSelector:\n\t
\ $patch: replace\n\t custom-key: custom-value\n\n**6.
Replacing Lists Entirely ($patch: replace):**\nIf you want to
strictly define a list and ignore all generated defaults, use
`$patch: replace`.\n\n\tservice:\n\t spec:\n\t ports:\n\t
\ - $patch: replace\n\t - name: http\n\t port: 80\n\t
\ targetPort: 8080\n\t protocol: TCP\n\t - name:
https\n\t port: 443\n\t targetPort: 8443\n\t protocol:
TCP"
\ $patch: delete\n\t containers:\n\t # Be
sure to use the correct proxy name here or you will add a container
instead of modifying a container:\n\t - name: proxy-name\n\t
\ # Delete container-level securityContext\n\t securityContext:\n\t
\ $patch: delete\n\n**4. Null Values (server-side
apply only):**\nSetting a field to `null` can also remove it,
but this ONLY works with\n`kubectl apply --server-side` or equivalent.
With regular client-side\n`kubectl apply`, null values are stripped
by kubectl before reaching\nthe API server, so the deletion
won't occur. Prefer `$patch: delete`\nfor consistent behavior
across both apply modes.\n\n\tspec:\n\t template:\n\t spec:\n\t
\ nodeSelector: null # Removes nodeSelector (server-side
apply only!)\n\n**5. Replacing Maps Entirely ($patch: replace):**\nTo
replace an entire map with your values (instead of merging),
use `$patch: replace`.\nThis removes all existing keys and replaces
them with only your specified keys.\n\n\tspec:\n\t template:\n\t
\ spec:\n\t nodeSelector:\n\t $patch: replace\n\t
\ custom-key: custom-value\n\n**6. Replacing Lists Entirely
($patch: replace):**\nIf you want to strictly define a list
and ignore all generated defaults, use `$patch: replace`.\n\n\tservice:\n\t
\ spec:\n\t ports:\n\t - $patch: replace\n\t -
name: http\n\t port: 80\n\t targetPort: 8080\n\t
\ protocol: TCP\n\t - name: https\n\t port:
443\n\t targetPort: 8443\n\t protocol: TCP"
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
shutdown:
description: |-
Shutdown delay configuration. How graceful planned or unplanned data
Shutdown delay configuration. How graceful planned or unplanned data
plane changes happen is in tension with how quickly rollouts of the data
plane complete. How long a data plane pod must wait for shutdown to be
perfectly graceful depends on how you have configured your `Gateway`
resources.
perfectly graceful depends on how you have configured your Gateways.
properties:
max:
description: |-
Maximum time (in seconds) to wait before allowing Agentgateway to
terminate. Refer to the `TERMINATION_GRACE_PERIOD_SECONDS`
environment variable for details.
terminate. Refer to the TERMINATION_GRACE_PERIOD_SECONDS environment
variable for details.
format: int64
maximum: 31536000
minimum: 0
@ -809,8 +793,8 @@ spec:
min:
description: |-
Minimum time (in seconds) to wait before allowing Agentgateway to
terminate. Refer to the `CONNECTION_MIN_TERMINATION_DEADLINE`
environment variable for details.
terminate. Refer to the CONNECTION_MIN_TERMINATION_DEADLINE environment
variable for details.
format: int64
maximum: 31536000
minimum: 0

View File

@ -44,14 +44,6 @@ spec:
{{- with .Values.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- else }}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop:
- ALL
{{- end }}
image: "{{ .Values.controller.image.registry | default .Values.image.registry }}/{{ .Values.controller.image.repository }}:{{ include "agentgateway.imageTag" (.Values.controller.image.tag | default .Values.image.tag | default .Chart.AppVersion) }}"
imagePullPolicy: {{ .Values.controller.image.pullPolicy | default .Values.image.pullPolicy }}
@ -112,30 +104,9 @@ spec:
- name: AGW_DISCOVERY_NAMESPACE_SELECTORS
value: {{ .Values.discoveryNamespaceSelectors | toJson | quote }}
{{- if .Values.controller.extraEnv }}
{{- $extraEnv := .Values.controller.extraEnv }}
{{- range $key := keys $extraEnv | sortAlpha }}
{{- $value := index $extraEnv $key }}
{{- range $key, $value := .Values.controller.extraEnv }}
- name: {{ $key }}
{{- if kindIs "map" $value }}
{{- $hasValue := hasKey $value "value" }}
{{- $hasValueFrom := hasKey $value "valueFrom" }}
{{- if and $hasValue $hasValueFrom }}
{{- fail (printf "controller.extraEnv.%s cannot set both value and valueFrom" $key) }}
{{- else if $hasValue }}
value: {{ get $value "value" | quote }}
{{- else if $hasValueFrom }}
{{- $valueFrom := get $value "valueFrom" }}
{{- if not $valueFrom }}
{{- fail (printf "controller.extraEnv.%s.valueFrom must be non-empty" $key) }}
{{- end }}
valueFrom:
{{- toYaml $valueFrom | nindent 16 }}
{{- else }}
{{- fail (printf "controller.extraEnv.%s must set either value or valueFrom" $key) }}
{{- end }}
{{- else }}
value: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.inferenceExtension.enabled }}

View File

@ -128,7 +128,6 @@ rules:
- gateways
- grpcroutes
- httproutes
- listenersets
- referencegrants
- tcproutes
- tlsroutes
@ -144,7 +143,6 @@ rules:
- gateways/status
- grpcroutes/status
- httproutes/status
- listenersets/status
- tcproutes/status
- tlsroutes/status
verbs:
@ -161,6 +159,21 @@ rules:
- patch
- update
- watch
- apiGroups:
- gateway.networking.x-k8s.io
resources:
- xlistenersets
verbs:
- get
- list
- watch
- apiGroups:
- gateway.networking.x-k8s.io
resources:
- xlistenersets/status
verbs:
- patch
- update
- apiGroups:
- networking.istio.io
resources:

View File

@ -112,16 +112,6 @@ controller:
# -- Traffic distribution.
trafficDistribution: ""
# -- Add extra environment variables to the controller container.
# Supports either a direct scalar value:
# extraEnv:
# LOG_FORMAT: json
# Or Kubernetes valueFrom sources:
# extraEnv:
# API_TOKEN:
# valueFrom:
# secretKeyRef:
# name: agentgateway-secrets
# key: apiToken
extraEnv: {}
# -- Configure TLS settings for the xDS gRPC servers.
xds:
@ -197,7 +187,7 @@ image:
# -- Set the default image pull policy.
pullPolicy: IfNotPresent
# -- Configure the integration with the Gateway API Inference Extension project, which lets you use agentgateway to route to AI inference workloads like LLMs that run locally in your Kubernetes cluster. Documentation for Inference Extension can be found here: https://agentgateway.dev/docs/kubernetes/latest/inference/
# -- Configure the integration with the Gateway API Inference Extension project, which lets you use agentgateway to route to AI inference workloads like LLMs that run locally in your Kubernetes cluster. Documentation for Inference Extension can be found here: https://kgateway.dev/docs/latest/agentgateway/inference/
inferenceExtension:
# -- Enable Inference Extension support in the agentgateway controller.
enabled: false

View File

@ -41,7 +41,6 @@ func NewConfigMapSyncer(client apiclient.Client, storePrefix, deploymentNamespac
cmCollection := krt.NewFilteredInformer[*corev1.ConfigMap](client,
kclient.Filter{
ObjectFilter: client.ObjectFilter(),
Namespace: deploymentNamespace,
LabelSelector: JwksStoreLabelSelector(storePrefix)},
krtOptions.ToOptions("config_map_syncer/ConfigMaps")...)

View File

@ -37,11 +37,10 @@ type JwksHttpClient interface {
}
type JwksSource struct {
JwksURL string
Ttl time.Duration
Deleted bool
// Exclude from JSON dump as this is not safe for marshaling
TlsConfig *tls.Config `json:"-"`
JwksURL string
Ttl time.Duration
Deleted bool
TlsConfig *tls.Config
}
func (js JwksSource) ResourceName() string {

View File

@ -9,7 +9,7 @@ import (
"github.com/agentgateway/agentgateway/controller/pkg/apiclient"
"github.com/agentgateway/agentgateway/controller/pkg/common"
"github.com/agentgateway/agentgateway/controller/pkg/logging"
"github.com/agentgateway/agentgateway/controller/pkg/pluginsdk/krtutil"
"github.com/agentgateway/agentgateway/controller/pkg/pluginsdk/collections"
)
// JwksStore is a top-level abstraction that relies on jwksCache and jwksFetcher to
@ -34,7 +34,7 @@ type JwksStore struct {
l sync.Mutex
}
func BuildJwksStore(cli apiclient.Client, krtOpts krtutil.KrtOptions, jwksChanges <-chan JwksSource, storePrefix, deploymentNamespace string) *JwksStore {
func BuildJwksStore(ctx context.Context, cli apiclient.Client, commonCols *collections.CommonCollections, jwksChanges <-chan JwksSource, storePrefix, deploymentNamespace string) *JwksStore {
logger.Info("creating jwks store")
jwksCache := NewJwksCache()
@ -43,7 +43,7 @@ func BuildJwksStore(cli apiclient.Client, krtOpts krtutil.KrtOptions, jwksChange
jwksCache: jwksCache,
jwksChanges: jwksChanges,
jwksFetcher: NewJwksFetcher(jwksCache),
configMapSyncer: NewConfigMapSyncer(cli, storePrefix, deploymentNamespace, krtOpts),
configMapSyncer: NewConfigMapSyncer(cli, storePrefix, deploymentNamespace, commonCols.KrtOpts),
cmNameToJwks: make(map[string]string),
}
BuildJwksConfigMapNamespacedNameFunc(storePrefix, deploymentNamespace)

View File

@ -13,9 +13,9 @@ import (
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
"github.com/agentgateway/agentgateway/controller/api/v1alpha1/agentgateway"
"github.com/agentgateway/agentgateway/controller/pkg/kgateway/wellknown"
krtpkg "github.com/agentgateway/agentgateway/controller/pkg/utils/krtutil"
"github.com/agentgateway/agentgateway/controller/pkg/utils/kubeutils"
"github.com/agentgateway/agentgateway/controller/pkg/wellknown"
)
type JwksUrlBuilder interface {
@ -191,7 +191,7 @@ func GetTLSConfig(
certPool := x509.NewCertPool()
for _, ref := range btls.CACertificateRefs {
nn := types.NamespacedName{
Name: ref.Name,
Name: string(ref.Name),
Namespace: namespace,
}
cfgmap := krt.FetchOne(krtctx, cfgmaps, krt.FilterObjectName(nn))

View File

@ -164,7 +164,8 @@ func TestRemoteJwksUrlBuilder(t *testing.T) {
}
func setup(t *testing.T, paths []string) plugins.PolicyCtx {
val := apitests.NewAgentgatewayValidatorSkipMissing(t)
val := apitests.NewKgatewayValidator(t)
val.SkipMissing = true
mockObjs := []any{}
for _, f := range paths {
data := file.AsStringOrFail(t, f)

View File

@ -13,8 +13,8 @@ import (
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/jwks_url"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/plugins"
"github.com/agentgateway/agentgateway/controller/pkg/apiclient"
"github.com/agentgateway/agentgateway/controller/pkg/kgateway/wellknown"
"github.com/agentgateway/agentgateway/controller/pkg/logging"
"github.com/agentgateway/agentgateway/controller/pkg/wellknown"
)
// JwksStorePolicyController watches AgentgatewayPolicies and Backends. When a resource containing

View File

@ -8,28 +8,25 @@ import (
"istio.io/istio/pkg/ptr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"github.com/agentgateway/agentgateway/api"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/utils"
"github.com/agentgateway/agentgateway/controller/pkg/kgateway/wellknown"
"github.com/agentgateway/agentgateway/controller/pkg/utils/kubeutils"
"github.com/agentgateway/agentgateway/controller/pkg/wellknown"
)
const (
legacyA2aProtocol = "kgateway.dev/a2a"
a2aProtocol = "agentgateway.dev/a2a"
a2aProtocol = "kgateway.dev/a2a"
)
// NewA2APlugin creates a new A2A policy plugin
func NewA2APlugin(agw *AgwCollections) AgwPlugin {
policyCol := krt.NewManyCollection(agw.Services, func(krtctx krt.HandlerContext, svc *corev1.Service) []AgwPolicy {
return translatePoliciesForService(svc, kubeutils.GetClusterDomainName())
})
return AgwPlugin{
ContributesPolicies: map[schema.GroupKind]PolicyPlugin{
wellknown.ServiceGVK.GroupKind(): {
Build: func(input PolicyPluginInput) (krt.StatusCollection[controllers.Object, any], krt.Collection[AgwPolicy]) {
policyCol := krt.NewManyCollection(agw.Services, func(krtctx krt.HandlerContext, svc *corev1.Service) []AgwPolicy {
return translatePoliciesForService(krtctx, svc, kubeutils.GetClusterDomainName(), input.References)
})
return nil, policyCol
},
},
@ -38,19 +35,11 @@ func NewA2APlugin(agw *AgwCollections) AgwPlugin {
}
// translatePoliciesForService generates A2A policies for a single service
func translatePoliciesForService(krtctx krt.HandlerContext, svc *corev1.Service, clusterDomain string, references ReferenceIndex) []AgwPolicy {
func translatePoliciesForService(svc *corev1.Service, clusterDomain string) []AgwPolicy {
var a2aPolicies []AgwPolicy
gatewayTargets := references.LookupGatewaysForBackend(krtctx, utils.TypedNamespacedName{
Kind: wellknown.ServiceKind,
NamespacedName: types.NamespacedName{
Namespace: svc.Namespace,
Name: svc.Name,
},
}).UnsortedList()
for _, port := range svc.Spec.Ports {
// support legacy kgateway.dev/a2a and agentgateway.dev/a2a
if port.AppProtocol != nil && (*port.AppProtocol == a2aProtocol || *port.AppProtocol == legacyA2aProtocol) {
if port.AppProtocol != nil && *port.AppProtocol == a2aProtocol {
logger.Debug("found A2A service", "service", svc.Name, "namespace", svc.Namespace, "port", port.Port)
hostname := fmt.Sprintf("%s.%s.svc.%s", svc.Name, svc.Namespace, clusterDomain)
policy := &api.Policy{
@ -71,7 +60,7 @@ func translatePoliciesForService(krtctx krt.HandlerContext, svc *corev1.Service,
},
}
a2aPolicies = appendPolicyForGateways(a2aPolicies, gatewayTargets, policy)
a2aPolicies = append(a2aPolicies, AgwPolicy{Policy: policy})
}
}

View File

@ -275,7 +275,7 @@ func processGoogleModelArmor(ctx PolicyCtx, namespace string, armor *agentgatewa
// Set location with default value if not specified
if armor.Location != nil {
pgArmor.Location = ptr.Of(*armor.Location)
pgArmor.Location = ptr.Of(string(*armor.Location))
} else {
pgArmor.Location = ptr.Of("us-central1")
}

View File

@ -12,7 +12,6 @@ import (
"istio.io/istio/pkg/ptr"
"istio.io/istio/pkg/slices"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@ -20,21 +19,19 @@ import (
"github.com/agentgateway/agentgateway/controller/api/v1alpha1/agentgateway"
"github.com/agentgateway/agentgateway/controller/api/v1alpha1/shared"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/jwks_url"
"github.com/agentgateway/agentgateway/controller/pkg/kgateway/translator/sslutils"
"github.com/agentgateway/agentgateway/controller/pkg/kgateway/wellknown"
"github.com/agentgateway/agentgateway/controller/pkg/utils/kubeutils"
"github.com/agentgateway/agentgateway/controller/pkg/wellknown"
)
const (
aiPolicySuffix = ":ai"
backendTlsPolicySuffix = ":backend-tls"
backendTunnelPolicySuffix = ":backend-tunnel"
backendauthPolicySuffix = ":backend-auth"
backendTransformationSuffix = ":backend-transformation"
tlsPolicySuffix = ":tls"
backendHttpPolicySuffix = ":backend-http"
mcpAuthorizationPolicySuffix = ":mcp-authorization"
mcpAuthenticationPolicySuffix = ":mcp-authentication"
healthPolicySuffix = ":health"
)
func TranslateInlineBackendPolicy(
@ -49,181 +46,92 @@ func TranslateInlineBackendPolicy(
},
Spec: agentgateway.AgentgatewayPolicySpec{Backend: policy},
}
res, err := translateBackendPolicyToAgw(ctx, dummy)
return slices.MapFilter(res, func(e *api.Policy) **api.BackendPolicySpec {
return ptr.Of(e.GetBackend())
res, err := translateBackendPolicyToAgw(ctx, dummy, nil)
return slices.MapFilter(res, func(e AgwPolicy) **api.BackendPolicySpec {
return ptr.Of(e.Policy.GetBackend())
}), err
}
func translateBackendPolicyToAgw(
ctx PolicyCtx,
policy *agentgateway.AgentgatewayPolicy,
) ([]*api.Policy, error) {
policyTarget *api.PolicyTarget,
) ([]AgwPolicy, error) {
backend := policy.Spec.Backend
if backend == nil {
return nil, nil
}
agwPolicies := make([]*api.Policy, 0)
agwPolicies := make([]AgwPolicy, 0)
var errs []error
policyName := getBackendPolicyName(policy.Namespace, policy.Name)
appendPolicy := func(kind string) func(*api.Policy, error) {
return func(p *api.Policy, err error) {
if err != nil {
name := fmt.Sprintf("%s %s", kind, policyName)
logger.Error("error processing policy", "policy", name, "error", err)
errs = append(errs, err)
}
if p != nil {
agwPolicies = append(agwPolicies, p)
}
}
}
if s := backend.HTTP; s != nil {
appendPolicy("backendHTTP")(translateBackendHTTP(policy), nil)
}
if s := backend.Tunnel; s != nil {
appendPolicy("backendTunnel")(translateBackendTunnel(ctx, policy))
pol := translateBackendHTTP(policy, policyTarget)
agwPolicies = append(agwPolicies, pol...)
}
if s := backend.TLS; s != nil {
appendPolicy("backendTLS")(translateBackendTLS(ctx, policy))
pol, err := translateBackendTLS(ctx, policy, policyTarget)
if err != nil {
logger.Error("error processing backend TLS", "err", err)
errs = append(errs, err)
}
agwPolicies = append(agwPolicies, pol...)
}
if s := backend.TCP; s != nil {
appendPolicy("backendTCP")(translateBackendTCP(ctx, policy, policyName))
}
if s := backend.Health; s != nil {
appendPolicy("backendHealth")(translateBackendHealthPolicy(policy))
}
if s := backend.Transformation; s != nil {
appendPolicy("backendTransformation")(translateBackendTransformation(policy))
pol, err := translateBackendTCP(ctx, policy, policyName, policyTarget)
if err != nil {
logger.Error("error processing backend TCP", "err", err)
errs = append(errs, err)
}
agwPolicies = append(agwPolicies, pol...)
}
if s := backend.MCP; s != nil {
if backend.MCP.Authorization != nil {
appendPolicy("backendMCPAuthorization")(translateBackendMCPAuthorization(policy))
pol := translateBackendMCPAuthorization(policy, policyTarget)
agwPolicies = append(agwPolicies, pol...)
}
if backend.MCP.Authentication != nil {
appendPolicy("backendMCPAuthentication")(translateBackendMCPAuthentication(ctx, policy))
pol, err := translateBackendMCPAuthentication(ctx, policy, policyTarget)
if err != nil {
logger.Error("error processing backend mcp auth", "err", err)
errs = append(errs, err)
}
agwPolicies = append(agwPolicies, pol...)
}
}
if s := backend.AI; s != nil {
appendPolicy("backendAI")(translateBackendAI(ctx, policy, policyName))
pol, err := translateBackendAI(ctx, policy, policyName, policyTarget)
if err != nil {
logger.Error("error processing backend AI", "err", err)
errs = append(errs, err)
}
agwPolicies = append(agwPolicies, pol...)
}
if s := backend.Auth; s != nil {
appendPolicy("backendAuth")(translateBackendAuth(ctx, policy, policyName))
pol, err := translateBackendAuth(ctx, policy, policyName, policyTarget)
if err != nil {
logger.Error("error processing backend Auth", "err", err)
errs = append(errs, err)
}
agwPolicies = append(agwPolicies, pol...)
}
return agwPolicies, errors.Join(errs...)
}
func translateBackendHealthPolicy(policy *agentgateway.AgentgatewayPolicy) (*api.Policy, error) {
var errs []error
healthPolicy := policy.Spec.Backend.Health
var evictionProto *api.BackendPolicySpec_Eviction
if healthPolicy.Eviction != nil {
var duration *durationpb.Duration
if healthPolicy.Eviction.Duration != nil {
duration = durationpb.New(healthPolicy.Eviction.Duration.Duration)
}
// Convert 0–100 integer scores into 0.0–1.0 doubles for proto
var healthThreshold *float64
if healthPolicy.Eviction.HealthThreshold != nil {
val := float64(*healthPolicy.Eviction.HealthThreshold) / 100.0
healthThreshold = &val
}
var restoreHealth *float64
if healthPolicy.Eviction.RestoreHealth != nil {
val := float64(*healthPolicy.Eviction.RestoreHealth) / 100.0
restoreHealth = &val
}
evictionProto = &api.BackendPolicySpec_Eviction{
Duration: duration,
RestoreHealth: restoreHealth,
ConsecutiveFailures: healthPolicy.Eviction.ConsecutiveFailures,
HealthThreshold: healthThreshold,
}
}
var unhealthyCondition string
if healthPolicy.UnhealthyCondition != nil {
unhealthyCondition = *castCELPtr(healthPolicy.UnhealthyCondition, func(expr shared.CELExpression) {
errs = append(errs, fmt.Errorf("backend health unhealthyCondition is not a valid CEL expression: %s", expr))
})
}
p := &api.BackendPolicySpec_Health{
UnhealthyCondition: unhealthyCondition,
Eviction: evictionProto,
}
evictPolicy := &api.Policy{
Key: policy.Namespace + "/" + policy.Name + healthPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Kind: &api.Policy_Backend{
Backend: &api.BackendPolicySpec{
Kind: &api.BackendPolicySpec_Health_{
Health: p,
},
},
},
}
return evictPolicy, errors.Join(errs...)
}
func translateBackendTCP(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy, name string) (*api.Policy, error) {
func translateBackendTCP(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy, name string, target *api.PolicyTarget) ([]AgwPolicy, error) {
// TODO
return nil, nil
}
func translateBackendTransformation(
policy *agentgateway.AgentgatewayPolicy,
) (*api.Policy, error) {
var errs []error
transformation := policy.Spec.Backend.Transformation
convertedReq, err := convertTransformSpec(transformation.Request)
if err != nil {
errs = append(errs, err)
}
convertedResp, err := convertTransformSpec(transformation.Response)
if err != nil {
errs = append(errs, err)
}
tp := &api.Policy{
Key: policy.Namespace + "/" + policy.Name + backendTransformationSuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Kind: &api.Policy_Backend{
Backend: &api.BackendPolicySpec{
Kind: &api.BackendPolicySpec_Transformation{
Transformation: &api.TrafficPolicySpec_TransformationPolicy{
Request: convertedReq,
Response: convertedResp,
},
},
},
},
}
logger.Debug("generated backend transformation policy",
"policy", policy.Name,
"agentgateway_policy", tp.Name)
return tp, errors.Join(errs...)
}
func translateBackendTLS(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy) (*api.Policy, error) {
func translateBackendTLS(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy, target *api.PolicyTarget) ([]AgwPolicy, error) {
var errs []error
tls := policy.Spec.Backend.TLS
@ -240,7 +148,7 @@ func translateBackendTLS(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy)
if scrt == nil {
errs = append(errs, fmt.Errorf("secret %s not found", nn))
} else {
if _, err := ValidateTlsSecretData(nn.Name, nn.Namespace, scrt.Data); err != nil {
if _, err := sslutils.ValidateTlsSecretData(nn.Name, nn.Namespace, scrt.Data); err != nil {
errs = append(errs, fmt.Errorf("secret %v contains invalid certificate: %v", nn, err))
}
p.Cert = scrt.Data[corev1.TLSCertKey]
@ -262,7 +170,7 @@ func translateBackendTLS(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy)
errs = append(errs, fmt.Errorf("ConfigMap %s not found", nn))
continue
}
pem, err := GetCACertFromConfigMap(ptr.Flatten(cfgmap))
pem, err := sslutils.GetCACertFromConfigMap(ptr.Flatten(cfgmap))
if err != nil {
errs = append(errs, fmt.Errorf("error extracting CA cert from ConfigMap %s: %w", nn, err))
continue
@ -272,9 +180,10 @@ func translateBackendTLS(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy)
}
sb.WriteString(pem)
}
// If we have a root set here, set it
// This may send an empty root, so that we trust nothing rather than system certs.
p.Root = []byte(sb.String())
// TODO: if none, submit something to make agentgateway reject requests instead of fail open.
if sb.Len() > 0 {
p.Root = []byte(sb.String())
}
}
if len(tls.VerifySubjectAltNames) > 0 {
@ -296,8 +205,9 @@ func translateBackendTLS(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy)
}
tlsPolicy := &api.Policy{
Key: policy.Namespace + "/" + policy.Name + tlsPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Key: policy.Namespace + "/" + policy.Name + tlsPolicySuffix + attachmentName(target),
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Target: target,
Kind: &api.Policy_Backend{
Backend: &api.BackendPolicySpec{
Kind: &api.BackendPolicySpec_BackendTls{
@ -311,10 +221,10 @@ func translateBackendTLS(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy)
"policy", policy.Name,
"agentgateway_policy", tlsPolicy.Name)
return tlsPolicy, errors.Join(errs...)
return []AgwPolicy{{Policy: tlsPolicy}}, errors.Join(errs...)
}
func translateBackendHTTP(policy *agentgateway.AgentgatewayPolicy) *api.Policy {
func translateBackendHTTP(policy *agentgateway.AgentgatewayPolicy, target *api.PolicyTarget) []AgwPolicy {
http := policy.Spec.Backend.HTTP
p := &api.BackendPolicySpec_BackendHTTP{}
if v := http.Version; v != nil {
@ -329,8 +239,9 @@ func translateBackendHTTP(policy *agentgateway.AgentgatewayPolicy) *api.Policy {
p.RequestTimeout = durationpb.New(rt.Duration)
}
tp := &api.Policy{
Key: policy.Namespace + "/" + policy.Name + backendHttpPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Key: policy.Namespace + "/" + policy.Name + backendHttpPolicySuffix + attachmentName(target),
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Target: target,
Kind: &api.Policy_Backend{
Backend: &api.BackendPolicySpec{
Kind: &api.BackendPolicySpec_BackendHttp{
@ -343,64 +254,32 @@ func translateBackendHTTP(policy *agentgateway.AgentgatewayPolicy) *api.Policy {
"policy", policy.Name,
"agentgateway_policy", tp.Name)
return tp
return []AgwPolicy{{Policy: tp}}
}
func translateBackendTunnel(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy) (*api.Policy, error) {
tunnel := policy.Spec.Backend.Tunnel
proxy, err := buildBackendRef(ctx, tunnel.BackendRef, policy.Namespace)
tunnelPolicy := &api.Policy{
Key: policy.Namespace + "/" + policy.Name + backendTunnelPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Kind: &api.Policy_Backend{
Backend: &api.BackendPolicySpec{
Kind: &api.BackendPolicySpec_BackendTunnel_{
BackendTunnel: &api.BackendPolicySpec_BackendTunnel{
Proxy: proxy,
},
},
},
},
}
logger.Debug("generated backend tunnel policy",
"policy", policy.Name,
"agentgateway_policy", tunnelPolicy.Name)
return tunnelPolicy, err
}
func translateBackendMCPAuthorization(policy *agentgateway.AgentgatewayPolicy) (*api.Policy, error) {
func translateBackendMCPAuthorization(policy *agentgateway.AgentgatewayPolicy, target *api.PolicyTarget) []AgwPolicy {
backend := policy.Spec.Backend
if backend == nil || backend.MCP == nil || backend.MCP.Authorization == nil {
return nil, nil
return nil
}
auth := backend.MCP.Authorization
var errs []error
var allowPolicies, denyPolicies, requirePolicies []string
policies := castCELSlice(auth.Policy.MatchExpressions, func(expr shared.CELExpression) {
errs = append(errs, fmt.Errorf("backend MCP authorization matchExpression is not a valid CEL expression: %s", expr))
})
var allowPolicies, denyPolicies []string
if auth.Action == shared.AuthorizationPolicyActionDeny {
denyPolicies = append(denyPolicies, policies...)
} else if auth.Action == shared.AuthorizationPolicyActionRequire {
requirePolicies = append(requirePolicies, policies...)
denyPolicies = append(denyPolicies, cast(auth.Policy.MatchExpressions)...)
} else {
allowPolicies = append(allowPolicies, policies...)
allowPolicies = append(allowPolicies, cast(auth.Policy.MatchExpressions)...)
}
mcpPolicy := &api.Policy{
Key: policy.Namespace + "/" + policy.Name + mcpAuthorizationPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Key: policy.Namespace + "/" + policy.Name + mcpAuthorizationPolicySuffix + attachmentName(target),
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Target: target,
Kind: &api.Policy_Backend{
Backend: &api.BackendPolicySpec{
Kind: &api.BackendPolicySpec_McpAuthorization_{
McpAuthorization: &api.BackendPolicySpec_McpAuthorization{
Allow: allowPolicies,
Deny: denyPolicies,
Require: requirePolicies,
Allow: allowPolicies,
Deny: denyPolicies,
},
},
},
@ -411,44 +290,30 @@ func translateBackendMCPAuthorization(policy *agentgateway.AgentgatewayPolicy) (
"policy", policy.Name,
"agentgateway_policy", mcpPolicy.Name)
return mcpPolicy, errors.Join(errs...)
return []AgwPolicy{{Policy: mcpPolicy}}
}
func translateBackendMCPAuthentication(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy) (*api.Policy, error) {
authnPolicy := policy.Spec.Backend.MCP.Authentication
mcpAuthn, err := translateMCPAuthenticationSpec(ctx, types.NamespacedName{
Namespace: policy.Namespace,
Name: policy.Name,
}, authnPolicy)
mcpAuthnPolicy := &api.Policy{
Key: policy.Namespace + "/" + policy.Name + mcpAuthenticationPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Kind: &api.Policy_Backend{
Backend: &api.BackendPolicySpec{
Kind: &api.BackendPolicySpec_McpAuthentication_{
McpAuthentication: mcpAuthn,
},
},
},
func translateBackendMCPAuthentication(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy, target *api.PolicyTarget) ([]AgwPolicy, error) {
backend := policy.Spec.Backend
if backend == nil || backend.MCP == nil || backend.MCP.Authentication == nil {
return nil, nil
}
authnPolicy := backend.MCP.Authentication
if authnPolicy == nil {
return nil, nil
}
logger.Debug("generated MCP authentication policy",
"policy", policy.Name,
"agentgateway_policy", mcpAuthnPolicy.Name)
idp := api.BackendPolicySpec_McpAuthentication_UNSPECIFIED
if authnPolicy.McpIDP != nil {
if *authnPolicy.McpIDP == agentgateway.Keycloak {
idp = api.BackendPolicySpec_McpAuthentication_KEYCLOAK
} else if *authnPolicy.McpIDP == agentgateway.Auth0 {
idp = api.BackendPolicySpec_McpAuthentication_AUTH0
}
}
return mcpAuthnPolicy, err
}
func translateMCPAuthenticationSpec(
ctx PolicyCtx,
policy types.NamespacedName,
authnPolicy *agentgateway.MCPAuthentication,
) (*api.BackendPolicySpec_McpAuthentication, error) {
idp := translateMcpIDP(authnPolicy.McpIDP)
// default mode is Strict
mode := api.BackendPolicySpec_McpAuthentication_STRICT
// default mode is Optional
mode := api.BackendPolicySpec_McpAuthentication_OPTIONAL
if authnPolicy.Mode == agentgateway.JWTAuthenticationModeStrict {
mode = api.BackendPolicySpec_McpAuthentication_STRICT
} else if authnPolicy.Mode == agentgateway.JWTAuthenticationModePermissive {
@ -457,70 +322,20 @@ func translateMCPAuthenticationSpec(
mode = api.BackendPolicySpec_McpAuthentication_OPTIONAL
}
var errs []error
jwksUrl, _, err := jwks_url.JwksUrlBuilderFactory().BuildJwksUrlAndTlsConfig(ctx.Krt, policy.Name, policy.Namespace, &authnPolicy.JWKS)
if err != nil {
logger.Error("failed resolving jwks url", "error", err)
errs = append(errs, err)
}
var translatedInlineJwks string
if err == nil {
translatedInlineJwks, err = resolveRemoteJWKSInline(ctx, jwksUrl)
return nil, err
}
translatedInlineJwks, err := resolveRemoteJWKSInline(ctx, jwksUrl)
if err != nil {
logger.Error("failed resolving jwks", "jwks_uri", jwksUrl, "error", err)
errs = append(errs, err)
}
extraResourceMetadata, metadataErr := translateMCPResourceMetadata(authnPolicy.ResourceMetadata)
if metadataErr != nil {
errs = append(errs, metadataErr)
}
mcpAuthn := &api.BackendPolicySpec_McpAuthentication{
Issuer: authnPolicy.Issuer,
Audiences: authnPolicy.Audiences,
Provider: idp,
ResourceMetadata: &api.BackendPolicySpec_McpAuthentication_ResourceMetadata{
Extra: extraResourceMetadata,
},
JwksInline: translatedInlineJwks,
Mode: mode,
}
return mcpAuthn, errors.Join(errs...)
}
func translateJWTMCPConfig(mcp *agentgateway.JWTMCPConfig) (*api.TrafficPolicySpec_JWT_MCP, error) {
extraResourceMetadata, err := translateMCPResourceMetadata(mcp.ResourceMetadata)
if err != nil {
return nil, err
}
return &api.TrafficPolicySpec_JWT_MCP{
Provider: translateMcpIDP(mcp.Provider),
ResourceMetadata: &api.BackendPolicySpec_McpAuthentication_ResourceMetadata{
Extra: extraResourceMetadata,
},
}, nil
}
func translateMcpIDP(provider *agentgateway.McpIDP) api.BackendPolicySpec_McpAuthentication_McpIDP {
if provider == nil {
return api.BackendPolicySpec_McpAuthentication_UNSPECIFIED
}
if *provider == agentgateway.Keycloak {
return api.BackendPolicySpec_McpAuthentication_KEYCLOAK
}
if *provider == agentgateway.Auth0 {
return api.BackendPolicySpec_McpAuthentication_AUTH0
}
return api.BackendPolicySpec_McpAuthentication_UNSPECIFIED
}
func translateMCPResourceMetadata(resourceMetadata map[string]apiextensionsv1.JSON) (map[string]*structpb.Value, error) {
var errs []error
var extraResourceMetadata map[string]*structpb.Value
for k, v := range resourceMetadata {
for k, v := range authnPolicy.ResourceMetadata {
if extraResourceMetadata == nil {
extraResourceMetadata = make(map[string]*structpb.Value)
}
@ -535,11 +350,39 @@ func translateMCPResourceMetadata(resourceMetadata map[string]apiextensionsv1.JS
extraResourceMetadata[k] = proto
}
return extraResourceMetadata, errors.Join(errs...)
mcpAuthn := &api.BackendPolicySpec_McpAuthentication{
Issuer: authnPolicy.Issuer,
Audiences: authnPolicy.Audiences,
Provider: idp,
ResourceMetadata: &api.BackendPolicySpec_McpAuthentication_ResourceMetadata{
Extra: extraResourceMetadata,
},
JwksInline: translatedInlineJwks,
Mode: mode,
}
mcpAuthnPolicy := &api.Policy{
Key: policy.Namespace + "/" + policy.Name + mcpAuthenticationPolicySuffix + attachmentName(target),
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Target: target,
Kind: &api.Policy_Backend{
Backend: &api.BackendPolicySpec{
Kind: &api.BackendPolicySpec_McpAuthentication_{
McpAuthentication: mcpAuthn,
},
},
},
}
logger.Debug("generated MCP authentication policy",
"policy", policy.Name,
"agentgateway_policy", mcpAuthnPolicy.Name)
return []AgwPolicy{{Policy: mcpAuthnPolicy}}, errors.Join(errs...)
}
// translateBackendAI processes AI configuration and creates corresponding Agw policies
func translateBackendAI(ctx PolicyCtx, agwPolicy *agentgateway.AgentgatewayPolicy, name string) (*api.Policy, error) {
func translateBackendAI(ctx PolicyCtx, agwPolicy *agentgateway.AgentgatewayPolicy, name string, policyTarget *api.PolicyTarget) ([]AgwPolicy, error) {
var errs []error
aiSpec := agwPolicy.Spec.Backend.AI
@ -573,18 +416,6 @@ func translateBackendAI(ctx PolicyCtx, agwPolicy *agentgateway.AgentgatewayPolic
}
translatedAIPolicy.Overrides[def.Field] = val
}
for _, xfm := range aiSpec.Transformations {
if translatedAIPolicy.Transformations == nil {
translatedAIPolicy.Transformations = make(map[string]string)
}
if !isCEL(xfm.Expression) {
errs = append(errs, fmt.Errorf("transformation %q is not a valid CEL expression: %v", xfm.Field, xfm.Expression))
}
// Still set it so it wipes out the value on error, mirroring the header value.
translatedAIPolicy.Transformations[xfm.Field] = string(xfm.Expression)
}
if aiSpec.PromptGuard != nil {
if translatedAIPolicy.PromptGuard == nil {
@ -622,9 +453,6 @@ func translateBackendAI(ctx PolicyCtx, agwPolicy *agentgateway.AgentgatewayPolic
CacheTools: aiSpec.PromptCaching.CacheTools,
}
translatedAIPolicy.PromptCaching.MinTokens = ptr.Of(uint32(aiSpec.PromptCaching.MinTokens)) //nolint:gosec // G115: MinTokens is validated by kubebuilder to be >= 0
if aiSpec.PromptCaching.CacheMessageOffset > 0 {
translatedAIPolicy.PromptCaching.CacheMessageOffset = ptr.Of(uint32(aiSpec.PromptCaching.CacheMessageOffset)) //nolint:gosec // G115: CacheMessageOffset is validated by kubebuilder to be >= 0
}
}
if aiSpec.Routes != nil {
@ -636,8 +464,9 @@ func translateBackendAI(ctx PolicyCtx, agwPolicy *agentgateway.AgentgatewayPolic
}
aiPolicy := &api.Policy{
Key: name + aiPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, agwPolicy),
Key: name + aiPolicySuffix + attachmentName(policyTarget),
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, agwPolicy),
Target: policyTarget,
Kind: &api.Policy_Backend{
Backend: &api.BackendPolicySpec{
Kind: &api.BackendPolicySpec_Ai_{
@ -651,15 +480,18 @@ func translateBackendAI(ctx PolicyCtx, agwPolicy *agentgateway.AgentgatewayPolic
"policy", agwPolicy.Name,
"agentgateway_policy", aiPolicy.Name)
return aiPolicy, errors.Join(errs...)
return []AgwPolicy{{Policy: aiPolicy}}, errors.Join(errs...)
}
func translateBackendAuth(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy, name string) (*api.Policy, error) {
func translateBackendAuth(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy, name string, target *api.PolicyTarget) ([]AgwPolicy, error) {
var errs []error
auth := policy.Spec.Backend.Auth
if auth == nil {
return nil, nil
}
var translatedAuth *api.BackendAuthPolicy
var kindErrs []error
if auth.InlineKey != nil && *auth.InlineKey != "" {
translatedAuth = &api.BackendAuthPolicy{
@ -672,11 +504,6 @@ func translateBackendAuth(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy
secret, err := kubeutils.GetSecret(ctx.Collections.Secrets, ctx.Krt, auth.SecretRef.Name, policy.Namespace)
if err != nil {
errs = append(errs, err)
translatedAuth = &api.BackendAuthPolicy{
Kind: &api.BackendAuthPolicy_Key{
Key: &api.Key{},
},
}
} else {
if authKey, ok := kubeutils.GetSecretAuth(secret); ok {
translatedAuth = &api.BackendAuthPolicy{
@ -686,25 +513,12 @@ func translateBackendAuth(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy
}
} else {
errs = append(errs, fmt.Errorf("secret %s/%s missing Authorization value", policy.Namespace, auth.SecretRef.Name))
translatedAuth = &api.BackendAuthPolicy{
Kind: &api.BackendAuthPolicy_Key{
Key: &api.Key{},
},
}
}
}
} else if auth.AWS != nil {
awsAuth, err := buildAwsAuthPolicy(ctx.Krt, auth.AWS, ctx.Collections.Secrets, policy.Namespace)
translatedAuth = awsAuth
if err != nil {
errs = append(errs, err)
}
} else if auth.Azure != nil {
azureAuth, err := buildAzureAuthPolicy(ctx.Krt, auth.Azure, ctx.Collections.Secrets, policy.Namespace)
translatedAuth = azureAuth
if err != nil {
errs = append(errs, err)
}
errs = append(errs, err)
} else if auth.GCP != nil {
translatedAuth = buildGcpAuthPolicy(auth.GCP)
} else if auth.Passthrough != nil {
@ -715,9 +529,14 @@ func translateBackendAuth(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy
}
}
if translatedAuth == nil {
return nil, errors.Join(errs...)
}
authPolicy := &api.Policy{
Key: name + backendauthPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Key: name + backendauthPolicySuffix + attachmentName(target),
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Target: target,
Kind: &api.Policy_Backend{
Backend: &api.BackendPolicySpec{
Kind: &api.BackendPolicySpec_Auth{
@ -730,7 +549,7 @@ func translateBackendAuth(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy
"policy", policy.Name,
"agentgateway_policy", authPolicy.Name)
return authPolicy, errors.Join(append(errs, kindErrs...)...)
return []AgwPolicy{{Policy: authPolicy}}, errors.Join(errs...)
}
// translateRouteType converts kgateway RouteType to agentgateway proto RouteType
@ -744,8 +563,6 @@ func translateRouteType(rt agentgateway.RouteType) api.BackendPolicySpec_Ai_Rout
return api.BackendPolicySpec_Ai_MODELS
case agentgateway.RouteTypePassthrough:
return api.BackendPolicySpec_Ai_PASSTHROUGH
case agentgateway.RouteTypeDetect:
return api.BackendPolicySpec_Ai_DETECT
case agentgateway.RouteTypeResponses:
return api.BackendPolicySpec_Ai_RESPONSES
case agentgateway.RouteTypeAnthropicTokenCount:
@ -762,39 +579,52 @@ func translateRouteType(rt agentgateway.RouteType) api.BackendPolicySpec_Ai_Rout
func buildAwsAuthPolicy(krtctx krt.HandlerContext, auth *agentgateway.AwsAuth, secrets krt.Collection[*corev1.Secret], namespace string) (*api.BackendAuthPolicy, error) {
var errs []error
if auth == nil {
logger.Warn("using implicit AWS auth for AI backend")
return &api.BackendAuthPolicy{
Kind: &api.BackendAuthPolicy_Aws{
Aws: &api.Aws{
Kind: &api.Aws_Implicit{
Implicit: &api.AwsImplicit{},
},
},
},
}, nil
}
if auth.SecretRef.Name == "" {
logger.Warn("not using any auth for AWS - it's most likely not what you want")
return nil, nil
}
var accessKeyId, secretAccessKey string
var sessionToken *string
// Get secret using the SecretIndex
secret, err := kubeutils.GetSecret(secrets, krtctx, auth.SecretRef.Name, namespace)
if err != nil {
errs = append(errs, err)
// Return nil auth policy if secret not found - this will be handled upstream
// TODO(npolshak): Add backend status errors https://github.com/kgateway-dev/kgateway/issues/11966
return nil, err
}
var accessKeyId, secretAccessKey string
var sessionToken *string
// Extract access key
if value, exists := kubeutils.GetSecretValue(secret, wellknown.AccessKey); !exists {
errs = append(errs, errors.New("accessKey is missing or not a valid string"))
} else {
// Extract access key
if value, exists := kubeutils.GetSecretValue(secret, wellknown.AccessKey); !exists {
errs = append(errs, errors.New("accessKey is missing or not a valid string"))
} else {
accessKeyId = value
}
accessKeyId = value
}
// Extract secret key
if value, exists := kubeutils.GetSecretValue(secret, wellknown.SecretKey); !exists {
errs = append(errs, errors.New("secretKey is missing or not a valid string"))
} else {
secretAccessKey = value
}
// Extract secret key
if value, exists := kubeutils.GetSecretValue(secret, wellknown.SecretKey); !exists {
errs = append(errs, errors.New("secretKey is missing or not a valid string"))
} else {
secretAccessKey = value
}
// Extract session token (optional)
if secret != nil {
if value, exists := kubeutils.GetSecretValue(secret, wellknown.SessionToken); exists {
sessionToken = ptr.Of(value)
}
}
// Extract session token (optional)
if value, exists := kubeutils.GetSecretValue(secret, wellknown.SessionToken); exists {
sessionToken = ptr.Of(value)
}
return &api.BackendAuthPolicy{
@ -813,98 +643,6 @@ func buildAwsAuthPolicy(krtctx krt.HandlerContext, auth *agentgateway.AwsAuth, s
}, errors.Join(errs...)
}
func buildAzureAuthPolicy(krtctx krt.HandlerContext, auth *agentgateway.AzureAuth, secrets krt.Collection[*corev1.Secret], namespace string) (*api.BackendAuthPolicy, error) {
var errs []error
if auth.SecretRef.Name != "" {
return buildAzureClientSecret(secrets, krtctx, auth, namespace, errs)
}
if auth.ManagedIdentity != nil {
uaid := &api.AzureManagedIdentityCredential_UserAssignedIdentity{}
if auth.ManagedIdentity.ClientID != "" {
uaid.Id = &api.AzureManagedIdentityCredential_UserAssignedIdentity_ClientId{
ClientId: auth.ManagedIdentity.ClientID,
}
} else if auth.ManagedIdentity.ObjectID != "" {
uaid.Id = &api.AzureManagedIdentityCredential_UserAssignedIdentity_ObjectId{
ObjectId: auth.ManagedIdentity.ObjectID,
}
} else if auth.ManagedIdentity.ResourceID != "" {
uaid.Id = &api.AzureManagedIdentityCredential_UserAssignedIdentity_ResourceId{
ResourceId: auth.ManagedIdentity.ResourceID,
}
} else {
errs = append(errs, errors.New("no valid User Assigned Identity identifier provided"))
return nil, errors.Join(errs...)
}
return &api.BackendAuthPolicy{
Kind: &api.BackendAuthPolicy_Azure{
Azure: &api.Azure{
Kind: &api.Azure_ExplicitConfig{
ExplicitConfig: &api.AzureExplicitConfig{
CredentialSource: &api.AzureExplicitConfig_ManagedIdentityCredential{
ManagedIdentityCredential: &api.AzureManagedIdentityCredential{
UserAssignedIdentity: uaid,
},
},
},
},
},
},
}, nil
}
errs = append(errs, errors.New("no valid Azure auth method provided"))
return nil, errors.Join(errs...)
}
func buildAzureClientSecret(secrets krt.Collection[*corev1.Secret], krtctx krt.HandlerContext, auth *agentgateway.AzureAuth, namespace string, errs []error) (*api.BackendAuthPolicy, error) {
var clientID, tenantID, clientSecret string
secret, err := kubeutils.GetSecret(secrets, krtctx, auth.SecretRef.Name, namespace)
if err != nil {
errs = append(errs, err)
} else {
// Extract client ID
if value, exists := kubeutils.GetSecretValue(secret, wellknown.ClientID); !exists {
errs = append(errs, errors.New("clientID is missing or not a valid string"))
} else {
clientID = value
}
// Extract tenant ID
if value, exists := kubeutils.GetSecretValue(secret, wellknown.TenantID); !exists {
errs = append(errs, errors.New("tenantID is missing or not a valid string"))
} else {
tenantID = value
}
// Extract client secret
if value, exists := kubeutils.GetSecretValue(secret, wellknown.ClientSecret); !exists {
errs = append(errs, errors.New("clientSecret is missing or not a valid string"))
} else {
clientSecret = value
}
}
return &api.BackendAuthPolicy{
Kind: &api.BackendAuthPolicy_Azure{
Azure: &api.Azure{
Kind: &api.Azure_ExplicitConfig{
ExplicitConfig: &api.AzureExplicitConfig{
CredentialSource: &api.AzureExplicitConfig_ClientSecret{
ClientSecret: &api.AzureClientSecret{
ClientSecret: clientSecret,
TenantId: tenantID,
ClientId: clientID,
},
},
},
},
},
},
}, errors.Join(errs...)
}
func buildGcpAuthPolicy(auth *agentgateway.GcpAuth) *api.BackendAuthPolicy {
if auth.Type == nil || *auth.Type == agentgateway.GcpAuthTypeAccessToken {
return &api.BackendAuthPolicy{

View File

@ -0,0 +1,18 @@
package plugins_test
import (
"testing"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/plugins"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/testutils"
)
func TestBackendPolicies(t *testing.T) {
testutils.RunForDirectory(t, "testdata/backendpolicy", func(t *testing.T, ctx plugins.PolicyCtx) (*gwv1.PolicyStatus, []plugins.AgwPolicy) {
pol := testutils.GetTestResource(t, ctx.Collections.AgentgatewayPolicies)
s, o := plugins.TranslateAgentgatewayPolicy(ctx.Krt, pol, ctx.Collections)
return s, o
})
}

View File

@ -20,8 +20,8 @@ import (
"github.com/agentgateway/agentgateway/api"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/utils"
"github.com/agentgateway/agentgateway/controller/pkg/pluginsdk/krtutil"
"github.com/agentgateway/agentgateway/controller/pkg/wellknown"
"github.com/agentgateway/agentgateway/controller/pkg/kgateway/translator/sslutils"
"github.com/agentgateway/agentgateway/controller/pkg/kgateway/wellknown"
)
// NewBackendTLSPlugin creates a new BackendTLSPolicy plugin
@ -43,9 +43,9 @@ func NewBackendTLSPlugin(agw *AgwCollections) AgwPlugin {
wellknown.BackendTLSPolicyGVK.GroupKind(): {
Build: func(input PolicyPluginInput) (krt.StatusCollection[controllers.Object, any], krt.Collection[AgwPolicy]) {
st, o := krt.NewStatusManyCollection(agw.BackendTLSPolicies, func(krtctx krt.HandlerContext, btls *gwv1.BackendTLSPolicy) (*gwv1.PolicyStatus, []AgwPolicy) {
return translatePoliciesForBackendTLS(krtctx, agw.ControllerName, input.References, agw.ConfigMaps, agw.Secrets, agw.Services, backendTLSTarget, agw.Gateways, btls)
return translatePoliciesForBackendTLS(krtctx, agw.ControllerName, input.Ancestors, agw.ConfigMaps, agw.Services, backendTLSTarget, btls)
}, agw.KrtOpts.ToOptions("agentgateway/BackendTLSPolicy")...)
return ConvertStatusCollection(st), o
return convertStatusCollection(st), o
},
},
},
@ -56,12 +56,10 @@ func NewBackendTLSPlugin(agw *AgwCollections) AgwPlugin {
func translatePoliciesForBackendTLS(
krtctx krt.HandlerContext,
controllerName string,
references ReferenceIndex,
ancestors krt.IndexCollection[utils.TypedNamespacedName, *utils.AncestorBackend],
cfgmaps krt.Collection[*corev1.ConfigMap],
secrets krt.Collection[*corev1.Secret],
svcs krt.Collection[*corev1.Service],
targetIndex krt.IndexCollection[utils.TypedNamespacedName, *gwv1.BackendTLSPolicy],
gateways krt.Collection[*gwv1.Gateway],
btls *gwv1.BackendTLSPolicy,
) (*gwv1.PolicyStatus, []AgwPolicy) {
logger := logger.With("plugin_kind", "backendtls")
@ -115,29 +113,23 @@ func translatePoliciesForBackendTLS(
Kind: string(target.Kind),
}
gatewayTargets := references.LookupGatewaysForBackend(krtctx, tgtRef).UnsortedList()
uniqueGateways = uniqueGateways.InsertAll(gatewayTargets...)
var mtlsClientRef *gwv1.SecretObjectReference
var mtlsClientRefNamespace string
if uniqueGateways.Len() == 1 {
// TODO: support from multiple gateways.
// This will require us to have per-gateway policies, not global ones.
gtw := ptr.Flatten(krt.FetchOne(krtctx, gateways, krt.FilterKey(uniqueGateways.UnsortedList()[0].String())))
if gtw != nil && gtw.Spec.TLS != nil && gtw.Spec.TLS.Backend != nil && gtw.Spec.TLS.Backend.ClientCertificateRef != nil {
mtlsClientRef = gtw.Spec.TLS.Backend.ClientCertificateRef
mtlsClientRefNamespace = gtw.Namespace
ancestorBackends := krt.Fetch(krtctx, ancestors, krt.FilterKey(tgtRef.String()))
for _, gwl := range ancestorBackends {
for _, i := range gwl.Objects {
uniqueGateways.Insert(i.Gateway)
}
}
backendTLSPoliciesForThisTarget := krtutil.FetchIndexObjects(krtctx, targetIndex, tgtRef)
if err := checkConflicted(btls, target, backendTLSPoliciesForThisTarget); err != nil {
conds[string(gwv1.PolicyConditionAccepted)].error = &ConfigError{
Reason: string(gwv1.PolicyReasonConflicted),
Message: err.Error(),
backendTLSPoliciesForThisTarget := krt.FetchOne(krtctx, targetIndex, krt.FilterKey(tgtRef.String()))
if backendTLSPoliciesForThisTarget != nil {
if err := checkConflicted(btls, target, backendTLSPoliciesForThisTarget); err != nil {
conds[string(gwv1.PolicyConditionAccepted)].error = &ConfigError{
Reason: string(gwv1.PolicyReasonConflicted),
Message: err.Error(),
}
// We cannot send this policy to agentgateway, as it would not know the priority logic.
continue
}
// We cannot send this policy to agentgateway, as it would not know the priority logic.
continue
}
switch string(target.Kind) {
@ -176,49 +168,6 @@ func translatePoliciesForBackendTLS(
continue
}
res := &api.BackendPolicySpec_BackendTLS{
Root: caCert,
// Used for mTLS, conditionally set below
Cert: nil,
Key: nil,
// Validation.Hostname is a required value and validated with CEL
Hostname: ptr.Of(string(btls.Spec.Validation.Hostname)),
VerifySubjectAltNames: sans,
}
if mtlsClientRef != nil {
skip := false
if mtlsClientRef.Namespace != nil {
// TODO Implement this later
logger.Warn("ignoring Gateway.spec.tls.backend; cross namespace not permitted")
skip = true
}
if mtlsClientRef.Kind != nil && *mtlsClientRef.Kind != wellknown.SecretKind {
logger.Warn("ignoring Gateway.spec.tls.backend; only Secret is allowed")
skip = true
}
if mtlsClientRef.Group != nil && string(*mtlsClientRef.Group) != wellknown.SecretGVK.Group {
logger.Warn("ignoring Gateway.spec.tls.backend; only core is allowed")
skip = true
}
if !skip {
nn := types.NamespacedName{
Namespace: mtlsClientRefNamespace,
Name: string(mtlsClientRef.Name),
}
scrt := ptr.Flatten(krt.FetchOne(krtctx, secrets, krt.FilterObjectName(nn)))
if scrt == nil {
logger.Warn("ignoring Gateway.spec.tls.backend; secret not found")
} else {
if _, err := ValidateTlsSecretData(nn.Name, nn.Namespace, scrt.Data); err != nil {
logger.Warn("ignoring Gateway.spec.tls.backend; secret not found")
} else {
res.Cert = scrt.Data[corev1.TLSCertKey]
res.Key = scrt.Data[corev1.TLSPrivateKeyKey]
}
}
}
}
policy := &api.Policy{
Key: btls.Namespace + "/" + btls.Name + backendTlsPolicySuffix + attachmentName(policyTarget),
Name: TypedResourceName(wellknown.BackendTLSPolicyKind, btls),
@ -226,12 +175,20 @@ func translatePoliciesForBackendTLS(
Kind: &api.Policy_Backend{
Backend: &api.BackendPolicySpec{
Kind: &api.BackendPolicySpec_BackendTls{
BackendTls: res,
BackendTls: &api.BackendPolicySpec_BackendTLS{
Root: caCert,
// Used for mTLS, not part of the spec currently
Cert: nil,
Key: nil,
// Validation.Hostname is a required value and validated with CEL
Hostname: ptr.Of(string(btls.Spec.Validation.Hostname)),
VerifySubjectAltNames: sans,
},
},
},
},
}
policies = appendPolicyForGateways(policies, gatewayTargets, policy)
policies = append(policies, AgwPolicy{policy})
}
ancestorStatus := make([]gwv1.PolicyAncestorStatus, 0, len(btls.Spec.TargetRefs))
for g := range uniqueGateways {
@ -252,9 +209,9 @@ func translatePoliciesForBackendTLS(
func checkConflicted(
btls *gwv1.BackendTLSPolicy,
target gwv1.LocalPolicyTargetReferenceWithSectionName,
allMatches []*gwv1.BackendTLSPolicy,
allMatches *krt.IndexObject[utils.TypedNamespacedName, *gwv1.BackendTLSPolicy],
) error {
for _, m := range allMatches {
for _, m := range allMatches.Objects {
if m.UID == btls.UID {
// This is ourself, skip it
continue
@ -351,7 +308,7 @@ func getBackendTLSCACert(
}
return nil, fmt.Errorf("certificate reference not found: %v", ref)
}
caCert, err := GetCACertFromConfigMap(ptr.Flatten(cfgmap))
caCert, err := sslutils.GetCACertFromConfigMap(ptr.Flatten(cfgmap))
if err != nil {
conds[string(gwv1.BackendTLSPolicyReasonResolvedRefs)].error = &ConfigError{
Reason: string(gwv1.BackendTLSPolicyReasonInvalidCACertificateRef),

View File

@ -7,31 +7,26 @@ import (
"istio.io/istio/pkg/kube/kclient"
"istio.io/istio/pkg/kube/krt"
"istio.io/istio/pkg/kube/kubetypes"
"istio.io/istio/pkg/ptr"
corev1 "k8s.io/api/core/v1"
discovery "k8s.io/api/discovery/v1"
inf "sigs.k8s.io/gateway-api-inference-extension/api/v1"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gwxv1a1 "sigs.k8s.io/gateway-api/apisx/v1alpha1"
apisettings "github.com/agentgateway/agentgateway/controller/api/settings"
"github.com/agentgateway/agentgateway/controller/api/v1alpha1/agentgateway"
"github.com/agentgateway/agentgateway/controller/pkg/apiclient"
kgwversioned "github.com/agentgateway/agentgateway/controller/pkg/client/clientset/versioned"
"github.com/agentgateway/agentgateway/controller/pkg/kgateway/wellknown"
"github.com/agentgateway/agentgateway/controller/pkg/pluginsdk/collections"
"github.com/agentgateway/agentgateway/controller/pkg/pluginsdk/krtutil"
krtpkg "github.com/agentgateway/agentgateway/controller/pkg/utils/krtutil"
"github.com/agentgateway/agentgateway/controller/pkg/wellknown"
)
type AgwCollections struct {
OurClient kgwversioned.Interface
Client apiclient.Client
KrtOpts krtutil.KrtOptions
Settings apisettings.Settings
GatewaysForDeployer krt.Collection[collections.GatewayForDeployer]
// Core Kubernetes resources
Namespaces krt.Collection[*corev1.Namespace]
@ -54,10 +49,10 @@ type AgwCollections struct {
HTTPRoutes krt.Collection[*gwv1.HTTPRoute]
GRPCRoutes krt.Collection[*gwv1.GRPCRoute]
TCPRoutes krt.Collection[*gwv1a2.TCPRoute]
TLSRoutes krt.Collection[*gwv1.TLSRoute]
TLSRoutes krt.Collection[*gwv1a2.TLSRoute]
ReferenceGrants krt.Collection[*gwv1b1.ReferenceGrant]
BackendTLSPolicies krt.Collection[*gwv1.BackendTLSPolicy]
ListenerSets krt.Collection[*gwv1.ListenerSet]
XListenerSets krt.Collection[*gwxv1a1.XListenerSet]
// Extended resources
InferencePools krt.Collection[*inf.InferencePool]
@ -68,12 +63,10 @@ type AgwCollections struct {
// ControllerName is the name of the Gateway controller.
ControllerName string
// SystemNamespace is control plane system namespace (default is agentgateway-system)
// SystemNamespace is control plane system namespace (default is kgateway-system)
SystemNamespace string
// IstioNamespace is the Istio control plane namespace (default is istio-system)
IstioNamespace string
// IstioRevision is the Istio revision of the Istio control plane (default is "default").
IstioRevision string
// ClusterID is the cluster ID of the cluster the proxy is running in.
ClusterID string
}
@ -82,108 +75,81 @@ type AgwCollections struct {
// Collections that rely on plugins aren't initialized here,
// and InitPlugins must be called.
func NewAgwCollections(
krtOptions krtutil.KrtOptions,
client apiclient.Client,
commoncol *collections.CommonCollections,
agwControllerName string,
settings apisettings.Settings,
systemNamespace string,
clusterID string,
) (*AgwCollections, error) {
filter := kclient.Filter{ObjectFilter: client.ObjectFilter()}
gateways := krt.WrapClient(kclient.NewFilteredDelayed[*gwv1.Gateway](
client, wellknown.GatewayGVR, filter), krtOptions.ToOptions("informer/Gateways")...)
gatewayClasses := krt.WrapClient(kclient.NewFilteredDelayed[*gwv1.GatewayClass](
client, wellknown.GatewayClassGVR, filter), krtOptions.ToOptions("informer/GatewayClasses")...)
listenerSets := krt.WrapClient(kclient.NewDelayedInformer[*gwv1.ListenerSet](
client, wellknown.ListenerSetGVR, kubetypes.StandardInformer, filter), krtOptions.ToOptions("informer/ListenerSets")...)
byParentRefIndex := krtpkg.UnnamedIndex(listenerSets, func(in *gwv1.ListenerSet) []collections.TargetRefIndexKey {
pRef := in.Spec.ParentRef
ns := ptr.OrDefault(pRef.Namespace, gwv1.Namespace(in.GetNamespace()))
// lookup by the root object
return []collections.TargetRefIndexKey{{
Group: wellknown.GatewayGroup,
Kind: wellknown.GatewayKind,
Name: string(pRef.Name),
Namespace: string(ns),
// this index intentionally doesn't include sectionName
}}
})
agwCollections := &AgwCollections{
Client: client,
KrtOpts: krtOptions,
Settings: settings,
GatewaysForDeployer: krt.NewCollection(gateways, collections.GatewaysForDeployerTransformationFunc(gatewayClasses, listenerSets, byParentRefIndex, agwControllerName)),
ControllerName: agwControllerName,
SystemNamespace: systemNamespace,
IstioNamespace: settings.IstioNamespace,
IstioRevision: settings.IstioRevision,
ClusterID: clusterID,
Client: commoncol.Client,
KrtOpts: commoncol.KrtOpts,
ControllerName: agwControllerName,
SystemNamespace: systemNamespace,
IstioNamespace: commoncol.Settings.IstioNamespace,
ClusterID: clusterID,
// Core Kubernetes resources
Namespaces: krt.NewInformer[*corev1.Namespace](client, krtOptions.ToOptions("informer/Namespaces")...),
Nodes: krt.NewFilteredInformer[*corev1.Node](client, kclient.Filter{
ObjectFilter: client.ObjectFilter(),
}, krtOptions.ToOptions("informer/Nodes")...),
Pods: krt.NewFilteredInformer[*corev1.Pod](client, kclient.Filter{
Namespaces: krt.NewInformer[*corev1.Namespace](commoncol.Client),
Nodes: krt.NewFilteredInformer[*corev1.Node](commoncol.Client, kclient.Filter{
ObjectFilter: commoncol.Client.ObjectFilter(),
}, commoncol.KrtOpts.ToOptions("informer/Nodes")...),
Pods: krt.NewFilteredInformer[*corev1.Pod](commoncol.Client, kclient.Filter{
ObjectTransform: istiokube.StripPodUnusedFields,
ObjectFilter: client.ObjectFilter(),
}, krtOptions.ToOptions("informer/Pods")...),
ObjectFilter: commoncol.Client.ObjectFilter(),
}, commoncol.KrtOpts.ToOptions("informer/Pods")...),
Secrets: krt.WrapClient(
kclient.NewFiltered[*corev1.Secret](client, kubetypes.Filter{
FieldSelector: apiclient.SecretsFieldSelector,
ObjectFilter: client.ObjectFilter(),
kclient.NewFiltered[*corev1.Secret](commoncol.Client, kubetypes.Filter{
ObjectFilter: commoncol.Client.ObjectFilter(),
}),
),
ConfigMaps: krt.WrapClient(
kclient.NewFiltered[*corev1.ConfigMap](client, kubetypes.Filter{
ObjectFilter: client.ObjectFilter(),
kclient.NewFiltered[*corev1.ConfigMap](commoncol.Client, kubetypes.Filter{
ObjectFilter: commoncol.Client.ObjectFilter(),
}),
krtOptions.ToOptions("informer/ConfigMaps")...,
commoncol.KrtOpts.ToOptions("informer/ConfigMaps")...,
),
Services: krt.WrapClient(
kclient.NewFiltered[*corev1.Service](client, kubetypes.Filter{ObjectFilter: client.ObjectFilter()}),
krtOptions.ToOptions("informer/Services")...),
kclient.NewFiltered[*corev1.Service](commoncol.Client, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}),
commoncol.KrtOpts.ToOptions("informer/Services")...),
EndpointSlices: krt.WrapClient(
kclient.NewFiltered[*discovery.EndpointSlice](client, kubetypes.Filter{ObjectFilter: client.ObjectFilter()}),
krtOptions.ToOptions("informer/EndpointSlices")...),
kclient.NewFiltered[*discovery.EndpointSlice](commoncol.Client, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}),
commoncol.KrtOpts.ToOptions("informer/EndpointSlices")...),
// Istio resources
WorkloadEntries: krt.WrapClient(
kclient.NewDelayedInformer[*networkingclient.WorkloadEntry](client, gvr.WorkloadEntry, kubetypes.StandardInformer, kclient.Filter{ObjectFilter: client.ObjectFilter()}),
krtOptions.ToOptions("informer/WorkloadEntries")...),
kclient.NewDelayedInformer[*networkingclient.WorkloadEntry](commoncol.Client, gvr.WorkloadEntry, kubetypes.StandardInformer, kclient.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}),
commoncol.KrtOpts.ToOptions("informer/WorkloadEntries")...),
ServiceEntries: krt.WrapClient(
kclient.NewDelayedInformer[*networkingclient.ServiceEntry](client, gvr.ServiceEntry, kubetypes.StandardInformer, kclient.Filter{ObjectFilter: client.ObjectFilter()}),
krtOptions.ToOptions("informer/ServiceEntries")...),
kclient.NewDelayedInformer[*networkingclient.ServiceEntry](commoncol.Client, gvr.ServiceEntry, kubetypes.StandardInformer, kclient.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}),
commoncol.KrtOpts.ToOptions("informer/ServiceEntries")...),
// Gateway API resources
GatewayClasses: gatewayClasses,
Gateways: gateways,
HTTPRoutes: krt.WrapClient(kclient.NewFilteredDelayed[*gwv1.HTTPRoute](client, wellknown.HTTPRouteGVR, kubetypes.Filter{ObjectFilter: client.ObjectFilter()}), krtOptions.ToOptions("informer/HTTPRoutes")...),
GRPCRoutes: krt.WrapClient(kclient.NewFilteredDelayed[*gwv1.GRPCRoute](client, wellknown.GRPCRouteGVR, kubetypes.Filter{ObjectFilter: client.ObjectFilter()}), krtOptions.ToOptions("informer/GRPCRoutes")...),
TLSRoutes: krt.WrapClient(kclient.NewDelayedInformer[*gwv1.TLSRoute](client, gvr.TLSRoute, kubetypes.StandardInformer, kubetypes.Filter{ObjectFilter: client.ObjectFilter()}), krtOptions.ToOptions("informer/TLSRoutes")...),
BackendTLSPolicies: krt.WrapClient(kclient.NewDelayedInformer[*gwv1.BackendTLSPolicy](client, gvr.BackendTLSPolicy, kubetypes.StandardInformer, kubetypes.Filter{ObjectFilter: client.ObjectFilter()}), krtOptions.ToOptions("informer/BackendTLSPolicies")...),
ListenerSets: listenerSets,
GatewayClasses: krt.WrapClient(kclient.NewFilteredDelayed[*gwv1.GatewayClass](commoncol.Client, wellknown.GatewayClassGVR, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}), commoncol.KrtOpts.ToOptions("informer/GatewayClasses")...),
Gateways: krt.WrapClient(kclient.NewFilteredDelayed[*gwv1.Gateway](commoncol.Client, wellknown.GatewayGVR, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}), commoncol.KrtOpts.ToOptions("informer/Gateways")...),
HTTPRoutes: krt.WrapClient(kclient.NewFilteredDelayed[*gwv1.HTTPRoute](commoncol.Client, wellknown.HTTPRouteGVR, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}), commoncol.KrtOpts.ToOptions("informer/HTTPRoutes")...),
GRPCRoutes: krt.WrapClient(kclient.NewFilteredDelayed[*gwv1.GRPCRoute](commoncol.Client, wellknown.GRPCRouteGVR, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}), commoncol.KrtOpts.ToOptions("informer/GRPCRoutes")...),
BackendTLSPolicies: krt.WrapClient(kclient.NewDelayedInformer[*gwv1.BackendTLSPolicy](commoncol.Client, gvr.BackendTLSPolicy, kubetypes.StandardInformer, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}), commoncol.KrtOpts.ToOptions("informer/BackendTLSPolicies")...),
// Gateway API alpha
TCPRoutes: krt.WrapClient(kclient.NewDelayedInformer[*gwv1a2.TCPRoute](client, gvr.TCPRoute, kubetypes.StandardInformer, kubetypes.Filter{ObjectFilter: client.ObjectFilter()}), krtOptions.ToOptions("informer/TCPRoutes")...),
ReferenceGrants: krt.WrapClient(kclient.NewFilteredDelayed[*gwv1b1.ReferenceGrant](client, wellknown.ReferenceGrantGVR, kubetypes.Filter{ObjectFilter: client.ObjectFilter()}), krtOptions.ToOptions("informer/ReferenceGrants")...),
TCPRoutes: krt.WrapClient(kclient.NewDelayedInformer[*gwv1a2.TCPRoute](commoncol.Client, gvr.TCPRoute, kubetypes.StandardInformer, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}), commoncol.KrtOpts.ToOptions("informer/TCPRoutes")...),
TLSRoutes: krt.WrapClient(kclient.NewDelayedInformer[*gwv1a2.TLSRoute](commoncol.Client, gvr.TLSRoute, kubetypes.StandardInformer, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}), commoncol.KrtOpts.ToOptions("informer/TLSRoutes")...),
ReferenceGrants: krt.WrapClient(kclient.NewFilteredDelayed[*gwv1b1.ReferenceGrant](commoncol.Client, wellknown.ReferenceGrantGVR, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}), commoncol.KrtOpts.ToOptions("informer/ReferenceGrants")...),
XListenerSets: krt.WrapClient(kclient.NewDelayedInformer[*gwxv1a1.XListenerSet](commoncol.Client, gvr.XListenerSet, kubetypes.StandardInformer, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}), commoncol.KrtOpts.ToOptions("informer/XListenerSets")...),
// BackendTrafficPolicy?
// inference extensions need to be enabled so control plane has permissions to watch resource. Disable by default
InferencePools: krt.NewStaticCollection[*inf.InferencePool](nil, nil, krtOptions.ToOptions("disable/inferencepools")...),
InferencePools: krt.NewStaticCollection[*inf.InferencePool](nil, nil, commoncol.KrtOpts.ToOptions("disable/inferencepools")...),
// agentgateway-specific CRDs
AgentgatewayPolicies: krt.NewInformer[*agentgateway.AgentgatewayPolicy](client),
Backends: krt.NewInformer[*agentgateway.AgentgatewayBackend](client),
AgentgatewayPolicies: krt.NewInformer[*agentgateway.AgentgatewayPolicy](commoncol.Client),
Backends: krt.NewInformer[*agentgateway.AgentgatewayBackend](commoncol.Client),
}
if settings.EnableInferExt {
if commoncol.Settings.EnableInferExt {
// inference extensions cluster watch permissions are controlled by enabling EnableInferExt
inferencePoolGVR := wellknown.InferencePoolGVK.GroupVersion().WithResource("inferencepools")
agwCollections.InferencePools = krt.WrapClient(kclient.NewDelayedInformer[*inf.InferencePool](client, inferencePoolGVR, kubetypes.StandardInformer, kclient.Filter{ObjectFilter: client.ObjectFilter()}), krtOptions.ToOptions("informer/InferencePools")...)
agwCollections.InferencePools = krt.WrapClient(kclient.NewDelayedInformer[*inf.InferencePool](commoncol.Client, inferencePoolGVR, kubetypes.StandardInformer, kclient.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}), commoncol.KrtOpts.ToOptions("informer/InferencePools")...)
}
agwCollections.SetupIndexes()
@ -194,7 +160,3 @@ func (c *AgwCollections) SetupIndexes() {
c.SecretsByNamespace = krt.NewNamespaceIndex(c.Secrets)
c.ServicesByNamespace = krt.NewNamespaceIndex(c.Services)
}
func (c *AgwCollections) HasSynced() bool {
return c.GatewaysForDeployer.HasSynced()
}

View File

@ -6,16 +6,15 @@ import (
"google.golang.org/protobuf/types/known/durationpb"
"istio.io/istio/pkg/ptr"
"istio.io/istio/pkg/slices"
"github.com/agentgateway/agentgateway/api"
"github.com/agentgateway/agentgateway/controller/api/v1alpha1/agentgateway"
"github.com/agentgateway/agentgateway/controller/api/v1alpha1/shared"
"github.com/agentgateway/agentgateway/controller/pkg/wellknown"
"github.com/agentgateway/agentgateway/controller/pkg/kgateway/wellknown"
)
const (
frontendTcpPolicySuffix = ":frontend-tcp"
frontendNetworkAuthzSuffix = ":frontend-network-authz"
frontendTlsPolicySuffix = ":frontend-tls"
frontendHttpPolicySuffix = ":frontend-http"
frontendLoggingPolicySuffix = ":frontend-logging"
@ -25,70 +24,64 @@ const (
func translateFrontendPolicyToAgw(
policyCtx PolicyCtx,
policy *agentgateway.AgentgatewayPolicy,
) ([]*api.Policy, error) {
policyTarget *api.PolicyTarget,
) ([]AgwPolicy, error) {
frontend := policy.Spec.Frontend
if frontend == nil {
return nil, nil
}
agwPolicies := make([]*api.Policy, 0)
agwPolicies := make([]AgwPolicy, 0)
var errs []error
policyName := getFrontendPolicyName(policy.Namespace, policy.Name)
appendPolicy := func(kind string) func(*api.Policy, error) {
return func(p *api.Policy, err error) {
if err != nil {
name := fmt.Sprintf("%s %s", kind, policyName)
logger.Error("error processing policy", "policy", name, "error", err)
errs = append(errs, err)
}
if p != nil {
agwPolicies = append(agwPolicies, p)
}
}
}
if s := frontend.HTTP; s != nil {
appendPolicy("http")(translateFrontendHTTP(policy, policyName), nil)
pol := translateFrontendHTTP(policy, policyName, policyTarget)
agwPolicies = append(agwPolicies, pol...)
}
if s := frontend.TLS; s != nil {
appendPolicy("tls")(translateFrontendTLS(policy, policyName), nil)
pol := translateFrontendTLS(policy, policyName, policyTarget)
agwPolicies = append(agwPolicies, pol...)
}
if s := frontend.TCP; s != nil {
appendPolicy("tcp")(translateFrontendTCP(policy, policyName), nil)
}
if s := frontend.NetworkAuthorization; s != nil {
appendPolicy("networkAuthorization")(translateFrontendNetworkAuthorization(policy, policyName), nil)
pol := translateFrontendTCP(policy, policyName, policyTarget)
agwPolicies = append(agwPolicies, pol...)
}
if s := frontend.AccessLog; s != nil {
appendPolicy("accessLog")(translateFrontendAccessLog(policyCtx, policy, policyName))
pol := translateFrontendAccessLog(policy, policyName, policyTarget)
agwPolicies = append(agwPolicies, pol...)
}
if s := frontend.Tracing; s != nil {
appendPolicy("tracing")(translateFrontendTracing(policyCtx, policy, policyName))
pol, err := translateFrontendTracing(policyCtx, policy, policyName, policyTarget)
if err != nil {
logger.Error("error processing tracing", "err", err)
errs = append(errs, err)
}
agwPolicies = append(agwPolicies, pol...)
}
return agwPolicies, errors.Join(errs...)
}
func translateFrontendTracing(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy, name string) (*api.Policy, error) {
func translateFrontendTracing(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy, name string, target *api.PolicyTarget) ([]AgwPolicy, error) {
tracing := policy.Spec.Frontend.Tracing
var errs []error
if tracing == nil {
return nil, nil
}
provider, err := buildBackendRef(ctx, tracing.BackendRef, policy.Namespace)
if err != nil {
errs = append(errs, fmt.Errorf("failed to translate tracing backend ref: %v", err))
return nil, fmt.Errorf("failed to translate tracing backend ref: %v", err)
}
var addAttributes []*api.FrontendPolicySpec_TracingAttribute
var rmAttributes []string
if tracing.Attributes != nil {
for _, add := range tracing.Attributes.Add {
if !isCEL(add.Expression) {
errs = append(errs, fmt.Errorf("frontend tracing attribute %q is not a valid CEL expression: %s", add.Name, add.Expression))
}
addAttributes = append(addAttributes, &api.FrontendPolicySpec_TracingAttribute{
Name: add.Name,
Value: string(add.Expression),
@ -102,9 +95,6 @@ func translateFrontendTracing(ctx PolicyCtx, policy *agentgateway.AgentgatewayPo
var addResources []*api.FrontendPolicySpec_TracingAttribute
if tracing.Resources != nil {
for _, add := range tracing.Resources {
if !isCEL(add.Expression) {
errs = append(errs, fmt.Errorf("frontend tracing resource %q is not a valid CEL expression: %s", add.Name, add.Expression))
}
addResources = append(addResources, &api.FrontendPolicySpec_TracingAttribute{
Name: add.Name,
Value: string(add.Expression),
@ -114,37 +104,29 @@ func translateFrontendTracing(ctx PolicyCtx, policy *agentgateway.AgentgatewayPo
var randomSampling *string
if tracing.RandomSampling != nil {
randomSampling = castCELPtr(tracing.RandomSampling, func(expr shared.CELExpression) {
errs = append(errs, fmt.Errorf("frontend tracing randomSampling is not a valid CEL expression: %s", expr))
})
randomSampling = ptr.Of(string(*tracing.RandomSampling))
}
var clientSampling *string
if tracing.ClientSampling != nil {
clientSampling = castCELPtr(tracing.ClientSampling, func(expr shared.CELExpression) {
errs = append(errs, fmt.Errorf("frontend tracing clientSampling is not a valid CEL expression: %s", expr))
})
}
var path *string
if tracing.Path != nil {
path = ptr.Of(*tracing.Path)
clientSampling = ptr.Of(string(*tracing.ClientSampling))
}
var protocol api.FrontendPolicySpec_Tracing_Protocol
switch tracing.Protocol {
case agentgateway.OTLPProtocolGrpc:
case agentgateway.TracingProtocolGrpc:
protocol = api.FrontendPolicySpec_Tracing_GRPC
case agentgateway.OTLPProtocolHttp:
case agentgateway.TracingProtocolHttp:
protocol = api.FrontendPolicySpec_Tracing_HTTP
default:
// default to HTTP
protocol = api.FrontendPolicySpec_Tracing_GRPC
protocol = api.FrontendPolicySpec_Tracing_HTTP
}
tracingPolicy := &api.Policy{
Key: name + frontendTracingPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Key: name + frontendTracingPolicySuffix + attachmentName(target),
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Target: target,
Kind: &api.Policy_Frontend{
Frontend: &api.FrontendPolicySpec{
Kind: &api.FrontendPolicySpec_Tracing_{Tracing: &api.FrontendPolicySpec_Tracing{
@ -153,7 +135,6 @@ func translateFrontendTracing(ctx PolicyCtx, policy *agentgateway.AgentgatewayPo
Remove: rmAttributes,
Resources: addResources,
Protocol: protocol,
Path: path,
RandomSampling: randomSampling,
ClientSampling: clientSampling,
}},
@ -163,68 +144,35 @@ func translateFrontendTracing(ctx PolicyCtx, policy *agentgateway.AgentgatewayPo
logger.Debug("generated tracing policy",
"policy", policy.Name,
"agentgateway_policy", tracingPolicy.Name)
"agentgateway_policy", tracingPolicy.Name,
"target", target)
return tracingPolicy, errors.Join(errs...)
return []AgwPolicy{{Policy: tracingPolicy}}, nil
}
func translateFrontendAccessLog(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy, name string) (*api.Policy, error) {
func translateFrontendAccessLog(policy *agentgateway.AgentgatewayPolicy, name string, target *api.PolicyTarget) []AgwPolicy {
logging := policy.Spec.Frontend.AccessLog
spec := &api.FrontendPolicySpec_Logging{}
var errs []error
if f := logging.Filter; f != nil {
spec.Filter = castCELPtr(f, func(expr shared.CELExpression) {
errs = append(errs, fmt.Errorf("frontend accessLog filter is not a valid CEL expression: %s", expr))
})
spec.Filter = (*string)(f)
}
if a := logging.Attributes; a != nil {
fields := make([]*api.FrontendPolicySpec_Logging_Field, 0, len(a.Add))
for _, add := range a.Add {
if !isCEL(add.Expression) {
errs = append(errs, fmt.Errorf("frontend accessLog field %q is not a valid CEL expression: %s", add.Name, add.Expression))
}
fields = append(fields, &api.FrontendPolicySpec_Logging_Field{
Name: add.Name,
Expression: string(add.Expression),
})
}
f := &api.FrontendPolicySpec_Logging_Fields{
Remove: a.Remove,
Add: fields,
Add: slices.Map(a.Add, func(e agentgateway.AttributeAdd) *api.FrontendPolicySpec_Logging_Field {
return &api.FrontendPolicySpec_Logging_Field{
Name: e.Name,
Expression: string(e.Expression),
}
}),
}
spec.Fields = f
}
if otlp := logging.Otlp; otlp != nil {
provider, err := buildBackendRef(ctx, otlp.BackendRef, policy.Namespace)
if err != nil {
errs = append(errs, fmt.Errorf("failed to translate access log OTLP backend ref: %v", err))
}
var protocol api.FrontendPolicySpec_Logging_OtlpAccessLog_Protocol
switch otlp.Protocol {
case agentgateway.OTLPProtocolGrpc:
protocol = api.FrontendPolicySpec_Logging_OtlpAccessLog_GRPC
case agentgateway.OTLPProtocolHttp:
protocol = api.FrontendPolicySpec_Logging_OtlpAccessLog_HTTP
default:
protocol = api.FrontendPolicySpec_Logging_OtlpAccessLog_GRPC
}
var path *string
if otlp.Path != nil {
path = ptr.Of(*otlp.Path)
}
spec.OtlpAccessLog = &api.FrontendPolicySpec_Logging_OtlpAccessLog{
ProviderBackend: provider,
Protocol: protocol,
Path: path,
}
}
loggingPolicy := &api.Policy{
Key: name + frontendLoggingPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Key: name + frontendLoggingPolicySuffix + attachmentName(target),
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Target: target,
Kind: &api.Policy_Frontend{
Frontend: &api.FrontendPolicySpec{
Kind: &api.FrontendPolicySpec_Logging_{
@ -236,12 +184,13 @@ func translateFrontendAccessLog(ctx PolicyCtx, policy *agentgateway.Agentgateway
logger.Debug("generated logging policy",
"policy", policy.Name,
"agentgateway_policy", loggingPolicy.Name)
"agentgateway_policy", loggingPolicy.Name,
"target", target)
return loggingPolicy, errors.Join(errs...)
return []AgwPolicy{{Policy: loggingPolicy}}
}
func translateFrontendTCP(policy *agentgateway.AgentgatewayPolicy, name string) *api.Policy {
func translateFrontendTCP(policy *agentgateway.AgentgatewayPolicy, name string, target *api.PolicyTarget) []AgwPolicy {
tcp := policy.Spec.Frontend.TCP
spec := &api.FrontendPolicySpec_TCP{}
if ka := tcp.KeepAlive; ka != nil {
@ -258,8 +207,9 @@ func translateFrontendTCP(policy *agentgateway.AgentgatewayPolicy, name string)
}
tcpPolicy := &api.Policy{
Key: name + frontendTcpPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Key: name + frontendTcpPolicySuffix + attachmentName(target),
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Target: target,
Kind: &api.Policy_Frontend{
Frontend: &api.FrontendPolicySpec{
Kind: &api.FrontendPolicySpec_Tcp{
@ -271,50 +221,17 @@ func translateFrontendTCP(policy *agentgateway.AgentgatewayPolicy, name string)
logger.Debug("generated tcp policy",
"policy", policy.Name,
"agentgateway_policy", tcpPolicy.Name)
"agentgateway_policy", tcpPolicy.Name,
"target", target)
return tcpPolicy
}
func translateFrontendNetworkAuthorization(policy *agentgateway.AgentgatewayPolicy, name string) *api.Policy {
auth := policy.Spec.Frontend.NetworkAuthorization
var allowPolicies, denyPolicies, requirePolicies []string
if auth.Action == shared.AuthorizationPolicyActionDeny {
denyPolicies = append(denyPolicies, cast(auth.Policy.MatchExpressions)...)
} else if auth.Action == shared.AuthorizationPolicyActionRequire {
requirePolicies = append(requirePolicies, cast(auth.Policy.MatchExpressions)...)
} else {
allowPolicies = append(allowPolicies, cast(auth.Policy.MatchExpressions)...)
}
pol := &api.Policy{
Key: name + frontendNetworkAuthzSuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Kind: &api.Policy_Frontend{
Frontend: &api.FrontendPolicySpec{
Kind: &api.FrontendPolicySpec_NetworkAuthorization_{
NetworkAuthorization: &api.FrontendPolicySpec_NetworkAuthorization{
Allow: allowPolicies,
Deny: denyPolicies,
Require: requirePolicies,
},
},
},
},
}
logger.Debug("generated frontend network authorization policy",
"policy", policy.Name,
"agentgateway_policy", pol.Name)
return pol
return []AgwPolicy{{Policy: tcpPolicy}}
}
func castUint32[T ~int32](ka *T) *uint32 {
return ptr.Of((uint32)(*ka))
}
func translateFrontendTLS(policy *agentgateway.AgentgatewayPolicy, name string) *api.Policy {
func translateFrontendTLS(policy *agentgateway.AgentgatewayPolicy, name string, target *api.PolicyTarget) []AgwPolicy {
tls := policy.Spec.Frontend.TLS
spec := &api.FrontendPolicySpec_TLS{}
if ka := tls.HandshakeTimeout; ka != nil {
@ -380,8 +297,9 @@ func translateFrontendTLS(policy *agentgateway.AgentgatewayPolicy, name string)
}
tlsPolicy := &api.Policy{
Key: name + frontendTlsPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Key: name + frontendTlsPolicySuffix + attachmentName(target),
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Target: target,
Kind: &api.Policy_Frontend{
Frontend: &api.FrontendPolicySpec{
Kind: &api.FrontendPolicySpec_Tls{
@ -393,12 +311,13 @@ func translateFrontendTLS(policy *agentgateway.AgentgatewayPolicy, name string)
logger.Debug("generated tls policy",
"policy", policy.Name,
"agentgateway_policy", tlsPolicy.Name)
"agentgateway_policy", tlsPolicy.Name,
"target", target)
return tlsPolicy
return []AgwPolicy{{Policy: tlsPolicy}}
}
func translateFrontendHTTP(policy *agentgateway.AgentgatewayPolicy, name string) *api.Policy {
func translateFrontendHTTP(policy *agentgateway.AgentgatewayPolicy, name string, target *api.PolicyTarget) []AgwPolicy {
http := policy.Spec.Frontend.HTTP
spec := &api.FrontendPolicySpec_HTTP{}
if v := http.MaxBufferSize; v != nil {
@ -427,8 +346,9 @@ func translateFrontendHTTP(policy *agentgateway.AgentgatewayPolicy, name string)
}
httpPolicy := &api.Policy{
Key: name + frontendHttpPolicySuffix,
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Key: name + frontendHttpPolicySuffix + attachmentName(target),
Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy),
Target: target,
Kind: &api.Policy_Frontend{
Frontend: &api.FrontendPolicySpec{
Kind: &api.FrontendPolicySpec_Http{
@ -440,7 +360,8 @@ func translateFrontendHTTP(policy *agentgateway.AgentgatewayPolicy, name string)
logger.Debug("generated http policy",
"policy", policy.Name,
"agentgateway_policy", httpPolicy.Name)
"agentgateway_policy", httpPolicy.Name,
"target", target)
return httpPolicy
return []AgwPolicy{{Policy: httpPolicy}}
}

View File

@ -0,0 +1,18 @@
package plugins_test
import (
"testing"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/plugins"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/testutils"
)
func TestFrontendPolicies(t *testing.T) {
testutils.RunForDirectory(t, "testdata/frontendpolicy", func(t *testing.T, ctx plugins.PolicyCtx) (*gwv1.PolicyStatus, []plugins.AgwPolicy) {
pol := testutils.GetTestResource(t, ctx.Collections.AgentgatewayPolicies)
s, o := plugins.TranslateAgentgatewayPolicy(ctx.Krt, pol, ctx.Collections)
return s, o
})
}

View File

@ -17,8 +17,8 @@ import (
"github.com/agentgateway/agentgateway/api"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/utils"
"github.com/agentgateway/agentgateway/controller/pkg/kgateway/wellknown"
"github.com/agentgateway/agentgateway/controller/pkg/utils/kubeutils"
"github.com/agentgateway/agentgateway/controller/pkg/wellknown"
)
const (
@ -33,9 +33,9 @@ func NewInferencePlugin(agw *AgwCollections) AgwPlugin {
wellknown.InferencePoolGVK.GroupKind(): {
Build: func(input PolicyPluginInput) (krt.StatusCollection[controllers.Object, any], krt.Collection[AgwPolicy]) {
status, policyCol := krt.NewStatusManyCollection(agw.InferencePools, func(krtctx krt.HandlerContext, infPool *inf.InferencePool) (*inf.InferencePoolStatus, []AgwPolicy) {
return translatePoliciesForInferencePool(krtctx, agw.ControllerName, input.References, agw.Services, infPool)
return translatePoliciesForInferencePool(krtctx, agw.ControllerName, input.Ancestors, agw.Services, infPool)
}, agw.KrtOpts.ToOptions("agentgateway/InferencePools")...)
return ConvertStatusCollection(status), policyCol
return convertStatusCollection(status), policyCol
},
},
},
@ -46,7 +46,7 @@ func NewInferencePlugin(agw *AgwCollections) AgwPlugin {
func translatePoliciesForInferencePool(
krtctx krt.HandlerContext,
controllerName string,
references ReferenceIndex,
ancestors krt.IndexCollection[utils.TypedNamespacedName, *utils.AncestorBackend],
services krt.Collection[*corev1.Service],
pool *inf.InferencePool,
) (*inf.InferencePoolStatus, []AgwPolicy) {
@ -54,7 +54,7 @@ func translatePoliciesForInferencePool(
epr := pool.Spec.EndpointPickerRef
validationErr := validateInferencePoolEndpointPickerRef(krtctx, pool, services)
attachedGateways := inferencePoolAttachedGateways(krtctx, references, pool)
attachedGateways := inferencePoolAttachedGateways(krtctx, ancestors, pool)
status := buildInferencePoolStatus(pool, controllerName, attachedGateways, validationErr)
// 'service/{namespace}/{hostname}:{port}'
@ -91,11 +91,7 @@ func translatePoliciesForInferencePool(
},
},
}
gatewayTargets := make([]types.NamespacedName, 0, len(attachedGateways))
for gatewayTarget := range attachedGateways {
gatewayTargets = append(gatewayTargets, gatewayTarget)
}
infPolicies = appendPolicyForGateways(infPolicies, gatewayTargets, inferencePolicy)
infPolicies = append(infPolicies, AgwPolicy{Policy: inferencePolicy})
// Create the TLS policy for the endpoint picker
// TODO: we would want some way if they explicitly set a BackendTLSPolicy for the EPP to respect that
@ -114,7 +110,7 @@ func translatePoliciesForInferencePool(
},
},
}
infPolicies = appendPolicyForGateways(infPolicies, gatewayTargets, inferencePolicyTLS)
infPolicies = append(infPolicies, AgwPolicy{Policy: inferencePolicyTLS})
logger.Debug("generated inference pool policies",
"pool", pool.Name,
@ -136,9 +132,9 @@ func validateInferencePoolEndpointPickerRef(krtctx krt.HandlerContext, pool *inf
kind := epr.Kind
if kind == "" {
// InferencePool defaults this field to Service.
kind = wellknown.ServiceKind
kind = inf.Kind(wellknown.ServiceKind)
}
if kind != wellknown.ServiceKind {
if kind != inf.Kind(wellknown.ServiceKind) {
errs = append(errs, fmt.Sprintf("endpointPickerRef.kind must be %q, got %q", wellknown.ServiceKind, kind))
}
@ -191,10 +187,13 @@ func inferencePoolValidationError(errs []string) error {
func inferencePoolAttachedGateways(
krtctx krt.HandlerContext,
references ReferenceIndex,
ancestors krt.IndexCollection[utils.TypedNamespacedName, *utils.AncestorBackend],
pool *inf.InferencePool,
) map[types.NamespacedName]struct{} {
gateways := make(map[types.NamespacedName]struct{})
if ancestors == nil {
return gateways
}
targetRef := utils.TypedNamespacedName{
NamespacedName: types.NamespacedName{
@ -204,8 +203,11 @@ func inferencePoolAttachedGateways(
Kind: wellknown.InferencePoolKind,
}
for gateway := range references.LookupGatewaysForBackend(krtctx, targetRef) {
gateways[gateway] = struct{}{}
ancestorBackends := krt.Fetch(krtctx, ancestors, krt.FilterKey(targetRef.String()))
for _, gwl := range ancestorBackends {
for _, i := range gwl.Objects {
gateways[i.Gateway] = struct{}{}
}
}
return gateways
}
@ -254,8 +256,8 @@ func desiredInferencePoolParentRefs(attachedGateways map[types.NamespacedName]st
return []inf.ParentReference{}
}
return []inf.ParentReference{{
Kind: defaultInferencePoolStatusKind,
Name: defaultInferencePoolStatusName,
Kind: inf.Kind(defaultInferencePoolStatusKind),
Name: inf.ObjectName(defaultInferencePoolStatusName),
}}
}
@ -274,7 +276,7 @@ func desiredInferencePoolParentRefs(attachedGateways map[types.NamespacedName]st
for _, g := range gateways {
refs = append(refs, inf.ParentReference{
Group: ptr.Of(inf.Group(wellknown.GatewayGroup)),
Kind: wellknown.GatewayKind,
Kind: inf.Kind(wellknown.GatewayKind),
Namespace: inf.Namespace(g.Namespace),
Name: inf.ObjectName(g.Name),
})

View File

@ -1,64 +1,70 @@
package plugins
import (
"sort"
"context"
"istio.io/istio/pilot/pkg/util/protoconv"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/kube/controllers"
"istio.io/istio/pkg/kube/krt"
"istio.io/istio/pkg/ptr"
"k8s.io/apimachinery/pkg/types"
"github.com/agentgateway/agentgateway/api"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/ir"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/utils"
"github.com/agentgateway/agentgateway/controller/pkg/apiclient"
)
type PolicyPluginInput struct {
References ReferenceIndex
}
// AgwResourceStatusSyncHandler defines a function that handles status syncing for a specific resource type in AgentGateway
type AgwResourceStatusSyncHandler func(ctx context.Context, client apiclient.Client, namespacedName types.NamespacedName, status any) error
type BackendPlugin struct {
Build func(PolicyPluginInput) (krt.StatusCollection[controllers.Object, any], krt.Collection[ir.AgwResource])
BuildReferences func() krt.Collection[*PolicyAttachment]
type PolicyPluginInput struct {
Ancestors krt.IndexCollection[utils.TypedNamespacedName, *utils.AncestorBackend]
}
type PolicyPlugin struct {
Build func(PolicyPluginInput) (krt.StatusCollection[controllers.Object, any], krt.Collection[AgwPolicy])
BuildReferences func(input PolicyPluginInput) krt.Collection[*PolicyAttachment]
Build func(PolicyPluginInput) (krt.StatusCollection[controllers.Object, any], krt.Collection[AgwPolicy])
}
// ApplyPolicies extracts all policies from the collection
func (p *PolicyPlugin) ApplyPolicies(inputs PolicyPluginInput) (krt.Collection[AgwPolicy], krt.StatusCollection[controllers.Object, any], krt.Collection[*PolicyAttachment]) {
func (p *PolicyPlugin) ApplyPolicies(inputs PolicyPluginInput) (krt.Collection[AgwPolicy], krt.StatusCollection[controllers.Object, any]) {
status, col := p.Build(inputs)
var refs krt.Collection[*PolicyAttachment]
if p.BuildReferences != nil {
refs = p.BuildReferences(inputs)
}
return col, status, refs
return col, status
}
// AgwPolicy wraps an Agw policy for collection handling
type AgwPolicy struct {
Gateway *types.NamespacedName
Policy *api.Policy
Policy *api.Policy
// TODO: track errors per policy
}
func (p AgwPolicy) Equals(in AgwPolicy) bool {
return ptr.Equal(p.Gateway, in.Gateway) && protoconv.Equals(p.Policy, in.Policy)
return protoconv.Equals(p.Policy, in.Policy)
}
func (p AgwPolicy) ResourceName() string {
return p.Gateway.String() + "/" + p.Policy.Key
return p.Policy.Key
}
type AddResourcesPlugin struct {
Binds krt.Collection[ir.AgwResource]
Listeners krt.Collection[ir.AgwResource]
Routes krt.Collection[ir.AgwResource]
AncestorBackends krt.Collection[*utils.AncestorBackend]
Binds krt.Collection[ir.AgwResource]
Listeners krt.Collection[ir.AgwResource]
Routes krt.Collection[ir.AgwResource]
}
// AddBinds extracts all bind resources from the collection
func (p *AddResourcesPlugin) AddBinds() krt.Collection[ir.AgwResource] {
return p.Binds
}
// AddListeners extracts all routes resources from the collection
func (p *AddResourcesPlugin) AddListeners() krt.Collection[ir.AgwResource] {
return p.Listeners
}
// AddRoutes extracts all routes resources from the collection
func (p *AddResourcesPlugin) AddRoutes() krt.Collection[ir.AgwResource] {
return p.Routes
}
func ResourceName[T config.Namer](o T) *api.ResourceName {
@ -83,16 +89,3 @@ func TypedResourceFromName(typ string, o types.NamespacedName) *api.TypedResourc
Name: o.Name,
}
}
func appendPolicyForGateways(policies []AgwPolicy, gatewayTargets []types.NamespacedName, policy *api.Policy) []AgwPolicy {
sort.Slice(gatewayTargets, func(i, j int) bool {
return gatewayTargets[i].String() < gatewayTargets[j].String()
})
for _, gatewayTarget := range gatewayTargets {
policies = append(policies, AgwPolicy{
Gateway: ptr.Of(gatewayTarget),
Policy: policy,
})
}
return policies
}

View File

@ -1,326 +0,0 @@
package plugins
import (
"fmt"
"strings"
"istio.io/istio/pkg/kube/krt"
"istio.io/istio/pkg/ptr"
"istio.io/istio/pkg/util/sets"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
"github.com/agentgateway/agentgateway/api"
"github.com/agentgateway/agentgateway/controller/pkg/agentgateway/utils"
"github.com/agentgateway/agentgateway/controller/pkg/pluginsdk/krtutil"
"github.com/agentgateway/agentgateway/controller/pkg/utils/kubeutils"
"github.com/agentgateway/agentgateway/controller/pkg/wellknown"
)
type ReferenceTypes struct {
PolicyTargets func(krtctx krt.HandlerContext, namespace string, name gwv1.ObjectName, gk schema.GroupKind, sectionName *gwv1.SectionName) ([]*api.PolicyTarget, bool)
PolicyBackend func(krtctx krt.HandlerContext, defaultNamespace string, gk schema.GroupKind, name gwv1.ObjectName, namespace *gwv1.Namespace, port *gwv1.PortNumber) (*api.BackendReference, error)
RouteBackend func(krtctx krt.HandlerContext, defaultNamespace string, gk schema.GroupKind, name gwv1.ObjectName, namespace *gwv1.Namespace, port *gwv1.PortNumber) (*api.BackendReference, error)
}
type BackendReferenceErrorReason string
const (
BackendReferenceErrorReasonBackendNotFound BackendReferenceErrorReason = "BackendNotFound"
BackendReferenceErrorReasonInvalidKind BackendReferenceErrorReason = "InvalidKind"
BackendReferenceErrorReasonUnsupportedValue BackendReferenceErrorReason = "UnsupportedValue"
)
type BackendReferenceError struct {
Reason BackendReferenceErrorReason
Message string
}
func (e *BackendReferenceError) Error() string {
return e.Message
}
func DefaultReferenceTypes(agw *AgwCollections) ReferenceTypes {
return ReferenceTypes{
// AgentgatewayPolicy targets
PolicyTargets: func(krtctx krt.HandlerContext, namespace string, name gwv1.ObjectName, gk schema.GroupKind, sectionName *gwv1.SectionName) ([]*api.PolicyTarget, bool) {
key := namespace + "/" + string(name)
switch gk {
case wellknown.GatewayGVK.GroupKind():
return []*api.PolicyTarget{{
Kind: utils.GatewayTarget(namespace, string(name), sectionName),
}}, ptr.Flatten(krt.FetchOne(krtctx, agw.Gateways, krt.FilterKey(key))) != nil
case wellknown.HTTPRouteGVK.GroupKind():
return []*api.PolicyTarget{{
Kind: utils.RouteTarget(namespace, string(name), wellknown.HTTPRouteGVK.Kind, sectionName),
}}, ptr.Flatten(krt.FetchOne(krtctx, agw.HTTPRoutes, krt.FilterKey(key))) != nil
case wellknown.GRPCRouteGVK.GroupKind():
return []*api.PolicyTarget{{
Kind: utils.RouteTarget(namespace, string(name), wellknown.GRPCRouteGVK.Kind, sectionName),
}}, ptr.Flatten(krt.FetchOne(krtctx, agw.GRPCRoutes, krt.FilterKey(key))) != nil
case wellknown.AgentgatewayBackendGVK.GroupKind():
return []*api.PolicyTarget{{
Kind: utils.BackendTarget(namespace, string(name), sectionName),
}}, ptr.Flatten(krt.FetchOne(krtctx, agw.Backends, krt.FilterKey(key))) != nil
case wellknown.ServiceGVK.GroupKind():
return []*api.PolicyTarget{{
Kind: utils.ServiceTarget(namespace, string(name), sectionName),
}}, ptr.Flatten(krt.FetchOne(krtctx, agw.Services, krt.FilterKey(key))) != nil
}
return nil, false
},
// AgentgatewayPolicy targets to backends (for things like ext_authz, etc)
PolicyBackend: func(krtctx krt.HandlerContext, defaultNamespace string, gk schema.GroupKind, name gwv1.ObjectName, namespace *gwv1.Namespace, port *gwv1.PortNumber) (*api.BackendReference, error) {
ns := string(ptr.OrDefault(namespace, gwv1.Namespace(defaultNamespace)))
switch gk {
case wellknown.ServiceGVK.GroupKind():
if strings.Contains(string(name), ".") {
return nil, &BackendReferenceError{
Reason: BackendReferenceErrorReasonUnsupportedValue,
Message: "service name invalid; the name of the Service, not the hostname",
}
}
key := ns + "/" + string(name)
svc := ptr.Flatten(krt.FetchOne(krtctx, agw.Services, krt.FilterKey(key)))
if svc == nil {
return nil, &BackendReferenceError{
Reason: BackendReferenceErrorReasonBackendNotFound,
Message: fmt.Sprintf("unable to find the Service %v", key),
}
}
if port == nil {
return nil, &BackendReferenceError{
Reason: BackendReferenceErrorReasonUnsupportedValue,
Message: "port is required for Service targets",
}
}
return &api.BackendReference{
Kind: &api.BackendReference_Service_{
Service: &api.BackendReference_Service{
Hostname: kubeutils.GetServiceHostname(string(name), ns),
Namespace: ns,
},
},
Port: uint32(*port), //nolint:gosec // G115: validated 1-65535
}, nil
case wellknown.AgentgatewayBackendGVK.GroupKind():
key := ns + "/" + string(name)
be := ptr.Flatten(krt.FetchOne(krtctx, agw.Backends, krt.FilterKey(key)))
if be == nil {
return nil, &BackendReferenceError{
Reason: BackendReferenceErrorReasonBackendNotFound,
Message: fmt.Sprintf("unable to find the Backend %v", key),
}
}
return &api.BackendReference{
Kind: &api.BackendReference_Backend{
Backend: key,
},
}, nil
default:
return nil, &BackendReferenceError{
Reason: BackendReferenceErrorReasonInvalidKind,
Message: fmt.Sprintf("unsupported backend %v", gk),
}
}
},
RouteBackend: func(krtctx krt.HandlerContext, defaultNamespace string, gk schema.GroupKind, name gwv1.ObjectName, namespace *gwv1.Namespace, port *gwv1.PortNumber) (*api.BackendReference, error) {
return DefaultRouteBackend(krtctx, agw, defaultNamespace, gk, name, namespace, port)
},
}
}
func DefaultRouteBackend(krtctx krt.HandlerContext, agw *AgwCollections, defaultNamespace string, gk schema.GroupKind, name gwv1.ObjectName, namespace *gwv1.Namespace, port *gwv1.PortNumber) (*api.BackendReference, error) {
ns := string(ptr.OrDefault(namespace, gwv1.Namespace(defaultNamespace)))
// All MUST return a BackendReference. We may not be able to fully populate it, though; this will get replaced with 'invalid'
ref := &api.BackendReference{}
switch gk {
case wellknown.InferencePoolGVK.GroupKind():
if strings.Contains(string(name), ".") {
return ref, &BackendReferenceError{
Reason: BackendReferenceErrorReasonUnsupportedValue,
Message: "InferencePool name invalid; the name of the InferencePool must be used, not the hostname.",
}
}
key := ns + "/" + string(name)
svc := ptr.Flatten(krt.FetchOne(krtctx, agw.InferencePools, krt.FilterKey(key)))
if svc == nil {
return ref, &BackendReferenceError{
Reason: BackendReferenceErrorReasonBackendNotFound,
Message: fmt.Sprintf("backendRef %s not found", key),
}
}
ref.Kind = &api.BackendReference_Service_{
Service: &api.BackendReference_Service{
Hostname: kubeutils.GetInferenceServiceHostname(string(name), ns),
Namespace: ns,
},
}
ref.Port = uint32(svc.Spec.TargetPorts[0].Number) //nolint:gosec // G115: validated 1-65535
case wellknown.ServiceGVK.GroupKind():
if strings.Contains(string(name), ".") {
return ref, &BackendReferenceError{
Reason: BackendReferenceErrorReasonUnsupportedValue,
Message: "service name invalid; the name of the Service must be used, not the hostname.",
}
}
if port == nil { // Validated by CEL so shouldn't happen
return ref, &BackendReferenceError{
Reason: BackendReferenceErrorReasonUnsupportedValue,
Message: "port is required in Service backendRef",
}
}
// Populate resp now, so even if the service doesn't exist we can return a better error (Service not found vs invalid)
ref.Kind = &api.BackendReference_Service_{
Service: &api.BackendReference_Service{
Hostname: kubeutils.GetServiceHostname(string(name), ns),
Namespace: ns,
}}
ref.Port = uint32(*port) //nolint:gosec // G115: validated 1-65535
key := ns + "/" + string(name)
svc := ptr.Flatten(krt.FetchOne(krtctx, agw.Services, krt.FilterKey(key)))
if svc == nil {
return ref, &BackendReferenceError{
Reason: BackendReferenceErrorReasonBackendNotFound,
Message: fmt.Sprintf("backend(%s) not found", kubeutils.GetServiceHostname(string(name), ns)),
}
}
case wellknown.AgentgatewayBackendGVK.GroupKind():
key := ns + "/" + string(name)
ref.Kind = &api.BackendReference_Backend{Backend: key}
// Populate resp now, so even if the service doesn't exist we can return a better error (Service not found vs invalid)
be := ptr.Flatten(krt.FetchOne(krtctx, agw.Backends, krt.FilterKey(key)))
if be == nil {
return ref, &BackendReferenceError{
Reason: BackendReferenceErrorReasonBackendNotFound,
Message: fmt.Sprintf("Backend not found: %s", key),
}
}
default:
return ref, &BackendReferenceError{
Reason: BackendReferenceErrorReasonInvalidKind,
Message: fmt.Sprintf("referencing unsupported backendRef: group %q kind %q", gk.Group, gk.Kind),
}
}
return ref, nil
}
type RouteAttachment struct {
// Route
From utils.TypedNamespacedName
// Immediate parent (Gateway or ListenerSet)
To utils.TypedNamespacedName
ListenerName string
// Eventual parent (always Gateway)
Gateway types.NamespacedName
}
func (r RouteAttachment) ResourceName() string {
to := r.To.String()
if r.To.Kind != wellknown.GatewayGVK.Kind {
to += "/" + r.Gateway.String()
}
return r.From.Kind + "/" + r.From.NamespacedName.String() + "->" + to + "/" + r.ListenerName
}
func (r RouteAttachment) Equals(other RouteAttachment) bool {
return r.From == other.From && r.To == other.To && r.ListenerName == other.ListenerName && r.Gateway == other.Gateway
}
// BuildReferenceIndex builds a set of indexes that can lookup objects through various means.
// For example, lookup associated Gateways for a Backend.
func BuildReferenceIndex(
ancestors krt.IndexCollection[utils.TypedNamespacedName, *utils.AncestorBackend],
attachments krt.IndexCollection[utils.TypedNamespacedName, *RouteAttachment],
referenceTypes ReferenceTypes,
) ReferenceIndex {
return ReferenceIndex{
Ancestors: ancestors,
attachments: attachments,
explicitReferences: referenceTypes,
}
}
type PolicyAttachment struct {
Target utils.TypedNamespacedName
Backend utils.TypedNamespacedName
Source utils.TypedNamespacedName
}
func (a PolicyAttachment) Equals(other PolicyAttachment) bool {
return a.Target == other.Target && a.Backend == other.Backend && a.Source == other.Source
}
func (a PolicyAttachment) ResourceName() string {
return a.Source.String() + "/" + a.Target.String() + "/" + a.Backend.String()
}
type ReferenceIndex struct {
// Backend --> Gateway via Route
Ancestors krt.IndexCollection[utils.TypedNamespacedName, *utils.AncestorBackend]
// Backend --> Target via Policy
PolicyAttachments krt.IndexCollection[utils.TypedNamespacedName, *PolicyAttachment]
// Route --> Gateway
attachments krt.IndexCollection[utils.TypedNamespacedName, *RouteAttachment]
// Gateway --> Gateway: trivial, no collection needed
// ListenerSet --> Gateway: NOT present; ListenerSet attachment not implemented (but really should be!) in AgentgatewayPolicy anyways
explicitReferences ReferenceTypes
}
func (p ReferenceIndex) LookupGatewaysForTarget(ctx krt.HandlerContext, object utils.TypedNamespacedName) sets.Set[types.NamespacedName] {
switch object.Kind {
case wellknown.GatewayGVK.Kind:
// Trivial case
return sets.New(object.NamespacedName)
case wellknown.HTTPRouteGVK.Kind, wellknown.GRPCRouteGVK.Kind, wellknown.TCPRouteGVK.Kind, wellknown.TLSRouteGVK.Kind:
gateways := sets.New[types.NamespacedName]()
for _, ancestor := range krtutil.FetchIndexObjects(ctx, p.attachments, object) {
gateways.Insert(ancestor.Gateway)
}
return gateways
default:
gateways := sets.New[types.NamespacedName]()
for _, ancestor := range krtutil.FetchIndexObjects(ctx, p.Ancestors, object) {
gateways.Insert(ancestor.Gateway)
}
return gateways
}
}
func (p ReferenceIndex) LookupGatewaysForBackend(ctx krt.HandlerContext, object utils.TypedNamespacedName) sets.Set[types.NamespacedName] {
return p.lookupGatewaysForBackend(ctx, object, sets.New[utils.TypedNamespacedName]())
}
func (p ReferenceIndex) lookupGatewaysForBackend(ctx krt.HandlerContext, object utils.TypedNamespacedName, seen sets.Set[utils.TypedNamespacedName]) sets.Set[types.NamespacedName] {
if seen.InsertContains(object) {
return sets.New[types.NamespacedName]()
}
base := p.LookupGatewaysForTarget(ctx, object)
if p.PolicyAttachments == nil {
return base
}
for _, pref := range krtutil.FetchIndexObjects(ctx, p.PolicyAttachments, object) {
base = base.Union(p.lookupGatewaysForBackend(ctx, pref.Target, seen))
}
return base
}
func (p ReferenceIndex) WithPolicyAttachments(references krt.IndexCollection[utils.TypedNamespacedName, *PolicyAttachment]) ReferenceIndex {
p.PolicyAttachments = references
return p
}
func (p ReferenceIndex) PolicyTarget(krtctx krt.HandlerContext, namespace string, name gwv1.ObjectName, gk schema.GroupKind, sectionName *gwv1.SectionName) ([]*api.PolicyTarget, bool) {
return p.explicitReferences.PolicyTargets(krtctx, namespace, name, gk, sectionName)
}
func (p ReferenceIndex) PolicyBackend(krtctx krt.HandlerContext, defaultNamespace string, gk schema.GroupKind, name gwv1.ObjectName, namespace *gwv1.Namespace, port *gwv1.PortNumber) (*api.BackendReference, error) {
return p.explicitReferences.PolicyBackend(krtctx, defaultNamespace, gk, name, namespace, port)
}
func (p ReferenceIndex) RouteBackend(krtctx krt.HandlerContext, defaultNamespace string, gk schema.GroupKind, name gwv1.ObjectName, namespace *gwv1.Namespace, port *gwv1.PortNumber) (*api.BackendReference, error) {
return p.explicitReferences.RouteBackend(krtctx, defaultNamespace, gk, name, namespace, port)
}

View File

@ -9,18 +9,15 @@ import (
type AgwPlugin struct {
AddResourceExtension *AddResourcesPlugin
ContributesPolicies map[schema.GroupKind]PolicyPlugin
ContributesBackends map[schema.GroupKind]BackendPlugin
}
func MergePlugins(plug ...AgwPlugin) AgwPlugin {
ret := AgwPlugin{
ContributesPolicies: make(map[schema.GroupKind]PolicyPlugin),
ContributesBackends: make(map[schema.GroupKind]BackendPlugin),
}
for _, p := range plug {
// Merge contributed policies
maps.Copy(ret.ContributesPolicies, p.ContributesPolicies)
maps.Copy(ret.ContributesBackends, p.ContributesBackends)
if p.AddResourceExtension != nil {
if ret.AddResourceExtension == nil {
ret.AddResourceExtension = &AddResourcesPlugin{}
@ -34,10 +31,17 @@ func MergePlugins(plug ...AgwPlugin) AgwPlugin {
if p.AddResourceExtension.Routes != nil {
ret.AddResourceExtension.Routes = p.AddResourceExtension.Routes
}
if p.AddResourceExtension.AncestorBackends != nil {
ret.AddResourceExtension.AncestorBackends = p.AddResourceExtension.AncestorBackends
}
}
}
return ret
}
// Plugins registers all built-in policy plugins
func Plugins(agw *AgwCollections) []AgwPlugin {
return []AgwPlugin{
NewAgentPlugin(agw),
NewInferencePlugin(agw),
NewA2APlugin(agw),
NewBackendTLSPlugin(agw),
}
}

View File

@ -1,21 +0,0 @@
package plugins
import (
"testing"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func TestMergePluginsMergesBackendContributions(t *testing.T) {
backendGK := schema.GroupKind{Group: "enterpriseagentgateway.solo.io", Kind: "EnterpriseAgentgatewayBackend"}
merged := MergePlugins(AgwPlugin{
ContributesBackends: map[schema.GroupKind]BackendPlugin{
backendGK: {},
},
})
if _, ok := merged.ContributesBackends[backendGK]; !ok {
t.Fatalf("expected backend contribution %v to be preserved", backendGK)
}
}

View File

@ -1,11 +1,4 @@
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: agentgateway
spec:
controllerName: agentgateway.dev/agentgateway
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: test
@ -31,9 +24,6 @@ spec:
- backendRefs:
- name: reviews
port: 8080
- name: be
group: agentgateway.dev
kind: AgentgatewayBackend
---
apiVersion: v1
kind: Secret

View File

@ -114,109 +114,94 @@ spec:
---
# Output
output:
- gateway:
Name: test
Namespace: default
resource:
policy:
backend:
ai:
defaults:
logit_bias: '{"50256":-100}'
modelAliases:
fast: amazon.nova-micro-v1:0
smart: anthropic.claude-3-5-sonnet-20241022-v2:0
overrides:
model: '"gpt-4"'
promptCaching:
cacheMessages: true
cacheSystem: true
minTokens: 1024
promptGuard:
request:
- regex:
rules:
- regex: bad.*
- builtin: CREDIT_CARD
rejection:
body: cmVnZXggcmVqZWN0ZWQgb24gcmVxdWVzdA==
- openaiModeration:
inlinePolicies:
- backendTls:
verification: INSECURE_ALL
- bedrockGuardrails:
identifier: bedrock-guardrail-identifier
region: us-west-2
version: DRAFT
- googleModelArmor:
location: us-central1
projectId: model-armor-project-id
templateId: model-armor-template-id
- webhook:
backend:
port: 80
service:
hostname: webhook.default.svc.cluster.local
namespace: default
prompts:
append:
- content: hello!
role: user
prepend:
- content: be nice
role: system
routes:
'*': PASSTHROUGH
/v1/chat/completions: COMPLETIONS
/v1/embeddings: PASSTHROUGH
/v1/models: PASSTHROUGH
key: backend/default/agw:ai:default/test
name:
kind: AgentgatewayPolicy
name: agw
namespace: default
target:
route:
kind: HTTPRoute
name: test
namespace: default
- gateway:
Name: test
Namespace: default
resource:
policy:
key: traffic/default/agw:rbac:default/test
name:
kind: AgentgatewayPolicy
name: agw
namespace: default
target:
route:
kind: HTTPRoute
name: test
namespace: default
traffic:
authorization:
deny:
- "true"
status:
- apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: agw
namespace: default
spec: null
status:
ancestors:
- ancestorRef:
group: gateway.networking.k8s.io
kind: Gateway
- Policy:
key: traffic/default/agw:rbac:default/test
name:
kind: AgentgatewayPolicy
name: agw
namespace: default
target:
route:
kind: HTTPRoute
name: test
namespace: default
conditions:
- lastTransitionTime: fake
message: 'failed to build webhook: unable to find the Service default/ai-guardrails-webhook'
reason: PartiallyValid
status: "True"
type: Accepted
controllerName: agentgateway.dev/agentgateway
traffic:
authorization:
deny:
- "true"
- Policy:
backend:
ai:
defaults:
logit_bias: '{"50256":-100}'
modelAliases:
fast: amazon.nova-micro-v1:0
smart: anthropic.claude-3-5-sonnet-20241022-v2:0
overrides:
model: '"gpt-4"'
promptCaching:
cacheMessages: true
cacheSystem: true
minTokens: 1024
promptGuard:
request:
- regex:
rules:
- regex: bad.*
- builtin: CREDIT_CARD
rejection:
body: cmVnZXggcmVqZWN0ZWQgb24gcmVxdWVzdA==
- openaiModeration:
inlinePolicies:
- backendTls:
verification: INSECURE_ALL
- bedrockGuardrails:
identifier: bedrock-guardrail-identifier
region: us-west-2
version: DRAFT
- googleModelArmor:
location: us-central1
projectId: model-armor-project-id
templateId: model-armor-template-id
- webhook:
backend:
port: 80
service:
hostname: webhook.default.svc.cluster.local
namespace: default
prompts:
append:
- content: hello!
role: user
prepend:
- content: be nice
role: system
routes:
'*': PASSTHROUGH
/v1/chat/completions: COMPLETIONS
/v1/embeddings: PASSTHROUGH
/v1/models: PASSTHROUGH
key: backend/default/agw:ai:default/test
name:
kind: AgentgatewayPolicy
name: agw
namespace: default
target:
route:
kind: HTTPRoute
name: test
namespace: default
status:
ancestors:
- ancestorRef:
group: gateway.networking.k8s.io
kind: Gateway
name: test
namespace: default
conditions:
- lastTransitionTime: fake
message: 'failed to build webhook: unable to find the Service default/ai-guardrails-webhook'
reason: PartiallyValid
status: "True"
type: Accepted
controllerName: agentgateway.dev/agentgateway

View File

@ -27,51 +27,40 @@ data:
---
# Output
output:
- gateway:
Name: test
Namespace: default
resource:
policy:
backend:
auth:
aws:
explicitConfig:
accessKeyId: secret-accessKey
secretAccessKey: secret-secretKey
sessionToken: secret-sessionToken
key: backend/default/agw:backend-auth:default/test
name:
kind: AgentgatewayPolicy
name: agw
namespace: default
target:
route:
kind: HTTPRoute
name: test
namespace: default
status:
- apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: agw
namespace: default
spec: null
status:
ancestors:
- ancestorRef:
group: gateway.networking.k8s.io
kind: Gateway
- Policy:
backend:
auth:
aws:
explicitConfig:
accessKeyId: secret-accessKey
secretAccessKey: secret-secretKey
sessionToken: secret-sessionToken
key: backend/default/agw:backend-auth:default/test
name:
kind: AgentgatewayPolicy
name: agw
namespace: default
target:
route:
kind: HTTPRoute
name: test
namespace: default
conditions:
- lastTransitionTime: fake
message: Policy accepted
reason: Valid
status: "True"
type: Accepted
- lastTransitionTime: fake
message: Attached to all targets
reason: Attached
status: "True"
type: Attached
controllerName: agentgateway.dev/agentgateway
status:
ancestors:
- ancestorRef:
group: gateway.networking.k8s.io
kind: Gateway
name: test
namespace: default
conditions:
- lastTransitionTime: fake
message: Policy accepted
reason: Valid
status: "True"
type: Accepted
- lastTransitionTime: fake
message: Attached to all targets
reason: Attached
status: "True"
type: Attached
controllerName: agentgateway.dev/agentgateway

View File

@ -1,68 +0,0 @@
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: agw
namespace: default
spec:
targetRefs:
- kind: HTTPRoute
name: test
group: gateway.networking.k8s.io
backend:
auth:
azure:
managedIdentity:
objectId: mi-object-id
resourceId: my-resource-id
clientId: my-client-id
---
# Output
output:
- gateway:
Name: test
Namespace: default
resource:
policy:
backend:
auth:
azure:
explicitConfig:
managedIdentityCredential:
userAssignedIdentity:
clientId: my-client-id
key: backend/default/agw:backend-auth:default/test
name:
kind: AgentgatewayPolicy
name: agw
namespace: default
target:
route:
kind: HTTPRoute
name: test
namespace: default
status:
- apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: agw
namespace: default
spec: null
status:
ancestors:
- ancestorRef:
group: gateway.networking.k8s.io
kind: Gateway
name: test
namespace: default
conditions:
- lastTransitionTime: fake
message: Policy accepted
reason: Valid
status: "True"
type: Accepted
- lastTransitionTime: fake
message: Attached to all targets
reason: Attached
status: "True"
type: Attached
controllerName: agentgateway.dev/agentgateway

View File

@ -25,40 +25,29 @@ spec:
---
# Output
output:
- gateway:
Name: test
Namespace: default
resource:
policy:
- Policy:
backend:
backendTls: {}
key: default/agw:tls:default/be
name:
kind: AgentgatewayPolicy
name: agw
namespace: default
target:
backend:
backendTls: {}
key: default/agw:tls:default/be
name:
kind: AgentgatewayPolicy
name: agw
name: be
namespace: default
target:
backend:
name: be
namespace: default
status:
- apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: agw
namespace: default
spec: null
status:
ancestors:
- ancestorRef:
group: gateway.networking.k8s.io
kind: Gateway
name: test
namespace: default
conditions:
- lastTransitionTime: fake
message: secret default/mtls not found
reason: PartiallyValid
status: "True"
type: Accepted
controllerName: agentgateway.dev/agentgateway
ancestors:
- ancestorRef:
group: agentgateway.dev
kind: AgentgatewayBackend
name: be
namespace: default
conditions:
- lastTransitionTime: fake
message: secret default/mtls not found
reason: PartiallyValid
status: "True"
type: Accepted
controllerName: agentgateway.dev/agentgateway

View File

@ -1,4 +1,3 @@
# Intentionally no output. There is no backend, so nothing to attach to.
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
@ -15,29 +14,33 @@ spec:
- name: mtls
---
# Output
output: []
output:
- Policy:
backend:
backendTls: {}
key: default/agw:tls:default/missing
name:
kind: AgentgatewayPolicy
name: agw
namespace: default
target:
backend:
name: missing
namespace: default
status:
- apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: agw
namespace: default
spec: null
status:
ancestors:
- ancestorRef:
group: agentgateway.dev
name: StatusSummary
conditions:
- lastTransitionTime: fake
message: secret default/mtls not found
reason: PartiallyValid
status: "True"
type: Accepted
- lastTransitionTime: fake
message: 'Policy is not attached: AgentgatewayBackend default/missing not
found'
reason: Pending
status: "False"
type: Attached
controllerName: agentgateway.dev/agentgateway
ancestors:
- ancestorRef:
group: agentgateway.dev
name: StatusSummary
conditions:
- lastTransitionTime: fake
message: Policy accepted
reason: Valid
status: "True"
type: Accepted
- lastTransitionTime: fake
message: 'Policy is not attached: AgentgatewayBackend default/missing not found'
reason: Pending
status: "False"
type: Attached
controllerName: agentgateway.dev/agentgateway

View File

@ -1,66 +0,0 @@
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
name: be
namespace: default
spec:
static:
host: example.com
port: 80
---
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: eviction-invalid-cel
namespace: default
spec:
targetRefs:
- kind: AgentgatewayBackend
name: be
group: agentgateway.dev
backend:
health:
unhealthyCondition: foolen_{{response.code}}
---
# Output
output:
- gateway:
Name: test
Namespace: default
resource:
policy:
backend:
health:
unhealthyCondition: foolen_{{response.code}}
key: default/eviction-invalid-cel:health:default/be
name:
kind: AgentgatewayPolicy
name: eviction-invalid-cel
namespace: default
target:
backend:
name: be
namespace: default
status:
- apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: eviction-invalid-cel
namespace: default
spec: null
status:
ancestors:
- ancestorRef:
group: gateway.networking.k8s.io
kind: Gateway
name: test
namespace: default
conditions:
- lastTransitionTime: fake
message: 'backend health unhealthyCondition is not a valid CEL expression:
foolen_{{response.code}}'
reason: PartiallyValid
status: "True"
type: Accepted
controllerName: agentgateway.dev/agentgateway

View File

@ -1,76 +0,0 @@
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: agw
namespace: default
spec:
targetRefs:
- kind: AgentgatewayBackend
name: be
group: agentgateway.dev
backend:
health:
unhealthyCondition: "response.code >= 500"
eviction:
duration: 60s
restoreHealth: 100
consecutiveFailures: 3
healthThreshold: 50
---
apiVersion: v1
kind: Service
metadata:
name: webhook
namespace: default
spec:
ports:
- port: 80
---
# Output
output:
- gateway:
Name: test
Namespace: default
resource:
policy:
backend:
health:
eviction:
consecutiveFailures: 3
duration: 60s
healthThreshold: 0.5
restoreHealth: 1
unhealthyCondition: response.code >= 500
key: default/agw:health:default/be
name:
kind: AgentgatewayPolicy
name: agw
namespace: default
target:
backend:
name: be
namespace: default
status:
- apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayPolicy
metadata:
name: agw
namespace: default
spec: null
status:
ancestors:
- ancestorRef:
group: agentgateway.dev
name: StatusSummary
conditions:
- lastTransitionTime: fake
message: Policy accepted
reason: Valid
status: "True"
type: Accepted
- lastTransitionTime: fake
message: 'Policy is not attached: AgentgatewayBackend default/be not found'
reason: Pending
status: "False"
type: Attached
controllerName: agentgateway.dev/agentgateway

Some files were not shown because too many files have changed in this diff Show More