-
Notifications
You must be signed in to change notification settings - Fork 72
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
How to Overwrite Destination Branch and Keep One Single Commit #735
Comments
Hello @squat! I'm trying to follow the Gerrit / refspec docs, but I'm not sure I'm fully understanding. We are talking about it in Flux Bug Scrub now. I see in the https://fluxcd.io/flux/components/image/imageupdateautomations/#gerrit Have you seen this already? I'm still wrapping my head around these docs, but reading carefully I noticed two things differ from the example in the spec:
git:
checkout:
ref:
branch: main
commit:
author:
email: flux@localdomain
name: flux
messageTemplate: |
...
push:
branch: auto
refspec: refs/heads/auto:refs/heads/main Note that Note also that The branch We're sorry if the documentation is unclear! Have you seen this other Please have a look, and let us know if this is any help. |
Hi @kingdonb , yes I saw the Gerrit docs though I mostly ignored it since Gerrit is kind of its own thing. Some details in there caught my eye and seems relevant, e.g. (emphasis mine):
Concerning the inverted order of the refspec components in the Gerrit example, the Flux docs say (emphasis mine):
Pushing to main is expressly something I want to avoid entirely. I want my single commit to end up in My assumption is that there's no bug and I'm simply failing to understand the docs, how Flux deals with refspecs, and how to push a single bundled commit to a desired branch without pushing to main. I read through the source code a bit and it looks to me like the Flux image-automation-controller will always push to a branch even if you don't specify one under push and even if a refspec is specified. This was not obvious to me and definitely explains why commits ended up in the main branch: https://github.com/fluxcd/image-automation-controller/blob/main/internal/source/source.go#L277-L296. I'm still stumped on how to push a single, bundled commit to a remote branch. |
I think you want to set the checkout branch and the push branch, and avoid setting refspec altogether. You can set the checkout branch to |
This is the original, non-working state of my configuration. With these settings, Flux pushes a new commit onto the
The documentation seems to imply that
Is this not the case? Do I simply have to enable a feature flag? |
Hi, I gave this a try and your observations are the expected default behavior. Force push is enabled by default, but the reason for including the old commits from the push branch is the Disabling this flag removes the old commits from the push branch. ...
git:
checkout:
ref:
branch: main
push:
branch: update
... No refspec needed. |
@darkowlzz thanks! That's really helpful. That means that if I disable the feature flag, my Git repo will see the branch overwritten with new commit every |
Yes, but please give it a try and see if it meets your expectation. We do have some reconciliation optimizations when the checkout branch and push branch are the same to determine if there is any change by checking the image policy or the checkout branch to prevent unnecessary image update processing when nothing has changed. If no explicit push branch is defined, the checkout and push branch will be the same, and new image update commits will only be made, if any, if there's a change in the checkout branch or the image policy, at the reconciliation interval. |
Thanks @darkowlzz, I'll give this a shot now. It sounds like the optimizations you were describing won't apply to the case at hand where push branch and checkout branches are different, e.g. ...
git:
checkout:
ref:
branch: main
push:
branch: update
... since the optimizations seem to depend on the checkout and push branches being the same. |
I finally got around to testing this on our cluster and I'm sad to report that the workaround proposed by @darkowlzz doesn't meet my expectations. Indeed, the image automation controller will push a new commit every time reconciliation is triggered. This is annoying because it triggers our CI e2e tests every time a new commit is pushed. I still think it would be a valuable feature to be able to consolidate changes into a single commit without pushing if there is no diff between the current state of the target branch and the commit generated by the controller. |
My goal is that I want my ImageUpdateAutomation to push commits to a
bump-x
branch, always overriding any old commit in the branch and keeping a single commit that updates an image tag in themain
branch directly to the newest image tag in my registry.Image updates are working in my repo today, however when multiple image tags have been pushed since the last time the
bump-x
branch was merged tomain
, then mybump-x
branch will have multiple commits in it. This is annoying because I use a commit template that inserts a link to the GitHub comparison between the the commit SHA found in the newest image tag and the commit SHA found in the second newest image tag. However, the comparison links that are generated are always for the difference between this newest image tag and the image tag found in the previous commit in thebump-x
branch, not the difference between the newest image tag and the image tag currently on themain
branch. My automation uses the body of the latest commit message as the PR body, so that reviewers can easily click on comparison links and know what changes are going into production, however these comparison links are misleading today because they only show a fraction of the whole changeset.For this reason, I'd like to find way for the image-automation-controller to always plan the commit using the
main
branch and then force push that to thebump-x
branch. Reading the documentation, I thought this would be possible using therefspec
field:From my reading, Flux would work on the main branch locally and then push images to the
auto
branch. In my case, I used arefspec
ofrefs/heads/main:refs/heads/bump-x
. However, this had a very unintended result where the changeset was pushed directly to themain
branch on the remote.How can I achieve the desired goal of always having a single commit on the
bump-x
branch? If using refspecs is the way to do it, then I'm confused about the semantics of therefspec
field and how it interacts with branches that are explicitly or implicitly defined in an ImageUpdateAutomation.The text was updated successfully, but these errors were encountered: