-
Notifications
You must be signed in to change notification settings - Fork 1.6k
✨ (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
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: vitorfloriano 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 |
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 Once the patch is verified, the new status will be reflected by the 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. |
30c0180
to
033a9d0
Compare
033a9d0
to
ad04246
Compare
|
||
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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
ad04246
to
7fd5446
Compare
This PR adds the
--force
flag to thealpha update
command, as well as e2e tests for the flag.The
--force
flag makes it possible to run thealpha 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:If the
--force
flag is passed, the update will proceed, despite the conflicts, and commit the markers as is: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: