apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: policygentemplates.ran.openshift.io
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: ran.openshift.io
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: policygentemplates
    # singular name to be used as an alias on the CLI and for display
    singular: policygentemplate
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: PolicyGenTemplate
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - policygentemplate
  # list of versions supported by this CustomResourceDefinition
  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
      # A schema is required
      schema:
        openAPIV3Schema:
          type: object
          properties:
            apiVersion:
              type: string
            kind:
              type: string
            metadata:
              type: object
            spec:
              type: object
              properties:
                bindingRules:
                  type: object
                  description: |
                    Placement rule data for generated policies. The key/value
                    pairs in this list identify the cluster labels/values to which
                    the policy applies.
                  x-kubernetes-preserve-unknown-fields: true
                mcp:
                  type: string
                  description: |
                    The MachineConfigPool name that will apply the following CRs.
                wrapInPolicy:
                  type: boolean
                  default: true
                  description: |
                    Boolean flag to allow the user to create custom resources wrapped or unwrapped by ACM policies.
                    This is set to true by default but can be overriden by the command line parameter wrapInPolicy
                    passed during policyGenerator invocation.
                sourceFiles:
                  type: array
                  items:
                    type: object
                    required:
                      - fileName
                    properties:
                      fileName:
                        description: |
                          Name of source file to include in generation. The fileName
                          values must be same as file name in the sourcePolicies dir
                          ex; SriovNetwork.yaml
                        type: string
                      policyName:
                        description: |
                          The policyName will be used with the bindingRules keys
                          to set the generated policy name. ex; common-ptp-sub-policy
                          When you create a policy, make sure that the length of the
                          namespaceName.policyName must not exceed 63 characters
                          due to the Kubernetes limit for object names.
                          Note; Repeating the policyName across the sourceFile items will append
                                each CR to the same generated ACM policy
                          Note; Having empty policyName OR not assign it will make the generator
                                to create only the CR without adding the ACM policy template.
                        type: string
                      complianceType:
                        description: |
                          The complianceType will be set on the underlying ConfigurationPolicy and
                          determines how the CR built from this sourceFile is reconciled against the
                          cluster.
                        type: string
                        default: mustonlyhave
                      metadata:
                        type: object
                        properties:
                          name:
                            description: |
                              Optional. The name will be used to set the generated
                              custom resource metadata.name. If name is defined as
                              "" or not set the name value exist in the sourcePolicies/{fileName}
                              will be used.
                              If there is no policyName assigned to the sourceFile item, the metadat.name
                              and CR.kind will be used to name the generated file.
                            type: string
                          namespace:
                            description: |
                              Optional. The namespace will be used to set the
                              generated custom resource metadata.namespace.  If
                              namespace is defined as "" or not set the
                              namespace value exist in the sourcePolicies/{fileName}
                              will be used.
                            type: string
                          labels:
                            description: |
                              Optional. List of labels that that will be generated
                              with the custom resource policy. If labels are defined
                              as "" or not set the labels value exist in the
                              sourcePolicies/{fileName} will be used.
                            type: object
                            x-kubernetes-preserve-unknown-fields: true
                          annotations:
                            description: |
                              Optional. List of annotations that that will be
                              generated with the custom resource policy.  If
                              annotations are defined as "" or not set the
                              annotations value exist in the
                              sourcePolicies/{fileName} will be used.
                            type: object
                            x-kubernetes-preserve-unknown-fields: true
                      spec:
                        type: object
                        description: |
                          Optional. spec contains the values that will be set in the
                          source policy following the exact same path. If the spec
                          is not defined, the defined spec in the sourcePolicies/{fileName}
                          will be carried out to the generated custom resource.
                          If any of the spec's item fields its value starts with $, the item
                          will be deleted from the generated spec items if it is not
                          setted in the sourceFile.spec.
                        x-kubernetes-preserve-unknown-fields: true
                      data:
                        type: object
                        description: |
                          (optional) data contains the values that will be set in
                          the source policy following the exact same path. If the
                          data is not defined, the defined data in the
                          sourcePolicies/{fileName} will be carried out to the
                          generated custom resource. If any of the data's item
                          fields its value starts with $, the item will be deleted
                          from the generated data items if it is not setted in
                          the sourceFile.data.
                        x-kubernetes-preserve-unknown-fields: true
