-
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
add replacements field #1594
add replacements field #1594
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Liujingfang1 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
If it was possible to source the value of a replacement from a file this could resolve a lot of additional use cases this feature currently can't cover. |
bd3fcc5
to
0a3b751
Compare
@tkellen Why do you need to put the literal values in a file? You can put them directly in kustomization.yaml. If you need to overwrite some of those values in overlay, you can replacements in the overlay kustomization.yaml as well. |
Because I want to generate them in CI and commit them and re-use the values in numerous |
Or, if you imagine that I have a dev/preprod/prod cluster each with a different RDS host I want to check in a plain text file at the time the cluster is created and re-use that file in every application's kustomization yaml that requires a database connection. |
Additionally and critically missing from this feature is the ability to interpolate the literal value with an existing other value. For example, when using an external secret store (e.g. hashicorp vault, aws secrets manager, etc) and authoring an application who looks up secrets at runtime, the secret paths for the application to retrieve are sent in as environment variables. I need to capture the prefix from a shared external file and append the application specific values to it. |
Are those values different in every CI job? If most of them are the same, you can update your Kustomize base to use those values directly. If they are different, you can write some script to provide them to kustomization.yaml. Later we will develop the edit commands for replacements. You can leverage it in scripts. More about the edit commands, it should support reading from an environment variable. For example
will read the value of ${ENV} and write it into kustomization.yaml.
Sounds like you can put this database connection into a ConfigMap or a Secret. You can put that ConfigMap or Secret in to base and use it for every application. |
ConfigMaps refs for environment variables only cover the case where the entire value is used wholesale. K8s offers no affordance for interpolating values (e.g. the case where a cluster-wide secret prefix is consumed by hundreds of microservices who append application specific values to it). However, using ConfigMaps for this purpose does not work with kustomize today because it cannot handle the same configmap being used multiple times. Here is a simple example:
Finally, I don't want to use |
Apologies if my comment about not wanting to use I can explain why in a more nuanced fashion: K8s isn't the only component in a modern infrastructure repo that needs access to shared environment/cluster-wide values. Operators should not be required to encode their source of truth in a I understand that refusing to succumb to dollar values and templating constructs is what paved the way for kustomize to come into being but you're throwing the baby out with the bath water if you don't put some of that power back into the kustomization.yml file proper. I truly realize I should roll up my sleeves and start opening PRs if I really want to see things happen but would the maintainers of this project please read this and internalize what it does? It's likely an overreach but I just can't understand how the power and clarity of what it does isn't moving to you given what you're suggesting users do instead. I agree wholeheartedly we shouldn't litter k8s manifest files with variables. I either have a fundamental misunderstanding about how this software works or there are massive feature gaps for cleanly handling a myriad standard real world use cases that operators encounter. Note: I am aware that #1594 (comment) would be better expressed using patches but I hadn't realized that six months ago when I first shared it |
@tkellen The example you wrote perfectly explained that you can use values from files through ConfigMap. You can optimize it by
where env.txt contains
Your script only need to update the file If you mean you have to use |
@Liujingfang1 Yes, it's true that I can use files in a way that is very indirect and quite confusing for everyone on my team but me and a few people who have gone fully down the rabbit hole with me. My use-case above is broken but this conversation has illuminated for me that this would fix it: #1600. If you would accept a PR for that this would go a long way for my team. I still view it as unnecessary indirection but it answers my use-cases in a way the current implementation suggested here cannot. |
I do not use this ConfigMap at all for anything other than the variable references it enables. This means my deployments are totally self-contained and can be rolled back without producing a sea of intermediate ConfigMaps. In my example above (#1594 (comment)) the ConfigMap is applied into the cluster and completely ignored. I am aware I could use a |
I believe I'll be able to satisfy the majority of my desired use-cases with the closing of gh-1600 but I am curious, @Liujingfang1 or @monopole, if you can explain why you are (if you are) against the notion of supporting the sourcing of values from external files for this feature? If you are not, would you accept a PR that expands upon this work to add it? |
superseded by #1631 |
The replacement fields is to support substitution
Target
and a list offieldrefs
, whereTarget
usesSelector
to filter targets, which is also used in the patches for multi objects.Example: