composable-operator/composable

getValueFrom.path to support keys containing character "."

lluan444 opened this issue · 2 comments

There are some fields in k8s objects that may contain character . in the keys. For example the first posting below contains a key .dockerconfigjson, the second one two keys tls.key and ca.crt. (These two example secrets are created by k8s cluster in IBM cloud.)

The jsonpath scheme for path is not able to support these cases. The composable operator would threw exceptions when creating a composable resource referencing to these keys, see the third posting below.

apiVersion: v1
data:
  .dockerconfigjson: eyJhdXRocyI6eyJpY3IuaW8iOnsidXNlcm5hbWUiOiJpYW1hcGlrZXkiLCJwYXNzd29yZCI6IlNGNVhCekY2cktoS2IwM1ZSS01rVUc1ZE1VazFFlSWFppIn19fQ==
kind: Secret
metadata:
  creationTimestamp: "2019-08-19T17:12:35Z"
  name: default-icr-io
  namespace: default
  selfLink: /api/v1/namespaces/default/secrets/default-icr-io
  uid: 89cf9a18-c2a4-11e9-93e6-c6b8d18006b4
type: kubernetes.io/dockerconfigjson
apiVersion: v1
data:
  tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUZ6ekNDQkxlZ0F3SUJBZ0lTQTE0RzB4bi9ad2Q....KS09xa3FtNTdUSDJIM2VESkFrU25oNi9ETkZ1MFFnPT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
  tls.key: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb3dJQkFBS0NBUUVBdFA2R0JxekxaanhU.....VGIvQUlqMlM1Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
kind: Secret
metadata:
  name: dallascluster
  namespace: default
  selfLink: /api/v1/namespaces/default/secrets/dallascluster
type: Opaque

(composable example)

apiVersion: ibmcloud.ibm.com/v1alpha1
kind: Composable
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: mycomp
spec:
  template: 
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: myconfigmap
      namespace: default
    data:
      key:
        getValueFrom:
          kind: Secret
          name: dallascluster
          namespace: default
          path: '{.data.tls.key}'
          format-transformers:
          - "Base64ToString"      
      dockerconfig:
        getValueFrom:
          kind: Secret
          name: default-icr-io
          namespace: default
          path: '{.data..dockerconfigjson}'
          format-transformers:
          - "Base64ToString"

Hi Laura @lluan444 , you have to escaping dots, the following composable yaml configuration works fine with your examples.

apiVersion: ibmcloud.ibm.com/v1alpha1
kind: Composable
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: mycomp-dot
spec:
  template:
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: myconfigmap-dot
      namespace: default
    data:
      key:
        getValueFrom:
          kind: Secret
          name: dallascluster
          namespace: default
          path: '{.data.tls\.key}'
          format-transformers:
          - "Base64ToString"
      dockerconfig:
        getValueFrom:
          kind: Secret
          name: default-icr-io
          namespace: default
          path: '{.data.\.dockerconfigjson}'
          format-transformers:
          - "Base64ToString"

P.S. Actually I had to slightly modify your base64 input strings, probably your examples do not show the full strings.
P.S. 2 I will add a comment about the dots escaping in the README.md file.

Thanks Alexey

@roytman Thanks. I will close this issue.