testcontainers / testcontainers/testcontainers-python
Bug: KafkaContainer.tc_start not starting when using a Network
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 2.3k
- Fork
- 386
- Merge medio
- 4h 40m
- PR unite (30g)
- 1
Descrizione
If fails to start, since tc_start assumes that the container is using host networking
from docker.types import EndpointConfig
from testcontainers.core.container import DockerContainer
from testcontainers.core.network import Network
from testcontainers.kafka import KafkaContainer
def _connect_to_network(ctr: DockerContainer, network: Network, alias: str):
# Needed until https://github.com/testcontainers/testcontainers-python/issues/645 is fixed
ctr.with_kwargs(
network=network.name, networking_config={network.name: EndpointConfig("1.33", aliases=[alias])}
)
with Network() as network:
ctr = KafkaContainer(image=f"confluentinc/cp-kafka:{KAFKA_VERSION}")
_connect_to_network(ctr, network, "kafka")
with ctr:
assert ctr.get_bootstrap_server(). # This should start
A possible fix:
def tc_start(self):
# We replace these three lines, which assume host networking
# host = self.get_container_host_ip()
# port = self.get_exposed_port(self.port)
# listeners = f"PLAINTEXT://{host}:{port},BROKER://$(hostname -i | cut -d' ' -f1):9092"
listeners = f"PLAINTEXT://{self._get_network_alias()}:{self.port},BROKER://$(hostname -i | cut -d' ' -f1):9092"
data = (
dedent(
f"""
#!/bin/bash
{self.boot_command}
export KAFKA_ADVERTISED_LISTENERS={listeners}
. /etc/confluent/docker/bash-config
/etc/confluent/docker/configure
/etc/confluent/docker/launch
"""
)
.strip()
.encode("utf-8")
)
self.create_file(data, KafkaContainer.TC_START_SCRIPT)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da KafkaContainer.tc_start e confronta le sue ipotesi sulla rete dell’host con la configurazione di Network mostrata nell’issue. Traccia l’interazione tra _get_network_alias, get_bootstrap_server e lo script di avvio del container. Il lavoro è completato quando KafkaContainer si avvia correttamente su un Network e get_bootstrap_server restituisce un bootstrap server utilizzabile.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- docker, kafka, python
- Ambito
- distributed-systems, networking
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100