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

Feature request: vars from ConfigMap #850

Closed
yujunz opened this issue Mar 5, 2019 · 9 comments
Closed

Feature request: vars from ConfigMap #850

yujunz opened this issue Mar 5, 2019 · 9 comments

Comments

@yujunz
Copy link
Member

yujunz commented Mar 5, 2019

Is it possible to create a LIST (not one by one) of variables from ConfigMap just like envFrom ?

Suppose I need to create a bunch of variables for external resources, like security group, domain name and etc. It seems the only way to do it is save them in ConfigMap and refer in variables.

For example:

configMapGenerator:
- name: public
  literals:
  - service-lbs-sg=sg-02f69a511136cb772
  - domain-name=example.com
  - data-store=s3-bucket-name

vars:
- name: SERVICE_LBS_SG
  objref:
    apiVersion: v1
    kind: ConfigMap
    name: public
  fieldref:
    fieldpath: data.service-lbs-sg
- name: DOMAIN_NAME
  objref:
    apiVersion: v1
    kind: ConfigMap
    name: public
  fieldref:
    fieldpath: data.domain-name
- name: DATA_STORE
  objref:
    apiVersion: v1
    kind: ConfigMap
    name: public
  fieldref:
    fieldpath: data.data-store

Ideally, we should be able to generate the variables with

varsFrom:
- configMapRef:
    name: public

If we have already an equivalent solution for this use case, please shed some light on it.

@Liujingfang1
Copy link
Contributor

@yujunz Using vars for ConfigMap data should work.

@yujunz
Copy link
Member Author

yujunz commented Mar 7, 2019

Yes, it works if I refer the data one by one. But it is not a joy to create one variable for each, whereas envFrom allows you create a list of environment variable with one item. How do I do it in Kustomize for vars? Could you give an example?

I am expecting something line

varsFrom:
- configMapRef:
    name: public

@Liujingfang1
Copy link
Contributor

I see what you mean. This feature is asking for an enhancement on vars to have a simple way of declaring multiple vars from the same object.

@Liujingfang1 Liujingfang1 reopened this Mar 7, 2019
@yujunz
Copy link
Member Author

yujunz commented Mar 9, 2019

I can work on it if no other developer has taken it, @Liujingfang1 . Is there a brief developer guide about how to extend kustomize?

@yujunz
Copy link
Member Author

yujunz commented Mar 9, 2019

It seems the build steps can be represented in pseudo code below

(o *Options).RunBuild(...)
    kt.MakeCustomizedResMap()

(kt *KustTarget).MakeCustomizeResMap (resmap.ResMap)
    ra := kt.AccuumulateTarget()
    ra.Transform(kt.tFactory.MakeHashTransformer())
    ra.FixBackReferences
    ra.ResolveVars
    return ra.ResMap()

We may need to insert an extra step to expand varsFrom to vars. Not sure where is the right insert point. Could you please shed some light on it, @Liujingfang1 @monopole ?

@Liujingfang1
Copy link
Contributor

I don't think it's necessary to extend current vars to support defining all of the ConfigMap’s data as variables.
Since the variables used in Kustomize are meant primarily to be injected to containers, as env or command arguments.
If you need to inject all of ConfigMap's data into containers, you can use envFrom and use environment variables correspondingly.
What is your usage other than that?

@yujunz
Copy link
Member Author

yujunz commented Mar 19, 2019

envFrom can not be used in annotations and other customized fields, as far as I know. I have a live example using a lot of external configurations.

# TODO(yujunz): use `varsFrom` when https://github.com/kubernetes-sigs/kustomize/issues/850 is implemented
- name: vars
  literals:
  - SERVICE_LBS_SG=sg-02f69a34243423
  - ETL_HOSTNAME=etl-controller.example.com
  - ETL_ENVIRONMENT=prod
  - ETL_CONTROLLER_IAM_ROLE=etl.prod.example.com
  - ETL_CONTROLLER_TLS=domain-tls
  - ETL_DATA_STORE=s3://etl-data-store-prod-example-com
  - ETL_AGENT_DOCKERCONFIG=awsecr-cred
  - INGEST_ETL_AGENT_IAM_ROLE=ingest.prod.example.com
  - ETL_ACM_CERT=arn:aws:acm:us-west-1:83423943289:certificate/...
  - APP_IAM_ROLE=app.prod.example.com
  - WORKER_IAM_ROLE=worker.prod.example.com

These variables are to be filled to mostly annotations and also some other fields, e.g.

varReference:
- kind: Deployment
  path: spec/template/spec/volumes/secret/secretName
- kind: Deployment
  path: spec/template/spec/volumes/awsElasticBlockStore/volumeID
- kind: Deployment
  path: spec/template/spec/nodeSelector/failure-domain.beta.kubernetes.io\/zone
- kind: Service
  path: metadata/annotations/service.beta.kubernetes.io\/aws-load-balancer-ssl-cert
- kind: Service
  path: metadata/annotations/service.beta.kubernetes.io\/aws-load-balancer-extra-security-group
- kind: Service
  path: metadata/annotations/external-dns.alpha.kubernetes.io\/hostname

As far as I know, env is limited to command and args. So it seems variable is the only way.

I'm open for better solution though. @Liujingfang1

@yujunz
Copy link
Member Author

yujunz commented Mar 25, 2019

It seems I can do it with jsonPatch6902 as mentioned in #318

@jbrette
Copy link
Contributor

jbrette commented Sep 30, 2019

@yujunz Just realized that this PR was fixing you problem. Have a look here.
This leverage the configmapgenerator env file, the common annotations ...and the autovariable

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

No branches or pull requests

3 participants