chaos-mesh icon indicating copy to clipboard operation
chaos-mesh copied to clipboard

Multi version support helper

Open YangKeao opened this issue 3 years ago • 15 comments

Add a code generator to support multiple versions. To add a new version, you need to do the following things:

  1. ./bin/chaos-multiversion-helper create --from v1alpha1 --to v1alpha2 --as-storage-version. It will copy the v1alpha1 to v1alpha2, and mark it as the storage version
  2. ./bin/chaos-multiversion-helper migrate --from v1alpha1 --to v1alpha2. It will modify every reference to v1alpha1 in the chaos mesh code base to become v1alpha2
  3. ./bin/chaos-multiversion-helper autoconvert --version v1alpha1 --hub v1alpha2 It will automatically generate the convert file. You may need to look at the api/v1alpha1/zz_generated.convert.chaosmesh.go to make sure it works as expected, as this program is not guaranteed to work for all situations.
  4. ./bin/chaos-multiversion-helper addoldobjs --version v1alpha1. It will add the old version objects to the cmd/chaos-controller-manager/provider/convert.go to register the convert webhook for them.
  5. Modify the graphql schema in pkg/ctrl/server/schema.graphqls from v1alpha1 to v1alpha2, which can be achieved through sed -i "s/v1alpha1/v1alpha2/g" pkg/ctrl/server/schema.graphqls
  6. Modify the version in cmd/chaos-builder/version.go from v1alpha1 to v1alpha2
  7. Modify the groupversion_info in api/v1alpha2 from v1alpha1 to v1alpha2
  8. Add old scheme to the cmd/chaos-controller-manager/provider/controller.go

Or, you can use a single command:

OLD_VERSION="v1alpha1" NEW_VERSION="v1alpha2" make migrate-version

TODO:

  • [x] Take care of the error and log

YangKeao avatar Mar 11 '22 05:03 YangKeao

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Andrewmatilde

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment. After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review. Reviewer can cancel approval by submitting a request changes review.

ti-chi-bot avatar Mar 11 '22 05:03 ti-chi-bot

Codecov Report

Merging #3009 (e170528) into master (6cc3590) will decrease coverage by 1.59%. The diff coverage is 7.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3009      +/-   ##
==========================================
- Coverage   41.09%   39.51%   -1.59%     
==========================================
  Files         165      170       +5     
  Lines       13850    14507     +657     
==========================================
+ Hits         5692     5732      +40     
- Misses       7725     8334     +609     
- Partials      433      441       +8     
Impacted Files Coverage Δ
api/v1alpha1/awschaos_types.go 0.00% <ø> (ø)
api/v1alpha1/azurechaos_types.go 0.00% <ø> (ø)
api/v1alpha1/blockchaos_types.go 0.00% <ø> (ø)
api/v1alpha1/dnschaos_type.go 0.00% <ø> (ø)
api/v1alpha1/gcpchaos_types.go 0.00% <ø> (ø)
api/v1alpha1/httpchaos_types.go 0.00% <ø> (ø)
api/v1alpha1/iochaos_types.go 0.00% <ø> (ø)
api/v1alpha1/jvmchaos_types.go 33.33% <ø> (ø)
api/v1alpha1/kernelchaos_types.go 0.00% <ø> (ø)
api/v1alpha1/networkchaos_types.go 0.00% <ø> (ø)
... and 17 more

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 6cc3590...e170528. Read the comment docs.

codecov[bot] avatar Mar 11 '22 06:03 codecov[bot]

@STRRL @iguoyr @cwen0 PTAL

YangKeao avatar Mar 14 '22 09:03 YangKeao

I got an error when running ./bin/chaos-multiversion-helper create --from v1alpha1 --to v2 --as-storage-version on my mac m1.

 ./bin/chaos-multiversion-helper create --from v1alpha1 --to v2 --as-storage-version
2022-03-17T17:15:19.659+0800	ERROR	chaos-multiversion-helper.create	create/create.go:43	create new version	{"error": "exit status 1", "errorVerbose": "exit status 1\ngithub.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create.run\n\t/Users/cwenyin/dev/go/src/github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create/create.go:124\ngithub.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create.NewCreateCmd.func1\n\t/Users/cwenyin/dev/go/src/github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create/create.go:41\ngithub.com/spf13/cobra.(*Command).execute\n\t/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:860\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\t/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:974\ngithub.com/spf13/cobra.(*Command).Execute\n\t/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:902\nmain.main\n\t/Users/cwenyin/dev/go/src/github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/main.go:47\nruntime.main\n\t/Users/cwenyin/dev/local/go/src/runtime/proc.go:255\nruntime.goexit\n\t/Users/cwenyin/dev/local/go/src/runtime/asm_arm64.s:1133"}
github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create.NewCreateCmd.func1
	/Users/cwenyin/dev/go/src/github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create/create.go:43
github.com/spf13/cobra.(*Command).execute
	/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:860
github.com/spf13/cobra.(*Command).ExecuteC
	/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:974
github.com/spf13/cobra.(*Command).Execute
	/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:902
main.main
	/Users/cwenyin/dev/go/src/github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/main.go:47
runtime.main
	/Users/cwenyin/dev/local/go/src/runtime/proc.go:255

cwen0 avatar Mar 17 '22 09:03 cwen0

I got an error when running ./bin/chaos-multiversion-helper create --from v1alpha1 --to v2 --as-storage-version on my mac m1.

 ./bin/chaos-multiversion-helper create --from v1alpha1 --to v2 --as-storage-version
2022-03-17T17:15:19.659+0800	ERROR	chaos-multiversion-helper.create	create/create.go:43	create new version	{"error": "exit status 1", "errorVerbose": "exit status 1\ngithub.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create.run\n\t/Users/cwenyin/dev/go/src/github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create/create.go:124\ngithub.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create.NewCreateCmd.func1\n\t/Users/cwenyin/dev/go/src/github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create/create.go:41\ngithub.com/spf13/cobra.(*Command).execute\n\t/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:860\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\t/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:974\ngithub.com/spf13/cobra.(*Command).Execute\n\t/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:902\nmain.main\n\t/Users/cwenyin/dev/go/src/github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/main.go:47\nruntime.main\n\t/Users/cwenyin/dev/local/go/src/runtime/proc.go:255\nruntime.goexit\n\t/Users/cwenyin/dev/local/go/src/runtime/asm_arm64.s:1133"}
github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create.NewCreateCmd.func1
	/Users/cwenyin/dev/go/src/github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/create/create.go:43
github.com/spf13/cobra.(*Command).execute
	/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:860
github.com/spf13/cobra.(*Command).ExecuteC
	/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:974
github.com/spf13/cobra.(*Command).Execute
	/Users/cwenyin/dev/go/pkg/mod/github.com/spf13/[email protected]/command.go:902
main.main
	/Users/cwenyin/dev/go/src/github.com/chaos-mesh/chaos-mesh/cmd/chaos-multiversion-helper/main.go:47
runtime.main
	/Users/cwenyin/dev/local/go/src/runtime/proc.go:255

It seems that the sed command is different between mac and GNU/Linux. It runs the sed -i /+kubebuilder:storageversion/d for every old API, but this command fails to run in a mac.

Maybe I should run this command in a container, but not on the host, which is unpredictable 😢

YangKeao avatar Mar 18 '22 05:03 YangKeao

@STRRL Please help 😢

YangKeao avatar Mar 31 '22 05:03 YangKeao

@STRRL Please help cry

Hi @cwen0 , please use homebrew to install the gnu-sed, then alias sed=gsed. I think that's the temporary solution before we moving the tool into dev-env image

STRRL avatar Apr 12 '22 06:04 STRRL

@YangKeao Hi, as we need to execute 8 steps according the document, maybe adding a command that including the above 8 steps could provide more convenient experience to users. 🤔

iguoyr avatar Apr 13 '22 07:04 iguoyr

I suggest to add some log in the PR . At least a word SUCCESS when it woks well.

Done :smile:

YangKeao avatar Apr 19 '22 08:04 YangKeao

@iguoyr Fixed. PTAL

YangKeao avatar Apr 21 '22 05:04 YangKeao

@YangKeao: PR needs rebase.

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/test-infra repository.

ti-chi-bot avatar Apr 27 '22 04:04 ti-chi-bot

image image image

cwen0 avatar May 09 '22 09:05 cwen0

image image image

@YangKeao PTAL

cwen0 avatar May 23 '22 02:05 cwen0

image image image

@YangKeao PTAL

Fixed. All new version will be renamed to "chaosmeshapi" + version, for example chaosmeshapiv1.

@cwen0 PTAL

YangKeao avatar Jun 22 '22 09:06 YangKeao

@YangKeao: PR needs rebase.

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/test-infra repository.

ti-chi-bot avatar Jun 30 '22 15:06 ti-chi-bot