-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could not find schema for CustomResourceDefinition #51
Comments
Hi Dewe, no it is not, servicemonitors.monitoring.coreos.com is part of Prometheus' operator CRD! The workflow to validate CRDs is described in the README, https://github.com/yannh/kubeconform#converting-an-openapi-file-to-a-json-schema - could you go through it and let me know whether its understandable? |
Hi, thanks for the quick answer. I've tried it out that workflow earlier today, it wasn't entirely clear how to do it, but eventually I got it working. One thing that could be improved is to emphasize the correct FILENAME_FORMAT (i.e. not the default). But... now, this issue, it's about the actual To reproduce, taking the ServiceMonitor definition as an example: $ URL=https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/master/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml
$ curl -s $URL | kubeconform
stdin - CustomResourceDefinition servicemonitors.monitoring.coreos.com failed validation: could not find schema for CustomResourceDefinition
Summary: 1 resource found parsing stdin - Valid: 0, Invalid: 0, Errors: 1, Skipped: 0 If I skip the CustomResourceDefinition schema, it passes, obviously:
To me, this indicates that the schema for CustomResourceDefinition cannot be found. And I think I've seen something similar with |
I can confirm this is the case. It is why we are skipping validation of CRDs in kube-prometheus (https://github.com/prometheus-operator/kube-prometheus/blob/main/Makefile#L43). |
I understand. The problem is due to the fact that the schema for CustomResourceDefinitions are not stored in the schema repository, most likely because of this While I am quite interested in getting this to work it is likely to take me some time to figure out why this limitation is in there. If anyone wants to give this a shot before me 👍 |
I ran into a similar issue, but after converting the yaml version of custom resource definition using yannh's openapi2jsonschema.py, I'm now able to validate. Similarly, if I use kubectl to Here's an example:
docker-compose.yml
add the urls to the location of the raw yaml files under mkdir -p ./converted
docker-compose up --build --remove-orphans --force-recreate -- convert-crd In the reset_color="\\e[0m"; color_red="\\e[31m"; color_green="\\e[32m"; color_blue="\\e[36m";
function echo_fail { echo -e "${color_red}✖ $*${reset_color}"; }
function echo_success { echo -e "${color_green}✔ $*${reset_color}"; }
function echo_info { echo -e "${color_blue}info: $*${reset_color}"; }
chart="production/default/helm/"
echo_info "Validating Chart '$chart'"
helm template ${FLAGS[@]} -- "$chart" | \
kubeconform -strict \
-schema-location default \
-schema-location "converted/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json" \
-summary \
&& echo_success "Kubeconform succeeded!" || echo_fail "Kubeconform failed!!" you should see this as an output (note, in this output below I'm running in a docker container):
my helm chart has these CustomResources:
Let me know if this helps. Perhaps kubeconform is supposed to automatically convert these yamls into json, but I don't think so... |
I'm very new to this, so someone feel free to educate me if there's a reason I shouldn't do this. The project I'm currently working on uses flux and has a lot of Hope this helps anyone that comes across the same problem. |
@Glitchm While your approach suppress the error, it is not catching the real issues.
Based on the schema validation, the Also, None of them are defined in the above example, but yet the validation succeeded. K8s API server is indeed complaining when trying to apply the same spec:
|
I solved it by adding to schema-location and using Datree's CRDs-catalog as it is mentioned in the Readme.
Now as you can see everything is validated:
|
Even for your own CRDs, it's possible to convert them to JSON and just point at them in GitHub as I've done here ~ https://github.com/premiscale/pass-operator/blob/master/helm/operator-crds/_json/PassSecret.json https://github.com/premiscale/pass-operator/blob/master/.circleci/helm.yml#L16 |
This issue thread is perplexing because everyone is talking about a different thing. When you have issue Validating a Custom Resource like ServiceMonitor or Certificate: Add this to your command line: -schema-location "https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json" When you have issues validating a Custom Resource Definition, which is a NATIVE Kubernetes Resource: Add this to your command line: -schema-location "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/{{.NormalizedKubernetesVersion}}/{{.ResourceKind}}.json" Your final command line should look like this: kubeconform -output pretty -strict \
-schema-location default \
-schema-location "https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json" \
-schema-location "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/{{.NormalizedKubernetesVersion}}/{{.ResourceKind}}.json" Edit: Fixed below comment. |
Hi @Skaronator , unfortunately that's not correct, -schema-location should not point to a single file - I obviously need to improve documentation. In the order you passed parameters, apis__apiextensions.k8s.io__v1_openapi.json will be used to validate all files that are not found in default or datree. |
yannh/kubernetes-json-schema#26 seemed to fix the issue for me. Although I do run into what Yannh mentioned above when I use multiple single file schema locations:
It acts like However this worked as expected:
|
@CyDickey-msr you can also use The final arguments should look like this:
|
Is this possible to include the CRDS to main repo by default ? Like a GH actions? If so, I can work on that. |
There's no need to include this one, I think, as they use (roughly?) the same source: https://github.com/yannh/kubeconform?tab=readme-ov-file#overriding-schemas-location:
|
When validating
apiextensions.k8s.io/v1
CustomResourceDefinition resources I get this error:Why is that? I thought this API was part of the Kubernetes API?
The text was updated successfully, but these errors were encountered: