Skip to content

Commit 930e1c8

Browse files
docs: Fix installation instructions for golangci-lint v2 compatibility
1 parent 5fca1e8 commit 930e1c8

File tree

3 files changed

+72
-28
lines changed

3 files changed

+72
-28
lines changed

.custom-gcl.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
version: v2.0.2
2-
name: golangci-kube-api-linter
1+
version: v2.5.0
2+
name: golangci-lint-kube-api-linter
33
destination: ./bin
44
plugins:
5-
- module: 'sigs.k8s.io/kube-api-linter'
6-
path: ./
5+
- module: 'sigs.k8s.io/kube-api-linter'
6+
version: 'v0.0.0-20251029172002-9992248f8813'

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ unit: ## Run unit tests.
6767

6868
.PHONY: build
6969
build: ## Build the golangci-lint custom plugin binary.
70-
go build -o ./bin ./cmd/golangci-lint-kube-api-linter
70+
go build -o ./bin/golangci-lint-kube-api-linter ./cmd/golangci-lint-kube-api-linter
7171

7272
.PHONY: verify-%
7373
verify-%:

README.md

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Kube API Linter ships as a standalone binary, golangci-lint plugin, and a golang
1616

1717
The binary version of Kube API Linter can be built with `make build` or a standard `go build` command.
1818
```bash
19-
go build -o ./bin ./cmd/golangci-lint-kube-api-linter
19+
go build -o ./bin/golangci-lint-kube-api-linter ./cmd/golangci-lint-kube-api-linter
2020
```
2121

2222
The binary builds a custom version of `golangci-lint` with Kube API Linter included as a module.
@@ -25,42 +25,58 @@ under `linter-settings`.
2525

2626
### Golangci-lint Module
2727

28-
To install the `golangci-lint` module, first you must have `golangci-lint` installed.
28+
To install the `golangci-lint` module, first you must have `golangci-lint` v2 installed.
2929
If you do not have `golangci-lint` installed, review the `golangci-lint` [install guide][golangci-lint-install].
3030

3131
[golangci-lint-install]: https://golangci-lint.run/welcome/install/
3232

33-
You will need to create a `.custom-gcl.yml` file to describe the custom linters you want to run. The following is an example of a `.custom-gcl.yml` file:
33+
You will need to create a `.custom-gcl.yml` file to describe the custom linters you want to run.
34+
35+
The following is an example of a `.custom-gcl.yml` file:
3436

