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.
@yujunz Using vars for ConfigMap data should work.
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
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.
I can work on it if no other developer has taken it, @Liujingfang1 . Is there a brief developer guide about how to extend kustomize?
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 ?
I don't think it's necessary to extend current vars to support defining all of the ConfigMap鈥檚 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?
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
It seems I can do it with jsonPatch6902 as mentioned in #318
Most helpful comment
I see what you mean. This feature is asking for an enhancement on
varsto have a simple way of declaring multiple vars from the same object.