Skip to content

Commit

Permalink
Merge pull request #66 from projectsyn/feat/ignore-degraded-cilium-en…
Browse files Browse the repository at this point in the history
…terprise-subscription

Add custom health check for OLM subscriptions
  • Loading branch information
simu authored Mar 14, 2022
2 parents 21b61df + 9ac3fe4 commit d0ec483
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 3 deletions.
43 changes: 43 additions & 0 deletions component/config.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,49 @@ 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
-- 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
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
-- 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
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',
},
Expand Down
28 changes: 27 additions & 1 deletion tests/golden/defaults/argocd/argocd/10_config/10_argocd-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,33 @@ 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 -- 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 ..\
\ \"\\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 -- 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 \
\ 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: {}
Expand Down
28 changes: 27 additions & 1 deletion tests/golden/openshift/argocd/argocd/10_config/10_argocd-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,33 @@ 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 -- 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 ..\
\ \"\\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 -- 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 \
\ 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: {}
Expand Down
28 changes: 27 additions & 1 deletion tests/golden/params/argocd/argocd/10_config/10_argocd-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,33 @@ 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 -- 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 ..\
\ \"\\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 -- 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 \
\ 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: {}
Expand Down

0 comments on commit d0ec483

Please sign in to comment.