Skip to content

✨ (alpha update command): add --force flag #4936

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vitorfloriano
Copy link
Contributor

@vitorfloriano vitorfloriano commented Jul 17, 2025

This PR adds the --force flag to the alpha update command, as well as e2e tests for the flag.

The --force flag makes it possible to run the alpha update command in CI workflows.

If the --force flag is not passed to the command, the update operation will abort if there are conflicts, informing the user that manual resolution is necessary:

vitor@pc:~/go/src/github.com/vitorfloriano/multiversion$ kubebuilder alpha update --from-version v4.5.0 --to-version v4.
6.0 --from-branch main
INFO Checking if is a git repository
INFO Checking if branch has uncommitted changes
INFO Binary version v4.5.0 is available
INFO Binary version v4.6.0 is available
INFO Checking out base branch: main
INFO Using branch names:
INFO   Ancestor: tmp-ancestor-16-07-25-23-25
INFO   Original:  tmp-original-16-07-25-23-25
INFO   Upgrade:  tmp-upgrade-16-07-25-23-25
INFO   Merge:    tmp-merge-16-07-25-23-25
...
...
...
...
WARN Merge stopped due to conflicts. Manual resolution is required. 
WARN After resolving the conflicts, run the following command: 
WARN     make manifests generate fmt vet lint-fix 
WARN This ensures manifests and generated files are up to date, and the project layout remains consistent. 
FATA Update failed: failed to merge upgrade into merge branch: merge stopped due to conflicts 

If the --force flag is passed, the update will proceed, despite the conflicts, and commit the markers as is:

vitor@pc:~/go/src/github.com/vitorfloriano/multiversion$ kubebuilder alpha update --from-version v4.5.0 --to-version v4.6.0 --from-branch main --force
INFO Checking if is a git repository
INFO Checking if branch has uncommitted changes
INFO Binary version v4.5.0 is available
INFO Binary version v4.6.0 is available
INFO Checking out base branch: main
INFO Using branch names:
INFO   Ancestor: tmp-ancestor-16-07-25-23-39
INFO   Original:  tmp-original-16-07-25-23-39
INFO   Upgrade:  tmp-upgrade-16-07-25-23-39
INFO   Merge:    tmp-merge-16-07-25-23-39
...
...
...
...
...
...
INFO Preparing Merge branch with name tmp-merge-16-07-25-23-39 and performing merge
WARN Merge completed with conflicts. Conflict markers will be committed.

As a follow-up, we could find a way to not run the make targets if there are conflicts, to avoid the stream of warnings about failing operations caused by the presence of the markers in the code. Ending the operation with so many warnings could be confusing to users:

WARN Merge completed with conflicts. Conflict markers will be committed.
...
...
WARN make manifests failed: error running "make": exit status 2
...
...
WARN make generate failed: error running "make": exit status 2
...
...
WARN make fmt failed: error running "make": exit status 2
...
...
WARN make vet failed: error running "make": exit status 2
...
...
ERRO Running error: context loading failed: failed to load packages: failed to load packages: failed to load with go/pac
...
...
WARN make lint-fix failed: error running "make": exit status 2

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 17, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vitorfloriano
Once this PR has been reviewed and has the lgtm label, please assign camilamacedo86 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 17, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @vitorfloriano. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 17, 2025

You might want to run `make all`, ensure that all tests are passing, and thoroughly validate the final result before committing and pushing a pull request to update your project from the `tmp-kb-update-merge` branch.

</aside>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to imrpove here maybe give a little more of info like

## Handling Merge Conflicts

If conflicts occur during a merge, Git will stop the process and leave the merge branch in a conflicted state for manual resolution.

To proceed with the merge despite conflicts, you can use the `--force` option. This is useful in automated environments, such as CI pipelines or cron jobs, where you want to create a pull request with the changes — even if conflicts are present.

