@@ -31,6 +31,7 @@ package restart
3131
3232import (
3333 "context"
34+ "net/url"
3435
3536 "github.com/containerd/containerd"
3637 "github.com/containerd/containerd/cio"
@@ -49,37 +50,49 @@ const (
4950 LogPathLabel = "containerd.io/restart.logpath"
5051)
5152
53+ // WithLogURI sets the specified log uri for a container.
54+ func WithLogURI (uri * url.URL ) func (context.Context , * containerd.Client , * containers.Container ) error {
55+ return WithLogURIString (uri .String ())
56+ }
57+
58+ // WithLogURIString sets the specified log uri string for a container.
59+ func WithLogURIString (uriString string ) func (context.Context , * containerd.Client , * containers.Container ) error {
60+ return func (_ context.Context , _ * containerd.Client , c * containers.Container ) error {
61+ ensureLabels (c )
62+ c .Labels [LogURILabel ] = uriString
63+ return nil
64+ }
65+ }
66+
5267// WithBinaryLogURI sets the binary-type log uri for a container.
68+ //
69+ // Deprecated(in release 1.5): use WithLogURI
5370func WithBinaryLogURI (binary string , args map [string ]string ) func (context.Context , * containerd.Client , * containers.Container ) error {
54- return func ( _ context. Context , _ * containerd. Client , c * containers. Container ) error {
55- uri , err := cio . LogURIGenerator ( "binary" , binary , args )
56- if err != nil {
71+ uri , err := cio . LogURIGenerator ( "binary" , binary , args )
72+ if err != nil {
73+ return func (context. Context , * containerd. Client , * containers. Container ) error {
5774 return err
5875 }
59-
60- ensureLabels (c )
61- c .Labels [LogURILabel ] = uri .String ()
62- return nil
6376 }
77+ return WithLogURI (uri )
6478}
6579
6680// WithFileLogURI sets the file-type log uri for a container.
81+ //
82+ // Deprecated(in release 1.5): use WithLogURI
6783func WithFileLogURI (path string ) func (context.Context , * containerd.Client , * containers.Container ) error {
68- return func ( _ context. Context , _ * containerd. Client , c * containers. Container ) error {
69- uri , err := cio . LogURIGenerator ( "file" , path , nil )
70- if err != nil {
84+ uri , err := cio . LogURIGenerator ( "file" , path , nil )
85+ if err != nil {
86+ return func (context. Context , * containerd. Client , * containers. Container ) error {
7187 return err
7288 }
73-
74- ensureLabels (c )
75- c .Labels [LogURILabel ] = uri .String ()
76- return nil
7789 }
90+ return WithLogURI (uri )
7891}
7992
8093// WithLogPath sets the log path for a container
8194//
82- // Deprecated(in release 1.5): use WithFileLogURI .
95+ // Deprecated(in release 1.5): use WithLogURI with "file://<path>" URI .
8396func WithLogPath (path string ) func (context.Context , * containerd.Client , * containers.Container ) error {
8497 return func (_ context.Context , _ * containerd.Client , c * containers.Container ) error {
8598 ensureLabels (c )
0 commit comments