Skip to content

Commit 51143ce

Browse files
authored
Add README and documentation (#5)
1 parent aa4e247 commit 51143ce

File tree

28 files changed

+536
-27
lines changed

28 files changed

+536
-27
lines changed

.circleci/config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ jobs:
1616
command: |
1717
make lint
1818
19+
- run:
20+
name: Ensure generated docs are up-to-date
21+
command: |
22+
make generated-docs
23+
git diff --exit-code HEAD
24+
25+
test:
26+
executor: custom
27+
steps:
28+
- checkout
29+
- run:
30+
name: Run unit tests
31+
command: |
32+
make test
33+
1934
workflows:
2035
version: 2
2136
build:
@@ -24,3 +39,7 @@ workflows:
2439
filters:
2540
tags:
2641
only: /.*/
42+
- test:
43+
filters:
44+
tags:
45+
only: /.*/

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ linters-settings:
5454
- unnecessaryDefer
5555
- importShadow
5656
- emptyStringTest
57+
- hugeParam
5758
nolintlint:
5859
allow-leading-space: false # require machine-readable nolint directives (i.e. with no leading space)
5960
allow-unused: false # report any unused nolint directives

Makefile

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,33 @@ staticcheck: $(STATICCHECK_BIN)
6060
.PHONY: lint
6161
lint: golangci-lint staticcheck
6262

63-
#############
64-
## Compile ##
65-
#############
63+
####################
64+
## Code generation #
65+
####################
66+
67+
.PHONY: generated-docs
68+
generated-docs: build
69+
./bin/kube-linter templates list --format markdown > docs/generated/templates.md
70+
./bin/kube-linter checks list --format markdown > docs/generated/checks.md
6671

6772
.PHONY: packr
6873
packr: $(PACKR_BIN)
6974
packr
7075

76+
#############
77+
## Compile ##
78+
#############
79+
80+
7181
.PHONY: build
7282
build: packr
73-
go build -o kube-linter ./cmd/kubelinter
83+
go build -o ./bin/kube-linter ./cmd/kube-linter
84+
85+
##########
86+
## Test ##
87+
##########
88+
89+
.PHONY: test
90+
test: packr
91+
go test ./...
92+

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
11
# kube-linter
2+
3+
kube-linter is a static analysis tool that checks Kubernetes YAML files to ensure the applications represented in them
4+
adhere to best practices.
5+
6+
In detail, `kube-linter` is a binary that takes in paths to YAML files, and runs a list of checks
7+
against them. If any lint errors are found, they are printed to standard error, and `kube-linter` returns a non-zero
8+
exit code.
9+
10+
The list of checks that is run is configurable. `kube-linter` comes with several built-in checks, only some of which
11+
are enabled by default. Users can also create custom checks.
12+
13+
## Install
14+
15+
If you have `go` installed, you can run `go get golang.stackrox.io/kube-linter/cmd/kube-linter`.
16+
17+
Alternatively, `kube-linter` binaries can be downloaded from [the Releases page](https://github.com/stackrox/kube-linter/releases).
18+
Download the `kube-linter` binary, and add it to your PATH.
19+
20+
You can also build `kube-linter` from source by cloning the repo, and running `make build`. This will compile a `kube-linter`
21+
binary into the `bin` folder inside the repo.
22+
23+
Note that you will need to have the `go` command installed for this to work.
24+
To install the Go command, follow the instructions [here](https://golang.org/doc/install).
25+
26+
## Usage
27+
28+
See the [documentation](./docs) for details on how to get started.
29+
30+
# WARNING: Breaking changes possible
31+
32+
kube-linter is currently in a very early stage of development. There may be breaking changes to the command usage, flags
33+
and config file formats.

bin/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
File renamed without changes.

config.yaml.example

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# customChecks defines custom checks.
2+
customChecks:
3+
- name: "required-label-app"
4+
template: "required-label"
5+
params:
6+
key: "app"
7+
checks:
8+
# if doNotAutoAddDefaults is true, default checks are not automatically added.
9+
doNotAutoAddDefaults: false
10+
11+
# include explicitly adds checks, by name. You can reference any of the built-in checks.
12+
# Note that customChecks defined above are included automatically.
13+
include:
14+
- "required-label-owner"
15+
# exclude explicitly excludes checks, by name. exclude has the highest priority: if a check is
16+
# in exclude, then it is not considered, even if it is in include as well.
17+
exclude:
18+
- "privileged"

docs/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
# Documentation
3+
4+
Welcome to the `kube-linter` documentation. Read on for more detailed information about using and configuring the tool.
5+
6+
## Exploring the CLI
7+
8+
You can run `kube-linter --help` to see a list of supported commands and flags. For each subcommand, you can
9+
run `kube-linter <subcommand> --help` to see detailed help text and flags for it.
10+
11+
## Running the linter
12+
13+
To lint directories or files, simply run `./kube-linter lint files_or_dirs ...`. If a directory is passed, all files
14+
with `.yaml` or `.yml` extensions are parsed, and Kubernetes objects are loaded from them. If a file is passed,
15+
it is parsed irrespective of extension.
16+
17+
Users can pass a config file using the `--config` flag to control which checks are executed, and to configure custom checks.
18+
An example config file is provided [here](../config.yaml.example).
19+
20+
## Built-in checks
21+
22+
`kube-linter` comes with a list of built-in checks, which you can find [here](generated/checks.md). Only some
23+
built-in checks are enabled by default -- others must be explicitly enabled in the config.
24+
25+
## Custom checks
26+
27+
### Check Templates
28+
29+
In `kube-linter`, checks are concrete realizations of check templates. A check template describes a class of check -- it
30+
contains logic (written in Go code) that would execute the check, and lays out (zero or more) parameters that it takes.
31+
32+
The list of supported check templates, along with their metadata, can be found [here](generated/templates.md).
33+
34+
### Custom checks
35+
36+
All checks in `kube-linter` are defined by referencing a check template, passing parameters to it, and adding additional
37+
check specific metadata (like check name and description). Users can configure custom checks the same way built-in checks
38+
are configured, and add them to the config file. The built-in checks are specified [here](../internal/builtinchecks).

docs/generated/checks.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The following table enumerates built-in checks:
2+
3+
| Name | Enabled by default | Description | Template | Parameters |
4+
| ---- | ------------------ | ----------- | -------- | ---------- |
5+
| env-var-secret | No | Alert on objects using a secret in an environment variable | env-var |- `name`: `.*secret.*` <br />|
6+
| privileged-container | Yes | Alert on deployments with containers running in privileged mode | privileged | none |
7+
| required-label-owner | No | Alert on objects without the 'owner' label | required-label |- `key`: `owner` <br />|

docs/generated/templates.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The following table enumerates supported check templates:
2+
3+
| Name | Description | Supported Objects | Parameters |
4+
| ---- | ----------- | ----------------- | ---------- |
5+
| env-var | Flag environment variables that match the provided patterns | DeploymentLike |- `name` (required): A regex for the env var name <br />- `value`: A regex for the env var value <br />|
6+
| privileged | Flag privileged containers | DeploymentLike | none |
7+
| required-label | Flag objects not carrying at least one label matching the provided patterns | Any |- `key` (required): A regex for the key of the required label <br />- `value`: A regex for the value of the required label <br />|

0 commit comments

Comments
 (0)