A FAST Kubernetes manifests validator, with support for Custom Resources!
Find a file
2020-06-07 19:00:28 +02:00
.github/workflows Add Dockerfile.bats 2020-06-04 19:46:53 +02:00
bin add -dir parameter 2020-05-30 15:49:02 +02:00
fixtures add test to validate a folder 2020-06-06 18:46:08 +02:00
pkg replace -schema with -local-registry 2020-06-07 18:59:03 +02:00
vendor vendor deps 2020-05-31 04:43:07 +02:00
.gitignore Add gitignore 2020-06-07 11:35:51 +02:00
.goreleaser.yml update goreleaser 2020-06-07 12:04:40 +02:00
acceptance.bats replace -schema with -local-registry 2020-06-07 18:59:03 +02:00
Dockerfile Add ca certificates to docker image 2020-06-07 13:14:17 +02:00
Dockerfile.bats Add Dockerfile.bats 2020-06-04 19:43:19 +02:00
go.mod skipKinds + better error logging 2020-05-30 07:02:48 +02:00
go.sum skipKinds + better error logging 2020-05-30 07:02:48 +02:00
LICENSE add License & simple Readme 2020-05-30 17:33:29 +02:00
main.go replace -schema with -local-registry 2020-06-07 18:59:03 +02:00
main_test.go loggers take an io.writer 2020-06-01 17:15:52 +02:00
Makefile Add ca certificates to docker image 2020-06-07 13:14:17 +02:00
Readme.md update readme 2020-06-07 19:00:28 +02:00

Kubeconform

Build status Go Report card

Kubeconform is a Kubernetes manifests validation tool. Build it into your CI to validate your Kubernetes configuration using the schemas from the registry maintained by the kubernetes-json-schema project!

It is inspired by and similar to Kubeval, but with the following improvements:

  • high performance: will validate & download manifests over multiple routines
  • support for Kubernetes CRDs

A small overview of Kubernetes manifest validation

Kubernetes's API is described using the OpenAPI (formerly swagger) specification, in a file checked into the main Kubernetes repository.

Because of the state of the tooling to perform validation against OpenAPI schemas, projects usually convert the OpenAPI schemas to JSON schemas first. Kubeval relies on instrumenta/OpenApi2JsonSchema to convert Kubernetes' Swagger file and break it down into multiple JSON schemas, stored in github at instrumenta/kubernetes-json-schema and published on kubernetesjsonschema.dev.

Kubeconform relies on the same JSON schemas from kubernetesjsonschema.dev, and will download required schemas at runtime as required.

Usage

$ ./bin/kubeconform -h
Usage of ./bin/kubeconform:
  -ignore-missing-schemas
        skip files with missing schemas instead of failing
  -k8sversion string
        version of Kubernetes to test against (default "1.18.0")
  -local-registry value
        folder containing additional schemas (can be specified multiple times)
  -n int
        number of routines to run in parallel (default 4)
  -output string
        output format - text, json (default "text")
  -skip string
        comma-separated list of kinds to ignore
  -strict
        disallow additional properties not in schema
  -summary
        print a summary at the end
  -verbose
        print results for all resources

Usage examples

  • Validating a single, valid file
$ ./bin/kubeconform fixtures/valid.yaml
$ echo $?
0
  • Validating a single invalid file, setting output to json, and printing a summary
$ ./bin/kubeconform -summary -output json fixtures/invalid.yaml
{
  "resources": [
    {
      "filename": "fixtures/invalid.yaml",
      "kind": "ReplicationController",
      "version": "v1",
      "status": "INVALID",
      "msg": "Additional property templates is not allowed - Invalid type. Expected: [integer,null], given: string"
    }
  ],
  "summary": {
    "valid": 0,
    "invalid": 1,
    "errors": 0,
    "skipped": 0
  }
}
$ echo $?
1
  • Validating a folder, increasing the number of parallel workers
$ ./bin/kubeconform -summary -n 16 fixtures
fixtures/multi_invalid.yaml - Service is invalid: Invalid type. Expected: integer, given: string
fixtures/invalid.yaml - ReplicationController is invalid: Invalid type. Expected: [integer,null], given: string
[...]
Summary: 48 resources found in 25 files - Valid: 39, Invalid: 2, Errors: 7 Skipped: 0

Credits