You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-59Lines changed: 32 additions & 59 deletions
Original file line number
Diff line number
Diff line change
@@ -1,48 +1,16 @@
1
-
# KAL - The Kubernetes API Linter
1
+
# Kube API Linter
2
2
3
-
KAL is a Golang based linter for Kubernetes API types. It checks for common mistakes and enforces best practices.
4
-
The rules implemented by KAL, are based on the [Kubernetes API Conventions][api-conventions].
3
+
Kube API Linter (KAL) is a Golang based linter for Kubernetes API types.
4
+
It checks for common mistakes and enforces best practices.
5
+
The rules implemented by the Kube API Linter, are based on the [Kubernetes API Conventions][api-conventions].
5
6
6
-
KAL is aimed at being an assistant to API review, by catching the mechanical elements of API review, and allowing reviewers to focus on the more complex aspects of API design.
7
+
Kube API Linter is aimed at being an assistant to API review, by catching the mechanical elements of API review, and allowing reviewers to focus on the more complex aspects of API design.
KAL currently comes in two flavours, a standalone binary, and a golangci-lint plugin.
13
-
14
-
### Standalone Binary
15
-
16
-
To install the standalone binary, run the following command:
17
-
18
-
```shell
19
-
go install sigs.k8s.io/kube-api-linter/cmd/kal@latest
20
-
```
21
-
22
-
The standalone binary can be run with the following command:
23
-
24
-
```shell
25
-
kal path/to/api/types
26
-
```
27
-
28
-
`kal` currently accepts no complex configuration, and will run all checks considered to be default.
29
-
30
-
Individual linters can be disabled with the flag corresponding to the linter name. For example, to disable the `commentstart` linter, run the following command:
31
-
32
-
```shell
33
-
kal -commentstart=false path/to/api/types
34
-
```
35
-
36
-
Where fixes are available, these can be applied automatically with the `-fix` flag.
37
-
Note, automatic fixing is currently only available via the standalone binary, and is not available via the `golangci-lint` plugin.
38
-
39
-
```shell
40
-
kal -fix path/to/api/types
41
-
```
42
-
43
-
Other standard Golang linter flags implemented by [multichecker][multichecker] based linters are also supported.
@@ -55,7 +23,7 @@ You will need to create a `.custom-gcl.yml` file to describe the custom linters
55
23
56
24
```yaml
57
25
version: v1.62.0
58
-
name: golangci-kal
26
+
name: golangci-kube-api-linter
59
27
destination: ./bin
60
28
plugins:
61
29
- module: 'sigs.k8s.io/kube-api-linter'
@@ -68,60 +36,65 @@ Once you have created the custom configuration file, you can run the following c
68
36
golangci-lint custom
69
37
```
70
38
71
-
The output binary will be a combination of the initial `golangci-lint` binary and the KAL linters.
72
-
This means that you can use any of the standard `golangci-lint` configuration or flags to run the binary, but may also include the KAL linters.
39
+
The output binary will be a combination of the initial `golangci-lint` binary and the Kube API linter plugin.
40
+
This means that you can use any of the standard `golangci-lint` configuration or flags to run the binary, but may also include the Kube API Linter rules.
73
41
74
-
If you wish to only use the KAL linters, you can configure your `.golangci.yml` file to only run the KAL linters:
42
+
If you wish to only use the Kube API Linter rules, you can configure your `.golangci.yml` file to only run the Kube API Linter:
75
43
76
44
```yaml
77
45
linters-settings:
78
46
custom:
79
-
kal:
47
+
kubeapilinter:
80
48
type: "module"
81
-
description: KAL is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices.
49
+
description: KubeAPI LInter lints Kube like APIs based on API conventions and best practices.
82
50
settings:
83
51
linters: {}
84
52
lintersConfig: {}
85
53
linters:
86
54
disable-all: true
87
55
enable:
88
-
- kal
56
+
- kubeapilinter
89
57
90
-
# To only run KAL on specific path
58
+
# To only run Kube API Linter on specific path
91
59
issues:
92
60
exclude-rules:
93
61
- path-except: "api/*"
94
62
linters:
95
-
- kal
63
+
- kubeapilinter
96
64
```
97
65
98
-
The settings for KAL are based on the [GolangCIConfig][golangci-config-struct] struct and allow for finer control over the linter rules.
99
-
The finer control over linter rules is not currently avaialable outside of the plugin based version of KAL.
66
+
The settings for Kube API Linter are based on the [GolangCIConfig][golangci-config-struct] struct and allow for finer control over the linter rules.
100
67
101
-
If you wish to use the KAL linters in conjunction with other linters, you can enable the KAL linters in the `.golangci.yml` file by ensuring that `kal` is in the `linters.enabled` list.
102
-
To provide further configuration, add the `custom.kal` section to your `linter-settings` as per the example above.
68
+
If you wish to use the Kube API Linter in conjunction with other linters, you can enable the Kube API Linter in the `.golangci.yml` file by ensuring that `kubeapilinter` is in the `linters.enabled` list.
69
+
To provide further configuration, add the `custom.kubeapilinter` section to your `linter-settings` as per the example above.
Where fixes are available within a rule, these can be applied automatically with the `--fix` flag.
74
+
75
+
```shell
76
+
golangci-kube-api-linter run path/to/api/types --fix
77
+
```
78
+
106
79
#### VSCode integration
107
80
108
81
Since VSCode already integrates with `golangci-lint` via the [Go][vscode-go] extension, you can use the `golangci-kal` binary as a linter in VSCode.
109
82
If your project authors are already using VSCode and have the configuration to lint their code when saving, this can be a seamless integration.
110
83
111
-
Ensure that your project setup includes building the `golangci-kal` binary, and then configure the `go.lintTool` and `go.alternateTools` settings in your project `.vscode/settings.json` file.
84
+
Ensure that your project setup includes building the `golangci-kube-api-linter` binary, and then configure the `go.lintTool` and `go.alternateTools` settings in your project `.vscode/settings.json` file.
Alternatively, you can also replace the binary with a script that runs the `golangci-kal` binary,
97
+
Alternatively, you can also replace the binary with a script that runs the `golangci-kube-api-linter` binary,
125
98
allowing for customisation or automatic copmilation of the project should it not already exist.
126
99
127
100
```json
@@ -164,7 +137,7 @@ lintersConfig:
164
137
usePatchStrategy: SuggestFix | Warn | Ignore | Forbid # The policy for the patchStrategy tag on the Conditions field. Defaults to `SuggestFix`.
165
138
```
166
139
167
-
### Fixes (via standalone binary only)
140
+
### Fixes
168
141
169
142
The `conditions` linter can automatically fix the tags on the `Conditions` field.
170
143
When they do not match the expected format, the linter will suggest to update the tags to match the expected format.
@@ -184,7 +157,7 @@ When `usePatchStrategy` is set to `Forbid`, the linter will suggest to remove th
184
157
The `commentstart` linter checks that all comments in the API types start with the serialized form of the type they are commenting on.
185
158
This helps to ensure that generated documentation reflects the most common usage of the field, the serialized YAML form.
186
159
187
-
### Fixes (via standalone binary only)
160
+
### Fixes
188
161
189
162
The `commentstart` linter can automatically fix comments that do not start with the serialized form of the type.
190
163
@@ -276,7 +249,7 @@ lintersConfig:
276
249
preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`.
277
250
```
278
251
279
-
### Fixes (via standalone binary only)
252
+
### Fixes
280
253
281
254
The `optionalorrequired` linter can automatically fix fields that are using the incorrect form of either the optional or required marker.
282
255
@@ -295,7 +268,7 @@ lintersConfig:
295
268
pointerPolicy: Warn | SuggestFix # The policy for pointers in required fields. Defaults to `SuggestFix`.
296
269
```
297
270
298
-
### Fixes (via standalone binary only)
271
+
### Fixes
299
272
300
273
The `requiredfields` linter can automatically fix fields that are marked as required, but are pointers.
301
274
@@ -313,7 +286,7 @@ OR when the `kubebuilder:subresource:status` marker is present on the struct the
313
286
314
287
This linter is not enabled by default as it is only applicable to CustomResourceDefinitions.
315
288
316
-
### Fixes (via standalone binary only)
289
+
### Fixes
317
290
318
291
In the case where there is a status field present but no `kubebuilder:subresource:status` marker, the
319
292
linter will suggest adding the comment `// +kubebuilder:subresource:status` above the struct.
Copy file name to clipboardExpand all lines: doc.go
+18-18Lines changed: 18 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -15,36 +15,36 @@ limitations under the License.
15
15
*/
16
16
17
17
/*
18
-
KAL is a linter for Kubernetes API types, that implements API conventions and best practices.
18
+
Kube API Linter (KAL) is a linter for Kubernetes API types, that implements API conventions and best practices.
19
19
20
20
This package provides a GolangCI-Lint plugin that can be used to build a custom linter for Kubernetes API types.
21
-
The custom golangci-lint binary can be built by checking out the KAL repository and running `make build-golangci`.
21
+
The custom golangci-lint binary can be built by checking out the Kube API Linter repository and running `make build`.
22
22
This will generate a custom golangci-lint binary in the `bin` directory.
23
23
24
-
The custom golangci-lint binary can be run with the `run` command, and the KAL linters can be enabled by setting the `kal` linter in the `.golangci.yml` configuration file.
24
+
The custom golangci-lint binary can be run with the `run` command, and the Kube API Linter rules can be enabled by setting the `kube-api-linter` linter in the `.golangci.yml` configuration file.
25
25
26
26
Example `.golangci.yml` configuration file:
27
27
28
28
linters-settings:
29
29
custom:
30
-
kal:
31
-
type: "module"
32
-
description: KAL is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices.
33
-
settings:
34
-
linters:
35
-
enabled: []
36
-
disabled: []
37
-
lintersConfig:
38
-
jsonTags:
39
-
jsonTagRegex: ""
40
-
optionalOrRequired:
41
-
preferredOptionalMarker: ""
42
-
preferredRequiredMarker: ""
30
+
kubeapilinter::
31
+
type: "module"
32
+
description: KubeAPI Linter lints Kube like APIs based on API conventions and best practices.
33
+
settings:
34
+
linters:
35
+
enabled: []
36
+
disabled: []
37
+
lintersConfig:
38
+
jsonTags:
39
+
jsonTagRegex: ""
40
+
optionalOrRequired:
41
+
preferredOptionalMarker: ""
42
+
preferredRequiredMarker: ""
43
43
linters:
44
44
disable-all: true
45
45
enable:
46
-
- kal
46
+
- kubeapilinter
47
47
48
48
New linters can be added in the [sigs.k8s.io/kube-api-linter/pkg/analysis] package.
0 commit comments