3537
```yaml
36-
version: v1.64.8
37-
name: golangci-kube-api-linter
38+
version: v2.5.0
39+
name: golangci-lint-kube-api-linter
3840
destination: ./bin
3941
plugins:
40-
- module: 'sigs.k8s.io/kube-api-linter'
41-
version: 'v0.0.0' # Replace with the latest version
42+
- module: 'sigs.k8s.io/kube-api-linter'
43+
version: 'v0.0.0-20251029102002-9992248f8813'
44+
```
45+
46+
**Important - Version Format**: Since this repository does not have releases yet, you must use a [pseudo-version](https://go.dev/ref/mod#pseudo-versions) in the format `v0.0.0-YYYYMMDDHHMMSS-commithash`.
47+
48+
To get the correct pseudo-version for the latest commit, run:
49+
50+
```bash
51+
TZ=UTC git --no-pager show --quiet --abbrev=12 --date='format-local:%Y%m%d%H%M%S' --format="%cd-%h"
4252
```
4353

44-
Once you have created the custom configuration file, you can run the following command to build the custom `golangci-kal` binary:
54+
This will output a string like `20251029102002-9992248f8813`. Prepend `v0.0.0-` to form the complete version: `v0.0.0-20251029102002-9992248f8813`.
55+
56+
Once you have created the custom configuration file, you can run the following command to build the custom binary:
4557

4658
```shell
4759
golangci-lint custom
4860
```
4961

50-
The output binary will be a combination of the initial `golangci-lint` binary and the Kube API linter plugin.
51-
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.
62+
The output binary `./bin/golangci-lint-kube-api-linter` will be a combination of the `golangci-lint` binary with the Kube API Linter included as a module.
63+
64+
This means you can use any of the standard `golangci-lint` configuration or flags to run the binary, with the addition of the Kube API Linter rules.
5265

5366
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:
5467

5568
```yaml
69+
version: "2"
70+
5671
linters-settings:
5772
custom:
5873
kubeapilinter:
5974
type: "module"
60-
description: Kube API LInter lints Kube like APIs based on API conventions and best practices.
75+
description: Kube API Linter lints Kube like APIs based on API conventions and best practices.
6176
settings:
6277
linters: {}
6378
lintersConfig: {}
79+
6480
linters:
6581
disable-all: true
6682
enable:
@@ -77,6 +93,8 @@ issues:
7793
If you wish to only run selected linters you can do so by specifying the linters you want to enable in the `linters` section:
7894

7995
```yaml
96+
version: "2"
97+
8098
linters-settings:
8199
custom:
82100
kubeapilinter:
@@ -89,6 +107,10 @@ linters-settings:
89107
- requiredfields
90108
- statusoptional
91109
- statussubresource
110+
111+
linters:
112+
enable:
113+
- kubeapilinter
92114
```
93115

94116
The settings for Kube API Linter are based on the [GolangCIConfig][golangci-config-struct] struct and allow for finer control over the linter rules.
@@ -98,63 +120,85 @@ To provide further configuration, add the `custom.kubeapilinter` section to your
98120

99121
[golangci-config-struct]: https://pkg.go.dev/sigs.k8s.io/kube-api-linter/pkg/config#GolangCIConfig
100122

101-
Where fixes are available within a rule, these can be applied automatically with the `--fix` flag.
123+
Where fixes are available within a rule, these can be applied automatically with the `--fix` flag:
102124

103125
```shell
104-
golangci-kube-api-linter run path/to/api/types --fix
126+
./bin/golangci-lint-kube-api-linter run path/to/api/types --fix
105127
```
106128

107129
### Golangci-lint Plugin
108130

109131
The Kube API Linter can also be used as a plugin for `golangci-lint`.
110-
To do this, you will need to install the `golangci-lint` binary and then install the Kube API Linter plugin.
132+
To do this, you will need to install the `golangci-lint` binary and then build the Kube API Linter plugin.
111133

112134
More information about golangci-lint plugins can be found in the [golangci-lint plugin documentation][golangci-lint-plugin-docs].
113135

114136
[golangci-lint-plugin-docs]: https://golangci-lint.run/plugins/go-plugins/
115137

138+
**Important**: The plugin must be built from the vendor directory, not directly from the module path.
139+
140+
**Step 1**: Ensure the module is in your project's vendor directory:
141+
142+
```shell
143+
go mod vendor
144+
```
145+
146+
**Step 2**: Build the plugin from the vendor directory:
147+
116148
```shell
117-
go build -buildmode=plugin -o bin/kube-api-linter.so sigs.k8s.io/kube-api-linter/pkg/plugin
149+
go build -mod=vendor -buildmode=plugin -o $(OUTPUT_DIR)/kube-api-linter.so ./vendor/sigs.k8s.io/kube-api-linter
118150
```
119151

120-
This will create a `kube-api-linter.so` file in the `bin` directory.
152+
Example - building into a `bin` directory:
153+
154+
```shell
155+
go build -mod=vendor -buildmode=plugin -o bin/kube-api-linter.so ./vendor/sigs.k8s.io/kube-api-linter
156+
```
121157

122-
The `golangci-lint` configuration is similar to the module configuration, however, you will need to specify the plugin path instead.
158+
This will create a `kube-api-linter.so` plugin file in the `bin` directory.
159+
160+
The `golangci-lint` configuration is similar to the module configuration, however, you will need to specify the plugin path instead in your `.golangci.yml`:
123161

124162
```yaml
163+
version: "2"
164+
125165
linters-settings:
126166
custom:
127167
kubeapilinter:
128168
path: "bin/kube-api-linter.so"
129-
description: Kube API LInter lints Kube like APIs based on API conventions and best practices.
169+
description: Kube API Linter lints Kube like APIs based on API conventions and best practices.
130170
original-url: sigs.k8s.io/kube-api-linter
131171
settings:
132172
linters: {}
133173
lintersConfig: {}
174+
175+
linters:
176+
enable:
177+
- kubeapilinter
134178
```
135179

136180
The rest of the configuration is the same as the module configuration, except the standard `golangci-lint` binary is invoked, rather than a custom binary.
137181

138182
#### VSCode integration
139183

140-
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.
184+
Since VSCode already integrates with `golangci-lint` via the [Go][vscode-go] extension, you can use the custom `golangci-lint-kube-api-linter` binary as a linter in VSCode.
185+
141186
If your project authors are already using VSCode and have the configuration to lint their code when saving, this can be a seamless integration.
142187

143-
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.
188+
Ensure that your project setup includes building the `golangci-lint-kube-api-linter` binary, then configure the `go.lintTool` and `go.alternateTools` settings in your project `.vscode/settings.json` file:
144189

145190
[vscode-go]: https://code.visualstudio.com/docs/languages/go
146191

147192
```json
148193
{
149194
"go.lintTool": "golangci-lint",
150195
"go.alternateTools": {
151-
"golangci-lint": "${workspaceFolder}/bin/golangci-kube-api-linter",
196+
"golangci-lint": "${workspaceFolder}/bin/golangci-lint-kube-api-linter"
152197
}
153198
}
154199
```
155200

156-
Alternatively, you can also replace the binary with a script that runs the `golangci-kube-api-linter` binary,
157-
allowing for customisation or automatic copmilation of the project should it not already exist.
201+
Alternatively, you can also replace the binary with a script that runs the `golangci-lint-kube-api-linter` binary, allowing for customization or automatic compilation of the project should it not already exist:
158202

159203
```json
160204
{

0 commit comments

Comments
 (0)