Update CRDs from v1beta1

OpenShift 4.9 and Kubernetes 1.22 will drop support for CRD v1beta1 from the API entirely. You must convert your CRD's to v1 to continue uninterrupted support for your operator in versions 4.9 and onward. Please refer to this blog post which also covers API deprecation and required actions.

If your operator was removed from OpenShift v4.9 please also reference this blog post for additional actions that may be required.

The operator-sdk uses CustomResourceDefinition v1 by default for all automatically generated CRD's. However, v1beta1 CRD's were required for operator certification as recently as Q2 CY21 and are being deprecated as per the above warning. Thus, if your operator was certified prior to this timeframe and you haven't yet switched, then you should do so as soon as possible to so that your operator will be listed in OpenShift 4.9.

Edit each of your CRs as follows:

$ vi config/crd/bases/<your CRD filename>

Here's a sample CRD shown before and after conversion. The apiVersion is changed to v1, and the schema is now defined per CR version (in v1beta1, you could only define per-version schemas if they were different).

Before:

my-crd.yaml
---
#change the apiVersion
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: mongodbs.database.dhoover103.com
spec:
  group: database.dhoover103.com
  names:
    kind: MongoDB
    listKind: MongoDBList
    plural: mongodbs
    singular: mongodb
  scope: Namespaced
  versions:
  - name: v1alpha1
    served: true
    storage: true
  # Pull out the per-verison schema and define it globally instead
  # Note that the "schema" line changes to "validation"
  # Make sure the new section lines up correctly - one less indent (2 fewer spaces)
  validation:
    openAPIV3Schema:
      description: MongoDB is the Schema for the mongodbs API
      properties:
        apiVersion:
          description: 'APIVersion defines the versioned schema of this representation
            of an object. Servers should convert recognized schemas to the latest
            internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
          type: string
        kind:
          description: 'Kind is a string value representing the REST resource this
            object represents. Servers may infer this from the endpoint the client
            submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
          type: string
        metadata:
          type: object
        spec:
          description: Spec defines the desired state of MongoDB
          type: object
          x-kubernetes-preserve-unknown-fields: true
        status:
          description: Status defines the observed state of MongoDB
          type: object
          x-kubernetes-preserve-unknown-fields: true
        type: object
    # The subresources stay where they are
    subresources:
      status: {}
    # Add a "version" section. This must match the name of your first listed version
    version: v1alpha1

After:

my-crd.yaml
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: mongodbs.database.dhoover103.com
spec:
  group: database.dhoover103.com
  names:
    kind: MongoDB
    listKind: MongoDBList
    plural: mongodbs
    singular: mongodb
  scope: Namespaced
  versions:
  - name: v1alpha1
    schema:
      openAPIV3Schema:
        description: MongoDB is the Schema for the mongodbs API
        properties:
          apiVersion:
            description: 'APIVersion defines the versioned schema of this representation
              of an object. Servers should convert recognized schemas to the latest
              internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
            type: string
          kind:
            description: 'Kind is a string value representing the REST resource this
              object represents. Servers may infer this from the endpoint the client
              submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
            type: string
          metadata:
            type: object
          spec:
            description: Spec defines the desired state of MongoDB
            type: object
            x-kubernetes-preserve-unknown-fields: true
          status:
            description: Status defines the observed state of MongoDB
            type: object
            x-kubernetes-preserve-unknown-fields: true
        type: object
    served: true
    storage: true
    subresources:
      status: {}

Last updated