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

Parameterization a block of k8s resource (set of key values) #2272

Closed
GoshaDo opened this issue Oct 25, 2022 · 0 comments · Fixed by #2273
Closed

Parameterization a block of k8s resource (set of key values) #2272

GoshaDo opened this issue Oct 25, 2022 · 0 comments · Fixed by #2273
Labels
bug Something isn't working

Comments

@GoshaDo
Copy link
Contributor

GoshaDo commented Oct 25, 2022

Describe the bug
I am trying to parametrize an entire block of k8s trigger using payload. the payload converted to string with backslashes and can't be injected to overwrite the block. Workflows CRD getting cannot unmarshall spec: cannot restore struct from: string.

Here is an example of the sensor:

kind: Sensor
metadata:
  name: example
  namespace: argocd
spec:
  template:
    serviceAccountName: argo-wf
  dependencies:
    - name: example-dep
      eventSourceName: example-event-source
      eventName: event-test
  triggers:
    - template:
        name: example-template
        k8s:
          operation: create
          source:
            resource:
              apiVersion: argoproj.io/v1alpha1
              kind: Workflow
              metadata:
                generateName: injected-block-
              spec:
                entrypoint: main
                arguments:
                  parameters:
                    - name: message
                      value: hello world
                serviceAccountName: argo-wf  
                templates:
                  - name: main
                    container:
                      image: docker/whalesay:latest
                      command: [cowsay]
                      args:
                        - "hello world"
          parameters:
            - src:
                dependencyName: example-dep
                dataKey: body.injected
              dest: spec.templates.0.container```

After debugging the sensor I have found that in line 124 sensors/triggers/params.go get serialized json with backslashes:

func ApplyParams(jsonObj []byte, params []v1alpha1.TriggerParameter, events map[string]*v1alpha1.Event) ([]byte, error) {
...
tmp, err := sjson.SetBytes(jsonObj, param.Dest, *value)
...

*values values is:

Actual state: "{\"image\":\"docker/whalesay:latest\",\"command\":[\"cowsay\"],\"args\":[\"injected\"]}"
 Desired state: "{"image":"docker/whalesay:latest","command":["cowsay"],"args":["injected"]}"

The source of that serialization in github.com/cloudevents/sdk-go/v2 that used in eventbus/stan/sensor.(*STANTriggerConn).Subscribe.func1.

Better option would be to use this differently and use sjson.SetRawBytes function instead of sjson.SetBytes in sensors/triggers/params.go

To Reproduce
Steps to reproduce the behavior:

  1. Deploy the sensor from above.
  2. send the following json body to the event source:
{
  "injected": {
    "image": "docker/whalesay:latest",
    "command": ,
    "args": [
      "injected"
    ]
  }
}

Expected behavior
Create a workflow that marshal spec right.

Screenshots
Screen Shot 2022-10-25 at 10 37 58

Environment (please complete the following information):

  • Kubernetes: v1.24.0
  • ArgoWorkflows: v3.4.2
  • Argo Events: v1.7.3

Additional context
Add any other context about the problem here.


Message from the maintainers:

If you wish to see this enhancement implemented please add a 👍 reaction to this issue! We often sort issues this way to know what to prioritize.

@GoshaDo GoshaDo added the bug Something isn't working label Oct 25, 2022
whynowy pushed a commit that referenced this issue Nov 11, 2022
Signed-off-by: goshado <goshatoo@gmail.com>
whynowy pushed a commit that referenced this issue Dec 12, 2022
Signed-off-by: goshado <goshatoo@gmail.com>
bilalba pushed a commit to intuit-data-os/argo-events that referenced this issue Jan 9, 2023
)

Signed-off-by: goshado <goshatoo@gmail.com>
Signed-off-by: Bilal Bakht Ahmad <tringingly@gmail.com>
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
1 participant