0

I have crd1.yaml

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
 # name must match the spec fields below, and be in the form: <plural>.<group>
 name: myplatforms.contoso.com
spec:
 # group name to use for REST API: /apis/<group>/<version>
 group: contoso.com
 names:
   # plural name to be used in the URL: /apis/<group>/<version>/<plural>
   plural: myplatforms
   # singular name to be used as an alias on the CLI and for display
   singular: myplatform
   # kind is normally the CamelCased singular type. Your resource manifests use this.
   kind: MyPlatform
   # shortNames allow shorter string to match your resource on the CLI
   shortNames:
   - myp
 # either Namespaced or Cluster
 scope: Namespaced
 versions:
   - name: v1beta1
     # Each version can be enabled/disabled by Served flag.
     served: true
     # One and only one version must be marked as the storage version.
     storage: true
     schema:
       openAPIV3Schema:
         type: object
         properties:
           spec:
             type: object
             properties:
               appId:
                 type: string
               language:
                 type: string
                 enum:
                 - csharp
                 - python
                 - go
               os:
                 type: string
                 enum:
                 - windows
                 - linux
               instanceSize:
                 type: string
                 enum:
                   - small
                   - medium
                   - large
               environmentType:
                 type: string
                 enum:
                 - dev
                 - test
                 - prod
               replicas:
                 type: integer
                 minimum: 1
             required: ["appId", "language", "environmentType"]
         required: ["spec"]

crd2.yaml

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
 # name must match the spec fields below, and be in the form: <plural>.<group>
 name: myplatformsnew.contoso.com
spec:
 # group name to use for REST API: /apis/<group>/<version>
 group: contoso.com
 names:
   # plural name to be used in the URL: /apis/<group>/<version>/<plural>
   plural: myplatformsnew
   # singular name to be used as an alias on the CLI and for display
   singular: myplatform
   # kind is normally the CamelCased singular type. Your resource manifests use this.
   kind: MyPlatform
   # shortNames allow shorter string to match your resource on the CLI
   shortNames:
   - myp
 # either Namespaced or Cluster
 scope: Namespaced
 versions:
   - name: v1
     # Each version can be enabled/disabled by Served flag.
     served: true
     # One and only one version must be marked as the storage version.
     storage: true
     schema:
       openAPIV3Schema:
         type: object
         properties:
           spec:
             type: object
             properties:
               appId:
                 type: string
               language:
                 type: string
                 enum:
                 - csharp
                 - python
                 - go
               os:
                 type: string
                 enum:
                 - windows
                 - linux
               instanceSize:
                 type: string
                 enum:
                   - small
                   - medium
                   - large
               environmentType:
                 type: string
                 enum:
                 - dev
                 - test
                 - prod
               replicas:
                 type: integer
                 minimum: 1
             required: ["appId", "language", "environmentType"]
         required: ["spec"]

cr.yaml

apiVersion: contoso.com/v1
kind: MyPlatform
metadata:
 name: test-dotnet-app
spec:
 appId: testdotnetapp
 language: csharp
 os: linux
 instanceSize: small
 environmentType: dev
 replicas: 3

I get error

error: resource mapping not found for name: "test-dotnet-app" namespace: "" from "testcr.yaml": no matches for kind "MyPlatform" in version "contoso.com/v1"
ensure CRDs are installed first

crd1.yaml is v1beta1 and crd2.yaml v1. Reason I am keeping 2 CRD is crd1 comes with cluster by default and I cannot override this CRD [ie apply patch to suppprt v1 version as well]. So I am creating new CRD with different name to support v1. But doesnt work. I am unable to understand the mistake

ambikanair
  • 4,004
  • 11
  • 43
  • 83
  • did you apply CRD2 to the cluster? Did it succeed? – Galletti_Lance Jun 09 '22 at 17:40
  • yes I applied. and succeeded. I doubt if we can have 2 different CRD for same resource type. Here in my case , just to support v1 version I am creating new CRD for resource "MyPlatform" – ambikanair Jun 10 '22 at 04:45
  • Dedicated CRDs for different versions are combined into one "object" as it will make the version tracking much harder. They need to put everything under a single [CRD object](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/). – Abhijith Chitrapu Aug 09 '22 at 08:53

0 Answers0