Commit graph

44948 commits

Author SHA1 Message Date
Cory Snider
1b64f2e28b libnetwork: stop caching global netlink handle
The global netlink handle ns.NlHandle() is indirectly cached for the
life of the process by the netutils.CheckRouteOverlaps() function. This
caching behaviour is a problem for the libnetwork unit tests as the
global netlink handle changes every time testutils.SetupTestOSContext()
is called, i.e. at the start of nearly every test case. Route overlaps
can be checked for in the wrong network namespace, causing spurious test
failures e.g. when running the same test twice in a row with -count=2.
Stop the netlink handle from being cached by shadowing the package-scope
variable with a function-scoped one.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-08 17:58:06 -05:00
Cory Snider
d0096bba21 libnetwork_test: overhaul TestParallel
TestParallel has been written in an unusual style which relies on the
testing package's intra-test parallelism feature and lots of global
state to test one thing using three cooperating parallel tests. It is
complicated to reason about and quite brittle. For example, the command

    go test -run TestParallel1 ./libnetwork

would deadlock, waiting until the test timeout for TestParallel2 and
TestParallel3 to run. And the test would be skipped if the
'-test.parallel' flag was less than three, either explicitly or
implicitly (default: GOMAXPROCS).

Overhaul TestParallel to address the aforementioned deficiencies and
get rid of mutable global state.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-08 17:58:06 -05:00
Cory Snider
32ace57479 libnetwork_test: isolate tests from each other
Reusing the same "OS context" (read: network namespace) and
NetworkController across multiple tests risks tests interfering with
each other, or worse: _depending on_ other tests to set up
preconditions. Construct a new controller for every test which needs
one, and run every test which mutates or inspects the host environment
in a fresh OS context.

The only outlier is runParallelTests. It is the only remaining test
implementation which references the "global" package-scoped controller,
so the global controller instance is effectively private to that one
test.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-08 17:56:45 -05:00
Cory Snider
0411336b49 libnetwork_test: pass controller into createTestNetwork
Sharing a single NetworkController instance between multiple tests
makes it possible for tests to interfere with each other. As a first
step towards giving each test its own private controller instance, make
explicit which controller createTestNetwork() creates the test network
on.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-08 17:55:25 -05:00
Cory Snider
9a0953a0a0 libnet/testutils: spawn goroutines in test OS ctxs
There are a handful of libnetwork tests which need to have multiple
concurrent goroutines inside the same test OS context (network
namespace), including some platform-agnostic tests. Provide test
utilities for spawning goroutines inside an OS context and
setting/restoring an existing goroutine's OS context to abstract away
platform differences and so that each test does not need to reinvent the
wheel.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-08 17:55:25 -05:00
Cory Snider
07be7b087d libnetwork_test: remove in-container special case
The SetupTestOSContext calls were made conditional in
https://github.com/moby/libnetwork/pull/148 to work around limitations
in runtime.LockOSThread() which existed before Go 1.10. This workaround
is no longer necessary now that runtime.UnlockOSThread() needs to be
called an equal number of times before the goroutine is unlocked from
the OS thread.

Unfortunately some tests break when SetupTestOSContext is not skipped.
(Evidently this code path has not been exercised in a long time.) A
newly-created network namespace is very barebones: it contains a
loopback interface in the down state and little else. Even pinging
localhost does not work inside of a brand new namespace. Set the
loopback interface to up during namespace setup so that tests which
need to use the loopback interface can do so.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-08 17:55:25 -05:00
Cory Snider
e2a89b7ad1 libnet/d/bridge: configure store when opts missing
If the GenericData option is missing from the map, the bridge driver
would skip configuration. At first glance this seems fine: the driver
defaults are to not configure anything. But it also skips over
initializing the persistent storage, which is configured through other
option keys in the map. Fix this oversight by removing the early return.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-08 17:55:25 -05:00
Cory Snider
8a20564847 libnet/datastore: stop sharing defaultScopes singleton
Each call to datastore.DefaultScopes() would modify and return the same
map. Consequently, some of the config for every NetworkController in the
process would be mutated each time one is constructed or reconfigured.
This behaviour is unexpected, unintended, and undesirable. Stop
accidentally sharing configuration by changing DefaultScopes() to return
a distinct map on each call.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-08 17:55:24 -05:00
Cory Snider
8404507b9b libnet/osl: stop assuming caller thread is clean
(*networkNamespace).InvokeFunc() cleaned up the state of the locked
thread by setting its network namespace to the netns of the goroutine
which called InvokeFunc(). If InvokeFunc() was to be called after the
caller had modified its thread's network namespace, InvokeFunc() would
incorrectly "restore" the state of its goroutine thread to the wrong
namespace, violating the invariant that unlocked threads are fungible.
Change the implementation to restore the thread's netns to the netns
that particular thread had before InvokeFunc() modified it.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-08 17:55:24 -05:00
Sebastiaan van Stijn
4f3c5b2568
Merge pull request #44304 from thaJeztah/sys_move_process
pkg/system: move process-functions to pkg/process, improve pkg/pidfile and reduce overlap
2022-11-05 18:41:32 +01:00
Cory Snider
781b7d4820
Merge pull request #44407 from corhere/fix-libnetwork-parallel-tests
Fix libnetwork `TestParallel` tests
2022-11-04 19:07:48 -04:00
Cory Snider
f39b83e232 libnetwork: fix TestParallel "bad file descriptor"
When running inside a container, testns == origns. Consequently, closing
testns causes the deferred netns.Set(origns) call to fail. Stop closing
the aliased original namespace handle.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-04 14:07:54 -04:00
Cory Snider
fe6706a2ce libnetwork: make tests less dependent on others
TestResolvConfHost and TestParallel both depended on a network named
"testhost" already existing in the libnetwork controller. Only TestHost
created that network, so the aforementioned tests would fail unless run
after TestHost. Fix those tests so they can be run in any order.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-04 13:55:26 -04:00
Sebastiaan van Stijn
cea8e9b583
libcontainerd/supervisor: use pkg/pidfile for reading and writing pidfile
Also updated a variable name that collided with a package const.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-04 01:50:26 +01:00
Sebastiaan van Stijn
14da1bfe40
cmd/dockerd: adjust error message for pidfile changes
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-04 01:50:26 +01:00
Sebastiaan van Stijn
7493debe26
pkg/pidfile: implement Read()
This allows consumers to read back the pidFile and to check if the
PID is still running.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-04 01:50:26 +01:00
Sebastiaan van Stijn
7d3e1ad943
pkg/pidfile: Write(): don't automatically create parent directories
While this was convenient for our use, it's somewhat unexpected for a function
that writes a file to also create all parent directories; even more because
this function may be executed as root.

This patch makes the package more "safe" to use as a generic package by removing
this functionality, and leaving it up to the caller to create parent directories,
if needed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-04 01:50:26 +01:00
Sebastiaan van Stijn
81945da0ac
pkg/pidfile: Write(): take pid as argument
This allows it to be used for processes other than the daemon itself.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-04 01:50:26 +01:00
Sebastiaan van Stijn
735e250326
pkg/process: Alive(): fix PID 0, -1, negative values
unix.Kill() does not produce an error for PID 0, -1. As a result, checking
process.Alive() would return "true" for both 0 and -1 on macOS (and previously
on Linux as well).

Let's shortcut these values to consider them "not alive", to prevent someone
trying to kill them.

A basic test was added to check the behavior.

Given that the intent of these functions is to handle single processes, this patch
also prevents 0 and negative values to be used.

From KILL(2): https://man7.org/linux/man-pages/man2/kill.2.html

    If pid is positive, then signal sig is sent to the process with
    the ID specified by pid.

    If pid equals 0, then sig is sent to every process in the process
    group of the calling process.

    If pid equals -1, then sig is sent to every process for which the
    calling process has permission to send signals, except for
    process 1 (init), but see below.

    If pid is less than -1, then sig is sent to every process in the
    process group whose ID is -pid.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-04 01:50:26 +01:00
Sebastiaan van Stijn
55d15e9d05
pkg/pidfile, pkg/process: use single implementation for process alive
Using the implementation from pkg/pidfile for windows, as that implementation
looks to be handling more cases to check if a process is still alive (or to be
considered alive).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-04 01:50:26 +01:00
Sebastiaan van Stijn
9d5e754caa
move pkg/system: process to a separate package
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-04 01:50:23 +01:00
Sebastiaan van Stijn
0040fb93d6
pkg/system: IsProcessZombie() skip conversion to string, use bytes instead
bytes.SplitN() is more performant, and skips having to do the conversion.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-04 01:49:54 +01:00
Sebastiaan van Stijn
970ad4e3c7
pkg/system: IsProcessZombie() ignore "os.ErrNotExist" errors
If the file doesn't exist, the process isn't running, so we should be able
to ignore that.

Also remove an intermediate variable.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-04 01:49:49 +01:00
Sebastiaan van Stijn
8d6da1e100
pkg/system: IsProcessAlive() remove redundant type-cast
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-04 01:48:54 +01:00
Sebastiaan van Stijn
6c829007cc
Merge pull request #44356 from corhere/libnetwork-namespace-correctness
libnetwork: fix restoring thread network namespaces
2022-11-03 22:33:29 +01:00
Sebastiaan van Stijn
e7f034fe4e
Merge pull request #44365 from vvoland/c8d-contexts
imageservice: Add context to various methods
2022-11-03 19:51:39 +01:00
Sebastiaan van Stijn
6bb909f152
Merge pull request #44367 from vvoland/oci-artifacts-error
distribution: Error when pulling OCI artifacts
2022-11-03 19:39:22 +01:00
Cory Snider
2006d9f7d1
cmd/dockerd: Rewrite shutdownDaemon to use context timeout
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2022-11-03 14:31:03 +01:00
Paweł Gronowski
66a0289081
builder: Don't store context in struct
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2022-11-03 12:22:46 +01:00
Paweł Gronowski
a181a825c8
daemon/start: Revert passing ctx to ctr.Start
This caused integration tests to timeout in the CI

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2022-11-03 12:22:44 +01:00
Nicolas De Loof
def549c8f6
imageservice: Add context to various methods
Co-authored-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2022-11-03 12:22:40 +01:00
Sebastiaan van Stijn
4c07d58592
Merge pull request #44401 from neersighted/swarmkit_revendor
vendor: github.com/moby/swarmkit/v2 v2.0.0-20221102165002-6341884e5fc9
2022-11-03 01:01:25 +01:00
Sebastiaan van Stijn
98f36bba9a
Merge pull request #44398 from thaJeztah/daemon_logger_godoc
daemon/logger: fix godoc
2022-11-02 23:50:29 +01:00
Sebastiaan van Stijn
781fd745ed
Merge pull request #44393 from thaJeztah/pkg_kernel_duplicate_docs
pkg/parsers/kernel: remove duplicate GoDoc and un-export Utsname
2022-11-02 23:49:48 +01:00
Bjorn Neergaard
57c2545cd5
vendor: github.com/moby/swarmkit/v2 v2.0.0-20221102165002-6341884e5fc9
full diff: 48dd89375d...6341884e5f

Pulls in a set of fixes to SwarmKit's nascent Cluster Volumes support
discovered during subsequent development and testing.

Signed-off-by: Bjorn Neergaard <bneergaard@mirantis.com>
2022-11-02 15:10:08 -06:00
Sebastiaan van Stijn
2a478f9215
Merge pull request #44399 from corhere/fix-task-delete-on-failed-start
Fix containerd task deletion after failed start
2022-11-02 21:48:56 +01:00
Cory Snider
1bef9e3fbf Fix containerd task deletion after failed start
Deleting a containerd task whose status is Created fails with a
"precondition failed" error. This is because (aside from Windows)
a process is spawned when the task is created, and deleting the task
while the process is running would leak the process if it was allowed.
libcontainerd and the containerd plugin executor mistakenly try to clean
up from a failed start by deleting the created task, which will always
fail with the aforementined error. Change them to pass the
`WithProcessKill` delete option so the cleanup has a chance to succeed.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-02 13:48:13 -04:00
Sebastiaan van Stijn
be1829f63d
daemon/logger: fix godoc
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-02 18:47:50 +01:00
Sebastiaan van Stijn
e1743888ed
Merge pull request #44384 from thaJeztah/idtools_cleanup4
pkg/idtools: remove execCmd() utility
2022-11-02 18:46:56 +01:00
Tianon Gravi
b76ccfef5f
Merge pull request #44289 from thaJeztah/windows_refactor_etwlogs
daemon/logger/etwlogs: rewrite to use go-winio/pkg/etw
2022-11-02 10:43:55 -07:00
Sebastiaan van Stijn
9899820a17
Merge pull request #44389 from tianon/debug-typo
Remove errant "runtime.GOARCH" from debug message
2022-11-02 18:23:11 +01:00
Sebastiaan van Stijn
4112481170
Merge pull request #44390 from tianon/rm-deprecated-arm-fallback
Remove long-deprecated "arm" fallback
2022-11-02 18:20:43 +01:00
Sebastiaan van Stijn
5a01c1dad1
Merge pull request #44383 from thaJeztah/improve_example
api/types/filters: add output to example
2022-11-02 17:29:37 +01:00
Brian Goff
8d15e7d742
Merge pull request #44073 from ndeloof/upstream_29
implement docker system df
2022-11-02 08:05:17 -07:00
Paweł Gronowski
407e3a4552
distribution: Error when pulling OCI artifacts
Currently an attempt to pull a reference which resolves to an OCI
artifact (Helm chart for example), results in a bit unrelated error
message `invalid rootfs in image configuration`.

This provides a more meaningful error in case a user attempts to
download a media type which isn't image related.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2022-11-02 12:51:03 +01:00
Sebastiaan van Stijn
4386e3f7c0
pkg/parsers/kernel: un-export Utsname
It's only used internally to allow the "unsupported" stub.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-02 10:55:54 +01:00
Sebastiaan van Stijn
775dcab7a2
pkg/parsers/kernel: remove duplicate Package godoc
It was present both in kernel.go and kernel_unix.go.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-02 10:44:50 +01:00
Nicolas De Loof
8d0dc69027
implement docker system df
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2022-11-02 09:35:18 +01:00
Samuel Karp
5dd50a381a
Merge pull request #44391 from tlgs/sort-names 2022-11-01 21:37:37 -07:00
Brian Goff
9fa38435aa
Merge pull request #44316 from thaJeztah/plugin_improve_test_errors
integration-cli: DockerPluginSuite: use gotest.tools compare utilities
2022-11-01 17:07:22 -07:00