Skip to content

Commit 7df15f7

Browse files
pymanderjoelbyronbarkermrbobbytables
committed
Update parts of the contributor guide to match the style guide
Edit parts of the Contributor Guide to match the Kubernetes Documentation style guide. This PR updates the following: - the GitHub Workflow document - the Help Wanted guide - the Coding Conventions document Co-authored-by: Joel Barker <[email protected]> Co-authored-by: Bob Killen <[email protected]>
1 parent ee18898 commit 7df15f7

File tree

3 files changed

+144
-236
lines changed

3 files changed

+144
-236
lines changed

contributors/guide/coding-conventions.md

Lines changed: 33 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -2,133 +2,61 @@
22
title: "Coding Conventions"
33
weight: 8
44
description: |
5-
A collection of guidelines, style suggestions, and tips for writing code in
6-
the different programming languages used throughout the project.
5+
This document outlines a collection of guidelines, style suggestions, and tips
6+
for writing code in the different programming languages used throughout the
7+
Kubernetes project.
78
---
89

9-
**Table of Contents**
10-
11-
- [Coding Conventions](#coding-conventions)
12-
- [Code conventions](#code-conventions)
13-
- [Testing conventions](#testing-conventions)
14-
- [Directory and file conventions](#directory-and-file-conventions)
15-
1610
## Code conventions
1711

1812
- Bash
19-
2013
- https://google.github.io/styleguide/shell.xml
21-
22-
- Ensure that build, release, test, and cluster-management scripts run on
23-
macOS
14+
- Ensure that build, release, test, and cluster-management scripts run on macOS
2415

2516
- Go
26-
27-
- [Go Code Review
28-
Comments](https://github.com/golang/go/wiki/CodeReviewComments)
29-
17+
- [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments)
3018
- [Effective Go](https://golang.org/doc/effective_go.html)
31-
3219
- Know and avoid [Go landmines](https://gist.github.com/lavalamp/4bd23295a9f32706a48f)
33-
3420
- Comment your code.
35-
- [Go's commenting
36-
conventions](http://blog.golang.org/godoc-documenting-go-code)
37-
- If reviewers ask questions about why the code is the way it is, that's a
38-
sign that comments might be helpful.
39-
21+
- [Go's commenting conventions](http://blog.golang.org/godoc-documenting-go-code)
22+
- If reviewers ask questions about why the code is the way it is, that's a sign that comments might be helpful.
4023
- Command-line flags should use dashes, not underscores
41-
4224
- Naming
43-
- Please consider package name when selecting an interface name, and avoid
44-
redundancy.
45-
46-
- e.g.: `storage.Interface` is better than `storage.StorageInterface`.
47-
48-
- Do not use uppercase characters, underscores, or dashes in package
49-
names.
50-
- Please consider parent directory name when choosing a package name.
51-
52-
- so pkg/controllers/autoscaler/foo.go should say `package autoscaler`
53-
not `package autoscalercontroller`.
54-
- Unless there's a good reason, the `package foo` line should match
55-
the name of the directory in which the .go file exists.
25+
- Please consider package name when selecting an interface name, and avoid redundancy. For example, `storage.Interface` is better than `storage.StorageInterface`.
26+
- Do not use uppercase characters, underscores, or dashes in package names.
27+
- Please consider parent directory name when choosing a package name. For example, `pkg/controllers/autoscaler/foo.go` should say `package autoscaler` not `package autoscalercontroller`.
28+
- Unless there's a good reason, the `package foo` line should match the name of the directory in which the `.go` file exists.
5629
- Importers can use a different name if they need to disambiguate.
57-
58-
- Locks should be called `lock` and should never be embedded (always `lock
59-
sync.Mutex`). When multiple locks are present, give each lock a distinct name
60-
following Go conventions - `stateLock`, `mapLock` etc.
61-
30+
- Locks should be called `lock` and should never be embedded (always `lock sync.Mutex`). When multiple locks are present, give each lock a distinct name following Go conventions: `stateLock`, `mapLock` etc.
6231
- [API changes](/contributors/devel/sig-architecture/api_changes.md)
63-
6432
- [API conventions](/contributors/devel/sig-architecture/api-conventions.md)
65-
6633
- [Kubectl conventions](/contributors/devel/sig-cli/kubectl-conventions.md)
67-
6834
- [Logging conventions](/contributors/devel/sig-instrumentation/logging.md)
6935

7036
## Testing conventions
7137

72-
- All new packages and most new significant functionality must come with unit
73-
tests
74-
75-
- Table-driven tests are preferred for testing multiple scenarios/inputs; for
76-
example, see [TestNamespaceAuthorization](https://git.k8s.io/kubernetes/test/integration/auth/auth_test.go)
77-
78-
- Significant features should come with integration (test/integration) and/or
79-
[end-to-end (test/e2e) tests](/contributors/devel/sig-testing/e2e-tests.md)
80-
- Including new kubectl commands and major features of existing commands
81-
82-
- Unit tests must pass on macOS and Windows platforms - if you use Linux
83-
specific features, your test case must either be skipped on windows or compiled
84-
out (skipped is better when running Linux specific commands, compiled out is
85-
required when your code does not compile on Windows).
86-
87-
- Avoid relying on Docker hub (e.g. pull from Docker hub). Use gcr.io instead.
88-
89-
- Avoid waiting for a short amount of time (or without waiting) and expect an
90-
asynchronous thing to happen (e.g. wait for 1 seconds and expect a Pod to be
91-
running). Wait and retry instead.
92-
38+
- All new packages and most new significant functionality must come with unit tests.
39+
- Table-driven tests are preferred for testing multiple scenarios/inputs. For an example, see [TestNamespaceAuthorization](https://git.k8s.io/kubernetes/test/integration/auth/auth_test.go).
40+
- Significant features should come with integration (test/integration) and/or [end-to-end (test/e2e) tests](/contributors/devel/sig-testing/e2e-tests.md).
41+
- Including new `kubectl` commands and major features of existing commands.
42+
- Unit tests must pass on macOS and Windows platforms - if you use Linux specific features, your test case must either be skipped on windows or compiled out (skipped is better when running Linux specific commands, compiled out is required when your code does not compile on Windows).
43+
- Avoid relying on Docker Hub. Use the [Google Cloud Container Registry](https://gcr.io) instead.
44+
- Do not expect an asynchronous thing to happen immediately---do not wait for one second and expect a pod to be running. Wait and retry instead.
9345
- See the [testing guide](/contributors/devel/sig-testing/testing.md) for additional testing advice.
9446

9547
## Directory and file conventions
9648

97-
- Avoid package sprawl. Find an appropriate subdirectory for new packages.
98-
(See [#4851](http://issues.k8s.io/4851) for discussion.)
99-
- Libraries with no more appropriate home belong in new package
100-
subdirectories of pkg/util
101-
102-
- Avoid general utility packages. Packages called "util" are suspect. Instead,
103-
derive a name that describes your desired function. For example, the utility
104-
functions dealing with waiting for operations are in the "wait" package and
105-
include functionality like Poll. So the full name is wait.Poll
106-
107-
- All filenames should be lowercase
108-
109-
- Go source files and directories use underscores, not dashes
110-
- Package directories should generally avoid using separators as much as
111-
possible (when packages are multiple words, they usually should be in nested
112-
subdirectories).
113-
114-
- Document directories and filenames should use dashes rather than underscores
115-
116-
- Contrived examples that illustrate system features belong in
117-
/docs/user-guide or /docs/admin, depending on whether it is a feature primarily
118-
intended for users that deploy applications or cluster administrators,
119-
respectively. Actual application examples belong in /examples.
120-
- Examples should also illustrate [best practices for configuration and using the system](https://kubernetes.io/docs/concepts/configuration/overview/)
121-
122-
- Third-party code
123-
124-
- Go code for normal third-party dependencies is managed using
125-
[go modules](https://github.com/golang/go/wiki/Modules) and is described in the kubernetes
126-
[vendoring guide](/contributors/devel/sig-architecture/vendor.md)
127-
128-
- Other third-party code belongs in `/third_party`
129-
- forked third party Go code goes in `/third_party/forked`
130-
- forked _golang stdlib_ code goes in `/third_party/forked/golang`
131-
132-
- Third-party code must include licenses
133-
134-
- This includes modified third-party code and excerpts, as well
49+
- Avoid package sprawl. Find an appropriate subdirectory for new packages. [See issue #4851](http://issues.k8s.io/4851) for discussion.
50+
- Libraries with no appropriate home belong in new package subdirectories of `pkg/util`.
51+
- Avoid general utility packages. Packages called "util" are suspect. Instead, derive a name that describes your desired function. For example, the utility functions dealing with waiting for operations are in the `wait` package and include functionality like `Poll`. The full name is `wait.Poll`.
52+
- All filenames should be lowercase.
53+
- Go source files and directories use underscores, not dashes.
54+
- Package directories should generally avoid using separators as much as possible. When package names are multiple words, they usually should be in nested subdirectories.
55+
- Document directories and filenames should use dashes rather than underscores.
56+
- Examples should also illustrate [best practices for configuration and using the system](https://kubernetes.io/docs/concepts/configuration/overview/).
57+
- Follow these conventions for third-party code:
58+
- Go code for normal third-party dependencies is managed using [go modules](https://github.com/golang/go/wiki/Modules) and is described in the kubernetes [vendoring guide](/contributors/devel/sig-architecture/vendor.md).
59+
- Other third-party code belongs in `third_party`.
60+
- forked third party Go code goes in `third_party/forked`.
61+
- forked _golang stdlib_ code goes in `third_party/forked/golang`.
62+
- Third-party code must include licenses. This includes modified third-party code and excerpts, as well.

0 commit comments

Comments
 (0)