diff --git a/resource_customizations/projectcontour.io/ExtensionService/health.lua b/resource_customizations/projectcontour.io/ExtensionService/health.lua new file mode 100644 index 0000000000..1a2b105a1b --- /dev/null +++ b/resource_customizations/projectcontour.io/ExtensionService/health.lua @@ -0,0 +1,27 @@ +-- Status reporting information detailed here +-- ExtensionService status conditions api information here: https://projectcontour.io/docs/v1.18.0/config/api/#projectcontour.io/v1alpha1.ExtensionServiceStatus + +hs = { + status = "Progressing", + message = "Waiting for status", +} + +if obj.status then + if obj.status.conditions then + for _, cond in ipairs(obj.status.conditions) do + if obj.metadata.generation == cond.observedGeneration then -- This must match so that we don't report a resource as healthy even though its status is stale + if cond.type == "Valid" and cond.status == "True" then -- Contour will update a single condition, Valid, that is in normal-true polarity. + hs.status = "Healthy" + hs.message = cond.message + return hs + elseif cond.type == "Valid" and cond.status == "False" then + hs.status = "Degraded" + hs.message = cond.message + return hs + end + end + end + end +end + +return hs \ No newline at end of file diff --git a/resource_customizations/projectcontour.io/ExtensionService/health_test.yaml b/resource_customizations/projectcontour.io/ExtensionService/health_test.yaml new file mode 100644 index 0000000000..c0827f0ca5 --- /dev/null +++ b/resource_customizations/projectcontour.io/ExtensionService/health_test.yaml @@ -0,0 +1,17 @@ +tests: +- healthStatus: + status: Healthy + message: "Valid ExtensionService" + inputPath: testdata/healthy.yaml +- healthStatus: + status: Progressing + message: 'Waiting for status' + inputPath: testdata/progressing.yaml +- healthStatus: + status: Degraded + message: 'At least one error present, see Errors for details' + inputPath: testdata/degraded.yaml +- healthStatus: + status: Progressing + message: 'Waiting for status' + inputPath: testdata/generation.yaml \ No newline at end of file diff --git a/resource_customizations/projectcontour.io/ExtensionService/testdata/degraded.yaml b/resource_customizations/projectcontour.io/ExtensionService/testdata/degraded.yaml new file mode 100644 index 0000000000..5c920df012 --- /dev/null +++ b/resource_customizations/projectcontour.io/ExtensionService/testdata/degraded.yaml @@ -0,0 +1,30 @@ +apiVersion: projectcontour.io/v1alpha1 +kind: ExtensionService +metadata: + generation: 1 + name: example +spec: + circuitBreakerPolicy: + maxConnections: 102400 + maxPendingRequests: 1024000 + maxRequests: 102400 + maxRetries: 102400 + protocol: h2c + services: + - name: doesnt-exist + port: 9091 + timeoutPolicy: + response: 1s +status: + conditions: + - errors: + - message: 'Spec.Routes unresolved service reference: service "doesnt-exist" not found' + reason: ServiceUnresolvedReference + status: "True" + type: ServiceError + lastTransitionTime: '2024-08-08T16:53:29Z' + message: At least one error present, see Errors for details + observedGeneration: 1 + reason: ErrorPresent + status: 'False' + type: Valid \ No newline at end of file diff --git a/resource_customizations/projectcontour.io/ExtensionService/testdata/generation.yaml b/resource_customizations/projectcontour.io/ExtensionService/testdata/generation.yaml new file mode 100644 index 0000000000..7d7a983d79 --- /dev/null +++ b/resource_customizations/projectcontour.io/ExtensionService/testdata/generation.yaml @@ -0,0 +1,25 @@ +apiVersion: projectcontour.io/v1alpha1 +kind: ExtensionService +metadata: + generation: 2 + name: example +spec: + circuitBreakerPolicy: + maxConnections: 102400 + maxPendingRequests: 1024000 + maxRequests: 102400 + maxRetries: 102400 + protocol: h2c + services: + - name: grpc-server + port: 9091 + timeoutPolicy: + response: 1s +status: + conditions: + - lastTransitionTime: '2024-08-08T16:53:29Z' + message: Valid ExtensionService + observedGeneration: 1 + reason: Valid + status: 'True' + type: Valid \ No newline at end of file diff --git a/resource_customizations/projectcontour.io/ExtensionService/testdata/healthy.yaml b/resource_customizations/projectcontour.io/ExtensionService/testdata/healthy.yaml new file mode 100644 index 0000000000..b76792a516 --- /dev/null +++ b/resource_customizations/projectcontour.io/ExtensionService/testdata/healthy.yaml @@ -0,0 +1,25 @@ +apiVersion: projectcontour.io/v1alpha1 +kind: ExtensionService +metadata: + generation: 1 + name: example +spec: + circuitBreakerPolicy: + maxConnections: 102400 + maxPendingRequests: 1024000 + maxRequests: 102400 + maxRetries: 102400 + protocol: h2c + services: + - name: grpc-server + port: 9091 + timeoutPolicy: + response: 1s +status: + conditions: + - lastTransitionTime: '2024-08-08T16:53:29Z' + message: Valid ExtensionService + observedGeneration: 1 + reason: Valid + status: 'True' + type: Valid \ No newline at end of file diff --git a/resource_customizations/projectcontour.io/ExtensionService/testdata/progressing.yaml b/resource_customizations/projectcontour.io/ExtensionService/testdata/progressing.yaml new file mode 100644 index 0000000000..c2c68b382e --- /dev/null +++ b/resource_customizations/projectcontour.io/ExtensionService/testdata/progressing.yaml @@ -0,0 +1,17 @@ +apiVersion: projectcontour.io/v1alpha1 +kind: ExtensionService +metadata: + generation: 1 + name: example +spec: + circuitBreakerPolicy: + maxConnections: 102400 + maxPendingRequests: 1024000 + maxRequests: 102400 + maxRetries: 102400 + protocol: h2c + services: + - name: grpc-server + port: 9091 + timeoutPolicy: + response: 1s \ No newline at end of file