Skip to content
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

Migrate operator to the latest operator-sdk #124

Merged
merged 52 commits into from
Nov 10, 2022
Merged

Conversation

edif2008
Copy link
Member

@edif2008 edif2008 commented Sep 13, 2022

Currently the operator is created based on the operator-sdk v0.18.0. The latest version is v1.25.0.
Packages were required to be updated which brought us to the need of migrating the operator-sdk to v1.

The migration process was performed by following the operator migration documentation.

Key changes in this migration:

  • Project structure
    • main.go is now in the root directory instead of cmd directory
    • api and controllers packages now are at the root directory instead of pkg. Also, these new directories are simplified.
    • yaml files are now in config directory instead of deploy directory.
    • yaml files used for deploying the operator are more granular.
    • RBAC permissions are now generated based on the RBAC markers found in the controllers.
  • Go code:
    • Reconciler structs are slightly changed. Most of functionality stays the same.
    • main.go is slightly simplified and adjusted to new way of initializing the operator.
  • Operator functionality
    • We now have the metrics included. There's no longer needed to create the metrics endpoint ourselves.
  • Operator tests
    • Our tests now use ginkgo, which is a more mature way of testing the actual behavior of the operator in a cluster.
  • Deployment
    • It has been significantly simplified. Users need to just run make deploy to deploy everything they need to use the operator and the OnePasswordItem CRD. To remove it, they can run make undeploy.
  • Documentation - reflects the new setup. For users already using the operator, updating the docker image should be enough (i.e. they shouldn't notice the migration)

For more details, check out the new elements brought with v1 of the operator-sdk.

The commit messages should reflect the migration process.

To be able to perform the migration, we need to start from an empty directory/repo.
Command executed: `operator-sdk init --domain onepassword.com --repo github.com/1Password/onepassword-operator --plugins=go/v4-alpha --license=none`
- `--plugin=go/v4-alpha` is used to enable support for Apple Sillicon environments.
- `--license=none` is used since the only option is Apache, and we use the MIT license. `hack/boilerplate.go.txt` is updated with the MIT license instead.
Command executed: `operator-sdk create api --version v1 --kind OnePasswordItem --resource --controller`
`--group` flag is skipped because we don't have a group in the previous version of the operator and we want to make things consistent and not bring any breaking changes.
- Define the API by modifying the `onepassworditem_types.go`.
- Commands executed after the API is defined: `make generate && make manifests`.
- Migrate the functionality of the Controller for the OnePasswordItem resource.
- Add the RBAC markers that will generate the RBAC permissions.
- Run `make manifests` to generate the RBAC permissions.
- Add the packages that help the operator work as expected.
- Update `go.mod` by running `go mod tidy`.
These yaml files are used when the environment variable `MANAGE_CONNECT` for the operator is set to `true`.
- `version` is used for getting the operator version and the operator SDK version in the logs.
- `k8suitl` is extracted from the operator-sdk to be able to fetch the namespace the operator is deployed to. This is used to deploy Connect in the same namespace if `MANAGE_CONNECT` is set to `true`. In the future, we may want to no rely on this, since this functionality is internal in the operator-sdk.
- `deploy/deployment.yaml` is now `config/manager/manager.yaml`
- `deploy/crds/onepassword.com_v1_onepassworditem_cr.yaml` is now `config/samples/onepassword_v1_onepassworditem.yaml`
Ginkgo has switched to v2 and we should make use of it instead. It doesn't affect how we make tests, but we get the latest enhancements and improvements on the ways tests are executed.
- Migrate `CHANGELOG.md`, `.VERSION`, `LICENSE`, GitHub pipelines, release script, GitHub issue templates.
- Add in Makefile the commands to prepare release and make the release tag.
@edif2008 edif2008 marked this pull request as draft September 13, 2022 14:47
@edif2008 edif2008 mentioned this pull request Sep 26, 2022
4 tasks
@edif2008 edif2008 marked this pull request as ready for review October 24, 2022 17:22
edif2008 and others added 2 commits October 26, 2022 15:18
This is made to eliminate the chance of tests being flaky when run in aprallel
generate random version each time calling mock onepassword item
Copy link
Collaborator

@jillianwilson jillianwilson left a comment

Choose a reason for hiding this comment

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

I'm approving under the assumption that all the features of the operator have been tested thoroughly.

@edif2008 edif2008 merged commit 6723967 into main Nov 10, 2022
@github-actions github-actions bot mentioned this pull request Nov 11, 2022
2 tasks
@edif2008 edif2008 deleted the feature/migrate-operator branch March 25, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants