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
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:
36
34
37
35
```yaml
38
36
version: v2.5.0
39
37
name: golangci-lint-kube-api-linter
40
38
destination: ./bin
41
39
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'
44
42
```
45
43
46
44
**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
45
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)
55
47
56
48
Once you have created the custom configuration file, you can run the following command to build the custom binary:
57
49
58
50
```shell
59
51
golangci-lint custom
60
52
```
61
53
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.
63
55
64
56
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.
65
57
66
58
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:
67
59
68
60
```yaml
69
61
version: "2"
70
-
71
62
linters-settings:
72
63
custom:
73
64
kubeapilinter:
@@ -94,7 +85,6 @@ If you wish to only run selected linters you can do so by specifying the linters
94
85
95
86
```yaml
96
87
version: "2"
97
-
98
88
linters-settings:
99
89
custom:
100
90
kubeapilinter:
@@ -107,7 +97,6 @@ linters-settings:
107
97
- requiredfields
108
98
- statusoptional
109
99
- statussubresource
110
-
111
100
linters:
112
101
enable:
113
102
- kubeapilinter
@@ -123,45 +112,36 @@ To provide further configuration, add the `custom.kubeapilinter` section to your
123
112
Where fixes are available within a rule, these can be applied automatically with the `--fix` flag:
124
113
125
114
```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
127
116
```
128
117
129
118
### Golangci-lint Plugin
130
119
131
120
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.
133
122
134
123
More information about golangci-lint plugins can be found in the [golangci-lint plugin documentation][golangci-lint-plugin-docs].
**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:
141
128
142
129
```shell
143
-
go mod vendor
130
+
go build -buildmode=plugin -o bin/kube-api-linter.so sigs.k8s.io/kube-api-linter/pkg/plugin
144
131
```
145
132
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:
147
134
148
135
```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
150
137
```
151
138
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.
159
140
160
141
The `golangci-lint` configuration is similar to the module configuration, however, you will need to specify the plugin path instead in your `.golangci.yml`:
0 commit comments