Replies: 2 comments 12 replies
-
Just a idea, but what if the GitRepository.status is extended with a field containing the GIT_SHA and variable substitution is extended to target not only Secret and ConfigMaps but any field of a CR? |
Beta Was this translation helpful? Give feedback.
-
So, I went and did some digging to see what would be needed to implement this proposal, and so far I am stuck. So I am going to write it out in detail in the hopes that I will get un-stuck and see a simple implementation without much change, to submit as a PR. Here's my research:
Currently
The easiest way to implement this change is to make it always-on, with no opt-out, then there is no need for any CRD change. This is a breaking change but with a limited blast radius, we can set an expectation that variables which start with So, in the code of
and we return In
I had hoped we would have the string somewhere handy that we can simply add it as a parameter to
On this line, we can see where the Revision string comes from: That's as far as I can afford to spend time digging into this today. At least I have demonstrated that the data we need is in the vicinity of where we need it to go, in order to make this feature work. It should be a simple matter to demonstrate how it can work next. I am not prepared to follow up this proposal with a PR just now, but would like to let it percolate while I work on documenting other use cases of Manifest Generation that are more interesting and definitely more urgent for me, like jsonnet and cdk8s, powerful tools that can be used for "rehydrating" structures that are simplified versions of the YAML manifests. Realistically, practically any one of these tools can do a better job than Doing this in CI solves another problem too... what happens if the manifest is sync'ed before the CI finishes, and the image is not ready yet? Since this is obviously not the only time and place one might need CI to commit back to the repo, it is not urgent for me to solve this. I would love to see a PR from any new contributor to whom this is either more important or more urgent; I think this small change I propose, while limited, is "low-hanging fruit" that knocks out a few troubled use cases without compromising much. I think we should do it, but I will understand if it is not a priority for the maintainers to implement this. It's small, and really any one of us community members could probably take it from here! |
Beta Was this translation helpful? Give feedback.
-
I have built an example which does manifest generation in the way that I think it is intended to be done (in CI) and I found there was a pretty common use case that could be facilitated by a little help that I think kustomize-controller is in position to lend without much (anything?) materially changing in the controller or in the CRD.
Proposal: make GIT_SHA (or
FLUX_GIT_SHA
) available as a variable that can be substituted atkustomize build
time throughenvsubst
. This can be used through thespec.postBuild
feature to avoid unnecessary kludges like, a CI job that takes the latest commit hash from a branch, and commits it back to the branch in a configmap like this one:kingdonb/any_old_app@388dfa3#diff-9105252cca777939348fc91a5a46ce69fa9da0a3346d31747cc9bbbe7ef0f680
... for use in later
postBuild
substitutions withsubstituteFrom
.There is a case that manifest generation tools can probably pick up the slack here, and if they are run in a scenario where they have access to the GIT_SHA, they can write it out in any deployments' image spec while remaining DRY. I have several examples for these kind of scenarios and I plan to add them to the documentation.
But this example in particular seems quite overcomplicated because it does not have access to the GIT_SHA variable at runtime for
kustomize build
. See #1002 - this is a use case that was very easy in.flux.yaml
(it is retrieved in-line since a git checkout is already present) and I've been able to replicate this with help of CI, but it sure looks a lot more complicated than it seems to need, than it was in Flux v1. I don't think you should need a CI task that writes back to git in order to solve this use case. (The git task that writes back to CI is still important, it just seems unnecessary for this particular use case.)Kustomization might already know its GIT_SHA, or if not, it should be in a position to retrieve it from the
source-controller
– sometimes you will be applying from aBucket
or other source and it might not be available. And that's fine... there could be more useful variables that would be made available depending on the source and what information it includes.There is also the possibility that
Kustomization
spec could include additional variables, like the kustomization's source name along with source ref, or even including variables with information about additional (external) source refs at the time of build, but there are some problems with this model that I won't approach in this proposal. However anyKustomization
, assuming a source of aGitRepository
, can probably make some fairly strong guarantees of a declarative nature (eg. GIT_SHA will always be the same for a givenkustomize build
) those guarantees that wouldn't be as strong for external sources that can move independently. (I'm talking about pulling variables fromsourceRef
eg. an unrelated source. It would be useful forfleet-infra
to know the current SHA of agitrepository
source that produces an image through CI, even if that source isn't associated with any downstreamkustomization
.)It would be really helpful for the purpose of manifest generation if Kustomization and its build had access to information about itself and the source it's reconciling in the form of making some variables available for use in
postBuild
substitution.Beta Was this translation helpful? Give feedback.
All reactions