From 66dfe00b452dd693757c5d0453911feef1046227 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Mon, 14 Mar 2022 10:30:54 +0100 Subject: [PATCH 1/2] Add custom health check for OLM subscription --- component/config.jsonnet | 40 +++++++++++++++++++ .../argocd/argocd/10_config/10_argocd-cm.yaml | 25 +++++++++++- .../argocd/argocd/10_config/10_argocd-cm.yaml | 25 +++++++++++- .../argocd/argocd/10_config/10_argocd-cm.yaml | 25 +++++++++++- 4 files changed, 112 insertions(+), 3 deletions(-) diff --git a/component/config.jsonnet b/component/config.jsonnet index 017fba93..101f360f 100644 --- a/component/config.jsonnet +++ b/component/config.jsonnet @@ -70,6 +70,46 @@ local config = [ hs.status = "Progressing" hs.message = "Waiting for provider to be installed" return hs + operators.coreos.com/Subscription: + health.lua.useOpenLibs: true + health.lua: | + -- Base check copied from upstream + health_status = {} + if obj.status ~= nil then + if obj.status.conditions ~= nil then + numDegraded = 0 + numPending = 0 + msg = "" + for i, condition in pairs(obj.status.conditions) do + msg = msg .. i .. ": " .. condition.type .. " | " .. condition.status .. "\n" + if condition.type == "InstallPlanPending" and condition.status == "True" then + numPending = numPending + 1 + elseif (condition.type == "CatalogSourcesUnhealthy" or condition.type == "InstallPlanMissing" or condition.type == "InstallPlanFailed" or condition.type == "ResolutionFailed") and condition.status == "True" then + if condition.type == "ResolutionFailed" and condition.reason == "ConstraintsNotSatisfiable" and string.find(condition.message, "cilium%-enterprise") then + msg = msg .. "; Ignoring ConstraintsNotSatisfiable for cilium-enterprise subscription" + else + numDegraded = numDegraded + 1 + end + end + end + if numDegraded == 0 and numPending == 0 then + health_status.status = "Healthy" + health_status.message = msg + return health_status + elseif numPending > 0 and numDegraded == 0 then + health_status.status = "Progressing" + health_status.message = "An install plan for a subscription is pending installation" + return health_status + else + health_status.status = "Degraded" + health_status.message = msg + return health_status + end + end + end + health_status.status = "Progressing" + health_status.message = "An install plan for a subscription is pending installation" + return health_status |||, 'application.instanceLabelKey': 'argocd.argoproj.io/instance', }, diff --git a/tests/golden/defaults/argocd/argocd/10_config/10_argocd-cm.yaml b/tests/golden/defaults/argocd/argocd/10_config/10_argocd-cm.yaml index 6019d644..151bb4ed 100644 --- a/tests/golden/defaults/argocd/argocd/10_config/10_argocd-cm.yaml +++ b/tests/golden/defaults/argocd/argocd/10_config/10_argocd-cm.yaml @@ -22,7 +22,30 @@ data: Healthy\"\n else\n hs.status = \"Degraded\"\n end\n \ \ hs.message = installed_message .. \" \" .. healthy_message\n return\ \ hs\n end\n end\n\n hs.status = \"Progressing\"\n hs.message =\ - \ \"Waiting for provider to be installed\"\n return hs\n" + \ \"Waiting for provider to be installed\"\n return hs\noperators.coreos.com/Subscription:\n\ + \ health.lua.useOpenLibs: true\n health.lua: |\n -- Base check copied from\ + \ upstream\n health_status = {}\n if obj.status ~= nil then\n if obj.status.conditions\ + \ ~= nil then\n numDegraded = 0\n numPending = 0\n msg =\ + \ \"\"\n for i, condition in pairs(obj.status.conditions) do\n \ + \ msg = msg .. i .. \": \" .. condition.type .. \" | \" .. condition.status ..\ + \ \"\\n\"\n if condition.type == \"InstallPlanPending\" and condition.status\ + \ == \"True\" then\n numPending = numPending + 1\n elseif\ + \ (condition.type == \"CatalogSourcesUnhealthy\" or condition.type == \"InstallPlanMissing\"\ + \ or condition.type == \"InstallPlanFailed\" or condition.type == \"ResolutionFailed\"\ + ) and condition.status == \"True\" then\n if condition.type == \"ResolutionFailed\"\ + \ and condition.reason == \"ConstraintsNotSatisfiable\" and string.find(condition.message,\ + \ \"cilium%-enterprise\") then\n msg = msg .. \"; Ignoring ConstraintsNotSatisfiable\ + \ for cilium-enterprise subscription\"\n else\n numDegraded\ + \ = numDegraded + 1\n end\n end\n end\n if numDegraded\ + \ == 0 and numPending == 0 then\n health_status.status = \"Healthy\"\n\ + \ health_status.message = msg\n return health_status\n \ + \ elseif numPending > 0 and numDegraded == 0 then\n health_status.status\ + \ = \"Progressing\"\n health_status.message = \"An install plan for a\ + \ subscription is pending installation\"\n return health_status\n \ + \ else\n health_status.status = \"Degraded\"\n health_status.message\ + \ = msg\n return health_status\n end\n end\n end\n \ + \ health_status.status = \"Progressing\"\n health_status.message = \"An install\ + \ plan for a subscription is pending installation\"\n return health_status\n" kind: ConfigMap metadata: annotations: {} diff --git a/tests/golden/openshift/argocd/argocd/10_config/10_argocd-cm.yaml b/tests/golden/openshift/argocd/argocd/10_config/10_argocd-cm.yaml index 6019d644..151bb4ed 100644 --- a/tests/golden/openshift/argocd/argocd/10_config/10_argocd-cm.yaml +++ b/tests/golden/openshift/argocd/argocd/10_config/10_argocd-cm.yaml @@ -22,7 +22,30 @@ data: Healthy\"\n else\n hs.status = \"Degraded\"\n end\n \ \ hs.message = installed_message .. \" \" .. healthy_message\n return\ \ hs\n end\n end\n\n hs.status = \"Progressing\"\n hs.message =\ - \ \"Waiting for provider to be installed\"\n return hs\n" + \ \"Waiting for provider to be installed\"\n return hs\noperators.coreos.com/Subscription:\n\ + \ health.lua.useOpenLibs: true\n health.lua: |\n -- Base check copied from\ + \ upstream\n health_status = {}\n if obj.status ~= nil then\n if obj.status.conditions\ + \ ~= nil then\n numDegraded = 0\n numPending = 0\n msg =\ + \ \"\"\n for i, condition in pairs(obj.status.conditions) do\n \ + \ msg = msg .. i .. \": \" .. condition.type .. \" | \" .. condition.status ..\ + \ \"\\n\"\n if condition.type == \"InstallPlanPending\" and condition.status\ + \ == \"True\" then\n numPending = numPending + 1\n elseif\ + \ (condition.type == \"CatalogSourcesUnhealthy\" or condition.type == \"InstallPlanMissing\"\ + \ or condition.type == \"InstallPlanFailed\" or condition.type == \"ResolutionFailed\"\ + ) and condition.status == \"True\" then\n if condition.type == \"ResolutionFailed\"\ + \ and condition.reason == \"ConstraintsNotSatisfiable\" and string.find(condition.message,\ + \ \"cilium%-enterprise\") then\n msg = msg .. \"; Ignoring ConstraintsNotSatisfiable\ + \ for cilium-enterprise subscription\"\n else\n numDegraded\ + \ = numDegraded + 1\n end\n end\n end\n if numDegraded\ + \ == 0 and numPending == 0 then\n health_status.status = \"Healthy\"\n\ + \ health_status.message = msg\n return health_status\n \ + \ elseif numPending > 0 and numDegraded == 0 then\n health_status.status\ + \ = \"Progressing\"\n health_status.message = \"An install plan for a\ + \ subscription is pending installation\"\n return health_status\n \ + \ else\n health_status.status = \"Degraded\"\n health_status.message\ + \ = msg\n return health_status\n end\n end\n end\n \ + \ health_status.status = \"Progressing\"\n health_status.message = \"An install\ + \ plan for a subscription is pending installation\"\n return health_status\n" kind: ConfigMap metadata: annotations: {} diff --git a/tests/golden/params/argocd/argocd/10_config/10_argocd-cm.yaml b/tests/golden/params/argocd/argocd/10_config/10_argocd-cm.yaml index 6019d644..151bb4ed 100644 --- a/tests/golden/params/argocd/argocd/10_config/10_argocd-cm.yaml +++ b/tests/golden/params/argocd/argocd/10_config/10_argocd-cm.yaml @@ -22,7 +22,30 @@ data: Healthy\"\n else\n hs.status = \"Degraded\"\n end\n \ \ hs.message = installed_message .. \" \" .. healthy_message\n return\ \ hs\n end\n end\n\n hs.status = \"Progressing\"\n hs.message =\ - \ \"Waiting for provider to be installed\"\n return hs\n" + \ \"Waiting for provider to be installed\"\n return hs\noperators.coreos.com/Subscription:\n\ + \ health.lua.useOpenLibs: true\n health.lua: |\n -- Base check copied from\ + \ upstream\n health_status = {}\n if obj.status ~= nil then\n if obj.status.conditions\ + \ ~= nil then\n numDegraded = 0\n numPending = 0\n msg =\ + \ \"\"\n for i, condition in pairs(obj.status.conditions) do\n \ + \ msg = msg .. i .. \": \" .. condition.type .. \" | \" .. condition.status ..\ + \ \"\\n\"\n if condition.type == \"InstallPlanPending\" and condition.status\ + \ == \"True\" then\n numPending = numPending + 1\n elseif\ + \ (condition.type == \"CatalogSourcesUnhealthy\" or condition.type == \"InstallPlanMissing\"\ + \ or condition.type == \"InstallPlanFailed\" or condition.type == \"ResolutionFailed\"\ + ) and condition.status == \"True\" then\n if condition.type == \"ResolutionFailed\"\ + \ and condition.reason == \"ConstraintsNotSatisfiable\" and string.find(condition.message,\ + \ \"cilium%-enterprise\") then\n msg = msg .. \"; Ignoring ConstraintsNotSatisfiable\ + \ for cilium-enterprise subscription\"\n else\n numDegraded\ + \ = numDegraded + 1\n end\n end\n end\n if numDegraded\ + \ == 0 and numPending == 0 then\n health_status.status = \"Healthy\"\n\ + \ health_status.message = msg\n return health_status\n \ + \ elseif numPending > 0 and numDegraded == 0 then\n health_status.status\ + \ = \"Progressing\"\n health_status.message = \"An install plan for a\ + \ subscription is pending installation\"\n return health_status\n \ + \ else\n health_status.status = \"Degraded\"\n health_status.message\ + \ = msg\n return health_status\n end\n end\n end\n \ + \ health_status.status = \"Progressing\"\n health_status.message = \"An install\ + \ plan for a subscription is pending installation\"\n return health_status\n" kind: ConfigMap metadata: annotations: {} From 9ac3fe457b78e8aa2c40c85537b5bb1d57394caa Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Mon, 14 Mar 2022 16:43:39 +0100 Subject: [PATCH 2/2] Add link to upstream check and comment for custom logic --- component/config.jsonnet | 3 +++ .../argocd/argocd/10_config/10_argocd-cm.yaml | 13 ++++++++----- .../argocd/argocd/10_config/10_argocd-cm.yaml | 13 ++++++++----- .../argocd/argocd/10_config/10_argocd-cm.yaml | 13 ++++++++----- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/component/config.jsonnet b/component/config.jsonnet index 101f360f..18bbdd34 100644 --- a/component/config.jsonnet +++ b/component/config.jsonnet @@ -74,6 +74,7 @@ local config = [ health.lua.useOpenLibs: true health.lua: | -- Base check copied from upstream + -- See https://github.com/argoproj/argo-cd/blob/f3730da01ef05c0b7ae97385aca6642faf9e4c52/resource_customizations/operators.coreos.com/Subscription/health.lua health_status = {} if obj.status ~= nil then if obj.status.conditions ~= nil then @@ -85,6 +86,8 @@ local config = [ if condition.type == "InstallPlanPending" and condition.status == "True" then numPending = numPending + 1 elseif (condition.type == "CatalogSourcesUnhealthy" or condition.type == "InstallPlanMissing" or condition.type == "InstallPlanFailed" or condition.type == "ResolutionFailed") and condition.status == "True" then + -- Custom check to ignore ConstraintsNotSatisfiable for + -- cilium-enterprise subscription. if condition.type == "ResolutionFailed" and condition.reason == "ConstraintsNotSatisfiable" and string.find(condition.message, "cilium%-enterprise") then msg = msg .. "; Ignoring ConstraintsNotSatisfiable for cilium-enterprise subscription" else diff --git a/tests/golden/defaults/argocd/argocd/10_config/10_argocd-cm.yaml b/tests/golden/defaults/argocd/argocd/10_config/10_argocd-cm.yaml index 151bb4ed..54b2906e 100644 --- a/tests/golden/defaults/argocd/argocd/10_config/10_argocd-cm.yaml +++ b/tests/golden/defaults/argocd/argocd/10_config/10_argocd-cm.yaml @@ -24,7 +24,8 @@ data: \ hs\n end\n end\n\n hs.status = \"Progressing\"\n hs.message =\ \ \"Waiting for provider to be installed\"\n return hs\noperators.coreos.com/Subscription:\n\ \ health.lua.useOpenLibs: true\n health.lua: |\n -- Base check copied from\ - \ upstream\n health_status = {}\n if obj.status ~= nil then\n if obj.status.conditions\ + \ upstream\n -- See https://github.com/argoproj/argo-cd/blob/f3730da01ef05c0b7ae97385aca6642faf9e4c52/resource_customizations/operators.coreos.com/Subscription/health.lua\n\ + \ health_status = {}\n if obj.status ~= nil then\n if obj.status.conditions\ \ ~= nil then\n numDegraded = 0\n numPending = 0\n msg =\ \ \"\"\n for i, condition in pairs(obj.status.conditions) do\n \ \ msg = msg .. i .. \": \" .. condition.type .. \" | \" .. condition.status ..\ @@ -32,10 +33,12 @@ data: \ == \"True\" then\n numPending = numPending + 1\n elseif\ \ (condition.type == \"CatalogSourcesUnhealthy\" or condition.type == \"InstallPlanMissing\"\ \ or condition.type == \"InstallPlanFailed\" or condition.type == \"ResolutionFailed\"\ - ) and condition.status == \"True\" then\n if condition.type == \"ResolutionFailed\"\ - \ and condition.reason == \"ConstraintsNotSatisfiable\" and string.find(condition.message,\ - \ \"cilium%-enterprise\") then\n msg = msg .. \"; Ignoring ConstraintsNotSatisfiable\ - \ for cilium-enterprise subscription\"\n else\n numDegraded\ + ) and condition.status == \"True\" then\n -- Custom check to ignore\ + \ ConstraintsNotSatisfiable for\n -- cilium-enterprise subscription.\n\ + \ if condition.type == \"ResolutionFailed\" and condition.reason ==\ + \ \"ConstraintsNotSatisfiable\" and string.find(condition.message, \"cilium%-enterprise\"\ + ) then\n msg = msg .. \"; Ignoring ConstraintsNotSatisfiable for\ + \ cilium-enterprise subscription\"\n else\n numDegraded\ \ = numDegraded + 1\n end\n end\n end\n if numDegraded\ \ == 0 and numPending == 0 then\n health_status.status = \"Healthy\"\n\ \ health_status.message = msg\n return health_status\n \ diff --git a/tests/golden/openshift/argocd/argocd/10_config/10_argocd-cm.yaml b/tests/golden/openshift/argocd/argocd/10_config/10_argocd-cm.yaml index 151bb4ed..54b2906e 100644 --- a/tests/golden/openshift/argocd/argocd/10_config/10_argocd-cm.yaml +++ b/tests/golden/openshift/argocd/argocd/10_config/10_argocd-cm.yaml @@ -24,7 +24,8 @@ data: \ hs\n end\n end\n\n hs.status = \"Progressing\"\n hs.message =\ \ \"Waiting for provider to be installed\"\n return hs\noperators.coreos.com/Subscription:\n\ \ health.lua.useOpenLibs: true\n health.lua: |\n -- Base check copied from\ - \ upstream\n health_status = {}\n if obj.status ~= nil then\n if obj.status.conditions\ + \ upstream\n -- See https://github.com/argoproj/argo-cd/blob/f3730da01ef05c0b7ae97385aca6642faf9e4c52/resource_customizations/operators.coreos.com/Subscription/health.lua\n\ + \ health_status = {}\n if obj.status ~= nil then\n if obj.status.conditions\ \ ~= nil then\n numDegraded = 0\n numPending = 0\n msg =\ \ \"\"\n for i, condition in pairs(obj.status.conditions) do\n \ \ msg = msg .. i .. \": \" .. condition.type .. \" | \" .. condition.status ..\ @@ -32,10 +33,12 @@ data: \ == \"True\" then\n numPending = numPending + 1\n elseif\ \ (condition.type == \"CatalogSourcesUnhealthy\" or condition.type == \"InstallPlanMissing\"\ \ or condition.type == \"InstallPlanFailed\" or condition.type == \"ResolutionFailed\"\ - ) and condition.status == \"True\" then\n if condition.type == \"ResolutionFailed\"\ - \ and condition.reason == \"ConstraintsNotSatisfiable\" and string.find(condition.message,\ - \ \"cilium%-enterprise\") then\n msg = msg .. \"; Ignoring ConstraintsNotSatisfiable\ - \ for cilium-enterprise subscription\"\n else\n numDegraded\ + ) and condition.status == \"True\" then\n -- Custom check to ignore\ + \ ConstraintsNotSatisfiable for\n -- cilium-enterprise subscription.\n\ + \ if condition.type == \"ResolutionFailed\" and condition.reason ==\ + \ \"ConstraintsNotSatisfiable\" and string.find(condition.message, \"cilium%-enterprise\"\ + ) then\n msg = msg .. \"; Ignoring ConstraintsNotSatisfiable for\ + \ cilium-enterprise subscription\"\n else\n numDegraded\ \ = numDegraded + 1\n end\n end\n end\n if numDegraded\ \ == 0 and numPending == 0 then\n health_status.status = \"Healthy\"\n\ \ health_status.message = msg\n return health_status\n \ diff --git a/tests/golden/params/argocd/argocd/10_config/10_argocd-cm.yaml b/tests/golden/params/argocd/argocd/10_config/10_argocd-cm.yaml index 151bb4ed..54b2906e 100644 --- a/tests/golden/params/argocd/argocd/10_config/10_argocd-cm.yaml +++ b/tests/golden/params/argocd/argocd/10_config/10_argocd-cm.yaml @@ -24,7 +24,8 @@ data: \ hs\n end\n end\n\n hs.status = \"Progressing\"\n hs.message =\ \ \"Waiting for provider to be installed\"\n return hs\noperators.coreos.com/Subscription:\n\ \ health.lua.useOpenLibs: true\n health.lua: |\n -- Base check copied from\ - \ upstream\n health_status = {}\n if obj.status ~= nil then\n if obj.status.conditions\ + \ upstream\n -- See https://github.com/argoproj/argo-cd/blob/f3730da01ef05c0b7ae97385aca6642faf9e4c52/resource_customizations/operators.coreos.com/Subscription/health.lua\n\ + \ health_status = {}\n if obj.status ~= nil then\n if obj.status.conditions\ \ ~= nil then\n numDegraded = 0\n numPending = 0\n msg =\ \ \"\"\n for i, condition in pairs(obj.status.conditions) do\n \ \ msg = msg .. i .. \": \" .. condition.type .. \" | \" .. condition.status ..\ @@ -32,10 +33,12 @@ data: \ == \"True\" then\n numPending = numPending + 1\n elseif\ \ (condition.type == \"CatalogSourcesUnhealthy\" or condition.type == \"InstallPlanMissing\"\ \ or condition.type == \"InstallPlanFailed\" or condition.type == \"ResolutionFailed\"\ - ) and condition.status == \"True\" then\n if condition.type == \"ResolutionFailed\"\ - \ and condition.reason == \"ConstraintsNotSatisfiable\" and string.find(condition.message,\ - \ \"cilium%-enterprise\") then\n msg = msg .. \"; Ignoring ConstraintsNotSatisfiable\ - \ for cilium-enterprise subscription\"\n else\n numDegraded\ + ) and condition.status == \"True\" then\n -- Custom check to ignore\ + \ ConstraintsNotSatisfiable for\n -- cilium-enterprise subscription.\n\ + \ if condition.type == \"ResolutionFailed\" and condition.reason ==\ + \ \"ConstraintsNotSatisfiable\" and string.find(condition.message, \"cilium%-enterprise\"\ + ) then\n msg = msg .. \"; Ignoring ConstraintsNotSatisfiable for\ + \ cilium-enterprise subscription\"\n else\n numDegraded\ \ = numDegraded + 1\n end\n end\n end\n if numDegraded\ \ == 0 and numPending == 0 then\n health_status.status = \"Healthy\"\n\ \ health_status.message = msg\n return health_status\n \