kubernetes-validate


Namekubernetes-validate JSON
Version 1.31.0 PyPI version JSON
download
home_pageNone
Summaryvalidates kubernetes resource definitions against schemas
upload_time2024-08-19 02:29:40
maintainerNone
docs_urlNone
authorNone
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": null,
    "name": "kubernetes-validate",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "kubernetes, schema, validate, validator",
    "author": null,
    "author_email": "Will Thames <will@thames.id.au>",
    "download_url": "https://files.pythonhosted.org/packages/0c/0d/da37f4659841716ad2acd9602bf6c4c3ac030ce8a78ba882c415eb547b23/kubernetes_validate-1.31.0.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.31.0",
    "project_urls": {
        "Homepage": "https://github.com/willthames/kubernetes-validate"
    },
    "split_keywords": [
        "kubernetes",
        " schema",
        " validate",
        " validator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0c0dda37f4659841716ad2acd9602bf6c4c3ac030ce8a78ba882c415eb547b23",
                "md5": "a58494bbd29b23acb3f76292b90d53e0",
                "sha256": "dfac1011e4d93e1b3633272b7fb1ecbfa6721c9393662859ccc252a7c4d8c555"
            },
            "downloads": -1,
            "filename": "kubernetes_validate-1.31.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a58494bbd29b23acb3f76292b90d53e0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7062231,
            "upload_time": "2024-08-19T02:29:40",
            "upload_time_iso_8601": "2024-08-19T02:29:40.604778Z",
            "url": "https://files.pythonhosted.org/packages/0c/0d/da37f4659841716ad2acd9602bf6c4c3ac030ce8a78ba882c415eb547b23/kubernetes_validate-1.31.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-19 02:29:40",
    "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.33219s