diff --git a/resource_customizations/_.cnrm.cloud.google.com/_/health.lua b/resource_customizations/_.cnrm.cloud.google.com/_/health.lua index cf5cf2ba23..0e89eea981 100644 --- a/resource_customizations/_.cnrm.cloud.google.com/_/health.lua +++ b/resource_customizations/_.cnrm.cloud.google.com/_/health.lua @@ -3,6 +3,22 @@ local hs = { message = "Update in progress" } if obj.status ~= nil then + -- ConfigConnector and ConfigConnectorContext use status.healthy instead of conditions + if (obj.kind == "ConfigConnector" or obj.kind == "ConfigConnectorContext") and obj.status.healthy ~= nil then + -- Check if status is stale + if obj.status.observedGeneration == nil or obj.status.observedGeneration == obj.metadata.generation then + if obj.status.healthy == true then + hs.status = "Healthy" + hs.message = obj.kind .. " is healthy" + return hs + else + hs.status = "Degraded" + hs.message = obj.kind .. " is not healthy" + return hs + end + end + end + if obj.status.conditions ~= nil then -- Progressing health while the resource status is stale, skip if observedGeneration is not set diff --git a/resource_customizations/_.cnrm.cloud.google.com/_/health_test.yaml b/resource_customizations/_.cnrm.cloud.google.com/_/health_test.yaml index 982aae23f0..a63e6bdbed 100644 --- a/resource_customizations/_.cnrm.cloud.google.com/_/health_test.yaml +++ b/resource_customizations/_.cnrm.cloud.google.com/_/health_test.yaml @@ -22,4 +22,24 @@ tests: - healthStatus: status: Progressing message: 'Update in progress' - inputPath: testdata/generation.yaml \ No newline at end of file + inputPath: testdata/generation.yaml +- healthStatus: + status: Healthy + message: "ConfigConnectorContext is healthy" + inputPath: testdata/config-connector-context.yaml +- healthStatus: + status: Degraded + message: "ConfigConnectorContext is not healthy" + inputPath: testdata/config-connector-context-unhealthy.yaml +- healthStatus: + status: Healthy + message: "ConfigConnector is healthy" + inputPath: testdata/config-connector-healthy.yaml +- healthStatus: + status: Degraded + message: "ConfigConnector is not healthy" + inputPath: testdata/config-connector-unhealthy.yaml +- healthStatus: + status: Progressing + message: "Update in progress" + inputPath: testdata/config-connector-stale.yaml diff --git a/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-context-unhealthy.yaml b/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-context-unhealthy.yaml new file mode 100644 index 0000000000..92b8929f7e --- /dev/null +++ b/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-context-unhealthy.yaml @@ -0,0 +1,11 @@ +apiVersion: core.cnrm.cloud.google.com/v1beta1 +kind: ConfigConnectorContext +metadata: + generation: 1 + name: configconnectorcontext.core.cnrm.cloud.google.com + namespace: foo +spec: + googleServiceAccount: foo@bar.iam.gserviceaccount.com +status: + healthy: false + observedGeneration: 1 diff --git a/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-context.yaml b/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-context.yaml new file mode 100644 index 0000000000..6e63298a9c --- /dev/null +++ b/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-context.yaml @@ -0,0 +1,11 @@ +apiVersion: core.cnrm.cloud.google.com/v1beta1 +kind: ConfigConnectorContext +metadata: + generation: 1 + name: configconnectorcontext.core.cnrm.cloud.google.com + namespace: foo +spec: + googleServiceAccount: foo@bar.iam.gserviceaccount.com +status: + healthy: true + observedGeneration: 1 diff --git a/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-healthy.yaml b/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-healthy.yaml new file mode 100644 index 0000000000..5095fac9dd --- /dev/null +++ b/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-healthy.yaml @@ -0,0 +1,12 @@ +apiVersion: core.cnrm.cloud.google.com/v1beta1 +kind: ConfigConnector +metadata: + finalizers: + - configconnector.cnrm.cloud.google.com/finalizer + generation: 2 + name: configconnector.core.cnrm.cloud.google.com +spec: + mode: namespaced +status: + healthy: true + observedGeneration: 2 diff --git a/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-stale.yaml b/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-stale.yaml new file mode 100644 index 0000000000..0b7ba3cd5a --- /dev/null +++ b/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-stale.yaml @@ -0,0 +1,12 @@ +apiVersion: core.cnrm.cloud.google.com/v1beta1 +kind: ConfigConnector +metadata: + finalizers: + - configconnector.cnrm.cloud.google.com/finalizer + generation: 3 + name: configconnector.core.cnrm.cloud.google.com +spec: + mode: namespaced +status: + healthy: true + observedGeneration: 2 diff --git a/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-unhealthy.yaml b/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-unhealthy.yaml new file mode 100644 index 0000000000..33eb5d8553 --- /dev/null +++ b/resource_customizations/_.cnrm.cloud.google.com/_/testdata/config-connector-unhealthy.yaml @@ -0,0 +1,12 @@ +apiVersion: core.cnrm.cloud.google.com/v1beta1 +kind: ConfigConnector +metadata: + finalizers: + - configconnector.cnrm.cloud.google.com/finalizer + generation: 2 + name: configconnector.core.cnrm.cloud.google.com +spec: + mode: namespaced +status: + healthy: false + observedGeneration: 2