---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
    controller-gen.kubebuilder.io/version: v0.17.2
  name: clusters.core.pingcap.com
spec:
  group: core.pingcap.com
  names:
    kind: Cluster
    listKind: ClusterList
    plural: clusters
    singular: cluster
  scope: Namespaced
  versions:
  - additionalPrinterColumns:
    - jsonPath: .status.components[?(@.kind=="PD")].replicas
      name: PD
      type: integer
    - jsonPath: .status.components[?(@.kind=="TiKV")].replicas
      name: TiKV
      type: integer
    - jsonPath: .status.components[?(@.kind=="TiDB")].replicas
      name: TiDB
      type: integer
    - jsonPath: .status.components[?(@.kind=="TiFlash")].replicas
      name: TiFlash
      type: integer
    - jsonPath: .status.components[?(@.kind=="TiProxy")].replicas
      name: TiProxy
      type: integer
    - jsonPath: .status.conditions[?(@.type=="Available")].status
      name: Available
      type: string
    - jsonPath: .metadata.creationTimestamp
      name: Age
      type: date
    name: v1alpha1
    schema:
      openAPIV3Schema:
        description: Cluster defines a TiDB cluster
        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:
            properties:
              bootstrapSQL:
                description: |-
                  BootstrapSQL refers to a configmap which contains the bootstrap SQL file with the key `bootstrap-sql`,
                  which will only be executed when a TiDB cluster bootstrap on the first time.
                  Only v6.5.1+ supports this feature.
                properties:
                  name:
                    default: ""
                    description: |-
                      Name of the referent.
                      This field is effectively required, but due to backwards compatibility is
                      allowed to be empty. Instances of this type with an empty value here are
                      almost certainly wrong.
                      More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
                    type: string
                type: object
                x-kubernetes-map-type: atomic
              customizedPDServiceName:
                description: |-
                  CustomizedPDServiceName is the internal pd service name which will be created by the cluster.
                  If MultiPDGroup feature is not enabled, this field doesn't work.
                  If MultiPDGroup feature is enabled, the default service name is ${clusterName}-pd.
                  This field is useful to keep use legacy pd service name when enable MultiPDGroup.
                type: string
              featureGates:
                items:
                  properties:
                    name:
                      description: |-
                        Feature defines a supported feature of a tidb cluster.
                        NOTE(liubo02): +enum is not supported now, we have to add all enum into comments
                        NOTE(liubo02): It's supported by https://github.com/kubernetes-sigs/controller-tools/pull/1179
                      enum:
                      - FeatureModification
                      - VolumeAttributesClass
                      - DisablePDDefaultReadinessProbe
                      - UsePDReadyAPI
                      - SessionTokenSigning
                      - ClusterSubdomain
                      - TerminableLogTailer
                      - UseTSOReadyAPI
                      - UseSchedulingReadyAPI
                      - UseTiKVReadyAPI
                      - UsePDReadyAPIV2
                      - UseTiFlashReadyAPI
                      - MultiPDGroup
                      type: string
                  required:
                  - name
                  type: object
                type: array
                x-kubernetes-list-map-keys:
                - name
                x-kubernetes-list-type: map
                x-kubernetes-validations:
                - message: can only enable FeatureModification if it's not enabled
                  rule: oldSelf.exists(fg, fg.name == 'FeatureModification') || self.filter(fg,
                    fg.name != 'FeatureModification') == oldSelf
                - message: cannot disable FeatureModification
                  rule: self.exists(fg, fg.name == 'FeatureModification') || !oldSelf.exists(fg,
                    fg.name == 'FeatureModification')
              paused:
                description: Paused specifies whether to pause the reconciliation
                  loop for all components of the cluster.
                type: boolean
              revisionHistoryLimit:
                description: |-
                  RevisionHistoryLimit is the maximum number of revisions that will
                  be maintained in each Group's revision history.
                  The revision history consists of all revisions not represented by a currently applied version.
                  The default value is 10.
                format: int32
                minimum: 0
                type: integer
              security:
                description: Security defines the security config of the whole cluster
                properties:
                  sessionTokenSigningCertKeyPair:
                    description: |-
                      SessionTokenSigningCertKeyPair is the name of the K8s secret, where stores certificates for signing the TiDB session token,
                      which is used by TiProxy for session migration.
                      You can generate certificates and create a secret by: kubectl create secret generic <secret-name> --namespace=<namespace> --from-file=tls.crt=<path/to/tls.crt> --from-file=tls.key=<path/to/tls.key>
                      Note: this field will only be used when the feature gate `SessionTokenSigning` is enabled.
                    properties:
                      name:
                        default: ""
                        description: |-
                          Name of the referent.
                          This field is effectively required, but due to backwards compatibility is
                          allowed to be empty. Instances of this type with an empty value here are
                          almost certainly wrong.
                          More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
                        type: string
                    type: object
                    x-kubernetes-map-type: atomic
                  tls:
                    description: TLS defines tls configs for the whole cluster
                    properties:
                      client:
                        description: Client defines the client tls for the tidb operator
                          to visit components
                        properties:
                          ca:
                            description: CA defines the ref of the secret which contains
                              ca.crt
                            properties:
                              name:
                                type: string
                            type: object
                          certKeyPair:
                            description: CertKeyPair defines the ref of the secret
                              which contains tls.crt and tls.key
                            properties:
                              name:
                                type: string
                            type: object
                          insecureSkipTLSVerify:
                            description: |-
                              If true, we will skip CA verification, it means CA can be omitted
                              Defaults to false
                            type: boolean
                        type: object
                    type: object
                type: object
              suspendAction:
                description: SuspendAction defines the suspend actions for the cluster.
                properties:
                  suspendCompute:
                    description: SuspendCompute indicates delete the pods but keep
                      the PVCs.
                    type: boolean
                type: object
              tlsCluster:
                description: Whether enable the TLS connection between TiDB cluster
                  components.
                properties:
                  enabled:
                    description: |-
                      Enable mutual TLS connection between TiDB cluster components.
                      Once enabled, the mutual authentication applies to all components,
                      and it does not support applying to only part of the components.
                      The steps to enable this feature:
                        1. Generate TiDB cluster components certificates and a client-side certifiacete for them.
                           There are multiple ways to generate these certificates:
                             - user-provided certificates: https://docs.pingcap.com/tidb/stable/generate-self-signed-certificates
                             - use the K8s built-in certificate signing system signed certificates: https://kubernetes.io/docs/tasks/tls/managing-tls-in-a-cluster/
                             - or use cert-manager signed certificates: https://cert-manager.io/
                        2. Create one secret object for one component group which contains the certificates created above.
                           The name of this Secret must be: <groupName>-<componentName>-cluster-secret.
                             For PD: kubectl create secret generic <groupName>-pd-cluster-secret --namespace=<namespace> --from-file=tls.crt=<path/to/tls.crt> --from-file=tls.key=<path/to/tls.key> --from-file=ca.crt=<path/to/ca.crt>
                             For TiKV: kubectl create secret generic <groupName>-tikv-cluster-secret --namespace=<namespace> --from-file=tls.crt=<path/to/tls.crt> --from-file=tls.key=<path/to/tls.key> --from-file=ca.crt=<path/to/ca.crt>
                             For TiDB: kubectl create secret generic <groupName>-tidb-cluster-secret --namespace=<namespace> --from-file=tls.crt=<path/to/tls.crt> --from-file=tls.key=<path/to/tls.key> --from-file=ca.crt=<path/to/ca.crt>
                             For TiBR: kubectl create secret generic <tibrName>-tibr-cluster-secret --namespace=<namespace> --from-file=tls.crt=<path/to/tls.crt> --from-file=tls.key=<path/to/tls.key> --from-file=ca.crt=<path/to/ca.crt>
                             For TiBRGC: kubectl create secret generic <tibrgcName>-tibrgc-cluster-secret --namespace=<namespace> --from-file=tls.crt=<path/to/tls.crt> --from-file=tls.key=<path/to/tls.key> --from-file=ca.crt=<path/to/ca.crt>
                             For Client: kubectl create secret generic <clusterName>-cluster-client-secret --namespace=<namespace> --from-file=tls.crt=<path/to/tls.crt> --from-file=tls.key=<path/to/tls.key> --from-file=ca.crt=<path/to/ca.crt>
                             Same for other components.
                    type: boolean
                type: object
              upgradePolicy:
                description: UpgradePolicy defines the upgrade policy for the cluster.
                type: string
            type: object
            x-kubernetes-validations:
            - message: bootstrapSQL can only be set at creation, can be unset, but
                cannot be changed to a different value
              rule: oldSelf == null || !has(self.bootstrapSQL) || (has(oldSelf.bootstrapSQL)
                && self.bootstrapSQL.name == oldSelf.bootstrapSQL.name)
            - message: tlsCluster is immutable
              rule: oldSelf == null || (has(oldSelf.tlsCluster) == has(self.tlsCluster))
                && (!has(self.tlsCluster) || self.tlsCluster.enabled == oldSelf.tlsCluster.enabled)
          status:
            properties:
              components:
                description: Components is the status of each component in the cluster.
                items:
                  description: ComponentStatus is the status of a component in the
                    cluster.
                  properties:
                    kind:
                      description: Kind is the kind of the component, e.g., PD, TiKV,
                        TiDB, TiFlash.
                      enum:
                      - PD
                      - TiKV
                      - TiDB
                      - TiFlash
                      - TiCDC
                      - TiProxy
                      type: string
                    replicas:
                      description: Replicas is the number of desired replicas of the
                        component.
                      format: int32
                      type: integer
                  required:
                  - kind
                  - replicas
                  type: object
                type: array
                x-kubernetes-list-map-keys:
                - kind
                x-kubernetes-list-type: map
              conditions:
                description: Conditions contains the current status of the cluster.
                items:
                  description: Condition contains details for one aspect of the current
                    state of this API Resource.
                  properties:
                    lastTransitionTime:
                      description: |-
                        lastTransitionTime is the last time the condition transitioned from one status to another.
                        This should be when the underlying condition changed.  If that is not known, then using the time when the API field changed is acceptable.
                      format: date-time
                      type: string
                    message:
                      description: |-
                        message is a human readable message indicating details about the transition.
                        This may be an empty string.
                      maxLength: 32768
                      type: string
                    observedGeneration:
                      description: |-
                        observedGeneration represents the .metadata.generation that the condition was set based upon.
                        For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
                        with respect to the current state of the instance.
                      format: int64
                      minimum: 0
                      type: integer
                    reason:
                      description: |-
                        reason contains a programmatic identifier indicating the reason for the condition's last transition.
                        Producers of specific condition types may define expected values and meanings for this field,
                        and whether the values are considered a guaranteed API.
                        The value should be a CamelCase string.
                        This field may not be empty.
                      maxLength: 1024
                      minLength: 1
                      pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
                      type: string
                    status:
                      description: status of the condition, one of True, False, Unknown.
                      enum:
                      - "True"
                      - "False"
                      - Unknown
                      type: string
                    type:
                      description: type of condition in CamelCase or in foo.example.com/CamelCase.
                      maxLength: 316
                      pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
                      type: string
                  required:
                  - lastTransitionTime
                  - message
                  - reason
                  - status
                  - type
                  type: object
                type: array
                x-kubernetes-list-map-keys:
                - type
                x-kubernetes-list-type: map
              featureGates:
                description: FeatureGates of this cluster
                items:
                  properties:
                    name:
                      description: |-
                        Feature defines a supported feature of a tidb cluster.
                        NOTE(liubo02): +enum is not supported now, we have to add all enum into comments
                        NOTE(liubo02): It's supported by https://github.com/kubernetes-sigs/controller-tools/pull/1179
                      enum:
                      - FeatureModification
                      - VolumeAttributesClass
                      - DisablePDDefaultReadinessProbe
                      - UsePDReadyAPI
                      - SessionTokenSigning
                      - ClusterSubdomain
                      - TerminableLogTailer
                      - UseTSOReadyAPI
                      - UseSchedulingReadyAPI
                      - UseTiKVReadyAPI
                      - UsePDReadyAPIV2
                      - UseTiFlashReadyAPI
                      - MultiPDGroup
                      type: string
                    stage:
                      type: string
                  required:
                  - name
                  - stage
                  type: object
                type: array
                x-kubernetes-list-map-keys:
                - name
                x-kubernetes-list-type: map
              id:
                description: ID is the cluster id.
                type: string
              observedGeneration:
                description: |-
                  observedGeneration is the most recent generation observed for this Cluster. It corresponds to the
                  Cluster's generation, which is updated on mutation by the API Server.
                format: int64
                type: integer
              pd:
                description: |-
                  PD means url of the pd service, it's prepared for internal use
                  e.g. https://pd:2379
                type: string
            required:
            - id
            type: object
        type: object
        x-kubernetes-validations:
        - message: name must not exceed 37 characters
          rule: size(self.metadata.name) <= 37
    served: true
    storage: true
    subresources:
      status: {}
