argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
17.83k stars 5.44k forks source link

kiali custom health check broken if using older version #11206

Open snuggie12 opened 2 years ago

snuggie12 commented 2 years ago

Checklist:

Describe the bug In https://github.com/argoproj/argo-cd/pull/10995 kiali's health check was updated to handle v1.57.1. I'm going to assume it's fine, but if you are using an earlier version then you are stuck continuously progressing.

I'll paste a most likely working version below. I say most likely because I obviously don't have the newer version of kiali and I use openlibs to perform the regex.

It compares the minor version of kiali and then follows the current health check if v1.57.X and above or follow the old one if below. Happy to make a PR but saw the contribution guide says to file an issue first so doing that.

To Reproduce Use kiali version lower than v1.57.1 (at the very least I'm on v1.37.0) and argocd v2.5.1+504da42. App should be stuck in progressing due to .status.conditions[0].reason being Successful where as the new health check is .status.conditions[0].type being Successful.

Expected behavior Health check works with both version ranges of kiali operator.

Screenshots

Version

argocd-server: v2.5.1+504da42
  BuildDate: 2022-11-01T21:14:30Z
  GitCommit: 504da424c2c9bb91d7fb2ebf3ae72162e7a5a5be
  GitTreeState: clean
  GoVersion: go1.18.8
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v3.9.3 2021-02-07T17:02:13Z
  Helm Version: v3.10.1+g9f88ccb
  Kubectl Version: v0.24.2
  Jsonnet Version: v0.18.0

Candidate Working Health Check

    kiali.io/Kiali:
      health.lua.useOpenLibs: true
      health.lua: |-
        hs = {}
        if obj.status ~= nil then
          if obj.status.environment ~= nil then
            if obj.status.environment.operatorVersion ~= nil then
              version = obj.status.environment.operatorVersion
              _, _, major, minor, patch = version:find("v(%d+)%.(%d+)%.(%d+)")
              if obj.status.conditions ~= nil then
                for i, condition in ipairs(obj.status.conditions) do
                  hs.message = condition.message
                  minor = tonumber(minor)
                  if minor > 56 then
                    if condition.type == "Successful" and condition.status == "True" then
                      hs.status = "Healthy"
                      return hs
                    end
                    if condition.type == "Failure" and condition.status == "True" then
                      hs.status = "Degraded"
                      return hs
                    end
                    if condition.type == "Running" and condition.reason == "Running" then
                      hs.status = "Progressing"
                      return hs
                    end
                  else
                    if condition.reason == "Successful" then
                      hs.status = "Healthy"
                      return hs
                    elseif condition.reason == "Running" then
                      hs.status = "Progressing"
                      return hs
                    else
                      hs.status = "Degraded"
                      return hs
                    end
                  end
                end
              end
            end
          end
        end
        hs.status = "Progressing"
        hs.message = "Waiting for Kiali"
        return hs
s7an-it commented 1 year ago

@snuggie12, I confirm this fix it for 1.54.0 operator installed with helm under the cm key:

    resource.customizations: |
      kiali.io/Kiali:
        health.lua.useOpenLibs: true
        health.lua: |-
          hs = {}
          if obj.status ~= nil then
            if obj.status.environment ~= nil then
              if obj.status.environment.operatorVersion ~= nil then
                version = obj.status.environment.operatorVersion
                _, _, major, minor, patch = version:find("v(%d+)%.(%d+)%.(%d+)")
                if obj.status.conditions ~= nil then
                  for i, condition in ipairs(obj.status.conditions) do
                    hs.message = condition.message
                    minor = tonumber(minor)
                    if minor > 56 then
                      if condition.type == "Successful" and condition.status == "True" then
                        hs.status = "Healthy"
                        return hs
                      end
                      if condition.type == "Failure" and condition.status == "True" then
                        hs.status = "Degraded"
                        return hs
                      end
                      if condition.type == "Running" and condition.reason == "Running" then
                        hs.status = "Progressing"
                        return hs
                      end
                    else
                      if condition.reason == "Successful" then
                        hs.status = "Healthy"
                        return hs
                      elseif condition.reason == "Running" then
                        hs.status = "Progressing"
                        return hs
                      else
                        hs.status = "Degraded"
                        return hs
                      end
                    end
                  end
                end
              end
            end
snuggie12 commented 1 year ago

We use kustomize to install argocd, but I think we're also wrapping up our istio 1.16 upgrade which means we should be above the kiali version.

I think the correct course is just to check it into the built-in health checks in this repo. At the time I think I was having some issue being able to contribute to this repo. Maybe you can make a PR?