Skip to content

Container api port watcher#2

Closed
Nino-K wants to merge 69 commits into
masterfrom
container-api-port-watcher
Closed

Container api port watcher#2
Nino-K wants to merge 69 commits into
masterfrom
container-api-port-watcher

Conversation

@Nino-K
Copy link
Copy Markdown
Owner

@Nino-K Nino-K commented Jun 6, 2025

Subscribe to the Docker API to monitor container creation and deletion events. Upon receiving these events, the event monitor immediately sends them as API events down the aggregated event channel.

@Nino-K Nino-K force-pushed the container-api-port-watcher branch 3 times, most recently from e79b166 to 6768030 Compare June 10, 2025 17:21
@Nino-K Nino-K force-pushed the container-api-port-watcher branch 4 times, most recently from 73f40ee to 9f2a092 Compare June 27, 2025 07:15
Signed-off-by: Ansuman Sahoo <anshumansahoo500@gmail.com>
@Nino-K Nino-K force-pushed the container-api-port-watcher branch 2 times, most recently from 24ac908 to 708a883 Compare July 10, 2025 06:26
Nino-K pushed a commit that referenced this pull request Jul 11, 2025
agetty segfaults on Ubuntu 25.04 (x86_64):

  (gdb) bt
  #0  __strncmp_evex () at ../sysdeps/x86_64/multiarch/strcmp-evex.S:316
  #1  0x000061700a0d3ee3 in parse_args (argc=9, argv=0x7ffc93bd6298, op=0x7ffc93bd4080) at term-utils/agetty.c:939
  #2  main (argc=9, argv=0x7ffc93bd6298) at term-utils/agetty.c:403

Should be fixed in Ubuntu 25.10 with util-linux >= 2.41

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
@Nino-K Nino-K force-pushed the container-api-port-watcher branch from 708a883 to 0c77e7e Compare July 11, 2025 07:24
Signed-off-by: Ansuman Sahoo <anshumansahoo500@gmail.com>
@Nino-K Nino-K force-pushed the container-api-port-watcher branch from 0c77e7e to c5c68f2 Compare July 11, 2025 17:24
Comment on lines +23 to +28
strip_array() {
val="${1#[}" # remove leading [
val="${val%]}" # remove trailing ]
printf '%s\n' "$val" | xargs # trim spaces
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why is this necessary? There should be no brackets in the strings.

--kubernetes-configs \"{LIMA_CIDATA_KUBERNETES_SERVICE_WATCHER_CONFIGS}" \
--vsock-port \"${LIMA_CIDATA_VSOCK_PORT}\" \
--virtio-port \"${LIMA_CIDATA_VIRTIO_PORT}\""
command_background=true pidfile="/run/lima-guestagent.pid"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Keep them on separate lines:

Suggested change
command_background=true pidfile="/run/lima-guestagent.pid"
command_background=true
pidfile="/run/lima-guestagent.pid"

Comment on lines +66 to +70
docker_args=""
docker_items="$(strip_array "${LIMA_CIDATA_DOCKER_PORT_MONITOR_SOCKETS}")"
if [ -n "$docker_items" ]; then
docker_args="--docker-sockets=${LIMA_CIDATA_DOCKER_PORT_MONITOR_SOCKETS}"
fi
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

strip_array should not be necessary. And the app should do the right thing when called with an empty argument --docker-sockets=. So I think this can be just

Suggested change
docker_args=""
docker_items="$(strip_array "${LIMA_CIDATA_DOCKER_PORT_MONITOR_SOCKETS}")"
if [ -n "$docker_items" ]; then
docker_args="--docker-sockets=${LIMA_CIDATA_DOCKER_PORT_MONITOR_SOCKETS}"
fi
docker_args="--docker-sockets=${LIMA_CIDATA_DOCKER_PORT_MONITOR_SOCKETS}"

Same argument applies to the next 2 conditionals.

Comment on lines +87 to +89
${docker_args:+${docker_args}} \
${containerd_args:+${containerd_args}} \
${kubernetes_args:+${kubernetes_args}}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

They are never empty, so this could just be:

Suggested change
${docker_args:+${docker_args}} \
${containerd_args:+${containerd_args}} \
${kubernetes_args:+${kubernetes_args}}
${docker_args} \
${containerd_args} \
${kubernetes_args}

Same in the next 2 blocks.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The naming convention is to call this file containerd_others.go and not _stub.

Comment thread pkg/limayaml/defaults.go Outdated
Comment on lines +603 to +564
if out, err := executeGuestTemplate(y.PortMonitors.Docker.Sockets[i], instDir, y.User, y.Param); err == nil {
y.PortMonitors.Docker.Sockets[i] = out.String()
} else {
logrus.WithError(err).Warnf("Couldn't process Docker socket %q as a template", y.PortMonitors.Docker.Sockets[i])
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe simplify:

Suggested change
if out, err := executeGuestTemplate(y.PortMonitors.Docker.Sockets[i], instDir, y.User, y.Param); err == nil {
y.PortMonitors.Docker.Sockets[i] = out.String()
} else {
logrus.WithError(err).Warnf("Couldn't process Docker socket %q as a template", y.PortMonitors.Docker.Sockets[i])
}
socket := &y.PortMonitors.Docker.Sockets[i]
if out, err := executeGuestTemplate(*socket, instDir, y.User, y.Param); err == nil {
*socket = out.String()
} else {
logrus.WithError(err).Warnf("Couldn't process Docker socket %q as a template", *socket)
}

Comment thread pkg/limayaml/defaults.go Outdated
}

if y.Containerd.System != nil && *y.Containerd.System {
if out, err := executeGuestTemplate("/run/containerd/containerd.sock", instDir, y.User, y.Param); err == nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There are no variables in the filename, so no need to run it through the templating.

Comment thread pkg/limayaml/limayaml.go Outdated
Certs []string `yaml:"certs,omitempty" json:"certs,omitempty" jsonschema:"nullable"`
}

// Engine is the name of the container engine, e.g. "docker", "containerd".
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The comment sounds wrong. Engine is a list of socket locations, not the name of the container engine.

Comment thread pkg/limayaml/validate.go

func validateSocket(engine, socket string) error {
if socket == "" {
return fmt.Errorf("%s socket path must not be empty", engine)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The normal format of validation errors would look more like

field `portMonitor.docker.sockets[1]` must not be empty

You will need to pass in the index too.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The validateSocket gets called in a loop, so no need for the index. The socket is individual and not a list.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No, the sockets are a list, so you should provide the list index for the error message. You can pass in the field name instead of the index if you want the caller to assemble it. But since it is called from 2 places, it would be simpler to pass in the index.

Suggested change
return fmt.Errorf("%s socket path must not be empty", engine)
return fmt.Errorf("field `portMonitor.%s.sockets[%d]` must not be empty", engine, i)

portMonitors:
docker:
sockets:
- "/var/run/docker.sock"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You don't really need to put quotes around paths that don't contain template variables. But I guess it doesn't hurt either.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I just wanted to keep it consistent with the reset of the file e.g:

portForwards:
- guestSocket: "/var/run/docker.sock"
  hostSocket: "{{.Dir}}/sock/docker.sock"

AkihiroSuda and others added 15 commits July 12, 2025 11:13
…system

Feature: Internal driver plugin system
Signed-off-by: Viktor Oreshkin <imselfish@stek29.rocks>
The UDP port forwarder previously used a single gRPC stream for all
clients, which could cause responses from the guest to be sent to the
wrong client on the host.

This occurred because the stream was created before client connections
were demultiplexed by `gvisor-tap-vsock`'s `UDPProxy`.

The root cause is the interaction with `gvisor-tap-vsock`'s `UDPProxy`,
which handles client demultiplexing internally based on the source
address of incoming datagrams. It expects its `dialer` function to
return a new `net.Conn` for each new client it detects.

This commit moves the gRPC stream creation into the `UDPProxy` dialer
function. This ensures a new, dedicated stream is created for each new
client, fixing the incorrect response routing.

Signed-off-by: Viktor Oreshkin <imselfish@stek29.rocks>
this setting is not necessary anymore on Oracle Linux 9, but produces a warning on vz vm types

Signed-off-by: Nandor Kracser <bonifaido@gmail.com>
remove unnecessary legacyBIOS setting
Signed-off-by: Ansuman Sahoo <anshumansahoo500@gmail.com>
I've spent some time debugging issues with UDP forwarding and got sidetracked because of this constant, so I decieded to submit this PR suggesting to change it

there's no "established" for the UDP, and 0x7 is usually called UNCONN in tools like net-tools or ss

Signed-off-by: Viktor Oreshkin <imselfish@stek29.rocks>
guestagent cidata: pass debug flag to guestagent systemd unit
…system

Feature: External driver plugin system and update Makefile
rename UDPEstablished to UDPUnconnected
Signed-off-by: Andrei Gaivoronskii <plandem@gmail.com>
The major version is now updated to highlight the introduction of the
pluggable VM driver framework.

See issue 3712

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Fix issue 3639

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
@Nino-K Nino-K force-pushed the container-api-port-watcher branch from 732f92d to ca0b9a0 Compare July 28, 2025 21:35
refactor: migrate `cpuType` to `vmOpts.qemu`
@Nino-K Nino-K force-pushed the container-api-port-watcher branch 2 times, most recently from c77f895 to 6e7b12f Compare July 29, 2025 18:24
dependabot Bot and others added 2 commits July 30, 2025 01:33
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.29.4 to 3.29.5.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@4e828ff...51f7732)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.29.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…s/github/codeql-action-3.29.5

build(deps): bump github/codeql-action from 3.29.4 to 3.29.5
@Nino-K Nino-K force-pushed the container-api-port-watcher branch 3 times, most recently from 9b6df83 to dbf9ca7 Compare July 31, 2025 19:12
Nino-K added 19 commits July 31, 2025 12:22
Subscribe to the Docker API to monitor container creation and deletion events.
Upon receiving these events, the event monitor immediately sends them as
API events down the aggregated event channel.

Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Subscribe to the containerd API to monitor published ports for containers.
Upon receiving these events, the event monitor immediately sends them as
API events down the aggregated event channel.

Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Subscribes to kube API for the published ports from
NodePort and Loadbalancer type.

Signed-off-by: Nino Kodabande <nkodabande@suse.com>
The Kubernetes service is not needed since it has been
replaced by the event-driven process.

Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Also, handle the defaults for Docker, Containerd

Signed-off-by: Nino Kodabande <nkodabande@suse.com>
This changes the Docker event monitor to accept socket
and create a per socket client to monitor events.

Signed-off-by: Nino Kodabande <nkodabande@suse.com>
This will start a containerd client per socket

Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Changes the kubernetes service watcher to accept a list of
config paths.

Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
@Nino-K Nino-K force-pushed the container-api-port-watcher branch from dbf9ca7 to f49244d Compare July 31, 2025 19:27
@Nino-K Nino-K closed this Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants