Skip to content

Commit 41da06a

Browse files
kartikaysaxenaSaranya-jenaKartikay
authored
Revamped Upgrade Agent for Litmus 3.x.x (#4740)
* initialise upgrade-agent Signed-off-by: Kartikay <[email protected]> * dockerfile revert Signed-off-by: Kartikay <[email protected]> * go.mod Signed-off-by: Kartikay <[email protected]> * litmus-portal to chaoscenter Signed-off-by: Kartikay <[email protected]> * dummy versions and log Signed-off-by: Kartikay <[email protected]> * CONTRIBUTING.md init Signed-off-by: Kartikay <[email protected]> * added checks while upgrading Signed-off-by: Kartikay <[email protected]> * transactions Signed-off-by: Kartikay <[email protected]> * transaction implemented in v3.4.0 Signed-off-by: Kartikay <[email protected]> * added upgrades for version 3.9.0 Signed-off-by: Kartikay <[email protected]> * nit: gofmt Signed-off-by: Kartikay <[email protected]> * Template for upgrades Signed-off-by: Kartikay <[email protected]> * refactoring and dumping dummy versions Signed-off-by: Kartikay <[email protected]> * gofmt Signed-off-by: Kartikay <[email protected]> * best practices Signed-off-by: Kartikay <[email protected]> * removed commented code Signed-off-by: Kartikay <[email protected]> * added flowchart Signed-off-by: Kartikay <[email protected]> * removed dummy version from map Signed-off-by: Kartikay <[email protected]> * refactor: better logs and comments Signed-off-by: Kartikay <[email protected]> --------- Signed-off-by: Kartikay <[email protected]> Signed-off-by: Kartikay <[email protected]> Signed-off-by: Kartikay <[email protected]> Co-authored-by: Saranya Jena <[email protected]> Co-authored-by: Kartikay <[email protected]>
1 parent ed7b5a8 commit 41da06a

18 files changed

+763
-347
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## Steps to Contribute
2+
3+
Fixes and improvements can be directly addressed by sending a Pull Request on GitHub. Pull requests will be reviewed by one or more maintainers and merged when acceptable.
4+
5+
We ask that before contributing, please make the effort to coordinate with the maintainers of the project before submitting large or high impact PRs. This will prevent you from doing extra work that may or may not be merged.
6+
7+
Use your judgement about what constitutes a large change. If you aren't sure, send a message to the **#litmus-dev** slack or submit an issue on GitHub.
8+
9+
10+
### **Sign your work with Developer Certificate of Origin**
11+
12+
To contribute to this project, you must agree to the Developer Certificate of Origin (DCO) for each commit you make. The DCO is a simple statement that you, as a contributor, have the legal right to make the contribution.
13+
14+
See the [DCO](https://developercertificate.org/) file for the full text of what you must agree to.
15+
16+
To successfully sign off your contribution you just add a line to every git commit message:
17+
18+
```git
19+
Signed-off-by: Joe Smith <[email protected]>
20+
```
21+
22+
Use your real name (sorry, no pseudonyms or anonymous contributions.)
23+
24+
If you set your `user.name` and `user.email` git configs, you can sign your commit automatically with `git commit -s`. You can also use git [aliases](https://git-scm.com/book/tr/v2/Git-Basics-Git-Aliases) like `git config --global alias.ci 'commit -s'`. Now you can commit with git ci and the commit will be signed.
25+
26+
## **Development Guide**
27+
28+
Start MongoDB, Auth and GraphQL server as mentioned in the [ChaosCenter Development Guide](https://github.com/litmuschaos/litmus/wiki/ChaosCenter-Development-Guide) to set up the basic structure of the DB. Then start the upgrade manager located in `chaoscenter/upgrade-agents/control-plane` by setting up the environment variables
29+
30+
```
31+
export DB_SERVER="mongodb://m1:27015,m2:27016,m3:27017/?replicaSet=rs0"
32+
export DB_USER=admin
33+
export DB_PASSWORD=1234
34+
export VERSION=<Version you need to upgrade to>
35+
```
36+
To run the upgrade-manager, run
37+
38+
```
39+
go run main.go
40+
```
41+
The upgrade-manager would get the current version of Litmus through the DB.
42+
43+
## **Version Upgrade Files**
44+
45+
`<version>/` folder contains files for the upgrade logic
46+
47+
- `upgrade-manager.go` - Contains a map of versions with their corresponding version-managers for the versions.
48+
- `vx.y.z/manager.go` - Instantiates the Version Manager and runs the upgradeExecutor in transactions which can be omitted if the operation doesn't support a transaction.
49+
- `vx.y.z/upgrade.go` - Contains the logic of upgradeExecutor of what schema changes are to be made in the specific version.
50+
51+
There are some other files not mentioned here.
52+
53+
## **Example: Upgrade to version 3.9.0**
54+
55+
In version 3.9.0 the following changes are done in DB schema
56+
57+
- In projects collection (auth DB), member role is updated from `Editor` to `Executor`
58+
- New `is_initial_login` field in users collection (auth DB) whose value is set as false
59+
60+
Run the upgrade-agent while specifying the version `VERSION=3.9.0` in the environmental variable, and it should now be upgraded.
61+
62+
## **Best Practices**
63+
64+
1) If upgrade volume is huge, then transaction is not favorable.
65+
2) Split the upgrades into proprietary functions depending on their purpose and database/collection names.
66+
3) Use logging techniques as used in other versions to provide the user an insight of how the upgrades are being done.
67+
4) While using a transaction, make sure the session context is properly passed into the relevant mongo operations and related functions.
68+
5) Script should be written in a way that even if run twice, should not affect the already updated documents.
69+
70+
71+
Below is the basic technical flow for the upgrade-agent
72+
73+
![image info](./Upgrade-Agent-Flow.png)
Loading
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
1-
module github.com/litmuschaos/litmus/litmus-portal/upgrader-agents/control-plane
1+
module github.com/litmuschaos/litmus/chaoscenter/upgrader-agents/control-plane
22

