Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Health Lua script cannot return nil status object #18604

Closed
agaudreault opened this issue Jun 11, 2024 · 1 comment · Fixed by #18700
Closed

Health Lua script cannot return nil status object #18604

agaudreault opened this issue Jun 11, 2024 · 1 comment · Fixed by #18700
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@agaudreault
Copy link
Member

Describe the bug

The goal is to only set the health on a resource when some conditions are, and not set any health on the object if the Lua script does not report any status.

  resource.customizations.health.Secret: |
    hs = {}

    if obj.metadata.annotations ~= nil and obj.metadata.annotations["my-annotation"] ~= nil and obj.metadata.annotations["my-annotation"] == "foo" then
      hs.status = "Healthy"
      hs.message = ""
      return hs
    end

    if obj.metadata.annotations ~= nil and obj.metadata.annotations["my-annotation"] ~= nil and obj.metadata.annotations["my-annotation"] == "bar" then
      hs.status = "Healthy"
      hs.message = ""
      return hs
    end

    if obj.metadata.annotations ~= nil and obj.metadata.annotations["my-annotation"] ~= nil then
      hs.status = "Degraded"
      hs.message = "this is an example"
      return hs
    end

    -- Here we want to return nil or empty object so that the health is not set
    return hs

When a health check on a resource is returning empty or nil from a Lua script, Argo is not able to ignore the Health of that resource.

To Reproduce

Setting the following script in argo-cm

  resource.customizations.health.Secret: |
    hs = {} 
    return hs

then it will return json: cannot unmarshal array into Go value of type health.HealthStatus

If we set it instead to the following

  resource.customizations.health.Secret: |
    hs = {} 
    return nil

then it will return expect table output from Lua script, not nil

If we set it instead to the following

  resource.customizations.health.Secret: |
	-- A script that does not return anything

then it will return expect table output from Lua script, not nil

Expected behavior

hs = {} should be unmarshaled correctly and not set (and remove) any health status in ArgoCD
return nil should be valid and not set (and remove) any health status in ArgoCD
return should be valid and not set (and remove) any health status in ArgoCD

Screenshots

image

Version

2.11.2

Workaround

We can set the health status to healthy

  resource.customizations.health.Secret: |
    hs = {} 
    hs.status = "Healthy"
    return nil
@agaudreault agaudreault added bug Something isn't working good first issue Good for newcomers labels Jun 11, 2024
@Yuni-sa
Copy link
Contributor

Yuni-sa commented Jun 17, 2024

hi, I have created a PR trying to fix this issue without using the workaround, not sure if this is the direction @agaudreault intended.
I would love if someone could check it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants