Skip to content

Commit 9ad19ec

Browse files
updated readme as per bryce's reviews
1 parent 930e1c8 commit 9ad19ec

File tree

3 files changed

+16
-37
lines changed

3 files changed

+16
-37
lines changed

.custom-gcl.yml

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

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/golangci-lint-kube-api-linter ./cmd/golangci-lint-kube-api-linter
70+
go build -o ./bin ./cmd/golangci-lint-kube-api-linter
7171

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

README.md

Lines changed: 13 additions & 34 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/golangci-lint-kube-api-linter ./cmd/golangci-lint-kube-api-linter
19+
go build -o ./bin ./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.
@@ -30,44 +30,35 @@ If you do not have `golangci-lint` installed, review the `golangci-lint` [instal
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.
34-
35-
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. The following is an example of a `.custom-gcl.yml` file:
3634

3735
```yaml
3836
version: v2.5.0
3937
name: golangci-lint-kube-api-linter
4038
destination: ./bin
4139
plugins:
42-
- module: 'sigs.k8s.io/kube-api-linter'
43-
version: 'v0.0.0-20251029102002-9992248f8813'
40+
- module: 'sigs.k8s.io/kube-api-linter'
41+
version: 'v0.0.0-20251029102002-9992248f8813'
4442
```
4543
4644
**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`.
4745

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"
52-
```
53-
54-
This will output a string like `20251029102002-9992248f8813`. Prepend `v0.0.0-` to form the complete version: `v0.0.0-20251029102002-9992248f8813`.
46+
To find the latest version listed, check [pkg.go.dev/sigs.k8s.io/kube-api-linter?tab=versions](https://pkg.go.dev/sigs.k8s.io/kube-api-linter?tab=versions)
5547

5648
Once you have created the custom configuration file, you can run the following command to build the custom binary:
5749

5850
```shell
5951
golangci-lint custom
6052
```
6153

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.
54+
The output binary will be created at the location specified by the `destination` field in `.custom-gcl.yml` and will be a combination of the `golangci-lint` binary with the Kube API Linter included as a module.
6355

6456
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.
6557

6658
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:
6759

6860
```yaml
6961
version: "2"
70-
7162
linters-settings:
7263
custom:
7364
kubeapilinter:
@@ -94,7 +85,6 @@ If you wish to only run selected linters you can do so by specifying the linters
9485

9586
```yaml
9687
version: "2"
97-
9888
linters-settings:
9989
custom:
10090
kubeapilinter:
@@ -107,7 +97,6 @@ linters-settings:
10797
- requiredfields
10898
- statusoptional
10999
- statussubresource
110-
111100
linters:
112101
enable:
113102
- kubeapilinter
@@ -123,45 +112,36 @@ To provide further configuration, add the `custom.kubeapilinter` section to your
123112
Where fixes are available within a rule, these can be applied automatically with the `--fix` flag:
124113

125114
```shell
126-
./bin/golangci-lint-kube-api-linter run path/to/api/types --fix
115+
golangci-lint-kube-api-linter run path/to/api/types --fix
127116
```
128117

129118
### Golangci-lint Plugin
130119

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

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

136125
[golangci-lint-plugin-docs]: https://golangci-lint.run/plugins/go-plugins/
137126

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:
127+
To build the plugin, use the `-buildmode=plugin` flag:
141128

142129
```shell
143-
go mod vendor
130+
go build -buildmode=plugin -o bin/kube-api-linter.so sigs.k8s.io/kube-api-linter/pkg/plugin
144131
```
145132

146-
**Step 2**: Build the plugin from the vendor directory:
133+
**Note**: If you're building the plugin from within another project that vendors kube-api-linter, use the vendor path:
147134

148135
```shell
149-
go build -mod=vendor -buildmode=plugin -o $(OUTPUT_DIR)/kube-api-linter.so ./vendor/sigs.k8s.io/kube-api-linter
136+
go build -mod=vendor -buildmode=plugin -o bin/kube-api-linter.so ./vendor/sigs.k8s.io/kube-api-linter/pkg/plugin
150137
```
151138

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-
```
157-
158-
This will create a `kube-api-linter.so` plugin file in the `bin` directory.
139+
This will create a `kube-api-linter.so` plugin file in the specified directory.
159140

160141
The `golangci-lint` configuration is similar to the module configuration, however, you will need to specify the plugin path instead in your `.golangci.yml`:
161142

162143
```yaml
163144
version: "2"
164-
165145
linters-settings:
166146
custom:
167147
kubeapilinter:
@@ -171,7 +151,6 @@ linters-settings:
171151
settings:
172152
linters: {}
173153
lintersConfig: {}
174-
175154
linters:
176155
enable:
177156
- kubeapilinter

0 commit comments

Comments
 (0)