-
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
Inject Host into Ingress #347
Comments
Recently we added JSON patch support, which is a good solution for this problem. Take a look at our example https://github.com/kubernetes-sigs/kustomize/blob/master/examples/jsonpatch.md |
ah right. Just create a JSON Patch and then use that to edit the build. |
I'm sorry @Liujingfang1, I read the example, and it does not seem like a suitable solution to what is, as @lswith mentioned, a common use case. I was thinking of incorporating Kustomize into our workflow as a low-overhead alternative to creating a helm chart, but a chart seems to be a much more elegant alternative at this point. Any opprotunity for native ingress variables in Kustomize? |
I agree: being able to patch the Ingress host value is super useful, and it would be preferable to be able to do it with a strategic merge. I am seeing a lot of feature requests closed with "use a JSON patch", without much consideration of the use cases. |
Same for me... 👍Could we reopen this one? |
Due to issue in kustomize (kubernetes-sigs/kustomize#347), I ducplicate the whole ingress in the kserver customization.
Also commenting in hopes that this get looked at as something that should be supported natively. Pushing jsonpatches as the solution doesn't seem viable for all use cases. For obscure things that aren't done often sure. But configuring an ingress is quite common, so having a cleaner way to kustomize that would be extremely beneficial. |
@davinkevin's referenced commit (davinkevin/Podcast-Server@9ca4be5) illustrates the problem very nicely — how do I make three different variants with three different ingress rules applying to three different hosts? Here's how I'm currently solving the problem — can y'all see how this is inelegant? Here's my base: broadcaster/broadcaster.yaml
broadcaster/kustomization.yaml
And here's what I'm using to produce ingresses for broadcaster-pokemon/kustomization.yaml
broadcaster-pokemon/squirtle/kustomization.yaml
broadcaster-pokemon/squirtle/hostname.yaml
broadcaster-pokemon/charmander/kustomization.yaml
broadcaster-pokemon/charmander/hostname.yaml
broadcaster-pokemon/bulbasaur/kustomization.yaml
broadcaster-pokemon/bulbasaur/hostname.yaml
I'd like to do something like this instead:broadcaster/kustomization.yaml
broadcaster-pokemon/squirtle/kustomization.yaml
broadcaster-pokemon/charmander/kustomization.yaml
broadcaster-pokemon/bulbasaur/kustomization.yaml
Much cleaner. |
Any chance to see that addressed in a future version? When you have a bunch of subdomains in an ingress, using json patch is not acceptable. It works, but referencing the hosts by index leads to odd errors if someone changes the order of the hosts in the original ingress. So having something like we have for the images would be so nice... In my team we ended up piping |
I ran into a different use-case for the same feature yesterday: |
I empathize with the Kustomize team, maybe this could be addressed in k/k with something like a |
Please add support for suffixes. |
Without features like this, being able to essentially string interpolate on fields, I'm not really sure how Kustomize really fits into the ecosystem. For me I was using it because Helm is way too complex for simple projects, Kustomize covers 99% of my needs - except that I can't configure hostnames of ingress routes. I know there is a design goal not to make this a templating project, but without some kind of basic templating/interpolation, does this not greatly limit the potential use cases? JSON Patch - clever, but grody for simple use cases. |
OK, I rescind my +1 on this. Using patches my specific usecase is actually very easy to solve by templating the patch files and creating a templated kustomize overlay (using ansible): [
{
"op": "replace",
"path": "/spec/tls/0/hosts/0",
"value": "{{ ingress.name }}-{{ ansible_env.USER }}.local"
},
{
"op": "replace",
"path": "/spec/rules/0/host",
"value": "{{ ingress.name }}-{{ ansible_env.USER }}.local"
}
]
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
patches:
{%- for ingress in operations.ingresses %}
- path: {{ ingress.name }}-ingress-patch.json
target:
group: networking.k8s.io
version: v1beta1
kind: Ingress
name: {{ ingress.name }}
{%- endfor %} I'm also beginning to think that implementing something like this in kustomize would erode some of its simplicity that I have grown really fond of. |
Ugh, I'm on my first day of Kustomize and foiled by this fundamental challenge. I have different domains for each environment. This seems like a basic use case. Options:
If there is a "bug" here, is it that the elements of "rules" don't have names, so they can't be strategically merged, breaking a basic use case for reusing code with different domains? Is there some other solution I'm missing?
|
@MichaelJCole the patches are just as stable as the Ingress API itself, so that shouldn't be any trouble. #!/usr/bin/env python3
"""IngressTransformer - Modify ingress domain names according to a template
Usage:
IngressTransformer <config-path>
Template pattern:
The template supports the following variables:
{_TLD} last part of the domain name
{_HOSTNAME} everything except the TLD
{_FQDN} the entire domain name
{...} any environment variable
"""
import docopt
import yaml
import os
import sys
def main():
params = docopt.docopt(__doc__)
config = yaml.load(open(params['<config-path>']), Loader=yaml.FullLoader)
template = config['spec']['template']
resources = yaml.load_all(sys.stdin, Loader=yaml.FullLoader)
ingresses = []
for resource in resources:
if resource['apiVersion'] in ['networking.k8s.io/v1', 'networking.k8s.io/v1beta1'] \
and resource['kind'] == 'Ingress':
for entry in resource['spec']['tls']:
for idx, domain in enumerate(entry['hosts']):
entry['hosts'][idx] = transform_host(domain, template)
for rule in resource['spec']['rules']:
rule['host'] = transform_host(domain, template)
ingresses.append(resource)
sys.stdout.write(yaml.dump_all(ingresses))
def transform_host(domain, template):
parts = domain.split('.')
return template.format(**{
**os.environ,
'_TLD': parts[-1],
'_HOSTNAME': '.'.join(parts[0:-1]),
'_FQDN': '.'.join(parts),
})
if __name__ == '__main__':
main() Place it in ---
apiVersion: APINAME
kind: IngressDomainTransformer
metadata:
name: username-suffix
spec:
template: '{_HOSTNAME}-{USER}.{_TLD}' |
As @andsens mentioned, the most flexible way to do any operation in kustomize is writing your own transformer. Meanwhile, kustomize now supports KRM functions as transformer. KRM function is containerized so it will be easier to reuse. Although we are in a lack of documentation about this feature, you can get some example from the test codes. |
FYI @andsens. The above example of a python3 transformer is badly broken. I tried to adapt it to my needs. First the docopt is not valid (it always errors out with latest docopt 0.6.2) in the end I had to remove "Template Pattern:" block completely. Then it doesn't check if the 'tls' or 'rules' key really exist and errors out if one of them is missing. And in case of 'rules' you're passing the undefined value of domain which is only populated in for loop for 'tls' but not for 'rule'. so I had to exchange 'domain' with rule['host']. and lastly you forget the part that you have to add:
to the kustomization.yaml to make it work. And last but not least, you might want to add this before calling main() or as first thing in main() as I was running this in a docker image of CentOS7 and had PyYAML issues with invalid characters as the input stream was not utf-8. Note that this requires Python 3.7 or higher:
|
@marcelser thank you for your notes. Indeed the for loop is badly broken. The docopt works for me, but I can see that I have an additional newline before the "Template patterns:", and testing it on try.docopt.org indeed confirms that the newline is needed. Thanks for the tip about utf-8, that'll definitely come in handy. |
I'd like to be able to dynamically add/remove/edit hosts during deployments. I need to deploy one namespace and ingress per branch, all other things being equal. IMO adding ingresses dynamically should as easy as adding labels, e.g.: kustomize edit set/add/remove ingress test.xmpl.com My use case is simple so I can reliably use |
If we are pushed to use workaround / templating either via |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
I guess this should be something similar to the images, which are, in some way, also URIs, you define your ingress with a placeholder host Prod: hosts:
- name: service1.myproject.local
newName: myservice1.company.com
- name: service2.myproject.local
newName: myservice2.company.com Test: hosts:
- name: service1.myproject.local
newName: myservice1.test.local
- name: service2.myproject.local
newName: myservice2.test.local this should update all host references, not just ingress routes, but also gateway apis, and preferrably also the tls hosts this is certainly more stable than having a json patch replace the xth, yth and zth element of an array. And if there really needs to be an update to something else, like a crd, the images transformer implementation already has a mechanism for that with configurations (https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/images/kustomization.yaml) It could even be that #3492/#3737 is enough, but that it's adoption is hindered by the lack of documentation? This is where i'm getting stuck at being able to use the replacements transformer for ingress hosts: replacements:
- source:
kind: Ingress
fieldPaths:
- spec.rules.*.host
- spec.tls.*.hosts.*
# what goes here to specify which host I want to replace?
target:
# what goes here to set a specific value? If a ReplacementTransformer won't do as-is, shouldn't we propose a modification to it, instead of going forward with an entire new transformer for now? |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
Kyverno seems to provide a solution for that: That may be a good workaround to the lack of support in kustomize |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
What about just adding a new directive that allows one to override arbitrary merge keys, something like: Base:
Patch:
|
i believed it should be possible with the replacements, but i never got to figure out how they worked exactly. Maybe it wasn't really designed for it and it's still lacking a simple tweak? I wrote this from what i could find in the ReplaceTransformer issues, but couldn't find how to tell it what to replacE.
|
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
I think a reasonably common use case is to swap an ingress's host value:
Can we get a feature to set this?
The text was updated successfully, but these errors were encountered: