|
5 | 5 | [](https://pkg.go.dev/github.com/yannh/kubeconform/pkg/validator) |
6 | 6 |
|
7 | 7 | Kubeconform is a Kubernetes manifests validation tool. Build it into your CI to validate your Kubernetes |
8 | | -configuration using the schemas from the registry maintained by the |
9 | | -[kubernetes-json-schema](https://github.com/instrumenta/kubernetes-json-schema) project! |
| 8 | +configuration! |
10 | 9 |
|
11 | 10 | It is inspired by, contains code from and is designed to stay close to |
12 | 11 | [Kubeval](https://github.com/instrumenta/kubeval), but with the following improvements: |
13 | 12 | * **high performance**: will validate & download manifests over multiple routines, caching |
14 | 13 | downloaded files in memory |
15 | 14 | * configurable list of **remote, or local schemas locations**, enabling validating Kubernetes |
16 | | - custom resources (CRDs) and offline validation capabilities. |
| 15 | + custom resources (CRDs) and offline validation capabilities |
| 16 | + * uses by default a [self-updating fork](https://github.com/yannh/kubernetes-json-schema) of the schemas registry maintained |
| 17 | + by the [kubernetes-json-schema](https://github.com/instrumenta/kubernetes-json-schema) project - which guarantees |
| 18 | + up-to-date **schemas for all recent versions of Kubernetes**. |
17 | 19 |
|
18 | 20 | ### A small overview of Kubernetes manifest validation |
19 | 21 |
|
@@ -132,29 +134,29 @@ Summary: 65 resources found in 34 files - Valid: 55, Invalid: 2, Errors: 8 Skipp |
132 | 134 |
|
133 | 135 | ### Overriding schemas location - CRD and Openshift support |
134 | 136 |
|
135 | | -When the `-schema-location` parameter is not used, kubeconform will default to downloading schemas from |
136 | | -`https://kubernetesjsonschema.dev`. Kubeconform however supports passing one, or multiple, schemas |
137 | | -locations - HTTP URLs, or local filesystem paths, in which case it will lookup for schema definitions |
| 137 | +When the `-schema-location` parameter is not used, or set to "default", kubeconform will default to downloading |
| 138 | +schemas from `https://github.com/yannh/kubernetes-json-schema`. Kubeconform however supports passing one, or multiple, |
| 139 | +schemas locations - HTTP(s) URLs, or local filesystem paths, in which case it will lookup for schema definitions |
138 | 140 | in each of them, in order, stopping as soon as a matching file is found. |
139 | 141 |
|
140 | 142 | * If the -schema-location value does not end with '.json', Kubeconform will assume filenames / a file |
141 | | - structure identical to that of kubernetesjsonschema.dev |
| 143 | + structure identical to that of kubernetesjsonschema.dev or github.com/yannh/kubernetes-json-schema. |
142 | 144 | * if the -schema-location value ends with '.json' - Kubeconform assumes the value is a Go templated |
143 | 145 | string that indicates how to search for JSON schemas. |
144 | | - |
145 | | -All 3 following command lines are equivalent: |
| 146 | +* the -schema-location value of "default" is an alias for https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/{{ .NormalizedKubernetesVersion }}-standalone{{ .StrictSuffix }}/{{ .ResourceKind }}{{ .KindSuffix }}.json. |
| 147 | +Both following command lines are equivalent: |
146 | 148 | ``` |
147 | 149 | $ ./bin/kubeconform fixtures/valid.yaml |
148 | | -$ ./bin/kubeconform -schema-location https://kubernetesjsonschema.dev fixtures/valid.yaml |
149 | | -$ ./bin/kubeconform -schema-location 'https://kubernetesjsonschema.dev/{{ .NormalizedKubernetesVersion }}-standalone{{ .StrictSuffix }}/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/valid.yaml |
| 150 | +$ ./bin/kubeconform -schema-location default fixtures/valid.yaml |
| 151 | +$ ./bin/kubeconform -schema-location 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/{{ .NormalizedKubernetesVersion }}-standalone{{ .StrictSuffix }}/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/valid.yaml |
150 | 152 | ``` |
151 | 153 |
|
152 | 154 | To support validating CRDs, we need to convert OpenAPI files to JSON schema, storing the JSON schemas |
153 | 155 | in a local folder - for example schemas. Then we specify this folder as an additional registry to lookup: |
154 | 156 |
|
155 | 157 | ``` |
156 | 158 | # If the resource Kind is not found in kubernetesjsonschema.dev, also lookup in the schemas/ folder for a matching file |
157 | | -$ ./bin/kubeconform -registry https://kubernetesjsonschema.dev -schema-location 'schemas/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/custom-resource.yaml |
| 159 | +$ ./bin/kubeconform -schema-location default -schema-location 'schemas/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/custom-resource.yaml |
158 | 160 | ``` |
159 | 161 |
|
160 | 162 | You can validate Openshift manifests using a custom schema location. Set the OpenShift version to validate |
|
0 commit comments