atlassian / smith

Smith is a Kubernetes workflow engine / resource manager
Apache License 2.0
285 stars 24 forks source link

Some nicer way to base64decode and jsondecode #263

Open wryun opened 6 years ago

wryun commented 6 years ago

If we reference into ConfigMaps and Secrets, it can be useful to parse JSON and base 64 decode (so complex configuration can be passed around safely).

Lack of json decoding means all ConfigMap/Secret references are shallow (i.e. top level k/v), and that we automatically base 64 decode secret references (since Go does - but this is not a good strategy in many cases when we want to put them in JSON as the output).

Possible ways to fix this:

  1. fork kubernetes jsonpath into voyager codebase (https://github.com/kubernetes/client-go/tree/master/util/jsonpath) and add these functions as 'identifiers' (cf range/end) - code looks straightforward. However, this will probably require us to remove the magic 'add {$.}' currently in the smith reference code.
  2. use jmespath instead of jsonpath and define custom functions. Unfortunately, looks like Go jmespath doesn't allow one to define custom functions in the current interface, unlike other jmespath implementations, but it's trivial to add and we may be able to upstream.
  3. add a 'subReference' (name?) to the top level references (cf #262 ) like:
    subReference:
    Path: 'inside.secret.path'
    Operations: [base64decode, jsondecode]

I'm in favour of Option 1 for now

wryun commented 6 years ago

I now think (1) would not be straightforward having looked more deeply into how the kubernetes hacked on identifier processing works.