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

redpanda: set entrypoint to the custom entrypoint file #2347

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

bojand
Copy link
Contributor

@bojand bojand commented Mar 13, 2024

What does this PR do?

Redpanda module has a custom entrypoint file /entrypoint-tc.sh that waits until the actual Redpanda broker node config file is mounted.
Then proceeds to call the normal Redpanda entryfile /entrypoint.sh.

The current implementation of the module sets the entrypoint file into the Cmd of the ContainerRequest.
This seems to work with Docker, but does not work with Podman.

This results in an error when starting the container:

+ '[' '' = true ']'
+ exec /usr/bin/rpk /entrypoint-tc.sh redpanda start --mode=dev-container --smp=1 --memory=1G
Error: unknown command "/entrypoint-tc.sh" for "rpk"
Run 'rpk --help' for usage.

Since the intent is to override the entrypoint, we should be setting Entrypoint property as this is more appropriate.

In more detail, if we inspect the Docker container:

{
    "Id": "52d5be52543a60e793fa4920fd81794fe646fff06d917c96d56cbdf164475925",
    "Created": "2024-03-12T18:42:46.003923967Z",
    "Path": "/entrypoint-tc.sh",
    "Args": [
        "redpanda",
        "start",
        "--mode=dev-container",
        "--smp=1",
        "--memory=1G"
    ],
    ...
    "Config": {
        "Hostname": "52d5be52543a",
        "Domainname": "",
        "User": "root:root",
        "AttachStdin": false,
        "AttachStdout": false,
        "AttachStderr": false,
        "ExposedPorts": {
            "8081/tcp": {},
            "8082/tcp": {},
            "9092/tcp": {},
            "9644/tcp": {}
        },
        "Tty": false,
        "OpenStdin": false,
        "StdinOnce": false,
        "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "EDITOR=vi"
        ],
        "Cmd": [
            "/entrypoint-tc.sh",
            "redpanda",
            "start",
            "--mode=dev-container",
            "--smp=1",
            "--memory=1G"
        ],
        "Image": "redpandadata/redpanda:v23.3.2",
        "Volumes": {
            "/var/lib/redpanda/data": {}
        },
        "WorkingDir": "",
        "Entrypoint": [],
        "OnBuild": null,
        "Labels": {
            "org.opencontainers.image.authors": "Redpanda Data <[email protected]>",
            "org.testcontainers": "true",
            "org.testcontainers.lang": "go",
            "org.testcontainers.sessionId": "353c39fb1e5c8ee2313ec527210b4ab8fcda2274b067bd4d2360bff88574f774",
            "org.testcontainers.version": "0.28.0"
        }
    },
    ...
}

But if we inspect the Podman container:

{
  "Id": "3f9bb85cc4761e06082d7add0c02937439eba3d05ec1febf48ad09667b7abae5",
  "Created": "2024-03-12T19:05:31.255025847Z",
  "Path": "/entrypoint.sh",
  "Args": [
    "/entrypoint-tc.sh",
    "redpanda",
    "start",
    "--mode=dev-container",
    "--smp=1",
    "--memory=1G"
  ],
...
"Config": {
    "Hostname": "3f9bb85cc476",
    "Domainname": "",
    "User": "root:root",
    "AttachStdin": false,
    "AttachStdout": false,
    "AttachStderr": false,
    "ExposedPorts": {
      "8081/tcp": {},
      "8082/tcp": {},
      "9092/tcp": {},
      "9644/tcp": {}
    },
    "Tty": false,
    "OpenStdin": false,
    "StdinOnce": false,
    "Env": [
      "container=podman",
      "EDITOR=vi",
      "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
      "HOME=/root",
      "HOSTNAME=3f9bb85cc476"
    ],
    "Cmd": [
      "/entrypoint-tc.sh",
      "redpanda",
      "start",
      "--mode=dev-container",
      "--smp=1",
      "--memory=1G"
    ],
    "Image": "docker.io/redpandadata/redpanda:v23.3.2",
    "Volumes": null,
    "WorkingDir": "/",
    "Entrypoint": [
      "/entrypoint.sh"
    ],
    "OnBuild": null,
    "Labels": {
      "org.opencontainers.image.authors": "Redpanda Data <[email protected]>",
      "org.testcontainers": "true",
      "org.testcontainers.lang": "go",
      "org.testcontainers.sessionId": "acef449fb3c94d212abe04df036b9e045292ce128eaf4a666f3d7340f9e421ad",
      "org.testcontainers.version": "0.28.0"
    },
    "StopSignal": "15",
    "StopTimeout": 10
  },
  ...
}

We can see the Entrypoint for Podman container includes the stock Redpanda entrypoint.sh.

Why is it important?

It is more correct to override entrypoint this way.

How to test this PR

I have tested this change using Docker, and also using Podman, without changing code under test.

TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE, TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED, and DOCKER_HOST env vars were set to accommodate proper running of Ryuk, and test environment. I ran into issues #2264 and #538.

@bojand bojand requested a review from a team as a code owner March 13, 2024 02:38
Copy link

netlify bot commented Mar 13, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 1925fe0
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/65f1118d1b2a6600080777d1
😎 Deploy Preview https://deploy-preview-2347--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kiview
Copy link
Member

kiview commented Mar 13, 2024

Hi @bojand, thanks for the PR.
You are right, the intent is to change the entrypoint (although I would like to loop in @eddumelendez, who originally implemented this pattern in tc-java). If we decide to merge this change, we should align the implementations in other languages as wel.

However, it is strange to me, that Podman and Docker behave different in this specific instance. So there are cases, where a withCommand() will effectively set an entrypoint in the case of Docker, while it won't in case of Podman?

@kiview
Copy link
Member

kiview commented Mar 13, 2024

I checked that we have the same situation in tc-java. For me it looks, like Podman does not handle setting an empty Entrypoint correctly (i.e. in the same way as Docker):
https://github.com/testcontainers/testcontainers-go/blob/main/modules/redpanda/redpanda.go#L75

If the Entrypoint is empty, the Cmd is supposed to become the Entrypoint (see Docker docs). While this PR would fix the issue for Podman users, we generally try to not perform Podman-specific changes, and rather prefer raising this as an issue with Podman (which is generally appreciated in bringing parity to Docker behavior).

@mdelapenya mdelapenya self-assigned this Mar 13, 2024
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Mar 13, 2024
Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

Thanks @kiview for your review and coming with your insights.

LGTM

@mdelapenya mdelapenya merged commit d243321 into testcontainers:main Mar 13, 2024
98 checks passed
mdelapenya added a commit to JJCinAZ/testcontainers-go that referenced this pull request Mar 15, 2024
* main:
  feat: support for waiting for response headers (testcontainers#2349)
  chore(deps): bump google.golang.org/protobuf from 1.32.0 to 1.33.0 (testcontainers#2392)
  redpanda: set entrypoint to the custom entrypoint file (testcontainers#2347)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Changes that do not impact the existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants