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

Custom resource actions overrides default actions #9147

Open
3 tasks done
pokgak opened this issue Apr 20, 2022 · 3 comments
Open
3 tasks done

Custom resource actions overrides default actions #9147

pokgak opened this issue Apr 20, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@pokgak
Copy link
Contributor

pokgak commented Apr 20, 2022

Checklist:

  • I've searched in the docs and FAQ for my answer: https://bit.ly/argocd-faq.
  • I've included steps to reproduce the bug.
  • I've pasted the output of argocd version.

Describe the bug

I added a custom resource action to Deployments in my argocd-cm.yaml and then after it is applied, I lost the option to restart my deployment. I am using Argo CD version 1.21 which only has restart defined in resource_customizations/apps/Deployment/actions.

When not using the same action name as the default actions, I expect the default actions will not be overwritten, and instead the custom resource actions will be appended to the list of actions allowed on the resource. If the user wants to explicitly override the default actions, then they can use the same action name as the default.

To Reproduce

Add the following entry to data in argocd-cm.yaml:

resource.customizations.actions.apps_Deployment: |
    discovery.lua: |
      actions = {}
      -- actions defaults to disabled
      actions["scaleReplicaToZero"] = {["disabled"] = true}

      local replicas
      -- get current replica count
      if obj.spec.replicas ~= nil then
          replicas = obj.spec.replicas
      end

      if replicas != 0 then
          -- enable scaleReplicaToZero if current replica count is not 0
          actions["scaleReplicaToZero"]["disabled"] = false
      end
      return actions
    definitions:
    - name: scaleReplicaToZero
      action.lua: |
        obj.spec.replicas = 0
        return obj

Expected behavior

Both the restart action and custom resource actions will show up in the UI/CLI.

Actual behavior

Only the custom resource actions showed up in the UI/CLI. The restart action is not there and got overwritten.

Screenshots

Version

argocd: v2.3.3+07ac038.dirty
  BuildDate: 2022-03-30T05:20:22Z
  GitCommit: 07ac038a8f97a93b401e824550f0505400a8c84e
  GitTreeState: dirty
  GoVersion: go1.18
  Compiler: gc
  Platform: darwin/amd64
argocd-server: v2.1.9+5c51d5d
  BuildDate: 2022-02-03T20:30:01Z
  GitCommit: 5c51d5dae0a8c8940979db3eff5cc6be7bff9250
  GitTreeState: clean
  GoVersion: go1.16.5
  Compiler: gc
  Platform: linux/amd64
  Ksonnet Version: v0.13.1
  Kustomize Version: v4.2.0 2021-06-30T22:49:26Z
  Helm Version: v3.6.0+g7f2df64
  Kubectl Version: v0.21.0
  Jsonnet Version: v0.17.0

Logs

Paste any relevant application logs here.
@pokgak pokgak added the bug Something isn't working label Apr 20, 2022
@pokgak
Copy link
Contributor Author

pokgak commented Apr 20, 2022

Looked into the code a bit and I think the following code is probably causing this issue. As I suspected, there's no merging of the config there, it's currently either-or. Will try to make it merge the config instead. Do point out if I'm wrong.

argo-cd/util/lua/lua.go

Lines 283 to 299 in 248929c

func (vm VM) GetResourceActionDiscovery(obj *unstructured.Unstructured) (string, error) {
key := GetConfigMapKey(obj.GroupVersionKind())
override, ok := vm.ResourceOverrides[key]
if ok && override.Actions != "" {
actions, err := override.GetActions()
if err != nil {
return "", err
}
return actions.ActionDiscoveryLua, nil
}
discoveryKey := fmt.Sprintf("%s/actions/", key)
discoveryScript, err := vm.getPredefinedLuaScripts(discoveryKey, actionDiscoveryScriptFile)
if err != nil {
return "", err
}
return discoveryScript, nil
}

@pokgak
Copy link
Contributor Author

pokgak commented Apr 20, 2022

The function above only returns a string and I don't know how to combine the two values from override and the predefined actions reliably. Changing the functions to return a list of strings and combine the outputs after executing the string as Lua code is probably a better approach.

@sumanthkumarc
Copy link

Hit this bug, just when i thought how modular Argo is :p I think the possible workaround for now is just adding the upstream actions into our own argocd-cm configmap?

For example for deployment, take everything under this https://github.com/argoproj/argo-cd/tree/master/resource_customizations/apps/Deployment/actions and add this to our list of custom actions i guess.

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

No branches or pull requests

2 participants