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

use data from ConfigMap with some hardcoded modifications #360

Open
edmondsw opened this issue Feb 11, 2022 · 2 comments
Open

use data from ConfigMap with some hardcoded modifications #360

edmondsw opened this issue Feb 11, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@edmondsw
Copy link

edmondsw commented Feb 11, 2022

We have a ConfigMap with some data in it, and I want to pull that data into another ConfigMap but with a few changes to add or override some things.

I think we should be able to use overrideStrategy for this, but it currently seems to expect the override data to come from another ConfigMap, whereas I want to be able to hardcode the data I want to add/override into the mtp. To do this we would need to be able to specify a block of json or yaml instead of a configMapKeyRef

Here's an example of one of the things I tried that did not work:

apiVersion: deploy.razee.io/v1alpha2
kind: MustacheTemplate
metadata:
  name: test-mtp-template
  namespace: mynamespace
spec:
  templateEngine: handlebars
  env:
  - name: foo
    valueFrom:
      configMapKeyRef:
        name: common-config
        key: foo
        type: jsonString
  - name: foo
    overrideStrategy: merge
    value: '{"bar": "something"}'
  strTemplates:
  - |
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: foo-cm
      namespace: mynamespace
    data:
      foo: "{{{ foo }}}"
@alewitt2
Copy link
Member

alewitt2 commented Feb 22, 2022

with the latest version of MTP https://github.com/razee-io/MustacheTemplate/releases/tag/2.1.0, i think we have a workaround for you.

instead of using value, use valueFrom, but point at some non-existant configmap. You will also need to define a default value. The only side effect from this work around, is there will be a warning message that says "couldnt find your value, we are using the default instead"

ex:

apiVersion: deploy.razee.io/v1alpha2
kind: MustacheTemplate
metadata:
  name: test-mtp-template
  namespace: mynamespace
spec:
  templateEngine: handlebars
  env:
  - name: foo
    valueFrom:
      configMapKeyRef:
        name: common-config
        key: foo
        type: json
  - name: foo
    overrideStrategy: merge
    default: '{"bar": "something"}'
    valueFrom:
      configMapKeyRef:
        name: this-config-doesnt-exist
        key: you-cant-find-me
        type: json
  strTemplates:
  - |
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: foo-cm
      namespace: mynamespace
    data:
      foo: "{{{ foo }}}"

i'll leave this issue open, as it probably makes sense to support typecasting a plain value at some point.

@alewitt2 alewitt2 added the enhancement New feature or request label Feb 22, 2022
@alewitt2
Copy link
Member

for future reference..
i think this will involve adding a type field at the same level as value in the schema, and then calling typeCast on env.value with said type, before doing the short circuit return of value

  #processEnv(envs) {
    return Promise.all(envs.map(async (env) => {
      if (env.value) {
        if (env.type) env.value = typeCast(env.value, env.type);
        return env;
      }
      ...
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants