1.17
We use the go modules semantic versioning convention, the git tags of the form vMAJOR.MINOR.PATCH
. The major version for this POC is 0
. The depending modules should specify the versions of the hub-of-hubs repositories explicitly, and not use pseudo-verisons (like v0.0.0-20200610161514-939cead3902c
).
The hub-of-hubs modules should use common versions of the dependencies. See the list of the dependencies, and the versions to use in the POC.
Context.Background()
should be defined in the beginning of each "main" method, such as Reconcile
, or of a method to be called as a go routine, and then passed to all the called methods. The functions that handle timers/timeouts/cancel events must handle cancelling the context.
References:
- http://p.agnihotry.com/post/understanding_the_context_package_in_golang/
- https://blog.golang.org/context
All the errors should be wrapped before returning, using fmt.Errorf("Some description: %w", err)
. The errors should only be logged once in the "main" method, such as Reconcile
or methods that do not return errors.
References:
We use controller-runtime logging and its Logging guidelines.
We should use go routines where possible. Note that the database concurrency is limited by the maximal number of database connections (about 100). The multiple connections to a database are handled by pgx connection pool.
While using controller-runtime Manager for controllers seems to be an obvious choice, using controller-runtime's Manager for other components (for example for DB synchronizers) is not. We try to use controller-runtime's Manager as much as possible, even for running components that are not controllers.
controller-runtime's Manager provides the following functionality in addition to managing controllers:
- Kubernetes client with caching
- start/stop Runnables.
- signal handling
- leader election
- metrics
- health/ready checks
- client-side event processing
See an example of using controller-runtime Manager features.
All the components are designed to run as singletons (a single active replica), since there is no load balancing between components. We use leader election of controller-runtime's Manager to implement the singleton pattern.
Currently we do not produce events.
Currently we do not publish any metrics.
Currently we do not use health/ready checks.
Global constants that can be used by global hub operator, manager and agent should be defined in pkg/constants/constants.go. Operator constants that can only be used by operator should be defined in operator/pkg/constants/constants.go.
When a new constant is defined, constant should be reflect the usage of the constant, for example, GlobalHubOwnerLabelKey
is the constant of label key added to resources managed by global hub.
Also make sure the new constant goes to correct section, if no section is suitable for the new constant, create new section and add comments for the section and new constant usage.
go vet
- golangci-lint, minimal version 1.43.0, the settings file is .golangci.yaml.
- golint
❗Remember to copy .golangci.yaml into your repo directory before linting.
ℹ️ If you want to specify something as false-positive, use the //nolint comment.
ℹ️ If you see stale errors from golangci-lint, run golangci-lint cache clean
.
We did not implement any unit/e2e tests for this POC.