apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: podloggingconfigs.deckhouse.io
  labels:
    heritage: deckhouse
    module: log-shipper
spec:
  group: deckhouse.io
  scope: Namespaced
  names:
    plural: podloggingconfigs
    singular: podloggingconfig
    kind: PodLoggingConfig
  preserveUnknownFields: false
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          required: ["spec"]
          description: |
            CustomResource for namespaced Kubernetes source in log-pipeline.

            Each CustomResource `PodLoggingConfig` describes rules for log fetching from specified Namespace.
          properties:
            spec:
              type: object
              required:
                - clusterDestinationRefs
              properties:
                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
                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` operator find substring in string
                          * `NotIn` operator is negative version of `In` operator
                          * `Regex` operator is trying to match regexp over field, only log events with matching fields will pass
                          * `NotRegex` operator is negative version of `Regex` operator, log events without fields or with not matched fields will pass
                          * `Exists` operator drop log event if it contains some fields
                          * `DoesNotExist` operator drop 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 with float or boolean values will be converted to strings during comparation.
                        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 - Try to match general multiline logs with space or tabulation on extra lines.
                        * Backslash - Try to match bash style logs with backslash on all lines except last event line.
                        * LogWithTime - Try to detect events by timestamps.
                        * MultilineJSON - Try to match json logs by `{` as a first symbol.
                      enum:
                        - None
                        - General
                        - Backslash
                        - LogWithTime
                        - MultilineJSON
                      default: None
                clusterDestinationRefs:
                  type: array
                  description: Array of `ClusterLogDestination` CustomResource names which this source will output with.
                  minItems: 1
                  items:
                    type: string
