kubernetes-validate


Namekubernetes-validate JSON
Version 1.29.1 PyPI version JSON
download
home_page
Summaryvalidates kubernetes resource definitions against schemas
upload_time2024-01-21 03:33:19
maintainer
docs_urlNone
author
requires_python>=3.7
licenseApache
keywords kubernetes schema validate validator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:
* Add API versions into schema names (built using https://github.com/garethr/openapi2jsonschema/pull/11)
* [Increase coverage of strict versions](https://github.com/garethr/kubernetes-json-schema/pull/8)
* [Update to latest Kubernetes released API versions](https://github.com/garethr/kubernetes-json-schema/pull/8)
* Provide local-strict schemas
* Reduce Kubernetes version support (v1.5 and v1.6 schemas are not included to reduce
  library size and schema build time)

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'
```


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "kubernetes-validate",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "kubernetes,schema,validate,validator",
    "author": "",
    "author_email": "Will Thames <will@thames.id.au>",
    "download_url": "https://files.pythonhosted.org/packages/59/4d/9a0771e386d1c9104fc250a52c12b71b971a8735492820f72be94a08de89/kubernetes-validate-1.29.1.tar.gz",
    "platform": null,
    "description": "# kubernetes-validate\n\nkubernetes-validate validates Kubernetes resource definitions against the\ndeclared Kubernetes schemas.\n\nBased on Gareth Rushgrove's excellent work providing a basis for turning Kubernetes\nSwagger API definitions into JSONSchema definitions, kubernetes-validate will report\non mismatches between schema defnition and resource definition\n\nNote that this currently uses a fork of kubernetes-json-schema for the following reasons:\n* Add API versions into schema names (built using https://github.com/garethr/openapi2jsonschema/pull/11)\n* [Increase coverage of strict versions](https://github.com/garethr/kubernetes-json-schema/pull/8)\n* [Update to latest Kubernetes released API versions](https://github.com/garethr/kubernetes-json-schema/pull/8)\n* Provide local-strict schemas\n* Reduce Kubernetes version support (v1.5 and v1.6 schemas are not included to reduce\n  library size and schema build time)\n\nFurthermore, the module now includes only the .0 API schemas, as they change so little within a Kubernetes\nversion (there are some differences but they seem to be mostly irrelevant to validation - e.g. description\nupdates). This has taken the module down from 300MB to less than 30MB.\n\nIf the relevant PRs get accepted upstream, then this will revert to the upstream fork.\n\n## Installation\n\npip install kubernetes-validate\n\n## Usage\n\n### Command line\n\n```\n$ kubernetes-validate\nusage: kubernetes-validate [-h] [-k KUBERNETES_VERSION] [--strict] [--version]\n                           ...\n\nvalidate a kubernetes resource definition\n\npositional arguments:\n  filenames\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -k KUBERNETES_VERSION, --kubernetes-version KUBERNETES_VERSION\n                        version of kubernetes against which to validate.\n                        Defaults to major/minor version of kubernetes-validate\n                        (i.e. 1.22.1 supports kubernetes 1.22). Patch versions\n                        of the version are ignored (1.22.4 validates against\n                        1.22.0)\n  --strict              whether to use strict validation, rejecting unexpected\n                        properties\n  --quiet               whether to only output warnings/failures\n  --no-warn             whether to hide warnings\n  --version             show program's version number and exit\n```\n\ne.g.\n\n```\n$ kubernetes-validate -k 1.27 --strict resource.yml\n```\n\n### Python\n\n```\nfrom __future__ import print_function\nimport kubernetes_validate\nimport yaml\n\ntry:\n    data = yaml.load(open('resource.yaml').read())\n    kubernetes_validate.validate(data, '1.22', strict=True)\nexcept kubernetes_validate.ValidationError as e:\n    print(''. join(e.path), e.message)\n```\n\n### Examples\n\n```\n$ kubernetes-validate -k 1.21 examples/kuard-extra-property.yaml\nINFO  examples/kuard-extra-property.yaml passed against version 1.21\n```\n\n```\n$ kubernetes-validate --strict examples/kuard-extra-property.yaml\nERROR examples/kuard-extra-property.yaml did not validate against version 1.28.0: spec.selector: Additional properties are not allowed ('unwanted' was unexpected)\n```\n\n```\n$ kubernetes-validate examples/kuard-invalid-type.yaml\nERROR examples/kuard-invalid-type.yaml did not validate against version 1.28.0: spec.replicas: 'hello' is not of type u'integer'\n```\n\n",
    "bugtrack_url": null,
    "license": "Apache",
    "summary": "validates kubernetes resource definitions against schemas",
    "version": "1.29.1",
    "project_urls": {
        "Homepage": "https://github.com/willthames/kubernetes-validate"
    },
    "split_keywords": [
        "kubernetes",
        "schema",
        "validate",
        "validator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "594d9a0771e386d1c9104fc250a52c12b71b971a8735492820f72be94a08de89",
                "md5": "0d40e77427438ae3fb205966c4d86e33",
                "sha256": "be68f9690346e956c16f316a2337173270a4cf986f5ca795a3065ed497802ea4"
            },
            "downloads": -1,
            "filename": "kubernetes-validate-1.29.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0d40e77427438ae3fb205966c4d86e33",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5429728,
            "upload_time": "2024-01-21T03:33:19",
            "upload_time_iso_8601": "2024-01-21T03:33:19.104175Z",
            "url": "https://files.pythonhosted.org/packages/59/4d/9a0771e386d1c9104fc250a52c12b71b971a8735492820f72be94a08de89/kubernetes-validate-1.29.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-21 03:33:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "willthames",
    "github_project": "kubernetes-validate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "kubernetes-validate"
}
        
Elapsed time: 0.19515s