---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: trafficprofiles.k8s-netem.riasc.eu

spec:
  group: k8s-netem.riasc.eu
  scope: Cluster

  names:
    plural: trafficprofiles
    singular: trafficprofile
    kind: TrafficProfile
    shortNames:
    - tp
    - tps

  versions:
  - name: v1
    served: true
    storage: true
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            required:
            - podSelector
            - parameters
            properties:
              podSelector:
                type: object
                description: >-
                  A label selector is a label query over a set of resources. The result of
                  matchLabels and matchExpressions are ANDed. An empty label selector
                  matches all objects. A null label selector matches no objects.
                properties:
                  matchExpressions:
                    description: >-
                      matchExpressions is a list of label selector requirements. The
                      requirements are ANDed.
                    items:
                      description: >-
                        A label selector requirement is a selector that contains values, a
                        key, and an operator that relates the key and values.
                      properties:
                        key:
                          description: key is the label key that the selector applies to.
                          type: string
                          x-kubernetes-patch-merge-key: key
                          x-kubernetes-patch-strategy: merge
                        operator:
                          description: >-
                            operator represents a key's relationship to a set of values.
                            Valid operators are In, NotIn, Exists and DoesNotExist.
                          type: string
                        values:
                          description: >-
                            values is an array of string values. If the operator is In or
                            NotIn, the values array must be non-empty. If the operator is
                            Exists or DoesNotExist, the values array must be empty. This
                            array is replaced during a strategic merge patch.
                          items:
                            type: string
                          type: array
                      required:
                        - key
                        - operator
                      type: object
                    type:  array
                  matchLabels:
                    additionalProperties:
                      type: string
                    description: >-
                      matchLabels is a map of {key,value} pairs. A single {key,value} in the
                      matchLabels map is equivalent to an element of matchExpressions, whose
                      key field is "key", the operator is "In", and the values array
                      contains only "value". The requirements are ANDed.
                    type: object

              type:
                type: string
                default: Builtin
                pattern: '^(Builtin|Script|Flexe)$'

              parameters:
                type: object

                # For type == 'Script'
                x-kubernetes-preserve-unknown-fields: true

                properties:
                  netem:
                    type: object
                    properties:
                      loss_ratio:
                        type: number
                        default: 0
                        description: Percentage of packets that will be lost
                        minimum: 0
                        maximum: 100
                      loss_correlation:
                        type: integer
                        default: 0
                        description: Correlation factor for the random packet loss
                        minimum: 0
                        maximum: 100
                      duplication_ratio:
                        type: integer
                        default: 0
                        description: Percentage of packets that will be duplicated
                        minimum: 0
                        maximum: 100
                      duplication_correlation:
                        type: integer
                        default: 0
                        description: Correlation factor for duplicated packets
                        minimum: 0
                        maximum: 100
                      delay:
                        type: number
                        default: 0
                        description: Overall delay for each packet in seconds
                        minimum: 0
                        maximum: 4294.967295
                      jitter:
                        type: number
                        default: 0
                        description: Amount of jitter in seconds
                        minimum: 0
                        maximum: 4294.967295
                      delay_jitter_correlation:
                        type: integer
                        default: 0
                        description: Correlation factor for the random jitter
                        minimum: 0
                        maximum: 100
                      distribution:
                        type: string
                        default: normal
                        description: Delay distribution
                        pattern: '^uniform|normal|pareto|paretonormal$'
                      reorder_ratio:
                        type: integer
                        default: 0
                        description: Percentage of packets that will be reordered
                        minimum: 0
                        maximum: 100
                      reorder_correlation:
                        type: integer
                        default: 0
                        description: Correlation factor for the random reordering
                        minimum: 0
                        maximum: 100
                      reorder_gap:
                        type: integer
                        default: 0
                      limit:
                        type: integer
                        default: 0
                        minimum: 0
                      rate:
                        type: integer
                        default: 0
                        minimum: 0
                      rate_packetoverhead:
                        type: integer
                        default: 0
                      rate_cellsize:
                        type: integer
                        default: 0
                      rate_celloverhead:
                        type: integer
                        default: 0
                      slot_min_delay:
                        type: number
                        default: 0
                      slot_max_delay:
                        type: number
                        default: 0
                      slot_distribution:
                        type: string
                        default: normal
                        pattern: '^uniform|normal|pareto|paretonormal$'
                      slot_delay:
                        type: number
                        default: 0
                      slot_jitter:
                        type: number
                        default: 0
                      slot_packets:
                        type: integer
                        default: 0
                      slot_bytes:
                        type: integer
                        default: 0

              egress:
                items:
                  properties:
                    ports:
                      items:
                        description: NetworkPolicyPort describes a port to allow traffic on
                        properties:
                          port:
                            type: integer
                          protocol:
                            type: string
                        type: object
                      type: array
                    to:
                      items:
                        properties:
                          ipBlock:
                            properties:
                              cidr:
                                type: string
                            required:
                            - cidr
                            type: object
                          podSelector:
                            properties:
                              matchExpressions:
                                items:
                                  properties:
                                    key:
                                      type: string
                                      x-kubernetes-patch-merge-key: key
                                      x-kubernetes-patch-strategy: merge
                                    operator:
                                      type: string
                                    values:
                                      items:
                                        type: string
                                      type: array
                                  required:
                                  - key
                                  - operator
                                  type: object
                                type: array
                              matchLabels:
                                additionalProperties:
                                  type: string
                                type: object
                            type: object
                        type: object
                      type: array
                  type: object
                type: array

              ingress:
                items:
                  properties:
                    from:
                      items:
                        properties:
                          ipBlock:
                            properties:
                              cidr:
                                type: string
                              except:
                                items:
                                  type: string
                                type: array
                            required:
                            - cidr
                            type: object
                          podSelector:
                            properties:
                              matchExpressions:
                                items:
                                  properties:
                                    key:
                                      type: string
                                      x-kubernetes-patch-merge-key: key
                                      x-kubernetes-patch-strategy: merge
                                    operator:
                                      type: string
                                    values:
                                      items:
                                        type: string
                                      type: array
                                  required:
                                    - key
                                    - operator
                                  type: object
                                type: array
                              matchLabels:
                                additionalProperties:
                                  type: string
                                type: object
                            type: object
                        type: object
                      type: array
                    ports:
                      items:
                        properties:
                          port:
                            type: integer
                          protocol:
                            type: string
                        type: object
                      type: array
                  type: object
                type: array
