Skip to content

Static analysis library for k8s operators created by operator-sdk

License

Notifications You must be signed in to change notification settings

gibizer/operator-lint

Repository files navigation

pre-commit.ci status

operator-lint

Static analysis library for k8s operators created by operator-sdk

Usage

  go install github.com/gibizer/operator-lint/
  go vet -vettool=$(which operator-lint)

Checks

Check Category Added in Description
T001 EnvTest v0.1.0 checks that Gomega's Eventually and Consistently blocks use a local Gomega instance for asserts
--- --- --- ---
C001 CRD v0.1.0 detects incompatible Required and Optional kubebuilder markers
C002 CRD v0.1.0 detects incompatible Required kubebuilder marker and omitemty golang tag
C003 CRD v0.2.2 detects incompatible defaulting via Optional kubebuilder marker and omitemty golang tag

Flags

Command line flags can be used to configure each check in the form of:

go vet -vettool=$(which operator-lint) -<check name>.<flag>

Common flags supported by each check:

  • <check name>.skip: can be used to disable the given check. E.g. the following command will not execute the check C003:
    go vet -vettool=$(which operator-lint) -C003.skip

You can use go vet -vettool=$(which operator-lint) -flags to print out all the supported flags

Adding a new check

  • Use make new-lint to generate a new empty linter under linters.
  • Update the README.md with the description of the check
  • If the test data for the check has dependencies then
    • Those dependencies needs to be imported in force_test_deps.go
    • The vendor directory needs to be symlinked to the directory holding the test data
    • Need to run
      go get <dep>
      go mod tidy
      go mod vendor

This whole dance is needed as the analysistest package does not support Go Modules currently.

About

Static analysis library for k8s operators created by operator-sdk

Resources

License

Stars

Watchers

Forks

Packages

No packages published