getporter / porter

Porter enables you to package your application artifact, client tools, configuration and deployment logic together as an installer that you can distribute, and install with a single command.
https://porter.sh
Apache License 2.0
1.23k stars 206 forks source link

exec mixin "outputs:" throws on hyphens in jsonpath that work directly (mongodb chart) #872

Closed squillace closed 3 years ago

squillace commented 4 years ago

Describe the bug

Using the exec mixin with jsonpath outputs, a jsonpath string with hyphens in it throws an error and brings action to a halt.

repro action:

testing-regex:
  - exec:
      command: kubectl
      description: "Grabbing the root db admin password..."
      arguments:
        - get
        - secret 
        - mongodb
      flags:
        namespace: default
        o: json 
      outputs:
        - name: mongo-root-pwd
          jsonPath: "$.data.mongodb-root-password"
   # kubectl get secret --namespace default mongodb -o jsonpath="{.data.mongodb-root-password}" | base64 -d

To Reproduce

Steps to reproduce the behavior:

  1. clone https://github.com/squillace/mongodb
  2. porter creds generate (for azure sp work + kubeconfig); porter install bundle
  3. wait for mongodb to get up and running
  4. porter invoke --action testing-regex -c azure-marketplace-mongodb-bitnami
  5. See error
╭─ralph at surfacebook in ~/work/nogo/squillace/marketplace/mongodb on master✘✘✘ using
╰─± porter invoke --action testing-regex -c azure-marketplace-mongodb-bitnami                                           

invoking custom action testing-regex on azure-marketplace-mongodb-bitnami...
executing testing-regex action from azure-marketplace-mongodb-bitnami (bundle instance: azure-marketplace-mongodb-bitnami)
Grabbing the root db admin password...
{
    "apiVersion": "v1",
    "data": {
        "mongodb-root-password": "WnV0SnpEM1NPQQ=="
    },
    "kind": "Secret",
    "metadata": {
        "creationTimestamp": "2020-02-01T17:57:19Z",
        "labels": {
            "app": "mongodb",
            "chart": "mongodb-7.6.2",
            "heritage": "Helm",
            "release": "mongodb"
        },
        "name": "mongodb",
        "namespace": "default",
        "resourceVersion": "8428801",
        "selfLink": "/api/v1/namespaces/default/secrets/mongodb",
        "uid": "4c063008-ed79-433b-8168-d45aebf5e59b"
    },
    "type": "Opaque"
}
Error: error evaluating jsonpath ".data.mongodb-root-password" for output "mongo-root-pwd" against {
    "apiVersion": "v1",
    "data": {
        "mongodb-root-password": "WnV0SnpEM1NPQQ=="
    },
    "kind": "Secret",
    "metadata": {
        "creationTimestamp": "2020-02-01T17:57:19Z",
        "labels": {
            "app": "mongodb",
            "chart": "mongodb-7.6.2",
            "heritage": "Helm",
            "release": "mongodb"
        },
        "name": "mongodb",
        "namespace": "default",
        "resourceVersion": "8428801",
        "selfLink": "/api/v1/namespaces/default/secrets/mongodb",
        "uid": "4c063008-ed79-433b-8168-d45aebf5e59b"
    },
    "type": "Opaque"
}
: parsing error: .data.mongodb-root-password    :1:1 - 1:2 unexpected "." while scanning extensions
Error: mixin execution failed: exit status 1
Error: 1 error occurred:
        * failed to invoke the bundle: container exit code: 1, message: <nil>

╭─ralph at surfacebook in ~/work/nogo/squillace/marketplace/mongodb on master✘✘✘ using
╰─± porter invoke --action testing-regex -c azure-marketplace-mongodb-bitnami
Building bundle ===>
Copying porter runtime ===> 
Copying mixins ===> 
Copying mixin helm3 ===> 
Copying mixin kubernetes ===> 
Copying mixin exec ===> 
Copying mixin az ===> 

Generating Dockerfile =======>

Writing Dockerfile =======>

Starting Invocation Image Build =======> 
invoking custom action testing-regex on azure-marketplace-mongodb-bitnami...
executing testing-regex action from azure-marketplace-mongodb-bitnami (bundle instance: azure-marketplace-mongodb-bitnami)
Grabbing the root db admin password...
{
    "apiVersion": "v1",
    "data": {
        "mongodb-root-password": "WnV0SnpEM1NPQQ=="
    },
    "kind": "Secret",
    "metadata": {
        "creationTimestamp": "2020-02-01T17:57:19Z",
        "labels": {
            "app": "mongodb",
            "chart": "mongodb-7.6.2",
            "heritage": "Helm",
            "release": "mongodb"
        },
        "name": "mongodb",
        "namespace": "default",
        "resourceVersion": "8428801",
        "selfLink": "/api/v1/namespaces/default/secrets/mongodb",
        "uid": "4c063008-ed79-433b-8168-d45aebf5e59b"
    },
    "type": "Opaque"
}
Error: error evaluating jsonpath "$.data.mongodb-root-password" for output "mongo-root-pwd" against {
    "apiVersion": "v1",
    "data": {
        "mongodb-root-password": "WnV0SnpEM1NPQQ=="
    },
    "kind": "Secret",
    "metadata": {
        "creationTimestamp": "2020-02-01T17:57:19Z",
        "labels": {
            "app": "mongodb",
            "chart": "mongodb-7.6.2",
            "heritage": "Helm",
            "release": "mongodb"
        },
        "name": "mongodb",
        "namespace": "default",
        "resourceVersion": "8428801",
        "selfLink": "/api/v1/namespaces/default/secrets/mongodb",
        "uid": "4c063008-ed79-433b-8168-d45aebf5e59b"
    },
    "type": "Opaque"
}
: parsing error: $.data.mongodb-root-password   :1:15 - 1:16 unexpected "-" while scanning operator
Error: mixin execution failed: exit status 1
Error: 1 error occurred:
        * failed to invoke the bundle: container exit code: 1, message: <nil>

Expected behavior

Porter should stash the mongodb pwd output in the value and it should be stored in the claim

Version

porter v0.22.2-beta.1 (4401e74)

vdice commented 4 years ago

@squillace it appears the error might be coming from jsonpath failing to parse the operator string (.data.mongodb-root-password and $.data.mongodb-root-password seen above).

I wonder if either wrapping the string in single quotes and perhaps including the {} might help? So, '.data.mongodb-root-password' or '{.data.mongodb-root-password}'.

carolynvs commented 3 years ago

Sounds like this is a jsonpath syntax error. Closing for now but let me know if we think a change to porter or its docs is necessary.