2018-02-05 21:05:59 +00:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2016-08-23 23:25:43 +00:00
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-10-18 04:36:52 +00:00
|
|
|
"regexp"
|
API: add "prune" events
This patch adds a new "prune" event type to indicate that pruning of a resource
type completed.
This event-type can be used on systems that want to perform actions after
resources have been cleaned up. For example, Docker Desktop performs an fstrim
after resources are deleted (https://github.com/linuxkit/linuxkit/tree/v0.7/pkg/trim-after-delete).
While the current (remove, destroy) events can provide information on _most_
resources, there is currently no event triggered after the BuildKit build-cache
is cleaned.
Prune events have a `reclaimed` attribute, indicating the amount of space that
was reclaimed (in bytes). The attribute can be used, for example, to use as a
threshold for performing fstrim actions. Reclaimed space for `network` events
will always be 0, but the field is added to be consistent with prune events for
other resources.
To test this patch:
Create some resources:
for i in foo bar baz; do \
docker network create network_$i \
&& docker volume create volume_$i \
&& docker run -d --name container_$i -v volume_$i:/volume busybox sh -c 'truncate -s 5M somefile; truncate -s 5M /volume/file' \
&& docker tag busybox:latest image_$i; \
done;
docker pull alpine
docker pull nginx:alpine
echo -e "FROM busybox\nRUN truncate -s 50M bigfile" | DOCKER_BUILDKIT=1 docker build -
Start listening for "prune" events in another shell:
docker events --filter event=prune
Prune containers, networks, volumes, and build-cache:
docker system prune -af --volumes
See the events that are returned:
docker events --filter event=prune
2020-07-25T12:12:09.268491000Z container prune (reclaimed=15728640)
2020-07-25T12:12:09.447890400Z network prune (reclaimed=0)
2020-07-25T12:12:09.452323000Z volume prune (reclaimed=15728640)
2020-07-25T12:12:09.517236200Z image prune (reclaimed=21568540)
2020-07-25T12:12:09.566662600Z builder prune (reclaimed=52428841)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-07-25 12:14:38 +00:00
|
|
|
"strconv"
|
2017-04-12 21:04:49 +00:00
|
|
|
"sync/atomic"
|
2016-12-07 22:02:13 +00:00
|
|
|
"time"
|
2016-10-18 04:36:52 +00:00
|
|
|
|
2023-06-23 00:33:17 +00:00
|
|
|
"github.com/containerd/containerd/log"
|
2016-08-23 23:25:43 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
API: add "prune" events
This patch adds a new "prune" event type to indicate that pruning of a resource
type completed.
This event-type can be used on systems that want to perform actions after
resources have been cleaned up. For example, Docker Desktop performs an fstrim
after resources are deleted (https://github.com/linuxkit/linuxkit/tree/v0.7/pkg/trim-after-delete).
While the current (remove, destroy) events can provide information on _most_
resources, there is currently no event triggered after the BuildKit build-cache
is cleaned.
Prune events have a `reclaimed` attribute, indicating the amount of space that
was reclaimed (in bytes). The attribute can be used, for example, to use as a
threshold for performing fstrim actions. Reclaimed space for `network` events
will always be 0, but the field is added to be consistent with prune events for
other resources.
To test this patch:
Create some resources:
for i in foo bar baz; do \
docker network create network_$i \
&& docker volume create volume_$i \
&& docker run -d --name container_$i -v volume_$i:/volume busybox sh -c 'truncate -s 5M somefile; truncate -s 5M /volume/file' \
&& docker tag busybox:latest image_$i; \
done;
docker pull alpine
docker pull nginx:alpine
echo -e "FROM busybox\nRUN truncate -s 50M bigfile" | DOCKER_BUILDKIT=1 docker build -
Start listening for "prune" events in another shell:
docker events --filter event=prune
Prune containers, networks, volumes, and build-cache:
docker system prune -af --volumes
See the events that are returned:
docker events --filter event=prune
2020-07-25T12:12:09.268491000Z container prune (reclaimed=15728640)
2020-07-25T12:12:09.447890400Z network prune (reclaimed=0)
2020-07-25T12:12:09.452323000Z volume prune (reclaimed=15728640)
2020-07-25T12:12:09.517236200Z image prune (reclaimed=21568540)
2020-07-25T12:12:09.566662600Z builder prune (reclaimed=52428841)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-07-25 12:14:38 +00:00
|
|
|
"github.com/docker/docker/api/types/events"
|
2016-11-17 05:46:37 +00:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
2016-12-07 22:02:13 +00:00
|
|
|
timetypes "github.com/docker/docker/api/types/time"
|
2018-03-22 21:11:03 +00:00
|
|
|
"github.com/docker/docker/errdefs"
|
2021-04-06 00:24:47 +00:00
|
|
|
"github.com/docker/docker/libnetwork"
|
2021-05-28 00:15:56 +00:00
|
|
|
"github.com/docker/docker/runconfig"
|
2018-03-22 21:11:03 +00:00
|
|
|
"github.com/pkg/errors"
|
2017-04-12 21:04:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-05-16 15:37:30 +00:00
|
|
|
// errPruneRunning is returned when a prune request is received while
|
2017-04-12 21:04:49 +00:00
|
|
|
// one is in progress
|
2018-03-22 21:11:03 +00:00
|
|
|
errPruneRunning = errdefs.Conflict(errors.New("a prune operation is already running"))
|
2017-05-05 16:37:06 +00:00
|
|
|
|
|
|
|
containersAcceptedFilters = map[string]bool{
|
|
|
|
"label": true,
|
|
|
|
"label!": true,
|
|
|
|
"until": true,
|
|
|
|
}
|
2018-02-21 22:10:18 +00:00
|
|
|
|
2017-05-05 16:37:06 +00:00
|
|
|
networksAcceptedFilters = map[string]bool{
|
|
|
|
"label": true,
|
|
|
|
"label!": true,
|
|
|
|
"until": true,
|
|
|
|
}
|
2016-08-23 23:25:43 +00:00
|
|
|
)
|
|
|
|
|
2016-10-08 10:38:25 +00:00
|
|
|
// ContainersPrune removes unused containers
|
2017-04-11 19:52:33 +00:00
|
|
|
func (daemon *Daemon) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (*types.ContainersPruneReport, error) {
|
2017-04-12 21:04:49 +00:00
|
|
|
if !atomic.CompareAndSwapInt32(&daemon.pruneRunning, 0, 1) {
|
2017-05-16 15:37:30 +00:00
|
|
|
return nil, errPruneRunning
|
2017-04-12 21:04:49 +00:00
|
|
|
}
|
|
|
|
defer atomic.StoreInt32(&daemon.pruneRunning, 0)
|
|
|
|
|
2016-08-23 23:25:43 +00:00
|
|
|
rep := &types.ContainersPruneReport{}
|
|
|
|
|
2017-05-05 16:37:06 +00:00
|
|
|
// make sure that only accepted filters have been received
|
|
|
|
err := pruneFilters.Validate(containersAcceptedFilters)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-12-07 22:02:13 +00:00
|
|
|
until, err := getUntilFromPruneFilters(pruneFilters)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-08-31 20:12:30 +00:00
|
|
|
cfg := &daemon.config().Config
|
2016-08-23 23:25:43 +00:00
|
|
|
allContainers := daemon.List()
|
|
|
|
for _, c := range allContainers {
|
2017-04-11 19:52:33 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(ctx).Debugf("ContainersPrune operation cancelled: %#v", *rep)
|
2017-07-06 08:47:21 +00:00
|
|
|
return rep, nil
|
2017-04-11 19:52:33 +00:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2016-08-23 23:25:43 +00:00
|
|
|
if !c.IsRunning() {
|
2016-12-07 22:02:13 +00:00
|
|
|
if !until.IsZero() && c.Created.After(until) {
|
|
|
|
continue
|
|
|
|
}
|
2017-02-04 17:10:05 +00:00
|
|
|
if !matchLabels(pruneFilters, c.Config.Labels) {
|
|
|
|
continue
|
|
|
|
}
|
2023-03-06 15:02:37 +00:00
|
|
|
cSize, _, err := daemon.imageService.GetContainerLayerSize(ctx, c.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-08-23 23:25:43 +00:00
|
|
|
// TODO: sets RmLink to true?
|
2022-08-17 21:13:49 +00:00
|
|
|
err = daemon.containerRm(cfg, c.ID, &types.ContainerRmConfig{})
|
2016-08-23 23:25:43 +00:00
|
|
|
if err != nil {
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(ctx).Warnf("failed to prune container %s: %v", c.ID, err)
|
2016-08-23 23:25:43 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if cSize > 0 {
|
|
|
|
rep.SpaceReclaimed += uint64(cSize)
|
|
|
|
}
|
|
|
|
rep.ContainersDeleted = append(rep.ContainersDeleted, c.ID)
|
|
|
|
}
|
|
|
|
}
|
2023-08-26 13:24:46 +00:00
|
|
|
daemon.EventsService.Log(events.ActionPrune, events.ContainerEventType, events.Actor{
|
API: add "prune" events
This patch adds a new "prune" event type to indicate that pruning of a resource
type completed.
This event-type can be used on systems that want to perform actions after
resources have been cleaned up. For example, Docker Desktop performs an fstrim
after resources are deleted (https://github.com/linuxkit/linuxkit/tree/v0.7/pkg/trim-after-delete).
While the current (remove, destroy) events can provide information on _most_
resources, there is currently no event triggered after the BuildKit build-cache
is cleaned.
Prune events have a `reclaimed` attribute, indicating the amount of space that
was reclaimed (in bytes). The attribute can be used, for example, to use as a
threshold for performing fstrim actions. Reclaimed space for `network` events
will always be 0, but the field is added to be consistent with prune events for
other resources.
To test this patch:
Create some resources:
for i in foo bar baz; do \
docker network create network_$i \
&& docker volume create volume_$i \
&& docker run -d --name container_$i -v volume_$i:/volume busybox sh -c 'truncate -s 5M somefile; truncate -s 5M /volume/file' \
&& docker tag busybox:latest image_$i; \
done;
docker pull alpine
docker pull nginx:alpine
echo -e "FROM busybox\nRUN truncate -s 50M bigfile" | DOCKER_BUILDKIT=1 docker build -
Start listening for "prune" events in another shell:
docker events --filter event=prune
Prune containers, networks, volumes, and build-cache:
docker system prune -af --volumes
See the events that are returned:
docker events --filter event=prune
2020-07-25T12:12:09.268491000Z container prune (reclaimed=15728640)
2020-07-25T12:12:09.447890400Z network prune (reclaimed=0)
2020-07-25T12:12:09.452323000Z volume prune (reclaimed=15728640)
2020-07-25T12:12:09.517236200Z image prune (reclaimed=21568540)
2020-07-25T12:12:09.566662600Z builder prune (reclaimed=52428841)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-07-25 12:14:38 +00:00
|
|
|
Attributes: map[string]string{"reclaimed": strconv.FormatUint(rep.SpaceReclaimed, 10)},
|
|
|
|
})
|
2016-08-23 23:25:43 +00:00
|
|
|
return rep, nil
|
|
|
|
}
|
|
|
|
|
2016-10-18 04:36:52 +00:00
|
|
|
// localNetworksPrune removes unused local networks
|
2017-04-11 19:52:33 +00:00
|
|
|
func (daemon *Daemon) localNetworksPrune(ctx context.Context, pruneFilters filters.Args) *types.NetworksPruneReport {
|
2016-10-18 04:36:52 +00:00
|
|
|
rep := &types.NetworksPruneReport{}
|
2016-12-07 22:02:13 +00:00
|
|
|
|
2016-12-29 12:09:55 +00:00
|
|
|
until, _ := getUntilFromPruneFilters(pruneFilters)
|
2016-12-07 22:02:13 +00:00
|
|
|
|
2016-10-18 04:36:52 +00:00
|
|
|
// When the function returns true, the walk will stop.
|
2023-07-21 22:38:57 +00:00
|
|
|
daemon.netController.WalkNetworks(func(nw *libnetwork.Network) bool {
|
2017-04-11 19:52:33 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2017-07-06 08:47:21 +00:00
|
|
|
// context cancelled
|
2017-04-11 19:52:33 +00:00
|
|
|
return true
|
|
|
|
default:
|
|
|
|
}
|
2023-07-25 15:37:19 +00:00
|
|
|
if nw.ConfigOnly() {
|
2017-04-07 18:18:51 +00:00
|
|
|
return false
|
|
|
|
}
|
2023-07-25 15:37:19 +00:00
|
|
|
if !until.IsZero() && nw.Created().After(until) {
|
2016-12-07 22:02:13 +00:00
|
|
|
return false
|
|
|
|
}
|
2023-07-25 15:37:19 +00:00
|
|
|
if !matchLabels(pruneFilters, nw.Labels()) {
|
2017-02-04 17:10:05 +00:00
|
|
|
return false
|
|
|
|
}
|
2016-10-18 04:36:52 +00:00
|
|
|
nwName := nw.Name()
|
2016-12-29 12:09:55 +00:00
|
|
|
if runconfig.IsPreDefinedNetwork(nwName) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if len(nw.Endpoints()) > 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if err := daemon.DeleteNetwork(nw.ID()); err != nil {
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(ctx).Warnf("could not remove local network %s: %v", nwName, err)
|
2016-12-29 12:09:55 +00:00
|
|
|
return false
|
2016-10-18 04:36:52 +00:00
|
|
|
}
|
2016-12-29 12:09:55 +00:00
|
|
|
rep.NetworksDeleted = append(rep.NetworksDeleted, nwName)
|
2016-10-18 04:36:52 +00:00
|
|
|
return false
|
2023-07-21 22:38:57 +00:00
|
|
|
})
|
2016-12-29 12:09:55 +00:00
|
|
|
return rep
|
2016-10-18 04:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// clusterNetworksPrune removes unused cluster networks
|
2017-04-11 19:52:33 +00:00
|
|
|
func (daemon *Daemon) clusterNetworksPrune(ctx context.Context, pruneFilters filters.Args) (*types.NetworksPruneReport, error) {
|
2016-10-18 04:36:52 +00:00
|
|
|
rep := &types.NetworksPruneReport{}
|
2016-12-07 22:02:13 +00:00
|
|
|
|
2016-12-29 12:09:55 +00:00
|
|
|
until, _ := getUntilFromPruneFilters(pruneFilters)
|
2016-12-07 22:02:13 +00:00
|
|
|
|
2016-10-18 04:36:52 +00:00
|
|
|
cluster := daemon.GetCluster()
|
2017-03-28 10:46:42 +00:00
|
|
|
|
|
|
|
if !cluster.IsManager() {
|
|
|
|
return rep, nil
|
|
|
|
}
|
|
|
|
|
2018-05-23 14:03:02 +00:00
|
|
|
networks, err := cluster.GetNetworks(pruneFilters)
|
2016-10-18 04:36:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return rep, err
|
|
|
|
}
|
|
|
|
networkIsInUse := regexp.MustCompile(`network ([[:alnum:]]+) is in use`)
|
|
|
|
for _, nw := range networks {
|
2017-04-11 19:52:33 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2017-07-06 08:47:21 +00:00
|
|
|
return rep, nil
|
2017-04-11 19:52:33 +00:00
|
|
|
default:
|
|
|
|
if nw.Ingress {
|
|
|
|
// Routing-mesh network removal has to be explicitly invoked by user
|
|
|
|
continue
|
2016-10-18 04:36:52 +00:00
|
|
|
}
|
2017-04-11 19:52:33 +00:00
|
|
|
if !until.IsZero() && nw.Created.After(until) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !matchLabels(pruneFilters, nw.Labels) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// https://github.com/docker/docker/issues/24186
|
|
|
|
// `docker network inspect` unfortunately displays ONLY those containers that are local to that node.
|
|
|
|
// So we try to remove it anyway and check the error
|
|
|
|
err = cluster.RemoveNetwork(nw.ID)
|
|
|
|
if err != nil {
|
|
|
|
// we can safely ignore the "network .. is in use" error
|
|
|
|
match := networkIsInUse.FindStringSubmatch(err.Error())
|
|
|
|
if len(match) != 2 || match[1] != nw.ID {
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(ctx).Warnf("could not remove cluster network %s: %v", nw.Name, err)
|
2017-04-11 19:52:33 +00:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
rep.NetworksDeleted = append(rep.NetworksDeleted, nw.Name)
|
2016-10-18 04:36:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NetworksPrune removes unused networks
|
2017-04-11 19:52:33 +00:00
|
|
|
func (daemon *Daemon) NetworksPrune(ctx context.Context, pruneFilters filters.Args) (*types.NetworksPruneReport, error) {
|
2017-04-12 21:04:49 +00:00
|
|
|
if !atomic.CompareAndSwapInt32(&daemon.pruneRunning, 0, 1) {
|
2017-05-16 15:37:30 +00:00
|
|
|
return nil, errPruneRunning
|
2017-04-12 21:04:49 +00:00
|
|
|
}
|
|
|
|
defer atomic.StoreInt32(&daemon.pruneRunning, 0)
|
|
|
|
|
2017-05-05 16:37:06 +00:00
|
|
|
// make sure that only accepted filters have been received
|
|
|
|
err := pruneFilters.Validate(networksAcceptedFilters)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-12-29 12:09:55 +00:00
|
|
|
if _, err := getUntilFromPruneFilters(pruneFilters); err != nil {
|
|
|
|
return nil, err
|
2016-10-18 04:36:52 +00:00
|
|
|
}
|
2016-12-29 12:09:55 +00:00
|
|
|
|
|
|
|
rep := &types.NetworksPruneReport{}
|
2017-04-11 19:52:33 +00:00
|
|
|
if clusterRep, err := daemon.clusterNetworksPrune(ctx, pruneFilters); err == nil {
|
2017-02-04 17:10:05 +00:00
|
|
|
rep.NetworksDeleted = append(rep.NetworksDeleted, clusterRep.NetworksDeleted...)
|
|
|
|
}
|
2016-12-29 12:09:55 +00:00
|
|
|
|
2017-04-11 19:52:33 +00:00
|
|
|
localRep := daemon.localNetworksPrune(ctx, pruneFilters)
|
2016-12-29 12:09:55 +00:00
|
|
|
rep.NetworksDeleted = append(rep.NetworksDeleted, localRep.NetworksDeleted...)
|
2017-04-11 19:52:33 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(ctx).Debugf("NetworksPrune operation cancelled: %#v", *rep)
|
2017-07-06 08:47:21 +00:00
|
|
|
return rep, nil
|
2017-04-11 19:52:33 +00:00
|
|
|
default:
|
|
|
|
}
|
2023-08-26 13:24:46 +00:00
|
|
|
daemon.EventsService.Log(events.ActionPrune, events.NetworkEventType, events.Actor{
|
API: add "prune" events
This patch adds a new "prune" event type to indicate that pruning of a resource
type completed.
This event-type can be used on systems that want to perform actions after
resources have been cleaned up. For example, Docker Desktop performs an fstrim
after resources are deleted (https://github.com/linuxkit/linuxkit/tree/v0.7/pkg/trim-after-delete).
While the current (remove, destroy) events can provide information on _most_
resources, there is currently no event triggered after the BuildKit build-cache
is cleaned.
Prune events have a `reclaimed` attribute, indicating the amount of space that
was reclaimed (in bytes). The attribute can be used, for example, to use as a
threshold for performing fstrim actions. Reclaimed space for `network` events
will always be 0, but the field is added to be consistent with prune events for
other resources.
To test this patch:
Create some resources:
for i in foo bar baz; do \
docker network create network_$i \
&& docker volume create volume_$i \
&& docker run -d --name container_$i -v volume_$i:/volume busybox sh -c 'truncate -s 5M somefile; truncate -s 5M /volume/file' \
&& docker tag busybox:latest image_$i; \
done;
docker pull alpine
docker pull nginx:alpine
echo -e "FROM busybox\nRUN truncate -s 50M bigfile" | DOCKER_BUILDKIT=1 docker build -
Start listening for "prune" events in another shell:
docker events --filter event=prune
Prune containers, networks, volumes, and build-cache:
docker system prune -af --volumes
See the events that are returned:
docker events --filter event=prune
2020-07-25T12:12:09.268491000Z container prune (reclaimed=15728640)
2020-07-25T12:12:09.447890400Z network prune (reclaimed=0)
2020-07-25T12:12:09.452323000Z volume prune (reclaimed=15728640)
2020-07-25T12:12:09.517236200Z image prune (reclaimed=21568540)
2020-07-25T12:12:09.566662600Z builder prune (reclaimed=52428841)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-07-25 12:14:38 +00:00
|
|
|
Attributes: map[string]string{"reclaimed": "0"},
|
|
|
|
})
|
2016-12-29 12:09:55 +00:00
|
|
|
return rep, nil
|
2016-10-18 04:36:52 +00:00
|
|
|
}
|
2016-12-07 22:02:13 +00:00
|
|
|
|
|
|
|
func getUntilFromPruneFilters(pruneFilters filters.Args) (time.Time, error) {
|
|
|
|
until := time.Time{}
|
2017-09-26 11:39:56 +00:00
|
|
|
if !pruneFilters.Contains("until") {
|
2016-12-07 22:02:13 +00:00
|
|
|
return until, nil
|
|
|
|
}
|
|
|
|
untilFilters := pruneFilters.Get("until")
|
|
|
|
if len(untilFilters) > 1 {
|
2023-04-07 11:31:45 +00:00
|
|
|
return until, errdefs.InvalidParameter(errors.New("more than one until filter specified"))
|
2016-12-07 22:02:13 +00:00
|
|
|
}
|
|
|
|
ts, err := timetypes.GetTimestamp(untilFilters[0], time.Now())
|
|
|
|
if err != nil {
|
2023-04-07 11:31:45 +00:00
|
|
|
return until, errdefs.InvalidParameter(err)
|
2016-12-07 22:02:13 +00:00
|
|
|
}
|
|
|
|
seconds, nanoseconds, err := timetypes.ParseTimestamps(ts, 0)
|
|
|
|
if err != nil {
|
2023-04-07 11:31:45 +00:00
|
|
|
return until, errdefs.InvalidParameter(err)
|
2016-12-07 22:02:13 +00:00
|
|
|
}
|
|
|
|
until = time.Unix(seconds, nanoseconds)
|
|
|
|
return until, nil
|
|
|
|
}
|
2017-02-04 17:10:05 +00:00
|
|
|
|
|
|
|
func matchLabels(pruneFilters filters.Args, labels map[string]string) bool {
|
|
|
|
if !pruneFilters.MatchKVList("label", labels) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// By default MatchKVList will return true if field (like 'label!') does not exist
|
2017-09-26 11:39:56 +00:00
|
|
|
// So we have to add additional Contains("label!") check
|
|
|
|
if pruneFilters.Contains("label!") {
|
2017-02-04 17:10:05 +00:00
|
|
|
if pruneFilters.MatchKVList("label!", labels) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|