```bash
git merge --force

The resulting commit will include conflict markers in the affected files:

<<<<<<< HEAD
Your changes
=======
Incoming changes
>>>>>>> branch-name

The commit message will indicate that conflicts are present and need to be resolved manually.

Note: This approach is typically used in automation workflows where conflict markers are later addressed by a human, or where preserving the conflicting changes is acceptable for follow-up processing.


Then, we might no longer put in a note
+ we still needing explaing the targets part

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I expanded this section with your suggestion.

@@ -105,6 +105,45 @@ var _ = Describe("kubebuilder", func() {
By("validating custom code preservation")
validateCustomCodePreservation(mockProjectDir)
})

It("should stop on merge conflicts when --force is not used", func() {
By("creating mock project with kubebuilder v4.5.2")
Copy link
Member

@camilamacedo86 camilamacedo86 Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, with conflict it is 4.5.0 to 4.6.0
Without conflict it is 4.5.2 to 4.6.0
Then, we can reuse the mock
and we can pass the version as arg.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camilamacedo86 I created a mock using v4.5.2 (init, create api, etc) for testing and got the conflicts when updating to v4.6.0:

~/go/src/github.com/vitorfloriano/operator-project/mock-operator$ kubebuilder alpha update --from-version v4.5.2 --to-version v4.6.0 --from-branch main
INFO Checking if is a git repository
INFO Checking if branch has uncommitted changes
INFO Binary version v4.5.2 is available
INFO Binary version v4.6.0 is available
INFO Checking out base branch: main
INFO Using branch names:
INFO   Ancestor: tmp-ancestor-17-07-25-11-13
INFO   Original:  tmp-original-17-07-25-11-13
INFO   Upgrade:  tmp-upgrade-17-07-25-11-13
INFO   Merge:    tmp-merge-17-07-25-11-13
INFO Preparing Ancestor branch with name tmp-ancestor-17-07-25-11-13
INFO Generating project with version v4.5.2
WARN Using current working directory to re-scaffold the project
WARN This directory will be cleaned up and all files removed before the re-generation
INFO Cleaning directory:/home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator
INFO Running cleanup:
$ sh -c rm -rf /home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/ *
INFO kubebuilder init:
$ kubebuilder init --plugins go.kubebuilder.io/v4 --domain example.com --repo github.com/example/mock-operator
INFO Writing kustomize manifests for you to edit...
INFO Writing scaffold for you to edit...
INFO Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.20.4
INFO Update dependencies:
$ go mod tidy
Next: define a resource with:
$ kubebuilder create api
INFO kubebuilder create api:
$ kubebuilder create api --plural webapps --group apps --version v1 --kind WebApp --resource --namespaced --controller
INFO Writing kustomize manifests for you to edit...
INFO Writing scaffold for you to edit...
INFO api/v1/webapp_types.go
INFO api/v1/groupversion_info.go
INFO internal/controller/suite_test.go
INFO internal/controller/webapp_controller.go
INFO internal/controller/webapp_controller_test.go
INFO Update dependencies:
$ go mod tidy
INFO Running make:
$ make generate
mkdir -p /home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/bin
Downloading sigs.k8s.io/controller-tools/cmd/controller-gen@v0.17.2
/home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
Next: implement your new API and generate the manifests (e.g. CRDs,CRs) with:
$ make manifests
INFO Grafana plugin not found, skipping migration
INFO Deploy-image plugin not found, skipping migration
INFO Successfully ran alpha generatev4.5.2
INFO Running make manifests:
$ make manifests
/home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
INFO Running make generate:
$ make generate
/home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
INFO Running make fmt:
$ make fmt
go fmt ./...
INFO Running make vet:
$ make vet
go vet ./...
INFO Running make lint-fix:
$ make lint-fix
Downloading github.com/golangci/golangci-lint/cmd/golangci-lint@v1.63.4
/home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/bin/golangci-lint run --fix
INFO Preparing Original branch with name tmp-original-17-07-25-11-13
INFO Preparing Upgrade branch with name tmp-upgrade-17-07-25-11-13
INFO Generating project with version v4.6.0
WARN Using current working directory to re-scaffold the project
WARN This directory will be cleaned up and all files removed before the re-generation
INFO Cleaning directory:/home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator
INFO Running cleanup:
$ sh -c rm -rf /home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/ *
INFO kubebuilder init:
$ kubebuilder init --plugins go.kubebuilder.io/v4 --domain example.com --repo github.com/example/mock-operator
INFO Writing kustomize manifests for you to edit...
INFO Writing scaffold for you to edit...
INFO Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.21.0
INFO Update dependencies:
$ go mod tidy
Next: define a resource with:
$ kubebuilder create api
INFO kubebuilder create api:
$ kubebuilder create api --plural webapps --group apps --version v1 --kind WebApp --resource --namespaced --controller
INFO Writing kustomize manifests for you to edit...
INFO Writing scaffold for you to edit...
INFO api/v1/webapp_types.go
INFO api/v1/groupversion_info.go
INFO internal/controller/suite_test.go
INFO internal/controller/webapp_controller.go
INFO internal/controller/webapp_controller_test.go
INFO Update dependencies:
$ go mod tidy
INFO Running make:
$ make generate
mkdir -p /home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/bin
Downloading sigs.k8s.io/controller-tools/cmd/controller-gen@v0.18.0
/home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
Next: implement your new API and generate the manifests (e.g. CRDs,CRs) with:
$ make manifests
INFO Grafana plugin not found, skipping migration
INFO Deploy-image plugin not found, skipping migration
INFO Successfully ran alpha generatev4.6.0
INFO Running make manifests:
$ make manifests
/home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
INFO Running make generate:
$ make generate
/home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
INFO Running make fmt:
$ make fmt
go fmt ./...
INFO Running make vet:
$ make vet
go vet ./...
INFO Running make lint-fix:
$ make lint-fix
Downloading github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.0
/home/vitor/go/src/github.com/vitorfloriano/operator-project/mock-operator/bin/golangci-lint run --fix
0 issues.
INFO Preparing Merge branch with name tmp-merge-17-07-25-11-13 and performing merge
WARN Merge stopped due to conflicts. Manual resolution is required.
WARN After resolving the conflicts, run the following command:
WARN     make manifests generate fmt vet lint-fix
WARN This ensures manifests and generated files are up to date, and the project layout remains consistent.
FATA Update failed: failed to merge upgrade into merge branch: merge stopped due to conflicts

So I believe we can use v4.5.2 for all test cases.

Let me know what you think.

This commit adds the --force flag to the alpha update command.
It also adds e2e tests and documentation for the flag.
The --force flag makes it possible to run the alpha update command in CI workflows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants