-
Notifications
You must be signed in to change notification settings - Fork 120
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
dev guidelines: updates and new things I learned #320
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,9 @@ title: Coding Guidelines for Carvel | |
## General Mindset and Sensibilities | ||
### Naming | ||
* Consistent and descriptive, without abandoning golang’s terse style. | ||
* Flag names should be nouns not verbs ( --warnings, not --warn) | ||
* Flag names should be nouns not verbs ( --warnings, not --warn). | ||
* Prefer names that indicate behavior or effect over names that describe | ||
implementation. | ||
|
||
### Modularity | ||
* Each Carvel tool is modular and composable, with aggressively limited scope | ||
|
@@ -68,6 +70,12 @@ Developers should feel free to add more structure as complexity grows by making | |
``` | ||
if err := foo(); err != nil { //… | ||
``` | ||
* Prefer to minimize empty lines: | ||
* One blank line between functions or sections can be helpful, two blank | ||
lines is gratuitous. | ||
* Don't leave blank lines at the bottom of a function or test | ||
* When defining a function with no implementation, keep the `{}` on the same | ||
line as the function declaration. | ||
* Dependencies | ||
* are all vendored locally and version controlled | ||
* `go mod vendor; go mod tidy` are your friends; hack/build.sh runs them. | ||
|
@@ -88,6 +96,7 @@ Developers should feel free to add more structure as complexity grows by making | |
* Generators can be run via hack/gen.sh | ||
* Kapp-controller’s aggregated API server has a separate generator: hack/gen-apiserver.sh | ||
* The CRD yaml is generated via[ a separate script](https://github.com/vmware-tanzu/carvel-kapp-controller/blob/85e814cda7109169809ede1c8a4f211739ad15d2/hack/gen-crds.sh) that is run by hack/build.sh | ||
* Imports: use the alias `metav1` when importing `"k8s.io/apimachinery/pkg/apis/meta/v1"` | ||
|
||
## Development Process | ||
### Controller specific workflows | ||
|
@@ -127,6 +136,8 @@ We write mainly e2es and units; some tools have [performance tests](https://git | |
* Test Assets: | ||
* If a test requires additional artifacts or assets they should live in a separate /assets subfolder. | ||
* Test assets should include comments describing how to generate or modify those assets. [example](https://github.com/vmware-tanzu/carvel-kapp-controller/blob/1844e157b6de4048cec3ba0e53fc699d37e9c71e/test/e2e/assets/https-server/certs-for-custom-ca.yml#L9) | ||
* Names: Omit words like "fake" or "mock" from the names of variables or dummies | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason for this guideline? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's basically this comment from DK: carvel-dev/secretgen-controller#41 (comment)
In that example I think Martin Fowler and his friend would've said I was using a 'stub' (a func that ignores its argument and always returns IMO part of the value of a guide like this is that it takes the approver's opinions and makes them available before code review, rather than after. In kpm-land, DK is basically the only approver, and I'm completely content to just take his opinions on things like this and enshrine them. If you're into debates though you-all can hash it out... and maybe his opinion/preference is more nuanced than I'm presenting it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to agree because usually, the Test Double names are used a little bit too freely. |
||
made for the test. | ||
|
||
### Issues, Branching, Pull Requests, Approval | ||
* Issues (see also, [issue triaging docs](https://www.google.com/url?q=https://github.com/vmware-tanzu/carvel/blob/develop/processes/issue-triage.md&sa=D&source=docs&ust=1634161804254000&usg=AOvVaw3al0fXNnNVR7ynUf-DwcU0) for more info!) | ||
|
@@ -174,5 +185,7 @@ Carvel uses semver, x.y.z version structure, with all tools at major version x=0 | |
* Aspirational: a single script that runs linter, no-dirty-files, and unit tests locally | ||
|
||
### Release Process | ||
* OSS Releases: We’re mostly trying to use goreleaser, which relies on git tags, but this varies by repo; see the relevant dev.md for details | ||
* OSS Releases: varies by tool, see the relevant dev.md for details. Many of the | ||
command line tools are using [shared | ||
scripts](https://github.com/vmware-tanzu/carvel-release-scripts). | ||
* Vmware releases: have their own process; Vmware employees should see internal docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this apply to all imports or only to imports that convey versions like
v1
orv1alpha1
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it applies to exactly this (very common in controllers) import. I didn't mean to imply any wildcards in this regex, although i guess there's a similar rule for
.../core/v1
. What should i change to make this more clear?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion would be:
Imports: when the imported package is named after a version, the previous package should be added for more context or something to identify the intent (ex:
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
orregv1 "github.com/google/go-containerregistry/pkg/v1"
)