Commit Graph

104 Commits

Author SHA1 Message Date
Marat Radchenko
0a5a80cfec Remove pre-Go 1.17 build tags
Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
2024-11-21 10:58:27 +03:00
Tonis Tiigi
e05a89e0b8 improve stacks of cancels from defers
In this case the current stack trace points to the line
where the context was created. Instead the stack should be
captured when the defer is running so the return path to
the defer call is also part of the stack.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-11-19 18:40:00 -08:00
Justin Chadwell
7e6c20a0db exec: allow specifying non-zero exit codes for execs
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-09-17 11:36:07 +01:00
Tõnis Tiigi
11a4a07060 Merge pull request #5260 from tonistiigi/executor-oomkiller
executor: detect containers killed by OOMKiller
2024-08-23 12:54:46 +03:00
Tonis Tiigi
bc9e857d0f executor: detect containers killed by OOMKiller
If container exits with error and has invoked OOMKiller
mark the origin error as ENOMEM so that it can be detected
on the client side.

gRPC will set ENOMEM as codes.ResouceExhausted based on #5182

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-08-16 11:56:58 +03:00
Tonis Tiigi
df0d9d791d ci: update golangci-lint to v1.60.1
Previous version runs out of memory on go1.23

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-08-14 16:29:22 +03:00
Tonis Tiigi
a7720ed2b1 executor: ensure deeper stacktraces for system errors
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-22 12:34:31 -07:00
Akihiro Suda
1f3eab8c59 Merge pull request #5107 from tonistiigi/json-decoder-fix
fix incorrect usage of json.NewDecoder
2024-07-02 12:42:50 +09:00
Tonis Tiigi
f8bc2e06da fix incorrect usage of json.NewDecoder
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-01 16:41:14 -07:00
Tonis Tiigi
7089987af1 executor: fix cancellation before start signal
If context is canceled before the process is ready
then kill goroutine returns early because there is nothing
to kill. But the process may still start after this and
that case remain running without cancellation. Fix is to skip
cancellation only if the run goroutine is ended, as then the
process will not be started.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-01 15:45:57 -07:00
Tonis Tiigi
4103099d94 ensure context.WithoutCancel in defer funcs
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-12 19:18:32 -07:00
racequite
f24c5756d6 chore: fix function names in comment
Signed-off-by: racequite <quiterace@gmail.com>
2024-04-19 12:23:28 +08:00
Tonis Tiigi
a07a92e157 lint: unusedparams fixes for windows
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-04-09 07:23:16 -07:00
Tonis Tiigi
1f9988911f lint: unusedparams fixes
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-04-09 07:23:16 -07:00
CrazyMax
b5506327cf keep local dns in resolv.conf when host network enabled
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-02-09 09:27:39 +01:00
Tonis Tiigi
09648f4d29 replace WithTimeout with WithTimeoutCause
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-12-06 22:15:12 -08:00
Tonis Tiigi
8a2a3e83ec replace context.WithCancel with WithCancelCause
Keep stack traces for cancellation errors where possible.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-12-06 22:15:06 -08:00
Justin Chadwell
a9b4dd5090 chore: fix windows variable naming issues
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-11-02 10:45:34 +00:00
Erik Sipsma
fa11bf9e57 executor: fix resource sampler goroutine leak
Before this, the runc executor did not close the cgroupRecord when the
container exited non-zero, which resulted in goroutines leaking.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2023-07-31 07:52:54 -07:00
Tonis Tiigi
6a2f92d08f resources: add sampler for periodic stat reads
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-08 15:51:35 -07:00
Tonis Tiigi
963f16179f resources: CNI network usage sampling support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-08 15:51:35 -07:00
Tonis Tiigi
6e87e4b455 resources: add build step resource tracking via cgroups
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-08 15:51:31 -07:00
Erik Sipsma
9b0bdb6006 Prevent overflow of runc exit code.
It's possible for the Status field of runc.ExitError to be set to -1, in
which case conversion to uint32 results in the error message to say that
the container exited with code 4294967295 (2^32-1).

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2023-03-31 19:31:55 -07:00
coryb
6073f5821e runc worker: fix sigkill handling
This fixes the incorrect kill handling introduced in
b76f8c0248.  We need to send the
SIGKILL to the in-container process, not the runc process.  This patch
adds an abstraction over the kill handling:
  * for `runc run` processes use `runc kill`
  * for `runc exec` processes, read pid (in host PID namespace) from
    pidfile created by `runc exec`, then send the signal directly to
    that process.
Also use the kill abstraction when we receive a SIGKILL over the
signal channel for containers created by gateway NewContainer

Signed-off-by: coryb <cbennett@netflix.com>
2023-03-31 12:56:41 -07:00
coryb
b76f8c0248 fix process termination handling for runc exec
This patch makes the process handling consistent between runc.Run and
runc.Exec usage.  Previously runc.Run would use context.Background
for the runc.Run process and would monitor the request context for
shutdown requests, sending a SIGKILL to the container pid1 process. This
allowed runc.Run to gracefully shutdown and reap child processes.  This
logic was not used for runc.Exec where instead we were passing in the
request context to runc.Exec, and if that request context was cancelled
the runc process would immediately terminate preventing runc from reaping
the child process.  In this scenario the extra pid will remain forever
and then when the pid1 process will get wedged in zap_pid_ns_processes
syscall upon shutdown waiting fo the zombie pid to exit.

With this fix both runc.Run and runc.Exec will use context.Background
for runc processes and monitor the request context for shutdown request
triggering a SIGKILL to the pid being monitored by runc.

Signed-off-by: coryb <cbennett@netflix.com>
2023-03-17 12:46:19 -07:00
coryb
a8aa7b200c use bklog.G(ctx) instead of logrus directly
Signed-off-by: coryb <cbennett@netflix.com>
2023-03-15 12:07:44 -07:00
Justin Chadwell
6b265b1bae gateway: add RemoveMountStubsRecursive to exec meta options
This allows a frontend to request a specific for stubs removal.

By default, if not specified, this will revert to the previous
behaviour. New gateway clients however will set the property to the
desired recursive removal mode.

This property needs to be set for both components that call the
executor: for ExecOp, as well as for the StartContainer API.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-12-07 19:06:47 +00:00
Akihiro Suda
bd57e5f6b8 Make SELinux labels opt-in (--oci-worker-selinux=<BOOL>)
Fix issue 3202

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-11-02 14:33:01 +09:00
Aaron Lehmann
588a72d04c Add network namespace pool support
This adds netNSPoolSize pool options which allow setting a target
network namespace pool size. buildkitd will create this number of
network namespaces at startup (without blocking). When a container
execution finishes, the network namespace gets returned to the pool. If
the pool goes above the target size, there is a grace period to allow
network namespaces to be reused, and if this passes without reuse, the
extra namespaces will be released.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2022-09-14 07:08:31 -07:00
Alex Suraci
e3c9e064a9 cniprovider: pass hostname as K8S_POD_NAME arg
Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
2022-08-21 15:43:12 -04:00
Edgar Lee
d21254e7f7 Add events for exec op
Signed-off-by: Edgar Lee <edgarl@netflix.com>
2022-03-02 12:05:35 -08:00
Cory Bennett
559d079902 Allow signals to be sent to gateway exec containers
Signed-off-by: Cory Bennett <cbennett@netflix.com>
2022-02-02 16:57:10 +00:00
Akihiro Suda
d47b46cf2a Merge pull request #2432 from crazy-max/gofmt
go fmt: add //go:build
2021-10-29 12:32:52 +09:00
CrazyMax
54b8ff2fc8 go fmt: add //go:build
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-10-28 13:26:43 +02:00
CrazyMax
c82ef274bf cgroup-parent support
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-10-27 23:50:20 +02:00
coryb
2bd37c8a7d Merge pull request #2286 from aaronlehmann/exiterror-over-grpc
Allow ExitError type to be transmitted over GRPC
2021-08-11 15:51:23 -07:00
Sebastiaan van Stijn
cea791d3fe replace use of deprecated github.com/docker/docker/pkg/signal
This package was moved to a separate module in github.com/moby/sys/signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-02 12:19:45 +02:00
Aaron Lehmann
890c3f77b6 Allow ExitError type to be transmitted over GRPC
This will allow clients to retrieve exit error codes returned during a
solve without parsing the error messages.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-07-28 15:01:05 -07:00
Morlay
18b49fd7dc refactor to use util/bklog instead of using logurs directly
Signed-off-by: Morlay <morlay.null@gmail.com>
2021-07-13 11:42:31 +08:00
Tonis Tiigi
d512920c24 support collecting traces from llb.Exec
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-06-20 21:57:35 -07:00
Brian Goff
d9834f872c Add support for apparmor/selinux
Set's an apparmor profile on the OCI spec if one is configred on the
worker.
Adds selinux labels to containers (only added if selinux is enabled on
the system).

This assumes that the specified apparmor profile is already loaded on
the system and does not try to load it or even check if it is loaded.

SELinux support requires the `selinux` build tag to be added.
Likewise, `runc` would require both the `apparmor` and `selinux` build
tags.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Vendored go-selinux to v1.8.0
Fixed tests

Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit 68bb095353)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-02-04 22:01:34 +01:00
Cory Bennett
9d3f55c400 move ExitError from solver/errdefs to frontend/gateway/errdefs
Signed-off-by: Cory Bennett <cbennett@netflix.com>
2020-12-07 01:09:59 +00:00
Sebastiaan van Stijn
67bcfe699a copy containerd.UnknownExitStatus to local const
Copy this const to a local constant to prevent importing the containerd
client in the front-end.

For consistency, I also updated the executor code to use the same const,
although not strictly needed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-11-18 00:11:09 +01:00
Tonis Tiigi
bdcee17437 executor: change mount to struct
Allows readonly passed cleanly.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-11-02 22:20:51 -08:00
Tonis Tiigi
e3b05289d8 add session injection to remote loading
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-11-02 22:20:44 -08:00
Cory Bennett
43d59b4aa1 update go-runc mod, use runc Started chan
Signed-off-by: Cory Bennett <cbennett@netflix.com>
2020-10-21 19:12:56 +00:00
Akihiro Suda
dda009a58c Merge pull request #1739 from tonistiigi/empty-layer
clear file mount stubs and fix empty layer cases
2020-10-21 00:42:45 +09:00
Cory Bennett
b464f1e315 update go-runc to use runc.ExitError for container exec status
Signed-off-by: Cory Bennett <cbennett@netflix.com>
2020-10-20 06:44:29 +00:00
Edgar Lee
5eaecb905c Merge pull request #1731 from coryb/issue-1714
add tty support for runc executor
2020-10-19 14:52:31 -07:00
Cory Bennett
74db85d357 syscall.Errno(0x5) == syscall.EIO
Signed-off-by: Cory Bennett <cbennett@netflix.com>
2020-10-19 21:28:39 +00:00