-
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
Conversation
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
test/e2e/alphaupdate/update_test.go
Outdated
@@ -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.
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 created a mock using v4.5.2 (init, create api, etc) for testing and got the conflicts when updating to v4.6.0:
We should not face conflict
When I test the PR: https://github.com/camilamacedo86/wordpress-operator/pull/4/commits
It has none conflicts se we will need to review it.
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 Alright, I updated the tests. For that, I removed the constants with hardcoded versions and added variable so that each test can set its fromVersion
value. Let me know what you think.
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.
If we have a conflict from 4.5.2 to 4.6.0, then we need to check the implementation.
Are we calling makeTargets after we call re-scaffold with 4.5.2 ?
PS. That test was done with the review PR
Also, check the mock.
See if it is == the example used
By last way that you can run those tests locally as well now ;-)
ad04246
to
7fd5446
Compare
deb2d09
to
3106fe8
Compare
3106fe8
to
bef2529
Compare
5391017
to
4c53ff4
Compare
4c53ff4
to
1eff876
Compare
159dfa7
to
a292c8f
Compare
updateCmd.Flags().BoolVar(&opts.Force, "force", false, | ||
"Force the update even if conflicts occur. Conflicted files will include conflict markers, and a "+ | ||
"commit will be created automatically. Ideal for automation (e.g., cronjobs, CI).") | ||
|
||
return updateCmd |
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.
Also, could we add the e2e tests as before?
We need supplement the tests.
I fixed the mock sample in https://github.com/kubernetes-sigs/kubebuilder/pull/4938/files for it be as it was done in our POCs.
Therefore, from 4.5.2 to 4.6.0, we should not have conflicts, as from 4.5.0 or 4.4.0 to 4.6.0, we will likely encounter them.
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.
Lets do one thing
We move forward with now, we have the flag + docs
And then, we add the e2e tests in a follow up 🙂
Is that OK?
This commit adds the --force flag to the alpha update command. It also adds documentation for the flag. The --force flag makes it possible to run the alpha update command in CI workflows.
3e943ad
to
7cadf21
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86, vitorfloriano 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 |
<aside class="note warning"> | ||
You must manually resolve these conflicts before merging into your main branch. | ||
|
||
```suggestion |
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.
```suggestion |
The suggestion should not be added
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: