Skip to content

feat: add ArgoCD health checks for gateway.kgateway.dev resources#13902

Open
Junnygram wants to merge 1 commit intokgateway-dev:mainfrom
Junnygram:feature/argocd-health-checks
Open

feat: add ArgoCD health checks for gateway.kgateway.dev resources#13902
Junnygram wants to merge 1 commit intokgateway-dev:mainfrom
Junnygram:feature/argocd-health-checks

Conversation

@Junnygram
Copy link
Copy Markdown
Contributor

@Junnygram Junnygram commented Apr 22, 2026

Description

This PR adds ArgoCD health check customizations for all gateway.kgateway.dev resources, as requested in issue #13871.

Status Patterns Implemented:

  • Pattern 1 (Standard conditions): Backend, GatewayExtension (Healthy when Accepted is True).
    • Pattern 2 (Policy Attachment): TrafficPolicy, ListenerPolicy, BackendConfigPolicy, HTTPListenerPolicy (Healthy when accepted by all ancestors; now requires at least one ancestor to be Healthy).
    • Pattern 3 (No Status / Default Healthy): DirectResponse, GatewayParameters (Default to Healthy).
      Contributes health check definitions to hack/argocd/ which can be shared with the ArgoCD community.

Change Type

/kind feature

Changelog

Add ArgoCD health check Lua scripts for gateway.kgateway.dev resources.

Copilot AI review requested due to automatic review settings April 22, 2026 11:40
@gateway-bot gateway-bot added kind/feature Categorizes issue or PR as related to a new feature. release-note labels Apr 22, 2026
@Junnygram Junnygram force-pushed the feature/argocd-health-checks branch from 0cbaaad to 7993c47 Compare April 22, 2026 11:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds ArgoCD health-check Lua scripts for gateway.kgateway.dev CRDs so ArgoCD can display meaningful health for kgateway custom resources (covering condition-based, policy-attachment, and no-status patterns).

Changes:

  • Introduces ArgoCD health.lua scripts for eight gateway.kgateway.dev kinds under hack/argocd/resource_customizations/.
  • Implements policy-attachment health evaluation via status.ancestors[].conditions for policy resources.
  • Adds hack/argocd/README.md documenting the patterns and how to install the customizations.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
hack/argocd/resource_customizations/gateway.kgateway.dev/TrafficPolicy/health.lua Policy-attachment health check based on ancestor acceptance conditions
hack/argocd/resource_customizations/gateway.kgateway.dev/ListenerPolicy/health.lua Policy-attachment health check based on ancestor acceptance conditions
hack/argocd/resource_customizations/gateway.kgateway.dev/HTTPListenerPolicy/health.lua Policy-attachment health check based on ancestor acceptance conditions
hack/argocd/resource_customizations/gateway.kgateway.dev/BackendConfigPolicy/health.lua Policy-attachment health check based on ancestor acceptance conditions
hack/argocd/resource_customizations/gateway.kgateway.dev/Backend/health.lua Condition-based health check using status.conditions[] Accepted
hack/argocd/resource_customizations/gateway.kgateway.dev/GatewayExtension/health.lua Condition-based health check using status.conditions[] Accepted
hack/argocd/resource_customizations/gateway.kgateway.dev/GatewayParameters/health.lua Condition-based health check using status.conditions[] Accepted
hack/argocd/resource_customizations/gateway.kgateway.dev/DirectResponse/health.lua No-status resource defaults to Healthy
hack/argocd/README.md Documents health-check patterns and installation approach

Comment on lines +3 to +7
local all_accepted = true
local any_rejected = false
local message = ""
for i, ancestor in ipairs(obj.status.ancestors) do
local accepted = false
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

all_accepted defaults to true, so an explicitly empty status.ancestors array will result in a Healthy status. The TrafficPolicy/PolicyStatus schema documents empty ancestors as “policy is not relevant for any ancestors”, so it should likely remain Progressing (or another non-Healthy status) until at least one ancestor reports Accepted=True. Add a non-empty ancestors guard before returning Healthy.

Copilot uses AI. Check for mistakes.
Comment on lines +2 to +15
if obj.status ~= nil and obj.status.conditions ~= nil then
for i, condition in ipairs(obj.status.conditions) do
if condition.type == "Accepted" then
if condition.status == "True" then
hs.status = "Healthy"
hs.message = condition.message
return hs
end
if condition.status == "False" then
hs.status = "Degraded"
hs.message = condition.message
return hs
end
end
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

The GatewayParameters CRD schema in this repo does not define status.conditions (it declares status as a generic object and notes status is not implemented). With this health check, GatewayParameters will therefore stay Progressing indefinitely in ArgoCD. Consider falling back to Healthy when status.conditions is missing (similar to DirectResponse), or update the health check to align with whatever status fields GatewayParameters actually exposes.

Suggested change
if obj.status ~= nil and obj.status.conditions ~= nil then
for i, condition in ipairs(obj.status.conditions) do
if condition.type == "Accepted" then
if condition.status == "True" then
hs.status = "Healthy"
hs.message = condition.message
return hs
end
if condition.status == "False" then
hs.status = "Degraded"
hs.message = condition.message
return hs
end
end
if obj.status == nil or obj.status.conditions == nil then
hs.status = "Healthy"
return hs
end
for i, condition in ipairs(obj.status.conditions) do
if condition.type == "Accepted" then
if condition.status == "True" then
hs.status = "Healthy"
hs.message = condition.message
return hs
end
if condition.status == "False" then
hs.status = "Degraded"
hs.message = condition.message
return hs
end

Copilot uses AI. Check for mistakes.
Comment thread hack/argocd/README.md Outdated
Comment on lines +7 to +13
### Pattern 1: Standard Kubernetes Conditions
Used by: `Backend`, `GatewayParameters`
Checks the `status.conditions[]` field for an `Accepted` condition.

### Pattern 2: Gateway API Policy Attachment
Used by: `TrafficPolicy`, `ListenerPolicy`, `BackendConfigPolicy`, `HTTPListenerPolicy`
Checks the `status.ancestors[].conditions[]` field. The resource is considered healthy only if all ancestors have accepted the policy.
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

The “Pattern 1” section says it’s used by Backend, GatewayParameters, but this PR also adds a Pattern-1-style health check for GatewayExtension. Also, GatewayParameters’ CRD schema in this repo does not define status.conditions, so listing it here may be misleading. Please update the pattern/resource list to match the scripts and actual status shapes.

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +7
local all_accepted = true
local any_rejected = false
local message = ""
for i, ancestor in ipairs(obj.status.ancestors) do
local accepted = false
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

In this logic, all_accepted starts as true, so if obj.status.ancestors is an empty list the loop never runs and the script will report Healthy even though the CRD defines an empty ancestors list as “policy is not relevant for any ancestors”. Consider requiring at least one ancestor (e.g., track has_ancestors / check #obj.status.ancestors > 0) before returning Healthy.

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +7
local all_accepted = true
local any_rejected = false
local message = ""
for i, ancestor in ipairs(obj.status.ancestors) do
local accepted = false
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

As written, all_accepted remains true when obj.status.ancestors is an empty array, causing the script to return Healthy. The TrafficPolicy CRD docs state an empty ancestors list means the policy is not relevant for any ancestors, so health should not be Healthy in that case. Add a guard so Healthy is only returned when there is at least one ancestor and all are accepted.

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +7
local all_accepted = true
local any_rejected = false
local message = ""
for i, ancestor in ipairs(obj.status.ancestors) do
local accepted = false
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

This script can return Healthy when obj.status.ancestors exists but is empty because all_accepted is initialized to true and the loop never runs. Given the PolicyStatus contract (empty ancestors => not relevant/attached), consider treating empty ancestors as Progressing and only returning Healthy when there is at least one ancestor and all have Accepted=True.

Copilot uses AI. Check for mistakes.
Signed-off-by: Junnygram <junnexclusive@gmail.com>
@Junnygram Junnygram force-pushed the feature/argocd-health-checks branch from 7993c47 to e51ca9c Compare April 22, 2026 12:15
@Junnygram
Copy link
Copy Markdown
Contributor Author

Addressed feedback from Copilot AI:

  • Policies (TrafficPolicy, etc.) now require at least one ancestor before returning Healthy (avoids false Healthy on empty ancestors).
    • GatewayParameters now defaults to Healthy (as it lacks status conditions in the current spec).
    • Updated README and PR description to reflect the resource groupings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants