Skip to content

Commit

Permalink
update style guide, accordingly to recent changes for all import chan…
Browse files Browse the repository at this point in the history
…ges for CR (#3462)
  • Loading branch information
andriisoldatenko committed Jul 15, 2024
1 parent 7677e1f commit fc77efd
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions doc/coding-style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
- [Errors](#errors)
- [Do's](#dos)
- [Don'ts](#donts)
- [Naming](#naming)
- [Do's](#dos-1)
- [Don'ts](#donts-1)
- [Logging](#logging)
- [Do's](#dos-1)
- [Don'ts](#donts-1)
Expand Down Expand Up @@ -161,6 +164,82 @@ sigs.k8s.io/controller-runtime@v0.16.3/pkg/internal/controller/controller.go:227
runtime.goexit
```
## Naming
### Do's
- Use `dynakube` or `edgeconnect` as default package name in imports to simplify CRD version maintenance.
For example:
```go
package abc
import (
"github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta2/dynakube"
)
```
```go
package abc
import (
"github.com/Dynatrace/dynatrace-operator/pkg/api/v1alpha1/edgeconnect"
)
```
> Note: Incase multiple versions of the same CR are used (conversion, webhook manager configuration, etc.),
> use the name of the CR as part of the package alias:
```go
package abc
import (
dynakubev1beta2 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta2/dynakube"
dynakubev1beta3 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta3/dynakube"
)
```
```go
package abc
import (
edgeconnectv1alpha1 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1alpha1/edgeconnect"
edgeconnectv1alpha2 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1alpha2/edgeconnect"
)
```
- Use `dk` or `ec` as short a version of variable name for instances of `dynakube.Dynakube`, or any func arguments
to not overlap with package name `dynakube` or `edgeconnect`.
For example:
```go
dk := dynakube.DynaKube{}
```
```go
ec := edgeconnect.EdgeConnect{}
```
```go
func (c component) getImage(dk *dynakube.DynaKube) (string, bool) {}
```
### Don'ts
- Use CRD version inside import alias name:
```go
package abc
import (
dynatracev1beta2 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta2/dynakube"
)
```
- Use `dynakube` or `edgeconnect` as variable name or function argument name.
- Use import alias for api package: `dynatracev1alpha1 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1alpha1"`
## Logging
### Do's
Expand Down

0 comments on commit fc77efd

Please sign in to comment.