# Defaults

KPOps has a very efficient way of dealing with repeating settings which manifests as [`defaults.yaml`](<https://bakdata.github.io/kpops/resources/pipeline-defaults/defaults>). This file provides the user with the power to set defaults for any and all [components](<https://bakdata.github.io/kpops/13.0/user/core-concepts/components/overview/index.md>), thus omitting the need to repeat the same settings in [`pipeline.yaml`](<https://bakdata.github.io/kpops/resources/pipeline-components/pipeline>).

[See real-world examples for `defaults`](<https://bakdata.github.io/kpops/resources/examples/defaults>).

## Features

### Inheritance

An important mechanic of KPOps is that `defaults` set for a component apply to all components that inherit from it.

### Configuration

KPOps allows using multiple default values. The `defaults.yaml` (or `defaults_<env>.yaml`) files can be distributed across multiple files. These will be picked up by KPOps and get merged into a single `pipeline.yaml` file. KPOps starts from reading the default files from where the pipeline path is defined and picks up every defaults file on its way to where the `pipeline_base_dir` is defined.

The deepest `defaults.yaml` file in the folder hierarchy (i.e., the closest one to the `pipeline.yaml`) overwrites the higher-level defaults' values.

It is important to note that `defaults_{environment}.yaml` overrides only the settings that are explicitly set to be different from the ones in the base `defaults` file.

> [!NOTE]
>
> **defaults merge priority**
>
> Imagine the following folder structure, where the `pipeline_base_dir` is configured to `pipelines`:
>
> ```text
> └─ pipelines
>    └── distributed-defaults
>        ├── defaults.yaml
>        ├── defaults_dev.yaml
>        └── pipeline-deep
>            ├── defaults.yaml
>            └── pipeline.yaml
> ```
>
> KPOps picks up the defaults in the following order (high to low priority):
>
> - `./pipelines/distributed-defaults/pipeline-deep/defaults.yaml`
> - `./pipelines/distributed-defaults/defaults_dev.yaml`
> - `./pipelines/distributed-defaults/defaults.yaml`

## Components

The `defaults` codeblocks in this section contain the full set of settings that are specific to the component. If a setting already exists in a parent config, it will not be included in the child's.

### [KubernetesApp](<https://bakdata.github.io/kpops/13.0/user/core-concepts/components/kubernetes-app/index.md>)

> [!NOTE]
>
> **`defaults.yaml`**
>
> ```yaml
> # Base Kubernetes App
> #
> # Parent of: HelmApp
> # Child of: PipelineComponent
> kubernetes-app:
>   # Pipeline prefix that will prefix every component name. If you wish to not
>   # have any prefix you can specify an empty string.
>   prefix: ${pipeline.name}-
>   namespace: namespace # required
>   values: # required
>     image: exampleImage # Example
>     debug: false # Example
>     commandLine: {} # Example
> ```

### [StreamsApp](<https://bakdata.github.io/kpops/13.0/user/core-concepts/components/streams-app/index.md>)

> [!NOTE]
>
> **`defaults.yaml`**
>
> ```yaml
> # Streams app component that configures a streams-bootstrap app.
> #
> # Child of: StreamsBootstrap
> # More documentation on StreamsApp: https://github.com/bakdata/streams-bootstrap
> streams-app:
>   from: # Must not be null
>     topics: # read from topic
>       ${pipeline.name}-input-topic:
>         type: input # Implied when role is NOT specified
>       ${pipeline.name}-extra-topic:
>         label: topic-role # Implies `type` to be extra
>       ${pipeline.name}-input-pattern-topic:
>         type: pattern # Implied to be an input pattern if `label` is undefined
>       ${pipeline.name}-extra-pattern-topic:
>         type: pattern # Implied to be an extra pattern if `label` is defined
>         label: some-role
>     components: # read from specific component
>       account-producer:
>         type: input # Implied when role is NOT specified
>       other-producer:
>         label: some-role # Implies `type` to be extra
>       component-as-input-pattern:
>         type: pattern # Implied to be an input pattern if `label` is undefined
>       component-as-extra-pattern:
>         type: pattern # Implied to be an extra pattern if `label` is defined
>         label: some-role
>   # Topic(s) into which the component will write output
>   to:
>     topics:
>       ${pipeline.name}-output-topic:
>         type: output # Implied when role is NOT specified
>       ${pipeline.name}-extra-topic:
>         label: topic-role # Implies `type` to be extra; Will throw an error if `type` is defined
>       ${pipeline.name}-error-topic:
>         type: error
>         # Currently KPOps supports Avro and JSON schemas.
>         key_schema: key-schema # must implement SchemaProvider to use
>         value_schema: value-schema
>         partitions_count: 1
>         replication_factor: 1
>         configs: # https://kafka.apache.org/documentation/#topicconfigs
>           cleanup.policy: compact
>     models: # SchemaProvider is initiated with the values given here
>       model: model
>   # No arbitrary keys are allowed under `app` here
>   # Allowed configs:
>   # https://github.com/bakdata/streams-bootstrap/tree/master/charts/streams-app
>   values: # required
>     # streams-bootstrap kafka section
>     kafka: # required, streams-app-specific
>       bootstrapServers: ${config.kafka_brokers}
>       schemaRegistryUrl: ${config.schema_registry.url}
>       applicationId: example-id
>       inputTopics:
>         - topic1
>         - topic2
>       outputTopic: output-topic
>       inputPattern: input-pattern
>       labeledInputTopics:
>         input_role1:
>           - input_topic1
>           - input_topic2
>         input_role2:
>           - input_topic3
>           - input_topic4
>       labeledInputPatterns:
>         pattern_role1: input_pattern1
>       labeledOutputTopics:
>         output_role1: output_topic1
>         output_role2: output_topic2
>       errorTopic: error-topic
>       config:
>         my.streams.config: my.value
>       deleteOutput: false
>     nameOverride: override-with-this-name # streams-app-specific
>     fullnameOverride: override-with-this-name # streams-app-specific
>     autoscaling: # streams-app-specific
>       enabled: false # Whether to enable auto-scaling using KEDA.
>       lagThreshold: 0 # Average target value to trigger scaling actions.
>       # This is the interval to check each trigger on.
>       # https://keda.sh/docs/2.9/concepts/scaling-deployments/#pollinginterval
>       pollingInterval: 30
>       # The period to wait after the last trigger reported active before scaling
>       #  the resource back to 0. https://keda.sh/docs/2.9/concepts/scaling-deployments/#cooldownperiod
>       cooldownPeriod: 300
>       # The offset reset policy for the consumer if the the consumer group is
>       # not yet subscribed to a partition.
>       offsetResetPolicy: earliest
>       # This setting is passed to the HPA definition that KEDA will create for a
>       # given resource and holds the maximum number of replicas of the target resource.
>       # https://keda.sh/docs/2.9/concepts/scaling-deployments/#maxreplicacount
>       maxReplicas: 1
>       # Minimum number of replicas KEDA will scale the resource down to.
>       # https://keda.sh/docs/2.7/concepts/scaling-deployments/#minreplicacount
>       minReplicas: 0
>       # If this property is set, KEDA will scale the resource down to this
>       # number of replicas.
>       # https://keda.sh/docs/2.9/concepts/scaling-deployments/#idlereplicacount
>       idleReplicas: 0
>       internalTopics: # List of auto-generated Kafka Streams topics used by the streams app.
>         - topic1
>         - topic2
>       topics: # List of topics used by the streams app.
>         - topic1
>         - topic2
>       # Complete list of KEDA triggers. When set, these replace all
>       # chart-generated Kafka lag triggers.
>       triggers: []
>       # - type: cron
>       #   name: business_hours
>       #   metadata:
>       #     timezone: Europe/Berlin
>       #     start: "0 8 * * 1-5"
>       #     end: "0 18 * * 1-5"
>       #     desiredReplicas: "2"
>       # List of KEDA triggers appended to chart-generated Kafka lag triggers.
>       additionalTriggers: []
>       # KEDA composite metric configuration. Requires explicit triggers.
>       # scalingModifiers:
>       #   formula: business_hours
>       #   target: "1"
>       #   metricType: AverageValue
> ```

### [ProducerApp](<https://bakdata.github.io/kpops/13.0/user/core-concepts/components/producer-app/index.md>)

> [!NOTE]
>
> **`defaults.yaml`**
>
> ```yaml
>
> ```

### [KafkaConnector](<https://bakdata.github.io/kpops/13.0/user/core-concepts/components/kafka-connector/index.md>)

> [!NOTE]
>
> **`defaults.yaml`**
>
> ```yaml
> # Kafka connector
> #
> # Parent of: KafkaSinkConnector, KafkaSourceConnector
> # Child of: KafkaApp
> kafka-connector:
>   # Topic(s) into which the component will write output
>   to:
>     topics:
>       ${pipeline.name}-output-topic:
>         type: output # Implied when role is NOT specified
>       ${pipeline.name}-extra-topic:
>         label: topic-role # Implies `type` to be extra; Will throw an error if `type` is defined
>       ${pipeline.name}-error-topic:
>         type: error
>         # Currently KPOps supports Avro and JSON schemas.
>         key_schema: key-schema # must implement SchemaProvider to use
>         value_schema: value-schema
>         partitions_count: 1
>         replication_factor: 1
>         configs: # https://kafka.apache.org/documentation/#topicconfigs
>           cleanup.policy: compact
>     models: # SchemaProvider is initiated with the values given here
>       model: model
>   # Full documentation on connectors: https://kafka.apache.org/documentation/#connectconfigs
>   config: # required
>     tasks.max: 1
> ```

### [KafkaSourceConnector](<https://bakdata.github.io/kpops/13.0/user/core-concepts/components/kafka-source-connector/index.md>)

> [!NOTE]
>
> **`defaults.yaml`**
>
> ```yaml
> # Kafka source connector
> #
> # Child of: KafkaConnector
> kafka-source-connector:
> ```

### [KafkaSinkConnector](<https://bakdata.github.io/kpops/13.0/user/core-concepts/components/kafka-sink-connector/index.md>)

> [!NOTE]
>
> **`defaults.yaml`**
>
> ```yaml
> # Kafka sink connector
> #
> # Child of: KafkaConnector
> kafka-sink-connector:
>   # No settings differ from `kafka-connector`
>   from: # Must not be null
>     topics: # read from topic
>       ${pipeline.name}-input-topic:
>         type: input # Implied when role is NOT specified
>       ${pipeline.name}-extra-topic:
>         label: topic-role # Implies `type` to be extra
>       ${pipeline.name}-input-pattern-topic:
>         type: pattern # Implied to be an input pattern if `label` is undefined
>       ${pipeline.name}-extra-pattern-topic:
>         type: pattern # Implied to be an extra pattern if `label` is defined
>         label: some-role
>     components: # read from specific component
>       account-producer:
>         type: input # Implied when role is NOT specified
>       other-producer:
>         label: some-role # Implies `type` to be extra
>       component-as-input-pattern:
>         type: pattern # Implied to be an input pattern if `label` is undefined
>       component-as-extra-pattern:
>         type: pattern # Implied to be an extra pattern if `label` is defined
>         label: some-role
> ```
