-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Vars substitution does not work in ConfigMap #1250
Comments
Hi You are missing a config in kustomization: in your kustomization.yaml configurations:
- kustomizeconfig.yaml in your kustomizeconfig.yaml varReference:
- path: data/CNAME
kind: ConfigMap apiVersion: v1
data:
CNAME: CNAME.DOMAIN.COM
ZZZ: YYY
kind: ConfigMap
metadata:
name: configmap
---
kind: Service
metadata:
name: service
apiVersion: v1
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- host: CNAME.DOMAIN.COM
http:
paths:
- backend:
serviceName: service
servicePort: 80
path: / For info there is a pull request which is attempting to do all that (kustomization.yaml var and kustomizeconfig.yaml varReference) automatically: #1217. The only requirement would be that you would have the name of your variable. apiVersion: v1
kind: ConfigMap
metadata:
name: configmap
data:
ZZZ: $(Ingress.my-ingress.spec.rules[0].http.paths[0].backend.servicePort)
CNAME: $(CNAME) becomes after kustomize build apiVersion: v1
data:
CNAME: CNAME.DOMAIN.COM
ZZZ: 80
kind: ConfigMap
metadata:
name: configmap |
Added automatic testing of your issue here: https://github.com/keleustes/kustomize/tree/allinone/examples/issues/issue_1250 |
@jbrette thank you for responding so quickly and helpfully, really appreciated. I think this points to an omission in the kubernetes documentation. Unless I've somehow missed it, I don't think |
@jonathanunderwood The only "locations" where kustomization can replace variables by default are listed here: https://github.com/kubernetes-sigs/kustomize/blob/master/pkg/transformers/config/defaultconfig/varreference.go kustomize is using those var reference to locate (across all the yaml files of your project) where it will potentially find a variable. Any other location is considered custom as in a CRD: Check here: https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/crd/README.md There is an outstanding PR doing all that for you: When a user uses the format list bellow, he already provides the "where" to replace and with "what" to replace. This simplifies and automatizes a lot of the variables declarations. Note that you can still use the "manual" mode if you discover that the "automatic" mode has an issue. data:
ZZZ: $(Ingress.my-ingress.spec.rules[0].http.paths[0].backend.servicePort) |
@jbrette adding the
|
@jonathanunderwood your kubectl is probably still using on older version of kubectl. Meanwhile you should use something like kustomize build . | kubectl apply -f - |
|
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/close |
Do varreferences work for generated configmaps? even with kustomizeconfig.yaml and the setup mentioned above, I get a "well-defined vars that were never replaced:" error. |
@Datamance Yes, it works with generated configmaps. If it doesn't work, you can file a bug by following this instruction. |
@Liujingfang1 nope that's ok - I just had an extra dash in the patch value (using this functionality to add a sidecar), once I removed it everything compiled just fine. Thanks! |
Kustomize doesn't seem to substitute values of
Vars
into thedata
section of a configmap.Reproducer below.
kustomization.yaml
:ingress.yaml
:service.yaml
:configmap.yaml
:Note below that the
$(CNAME)
var has not been susbstituted in the ConfigMap resource:Weirdly, with
kubectl
a different problem arises:The text was updated successfully, but these errors were encountered: