Merge pull request #4833 from AkihiroSuda/restart-with-log-uri
restart: allow passing existing log URI object
This commit is contained in:
commit
d1ced4f8ae
@ -31,6 +31,7 @@ package restart
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/cio"
|
"github.com/containerd/containerd/cio"
|
||||||
@ -49,37 +50,49 @@ const (
|
|||||||
LogPathLabel = "containerd.io/restart.logpath"
|
LogPathLabel = "containerd.io/restart.logpath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WithBinaryLogURI sets the binary-type log uri for a container.
|
// WithLogURI sets the specified log uri for a container.
|
||||||
func WithBinaryLogURI(binary string, args map[string]string) func(context.Context, *containerd.Client, *containers.Container) error {
|
func WithLogURI(uri *url.URL) func(context.Context, *containerd.Client, *containers.Container) error {
|
||||||
return func(_ context.Context, _ *containerd.Client, c *containers.Container) error {
|
return WithLogURIString(uri.String())
|
||||||
uri, err := cio.LogURIGenerator("binary", binary, args)
|
}
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// WithLogURIString sets the specified log uri string for a container.
|
||||||
|
func WithLogURIString(uriString string) func(context.Context, *containerd.Client, *containers.Container) error {
|
||||||
|
return func(_ context.Context, _ *containerd.Client, c *containers.Container) error {
|
||||||
ensureLabels(c)
|
ensureLabels(c)
|
||||||
c.Labels[LogURILabel] = uri.String()
|
c.Labels[LogURILabel] = uriString
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithFileLogURI sets the file-type log uri for a container.
|
// WithBinaryLogURI sets the binary-type log uri for a container.
|
||||||
func WithFileLogURI(path string) func(context.Context, *containerd.Client, *containers.Container) error {
|
//
|
||||||
return func(_ context.Context, _ *containerd.Client, c *containers.Container) error {
|
// Deprecated(in release 1.5): use WithLogURI
|
||||||
uri, err := cio.LogURIGenerator("file", path, nil)
|
func WithBinaryLogURI(binary string, args map[string]string) func(context.Context, *containerd.Client, *containers.Container) error {
|
||||||
if err != nil {
|
uri, err := cio.LogURIGenerator("binary", binary, args)
|
||||||
|
if err != nil {
|
||||||
|
return func(context.Context, *containerd.Client, *containers.Container) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureLabels(c)
|
|
||||||
c.Labels[LogURILabel] = uri.String()
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
return WithLogURI(uri)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithFileLogURI sets the file-type log uri for a container.
|
||||||
|
//
|
||||||
|
// Deprecated(in release 1.5): use WithLogURI
|
||||||
|
func WithFileLogURI(path string) func(context.Context, *containerd.Client, *containers.Container) error {
|
||||||
|
uri, err := cio.LogURIGenerator("file", path, nil)
|
||||||
|
if err != nil {
|
||||||
|
return func(context.Context, *containerd.Client, *containers.Container) error {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return WithLogURI(uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithLogPath sets the log path for a container
|
// WithLogPath sets the log path for a container
|
||||||
//
|
//
|
||||||
// Deprecated(in release 1.5): use WithFileLogURI.
|
// Deprecated(in release 1.5): use WithLogURI with "file://<path>" URI.
|
||||||
func WithLogPath(path string) func(context.Context, *containerd.Client, *containers.Container) error {
|
func WithLogPath(path string) func(context.Context, *containerd.Client, *containers.Container) error {
|
||||||
return func(_ context.Context, _ *containerd.Client, c *containers.Container) error {
|
return func(_ context.Context, _ *containerd.Client, c *containers.Container) error {
|
||||||
ensureLabels(c)
|
ensureLabels(c)
|
||||||
|
Loading…
Reference in New Issue
Block a user