Update k8s log options

This commit is contained in:
Asim Aslam
2019-12-24 17:33:05 +00:00
parent 81e20160f5
commit 5c8d1ae2b9
5 changed files with 40 additions and 29 deletions

View File

@@ -138,20 +138,21 @@ func (c *client) Get(r *Resource, labels map[string]string) error {
Into(r.Value)
}
// Logs returns logs for a pod
func (c *client) Logs(podName string, options ...LogOption) (io.ReadCloser, error) {
opts := &LogOptions{}
for _, o := range options {
o(opts)
// Log returns logs for a pod
func (c *client) Log(r *Resource, opts ...LogOption) (io.ReadCloser, error) {
var options LogOptions
for _, o := range opts {
o(&options)
}
req := api.NewRequest(c.opts).
Get().
Resource("pod").
Resource(r.Kind).
SubResource("log").
Name(podName)
Name(r.Name)
if opts.AdditionalParams != nil {
req.Params(&api.Params{Additional: opts.AdditionalParams})
if options.Params != nil {
req.Params(&api.Params{Additional: options.Params})
}
resp, err := req.Raw()

View File

@@ -25,8 +25,8 @@ type Kubernetes interface {
Delete(*Resource) error
// List lists API resources
List(*Resource) error
// Logs gets logs from a pod
Logs(string, ...LogOption) (io.ReadCloser, error)
// Log gets log for a pod
Log(*Resource, ...LogOption) (io.ReadCloser, error)
}
// NewService returns default micro kubernetes service definition

View File

@@ -1,13 +0,0 @@
package client
type LogOptions struct {
AdditionalParams map[string]string
}
type LogOption func(*LogOptions)
func AdditionalParams(p map[string]string) LogOption {
return func(l *LogOptions) {
l.AdditionalParams = p
}
}

View File

@@ -0,0 +1,14 @@
package client
type LogOptions struct {
Params map[string]string
}
type LogOption func(*LogOptions)
// LogParams provides additional params for logs
func LogParams(p map[string]string) LogOption {
return func(l *LogOptions) {
l.Params = p
}
}