| 17 | |
| 18 | |
| 19 | class Redpanda(Service): |
| 20 | def __init__( |
| 21 | self, |
| 22 | name: str = "redpanda", |
| 23 | version: str = REDPANDA_VERSION, |
| 24 | auto_create_topics: bool = False, |
| 25 | image: str | None = None, |
| 26 | aliases: list[str] | None = None, |
| 27 | ports: list[int] | None = None, |
| 28 | extra_cluster_settings: dict[str, str] | None = None, |
| 29 | ) -> None: |
| 30 | if image is None: |
| 31 | image = f"redpandadata/redpanda:{version}" |
| 32 | |
| 33 | if ports is None: |
| 34 | ports = [9092, 8081] |
| 35 | |
| 36 | # The Redpanda container provides both a Kafka and a Schema Registry replacement |
| 37 | if aliases is None: |
| 38 | aliases = ["kafka", "schema-registry"] |
| 39 | |
| 40 | # Most of these options are simply required when using Redpanda in Docker. |
| 41 | # See: https://docs.redpanda.com/current/get-started/quick-start/#Single-command-for-a-1-node-cluster |
| 42 | # The `enable_transactions` and `enable_idempotence` feature flags enable |
| 43 | # features Materialize requires that are present by default in Apache Kafka |
| 44 | # but not in Redpanda. |
| 45 | |
| 46 | command_list = [ |
| 47 | "redpanda", |
| 48 | "start", |
| 49 | "--overprovisioned", |
| 50 | "--smp=1", |
| 51 | "--memory=1G", |
| 52 | "--reserve-memory=0M", |
| 53 | "--node-id=0", |
| 54 | "--check=false", |
| 55 | "--set", |
| 56 | "redpanda.enable_transactions=true", |
| 57 | "--set", |
| 58 | "redpanda.enable_idempotence=true", |
| 59 | "--set", |
| 60 | f"redpanda.auto_create_topics_enabled={auto_create_topics}", |
| 61 | # Only require 4KB per topic partition rather than 4MiB. |
| 62 | "--set", |
| 63 | "redpanda.topic_memory_per_partition=4096", |
| 64 | ] |
| 65 | # Callers can inject additional `redpanda.<key>=<value>` cluster |
| 66 | # settings. We can't apply such settings broadly because the same |
| 67 | # `Redpanda()` is instantiated across `kafka-matrix`, which exercises |
| 68 | # historical Redpanda versions that don't recognize newer keys (a |
| 69 | # bad key crashes the container at startup). |
| 70 | for key, value in (extra_cluster_settings or {}).items(): |
| 71 | command_list += ["--set", f"redpanda.{key}={value}"] |
| 72 | command_list += [ |
| 73 | "--set", |
| 74 | f"--advertise-kafka-addr=kafka:{ports[0]}", |
| 75 | ] |
| 76 |
no outgoing calls
no test coverage detected