-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Ingress] How to use regexp in nginx.tmpl? #1695
Comments
@tjliupeng you need to use a custom template custom-nginx-template.
https://github.com/kubernetes/contrib/blob/master/ingress/controllers/nginx/nginx.tmpl#L165
https://github.com/kubernetes/contrib/blob/master/ingress/controllers/nginx/nginx.tmpl#L199 |
@aledbf , I know the location. But I don't know how to use regexp in the template. What I mean for "match specific string" is "containing some string" or "equal to some string". How to implement "containing some string" in the template? |
@tjliupeng please check https://golang.org/pkg/text/template/ and the template itself to see examples |
@aledbf , yes , I try before I post this issue. At present I can't find the solution. |
@tjliupeng like this
Can you post exactly what are you trying to achieve? |
@aledbf , in ingress controller, the upstream name is dynamically generated according to the k8s service name. What I want to do is: if the upstream name contains substring "sm-rte", this upstream should include a balancer_by_lua_block, and some extra work should be done at init_by_lua_block for this kind of upstream. The reason I can't use "eq" operator is that the upstream name generated by k8s also includes the namespace and port which could be configured by user. So, I can only use the string "sm-rte" which is constant for string matching. |
ok, you need to add a helper in the template
then you can use it in the template
|
Oh, thanks. Let me try. |
@aledbf , by the way, as you are a contributor of ingress, do you think supporting "contains" is useful and submit the helper above to template.go? |
Sure. Please submit a PR adding the function to |
@aledbf , seems your PR is in the queue for several days. As I have no experience on submit code to this repository, what is the meaning "PR has no LGTM" for your PR? |
Automatic merge from submit-queue [nginx-ingress-controller]: Add function helpers to nginx template fixes #1695
…funcmap Automatic merge from submit-queue [nginx-ingress-controller]: Add function helpers to nginx template fixes kubernetes-retired#1695
Hi,
According to our application requirement, I need to add some lua code block in nginx.tmpl. To limit the impact of these lua code, I want to achieve some limitation:
How can I implement these 2 limitations in nginx.tmpl?
Thanks
The text was updated successfully, but these errors were encountered: