Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: KafkaContainer networkAliases not available anymore after update to 1.19.2 #7823

Closed
chriskn opened this issue Nov 20, 2023 · 2 comments · Fixed by #7861
Closed

[Bug]: KafkaContainer networkAliases not available anymore after update to 1.19.2 #7823

chriskn opened this issue Nov 20, 2023 · 2 comments · Fixed by #7861

Comments

@chriskn
Copy link

chriskn commented Nov 20, 2023

Module

Kafka

Testcontainers version

1.19.2

Using the latest Testcontainers version?

Yes

Host OS

Windows

Host Arch

x86

Docker version

Client:
 Cloud integration: v1.0.29
 Version:           20.10.22
 API version:       1.41
 Go version:        go1.18.9
 Git commit:        3a2c30b
 Built:             Thu Dec 15 22:36:18 2022
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.16.3 (96739)
 Engine:
  Version:          20.10.22
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.9
  Git commit:       42c8b31
  Built:            Thu Dec 15 22:26:14 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.14
  GitCommit:        9ba4b250366a5ddde94bb7c9d1def331423aa323
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

Disclaimer: The error described in this issue can easily be avoided. I am just creating this issue to inform you about a regression issue, which was not expected from a minor version update.

We are using KafkaContainer together with a custom SchemaRegistryContainer for our Spring Boot Integration-Tests.

In order to connect both, we define a Network for the KafkaContainer and configure the SchemaRegistryContainer to use the same network with a network alias set as SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS url:

@Testcontainers
class KafkaContainerInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {
    companion object {
        private const val CONFLUENT_VERSION = "confluentinc/cp-kafka:7.0.10"

        @Container
        val kafkaContainer: KafkaContainer = KafkaContainer(DockerImageName.parse(CONFLUENT_VERSION))
            .withNetwork(Network.newNetwork())

        @Container
        val schemaRegistryContainer: SchemaRegistryContainer =
            SchemaRegistryContainer().withKafka(kafkaContainer)
    }

    override fun initialize(applicationContext: ConfigurableApplicationContext) {
        kafkaContainer.start()
        schemaRegistryContainer.start()
    }
}
class SchemaRegistryContainer : GenericContainer<SchemaRegistryContainer>(
    "confluentinc/cp-schema-registry:7.0.10"
) {

    init {
        withExposedPorts(8081)
    }

    fun withKafka(kafka: KafkaContainer): SchemaRegistryContainer {
        return withKafka(kafka.network!!,  "${kafka.networkAliases[0]}:9092")
    }

    private fun withKafka(network: Network, bootstrapServers: String): SchemaRegistryContainer {
        withNetwork(network)
        withEnv("SCHEMA_REGISTRY_HOST_NAME", "schema-registry")
        withEnv("SCHEMA_REGISTRY_LISTENERS", "http://0.0.0.0:8081")
        withEnv("SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS", "PLAINTEXT://$bootstrapServers")
        return this
    }
}

After the update to version 1.19.2 kafka.networkAliases[0] throws a IndexOutOfBoundsException because no network alias is configured. This is likely related to this commit: #7748

It can easily be fixed by setting an alias explicitly using the withNetworkAliases method but, as pointed out, such a regression issue was not expected by a minor version update. Therefore, and to make sure no other issues occurred with the change, I'm opening this bug.

Relevant log output

No response

Additional Information

No response

eddumelendez added a commit that referenced this issue Nov 21, 2023
Changes in 1dba8d1 doesn't register a default network alias
when implementing the new `ContainerDef`. This impacts to
kafka and mongodb modules.

Fixes #7823
@codefish1
Copy link

We have this problem on our Ubuntu GIthub Action runners but it works fine on MacOS

eddumelendez added a commit that referenced this issue Nov 21, 2023
Changes in 1dba8d1 doesn't register a default network alias
when implementing the new `ContainerDef`. This impacts to
kafka and mongodb modules.

Fixes #7823
@codefish1
Copy link

I'll try and get a new bug reported raised if required.

I made the changes in my code to use the .withNetworkAlias against 1.19.2 which got past this index out of bounds error but I then get problems on the kafka-streams health check failing.

Timed out waiting for node assignment. Call: listTopics

Again works fine on my work MacOS laptop but fails on the Ubuntu GHA runner we have.

1.19.1 worked fine, I'll try and get time towards the end of the week to make a reproducible version on my Linux laptop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants