kubernetes-client: Creating CRDs with schema validation is broken
the K8s api server makes a lot of strict checks, for instance it fails if the schema contains default values, definitions, $ref elements, etc. One of the checks is:
if schema.Dependencies != nil {
for dependency, jsonSchemaPropsOrStringArray := range schema.Dependencies {
allErrs = append(allErrs, ValidateCustomResourceDefinitionOpenAPISchema(jsonSchemaPropsOrStringArray.Schema, fldPath.Child("dependencies").Key(dependency), ssv)...)
}
}
However, even if the JSONSchemaProps
object has the dependecies
field set to null
, the object mapper from Jackson that’s being used in here converts the null
to an empty LinkedHashMap
and this fails on the K8s api server. So there is no way currently to create the schema validation with the fabric8 k8s client.
I am using the .withNewOpenAPIV3SchemaLike(schema)
method for the CustomResourceDefinitionBuilder
.
I believe there must be some configuration of the object mapper so that it shouldn’t translate nulls to empty maps.
JSON_MAPPER.setSerializationInclusion(Include.NON_NULL);
…looks promising
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 22 (11 by maintainers)
Commits related to this issue
- Fix #1486: Creating CRDs with schema validation is broken + Upgrade to sundrio v0.19.2 + Change sundrio configuration to disable lazy collection initialization — committed to rohanKanojia/kubernetes-client by rohanKanojia 5 years ago
- Fix #1486: Creating CRDs with schema validation is broken + Upgrade to sundrio v0.19.2 + Change sundrio configuration to disable lazy collection initialization — committed to rohanKanojia/kubernetes-client by rohanKanojia 5 years ago
- Fix #1486: Creating CRDs with schema validation is broken + Upgrade to sundrio v0.19.2 + Change sundrio configuration to disable lazy collection initialization — committed to rohanKanojia/kubernetes-client by rohanKanojia 5 years ago
- Fix #1486: Creating CRDs with schema validation is broken + Upgrade to sundrio v0.19.2 + Change sundrio configuration to disable lazy collection initialization — committed to rohanKanojia/kubernetes-client by rohanKanojia 5 years ago
- Fix #1486: Creating CRDs with schema validation is broken + Upgrade to sundrio v0.19.2 + Change sundrio configuration to disable lazy collection initialization — committed to rohanKanojia/kubernetes-client by rohanKanojia 5 years ago
- Fix #1486: Creating CRDs with schema validation is broken + Upgrade to sundrio v0.19.2 + Change sundrio configuration to disable lazy collection initialization — committed to rohanKanojia/kubernetes-client by rohanKanojia 5 years ago
@saturnism, @jorsol check my ugly workaround: https://github.com/jvm-operators/abstract-operator/blob/ddb89ad2b0eda8ec29121fc37a4de24a000588de/src/main/java/io/radanalytics/operator/common/crd/CrdDeployer.java#L71:L74
here is the reproducer:
content of
sparkCluster.json
:…but it would fail with any schema, even smaller one. Thanks for looking into this!
No no, this is an example of improved support for custom resources. For custom resource definitions it’s still the same:
https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CustomResourceDefinitionIT.java