apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: clusterloggingconfigs.deckhouse.io
  labels:
    heritage: deckhouse
    module: log-shipper
spec:
  group: deckhouse.io
  scope: Cluster
  names:
    plural: clusterloggingconfigs
    singular: clusterloggingconfig
    kind: ClusterLoggingConfig
  preserveUnknownFields: false
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          required: ["spec"]
          description: |
            Describes a log source in log-pipeline.

            Each CustomResource `ClusterLoggingConfig` describes rules for log fetching from cluster.
          properties:
            spec:
              type: object
              required:
                - type
                - destinationRefs
              anyOf:
                - oneOf:
                    - properties:
                        type:
                          enum: ["KubernetesPods"]
                        kubernetesPods: {}
                      required: ["kubernetesPods"]
                    - properties:
                        type:
                          enum: ["File"]
                        file: {}
                      required: ["file"]
              properties:
                type:
                  type: string
                  enum: ["KubernetesPods", "File"]
                  description: |
                    Set on of possible input sources.

                    `KubernetesPods` source reads logs from Kubernetes Pods.

                    `File` source reads local file from node filesystem.
                kubernetesPods:
                  type: object
                  default: {}
                  properties:
                    namespaceSelector:
                      type: object
                      description: Specifies the Namespace selector to filter Pods with.
                      properties:
                        matchNames:
                          type: array
                          items:
                            type: string
                    labelSelector:
                      type: object
                      description: |
                        Specifies the label selector to filter Pods with.

                        You can get more into [here](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/).
                      anyOf:
                        - required:
                            - matchLabels
                        - required:
                            - matchExpressions
                      properties:
                        matchLabels:
                          type: object
                          description: List of labels which Pod should have.
                          example: { "foo": "bar", "baz": "whooo" }
                          additionalProperties:
                            type: string
                        matchExpressions:
                          type: array
                          description: List of label expressions for Pods.
                          example: |
                            ```yaml
                            matchExpressions:
                            - key: tier
                              operator": In
                              values:
                              - production
                              - staging
                            ```
                          items:
                            type: object
                            required:
                              - key
                              - operator
                            properties:
                              key:
                                type: string
                              operator:
                                type: string
                                enum:
                                  - In
                                  - NotIn
                                  - Exists
                                  - DoesNotExist
                              values:
                                type: array
                                items:
                                  type: string
                file:
                  type: object
                  properties:
                    include:
                      type: array
                      description: Array of file patterns to include.
                      example: ["/var/log/*.log", "/var/log/nginx/*.log"]
                      items:
                        type: string
                    exclude:
                      type: array
                      description: Array of file patterns to exclude.
                      example:
                        ["/var/log/nginx/error.log", "/var/log/audit.log"]
                      items:
                        type: string
                    lineDelimiter:
                      type: string
                      description: String sequence used to separate one file line from another.
                      example: \r\n
                logFilter:
                  type: array
                  description: |
                    List of filter for logs.

                    Only matched lines would be stored to log destination.
                  example: |
                    ```yaml
                    logFilter:
                    - field: tier
                      operator: Exists
                    - field: tier
                      operator: In
                      values:
                      - production
                      - staging
                    - field: foo
                      operator: NotIn
                      values: 
                      - dev
                      - 42
                      - "true"
                      - "3.14"
                    - field: bar
                      operator: Regex
                      values:
                      - ^abc
                      - ^\d.+$
                    ```
                  items:
                    type: object
                    required:
                      - field
                      - operator
                    properties:
                      field:
                        description: Field name for filtering.
                        type: string
                      operator:
                        type: string
                        description: |
                          Operator for log field comparations:
                          * `In` — finds a substring in string
                          * `NotIn` — is a negative version of the `In` operator
                          * `Regex` — is trying to match regexp over field, only log events with matching fields will pass
                          * `NotRegex` — is a negative version of the `Regex` operator, log events without fields or with not matched fields will pass
                          * `Exists` — drops log event if it contains some fields
                          * `DoesNotExist` — drops log event if it does not contain some fields
                        enum:
                          - In
                          - NotIn
                          - Regex
                          - NotRegex
                          - Exists
                          - DoesNotExist
                      values:
                        type: array
                        description: |
                          Array of `ClusterLogDestination` CustomResource names which this source will output with.

                          Fields a with float or boolean values will be converted to strings during comparison.
                        items:
                          x-kubernetes-int-or-string: true
                          anyOf:
                            - type: integer
                            - type: string
                    oneOf:
                      - properties:
                          operator:
                            enum: ["Exists", "DoesNotExist"]
                          values:
                            maxItems: 0
                      - properties:
                          operator:
                            enum: ["Regex", "NotRegex", "In", "NotIn"]
                          values:
                            minItems: 1
                multilineParser:
                  type: object
                  description: Multiline parser for different patterns
                  required:
                    - type
                  properties:
                    type:
                      type: string
                      description: |
                        Parser types:
                        * `None` - do not parse logs
                        * `General` - tries to match general multiline logs with space or tabulation on extra lines
                        * `Backslash` - tries to match bash style logs with backslash on all lines except the last event line
                        * `LogWithTime` - tries to detect events by timestamp
                        * `MultilineJSON` - tries to match JSON logs, assuming the event starts with the `{` symbol
                      enum:
                        - None
                        - General
                        - Backslash
                        - LogWithTime
                        - MultilineJSON
                      default: None
                destinationRefs:
                  type: array
                  description: |
                    Array of `ClusterLogDestination` CustomResource names which this source will output with.
                    Fields with float or boolean values will be converted to string.
                  minItems: 1
                  items:
                    type: string
