Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

'Error generating params' error when using JSON array in Git files generator file #107

Closed
jgwest opened this issue Jan 27, 2021 · 2 comments · Fixed by #139
Closed

'Error generating params' error when using JSON array in Git files generator file #107

jgwest opened this issue Jan 27, 2021 · 2 comments · Fixed by #139
Assignees
Labels
bug Something isn't working

Comments

@jgwest
Copy link
Member

jgwest commented Jan 27, 2021

An 'error generating params' error is output when using the following ApplicationSet on the specified repo.

The following ApplicationSet will trigger the error:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: guestbook
spec:
  generators:
  - git:
      revision: HEAD
      repoURL: https://github.com/jgwest/argocd-example-apps.git
      files:
        - path: appset-examples/git-files-example/config/clusters.json   # <--- this line is the important one
  template:
    metadata:
      name: '{{cluster.name}}-guestbook'
    spec:
      project: default
      source:
        repoURL: https://github.com/jgwest/argocd-example-apps.git
        targetRevision: HEAD
        path: appset-examples/git-files-example/apps/guestbook/{{appVersions.guestbook}}
      destination:
        server: https://kubernetes.default.svc
        namespace: guestbook

This is because the cluster.json (referenced above) looks like this (source):

[
  {
    "account": "123456",
    "asset_id": "11223344",
    // ...
  },
  {
    "account": "456789",
    "asset_id": "55667788",
    // ...
  }
]

Notice that this is a JSON array (of objects), rather than a single JSON object... it appears the current Git file generator parsing code assumes that files will only be JSON objects, not JSON arrays.

Error log:

INFO[0448] Trace                                         args="[git clean -fdx]" dir="/tmp/https:__github.com_jgwest_argocd-example-apps" operation_name="exec git" time_ms=4.000146000000001
ERRO[0448] error generating params                       error="json: cannot unmarshal array into Go value of type map[string]interface {}" generator="&{0xc0003a4f00}"
2021-01-26T12:01:54.853-0500	ERROR	controller-runtime.manager.controller.applicationset	Reconciler error	{"reconciler group": "argoproj.io", "reconciler kind": "ApplicationSet", "name": "guestbook", "namespace": "argocd", "error": "json: cannot unmarshal array into Go value of type map[string]interface {}"}
@jgwest jgwest added the bug Something isn't working label Jan 27, 2021
@jgwest jgwest added this to the Milestone 1 milestone Jan 27, 2021
@OmerKahani
Copy link
Contributor

OmerKahani commented Jan 29, 2021

What should be the behavior with a JSON list? Should it iterate on the list, like the list generator?

@jgwest
Copy link
Member Author

jgwest commented Jan 29, 2021

Good question, I was thinking that generateParamsFromGitFile should first attempt to parse the JSON file as a JSON object, and then, if that fails, next try to parse it as a JSON array.

In the case of the JSON object, the code would work as it does now. In the case of the JSON array, it would instead attempt to parse each element in the array, and treat each element as a separate set of parameters (as you said, iterating through the list).

So for this...

[
  {
    "account": "123456",
    "asset_id": "11223344",
    // ...
  },
  {
    "account": "456789",
    "asset_id": "55667788",
    // ...
  }
]

... you would get 2 separate parameter maps, each to be passed separately to the template:

account: 123456
asset_id 11223344

and

account: 456789
asset_id: 55667788

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