Lint
- kosko v4.1.0
Install
- NPM
- Yarn
- PNPM
npm install @kosko/plugin-lint
yarn add @kosko/plugin-lint
pnpm install @kosko/plugin-lint
Usage
Enable the plugin with the recommended preset.
[[plugins]]
name = "@kosko/plugin-lint"
config.extends = ["@kosko/plugin-lint/presets/recommended"]
Enable specific rules.
[[plugins]]
name = "@kosko/plugin-lint"
[plugins.config.rules.no-missing-namespace]
severity = "error"
[plugins.config.rules.ban-image]
severity = "error"
config.images = ["*:latest"]
Configuration
extends
Load configuration from another file. The value could be a package name or a path to a JavaScript or JSON file.
Examples
# Preset
extends = ["@kosko/plugin-lint/presets/recommended"]
# Local file
extends = ["./lint-config.js"]
rules
Configure a lint rule. Every rule has two properties: config and severity. The config property is specific to each rule, and the severity property can be one of the following values:
"off",0,false- Disable the rule. (Default)"warning","warn",1- Enable the rule as a warning. When the rule is violated, a warning will be reported, but the validation won't fail."error",2,true- Enable the rule as an error. When the rule is violated, an error will be reported, and the validation will fail.
Examples
[rules.ban-image]
severity = "error"
config.images = ["*:latest"]
Preset
Currently there is only one preset available: @kosko/plugin-lint/presets/recommended. This preset contains rules with Rec badge.
You can enable it by adding extends to the configuration.
[[plugins]]
name = "@kosko/plugin-lint"
config.extends = ["@kosko/plugin-lint/presets/recommended"]
Disabling Rules
There are several ways to disable a lint rule. The simplest way is to set the severity to "off". However, it disables the rule for all manifests. To disable a rule for a specific manifest, you can use the config provided by some rules. For examples, the no-missing-* rules have an allow config which lets you allow some patterns to be missing.
Some rules don't have this kind of config. In this case, you can add kosko.dev/disable-lint annotation to a manifest to disable specific rules. The value should be a comma-separated list of rule names. You can also use * to disable all rules.
new Pod({
metadata: {
annotations: {
// Disable specific lint rules
"kosko.dev/disable-lint": "no-missing-pvc, require-namespace",
// Disable all lint rules
"kosko.dev/disable-lint": "*"
}
}
});
Caveats
- This plugin does not validate manifests against OpenAPI schema. That is what kubernetes-models does. See validation for more details.
- This plugin only executes when validation is enabled.
- Rules with All badge are disabled when
componentsis provided inkosko generateorkosko validatecommand, because these rules need to access all components to validate.