Resource Actions

Overview

Argo CD allows operators to define custom actions which users can perform on specific resource types. This is used internally to provide actions like restart for a DaemonSet, or retry for an Argo Rollout.

Operators can add actions to custom resources in form of a Lua script and expand those capabilities.

Custom Resource Actions

Argo CD supports custom resource actions written in Lua. This is useful if you:

  • Have a custom resource for which Argo CD does not provide any built-in actions.
  • Have a commonly performed manual task that might be error prone if executed by users via kubectl

You can define your own custom resource actions in the argocd-cm ConfigMap.

Define a Custom Resource Action in argocd-cm ConfigMap

Custom resource actions can be defined in resource.customizations.actions.<group_kind> field of argocd-cm. Following example demonstrates a set of custom actions for CronJob resources. The customizations key is in the format of resource.customizations.actions.<apiGroup_Kind>.

  1. resource.customizations.actions.batch_CronJob: |
  2. discovery.lua: |
  3. actions = {}
  4. actions["suspend"] = {["disabled"] = true}
  5. actions["resume"] = {["disabled"] = true}
  6. local suspend = false
  7. if obj.spec.suspend ~= nil then
  8. suspend = obj.spec.suspend
  9. end
  10. if suspend then
  11. actions["resume"]["disabled"] = false
  12. else
  13. actions["suspend"]["disabled"] = false
  14. end
  15. return actions
  16. definitions:
  17. - name: suspend
  18. action.lua: |
  19. obj.spec.suspend = true
  20. return obj
  21. - name: resume
  22. action.lua: |
  23. if obj.spec.suspend ~= nil and obj.spec.suspend then
  24. obj.spec.suspend = false
  25. end
  26. return obj

The discovery.lua script must return a table where the key name represents the action name. You can optionally include logic to enable or disable certain actions based on the current object state.

Each action name must be represented in the list of definitions with an accompanying action.lua script to control the resource modifications. The obj is a global variable which contains the resource. Each action script must return an optionally modified version of the resource. In this example, we are simply setting .spec.suspend to either true or false.