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

feat: enable access to kafka using container hostname #1786

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion modules/kafka/kafka.go
Expand Up @@ -77,7 +77,13 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
return err
}

scriptContent := fmt.Sprintf(starterScriptContent, host, port.Int(), host)
name, err := c.Name(ctx)
if err != nil {
return err
}
containerHost := strings.TrimPrefix(name, "/")

scriptContent := fmt.Sprintf(starterScriptContent, host, port.Int(), containerHost)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, I think we do not need to get the host in L70 anymore, right?

Could you update it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are one thing to care about. The advertised listeners should be two:

  1. one will be listening from outside the containers and used by the clients through Brokers fn. This one used the host from where docker executes and not the container host
  2. other will be listening in the container itself

You can look at the Java implementation. We can align both implementations and get the config.Hostname which looks like is not available in testcontainers.Container interface.


return c.CopyToContainer(ctx, []byte(scriptContent), starterScript, 0o755)
},
Expand Down