<p>Assuming I have a custom resource on my <code>k8s</code> cluster exposed on a proprietary api endpoint, e.g. <code>somecompany/v1</code></p>

<p>Is there a way to validate a <code>.yaml</code> manifest describing this resource?</p>

<p>It his a functionality the custom resource provider should expose or it is natively supported by <code>k8s</code> for CRDs? </p>

pkaramol
<p>Let's take a look on a simple example:</p>

<pre><code>apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: myresources.stable.example.com
spec:
  group: stable.example.com
  versions:
    - name: v1
      served: true
      storage: true
  scope: Namespaced
  names:
    plural: myresources
    singular: myresource
    kind: MyResource
    shortNames:
    - mr
  validation:
    openAPIV3Schema:
      required: ["spec"]
      properties:
        spec:
          required: ["cert","key","domain"]
          properties:
            cert:
              type: "string"
              minimum: 1
            key:
              type: "string"
              minimum: 1
            domain:
              type: "string"
              minimum: 1 
</code></pre>

<p><code>spec.validation</code> field describes custom validation methods for your custom resource. You can block the creation of resources using validation if certain fields are left empty. In this example, <code>OpenAPIV3Schema</code> validation conventions is used to check the type of some fields in our custom resource. We ensure that <code>spec</code> , <code>spec.cert</code> , <code>spec.key</code> , and <code>spec.domain</code>  fields of the custom resource do exist and that they are of a String type. Users can also use <a href="https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/" rel="nofollow noreferrer">validatingadmissionwebhook</a> as a validation schema. You can find more about restrictions for using this field in the <a href="https://v1-12.docs.kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#validation" rel="nofollow noreferrer">official documentation</a>.</p>
