Skip to main content

validates kubernetes resource definitions against schemas

Project description

kubernetes-validate

kubernetes-validate validates Kubernetes resource definitions against the declared Kubernetes schemas.

Based on Gareth Rushgrove's excellent work providing a basis for turning Kubernetes Swagger API definitions into JSONSchema definitions, kubernetes-validate will report on mismatches between schema defnition and resource definition

Note that this currently uses a fork of kubernetes-json-schema for the following reasons:

Furthermore, the module now includes only the .0 API schemas, as they change so little within a Kubernetes version (there are some differences but they seem to be mostly irrelevant to validation - e.g. description updates). This has taken the module down from 300MB to less than 30MB.

If the relevant PRs get accepted upstream, then this will revert to the upstream fork.

Installation

pip install kubernetes-validate

Usage

Command line

$ kubernetes-validate
usage: kubernetes-validate [-h] [-k KUBERNETES_VERSION] [--strict] [--version]
                           ...

validate a kubernetes resource definition

positional arguments:
  filenames

optional arguments:
  -h, --help            show this help message and exit
  -k KUBERNETES_VERSION, --kubernetes-version KUBERNETES_VERSION
                        version of kubernetes against which to validate.
                        Defaults to major/minor version of kubernetes-validate
                        (i.e. 1.22.1 supports kubernetes 1.22). Patch versions
                        of the version are ignored (1.22.4 validates against
                        1.22.0)
  --strict              whether to use strict validation, rejecting unexpected
                        properties
  --quiet               whether to only output warnings/failures
  --no-warn             whether to hide warnings
  --version             show program's version number and exit

e.g.

$ kubernetes-validate -k 1.27 --strict resource.yml

Python

from __future__ import print_function
import kubernetes_validate
import yaml

try:
    data = yaml.load(open('resource.yaml').read())
    kubernetes_validate.validate(data, '1.22', strict=True)
except kubernetes_validate.ValidationError as e:
    print(''. join(e.path), e.message)

Examples

$ kubernetes-validate -k 1.21 examples/kuard-extra-property.yaml
INFO  examples/kuard-extra-property.yaml passed against version 1.21
$ kubernetes-validate --strict examples/kuard-extra-property.yaml
ERROR examples/kuard-extra-property.yaml did not validate against version 1.28.0: spec.selector: Additional properties are not allowed ('unwanted' was unexpected)
$ kubernetes-validate examples/kuard-invalid-type.yaml
ERROR examples/kuard-invalid-type.yaml did not validate against version 1.28.0: spec.replicas: 'hello' is not of type u'integer'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kubernetes_validate-1.35.0.tar.gz (8.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kubernetes_validate-1.35.0-py3-none-any.whl (18.1 MB view details)

Uploaded Python 3

File details

Details for the file kubernetes_validate-1.35.0.tar.gz.

File metadata

  • Download URL: kubernetes_validate-1.35.0.tar.gz
  • Upload date:
  • Size: 8.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kubernetes_validate-1.35.0.tar.gz
Algorithm Hash digest
SHA256 50a9e46da2c0471c282bb3138c7d785d29231f6f1b7bc2e68a611ab41b228326
MD5 9ef8dc50e1c3c2e42203e7d14baefee1
BLAKE2b-256 278b35ae3142a373bc55746380e4f68e644e6c151ab1dc9f1646c0cb34504d57

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_validate-1.35.0.tar.gz:

Publisher: publish.yml on willthames/kubernetes-validate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kubernetes_validate-1.35.0-py3-none-any.whl.

File metadata

File hashes

Hashes for kubernetes_validate-1.35.0-py3-none-any.whl
Algorithm Hash digest
SHA256 768909f0cea1c7d77761c8fdea028c6aa553151dafeae099c453742ad3324b43
MD5 128d9def54948c86d458cbf966aad2da
BLAKE2b-256 fea81407781f65289dd1f19c73016a0a5271aadf5562ed0085c64130c3e49519

See more details on using hashes here.

Provenance

The following attestation bundles were made for kubernetes_validate-1.35.0-py3-none-any.whl:

Publisher: publish.yml on willthames/kubernetes-validate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page