33
go 1.22
44

55
require (
66
github.com/kelseyhightower/envconfig v1.4.0
7-
go.mongodb.org/mongo-driver v1.7.1
8-
go.uber.org/zap v1.18.1
7+
github.com/sirupsen/logrus v1.4.2
8+
go.mongodb.org/mongo-driver v1.11.9
9+
)
10+
11+
require (
12+
github.com/jessevdk/go-flags v1.5.0 // indirect
13+
github.com/montanaflynn/stats v0.7.1 // indirect
14+
golang.org/x/exp v0.0.0-20240529005216-23cca8864a10 // indirect
15+
golang.org/x/net v0.25.0 // indirect
16+
golang.org/x/term v0.20.0 // indirect
17+
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
18+
gopkg.in/yaml.v2 v2.4.0 // indirect
919
)
1020

1121
require (
1222
github.com/go-stack/stack v1.8.0 // indirect
13-
github.com/golang/snappy v0.0.1 // indirect
14-
github.com/google/go-cmp v0.5.5 // indirect
15-
github.com/klauspost/compress v1.9.5 // indirect
23+
github.com/golang/snappy v0.0.4 // indirect
24+
github.com/google/go-cmp v0.6.0 // indirect
25+
github.com/klauspost/compress v1.17.8 // indirect
26+
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
27+
github.com/mongodb/mongo-tools v0.0.0-20240711192303-088725fbaf4b
1628
github.com/pkg/errors v0.9.1 // indirect
29+
github.com/stretchr/testify v1.9.0 // indirect
1730
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
18-
github.com/xdg-go/scram v1.0.2 // indirect
19-
github.com/xdg-go/stringprep v1.0.2 // indirect
20-
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
21-
go.uber.org/atomic v1.9.0 // indirect
22-
go.uber.org/multierr v1.7.0 // indirect
23-
golang.org/x/crypto v0.17.0 // indirect
24-
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
25-
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
26-
golang.org/x/text v0.14.0 // indirect
31+
github.com/xdg-go/scram v1.1.2 // indirect
32+
github.com/xdg-go/stringprep v1.0.4 // indirect
33+
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
34+
golang.org/x/crypto v0.23.0 // indirect
35+
golang.org/x/sync v0.7.0 // indirect
36+
golang.org/x/sys v0.20.0 // indirect
37+
golang.org/x/text v0.15.0 // indirect
2738
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
28-
gopkg.in/yaml.v2 v2.4.0 // indirect
39+
gopkg.in/yaml.v3 v3.0.1 // indirect
2940
)

0 commit comments

Comments
 (0)