From ba430bfe5ef65d5aa5ffa1fef0087da76aafcc35 Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Thu, 16 Apr 2020 08:39:34 -0500 Subject: podman v2 remove bloat v2 rid ourseleves of libpod references in v2 client Signed-off-by: Brent Baude --- libpod/container.go | 9 ------ libpod/container.log.go | 75 --------------------------------------------- libpod/container_log.go | 76 ++++++++++++++++++++++++++++++++++++++++++++++ libpod/define/config.go | 9 ++++++ libpod/oci_conmon_linux.go | 10 +++--- libpod/options.go | 2 +- libpod/pod_api.go | 49 ++++++++++++++---------------- libpod/runtime_ctr.go | 2 +- 8 files changed, 114 insertions(+), 118 deletions(-) delete mode 100644 libpod/container.log.go create mode 100644 libpod/container_log.go (limited to 'libpod') diff --git a/libpod/container.go b/libpod/container.go index a1848b96a..5cd719ab6 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -34,15 +34,6 @@ const SystemdDefaultCgroupParent = "machine.slice" // manager in libpod when running as rootless const SystemdDefaultRootlessCgroupParent = "user.slice" -// JournaldLogging is the string conmon expects to specify journald logging -const JournaldLogging = "journald" - -// KubernetesLogging is the string conmon expects when specifying to use the kubernetes logging format -const KubernetesLogging = "k8s-file" - -// JSONLogging is the string conmon expects when specifying to use the json logging format -const JSONLogging = "json-file" - // DefaultWaitInterval is the default interval between container status checks // while waiting. const DefaultWaitInterval = 250 * time.Millisecond diff --git a/libpod/container.log.go b/libpod/container.log.go deleted file mode 100644 index 514edb8c8..000000000 --- a/libpod/container.log.go +++ /dev/null @@ -1,75 +0,0 @@ -package libpod - -import ( - "os" - - "github.com/containers/libpod/libpod/logs" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" -) - -// Log is a runtime function that can read one or more container logs. -func (r *Runtime) Log(containers []*Container, options *logs.LogOptions, logChannel chan *logs.LogLine) error { - for _, ctr := range containers { - if err := ctr.ReadLog(options, logChannel); err != nil { - return err - } - } - return nil -} - -// ReadLog reads a containers log based on the input options and returns loglines over a channel -func (c *Container) ReadLog(options *logs.LogOptions, logChannel chan *logs.LogLine) error { - // TODO Skip sending logs until journald logs can be read - // TODO make this not a magic string - if c.LogDriver() == JournaldLogging { - return c.readFromJournal(options, logChannel) - } - return c.readFromLogFile(options, logChannel) -} - -func (c *Container) readFromLogFile(options *logs.LogOptions, logChannel chan *logs.LogLine) error { - t, tailLog, err := logs.GetLogFile(c.LogPath(), options) - if err != nil { - // If the log file does not exist, this is not fatal. - if os.IsNotExist(errors.Cause(err)) { - return nil - } - return errors.Wrapf(err, "unable to read log file %s for %s ", c.ID(), c.LogPath()) - } - options.WaitGroup.Add(1) - if len(tailLog) > 0 { - for _, nll := range tailLog { - nll.CID = c.ID() - nll.CName = c.Name() - if nll.Since(options.Since) { - logChannel <- nll - } - } - } - - go func() { - var partial string - for line := range t.Lines { - nll, err := logs.NewLogLine(line.Text) - if err != nil { - logrus.Error(err) - continue - } - if nll.Partial() { - partial += nll.Msg - continue - } else if !nll.Partial() && len(partial) > 1 { - nll.Msg = partial - partial = "" - } - nll.CID = c.ID() - nll.CName = c.Name() - if nll.Since(options.Since) { - logChannel <- nll - } - } - options.WaitGroup.Done() - }() - return nil -} diff --git a/libpod/container_log.go b/libpod/container_log.go new file mode 100644 index 000000000..bfa303e84 --- /dev/null +++ b/libpod/container_log.go @@ -0,0 +1,76 @@ +package libpod + +import ( + "os" + + "github.com/containers/libpod/libpod/define" + "github.com/containers/libpod/libpod/logs" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" +) + +// Log is a runtime function that can read one or more container logs. +func (r *Runtime) Log(containers []*Container, options *logs.LogOptions, logChannel chan *logs.LogLine) error { + for _, ctr := range containers { + if err := ctr.ReadLog(options, logChannel); err != nil { + return err + } + } + return nil +} + +// ReadLog reads a containers log based on the input options and returns loglines over a channel +func (c *Container) ReadLog(options *logs.LogOptions, logChannel chan *logs.LogLine) error { + // TODO Skip sending logs until journald logs can be read + // TODO make this not a magic string + if c.LogDriver() == define.JournaldLogging { + return c.readFromJournal(options, logChannel) + } + return c.readFromLogFile(options, logChannel) +} + +func (c *Container) readFromLogFile(options *logs.LogOptions, logChannel chan *logs.LogLine) error { + t, tailLog, err := logs.GetLogFile(c.LogPath(), options) + if err != nil { + // If the log file does not exist, this is not fatal. + if os.IsNotExist(errors.Cause(err)) { + return nil + } + return errors.Wrapf(err, "unable to read log file %s for %s ", c.ID(), c.LogPath()) + } + options.WaitGroup.Add(1) + if len(tailLog) > 0 { + for _, nll := range tailLog { + nll.CID = c.ID() + nll.CName = c.Name() + if nll.Since(options.Since) { + logChannel <- nll + } + } + } + + go func() { + var partial string + for line := range t.Lines { + nll, err := logs.NewLogLine(line.Text) + if err != nil { + logrus.Error(err) + continue + } + if nll.Partial() { + partial += nll.Msg + continue + } else if !nll.Partial() && len(partial) > 1 { + nll.Msg = partial + partial = "" + } + nll.CID = c.ID() + nll.CName = c.Name() + if nll.Since(options.Since) { + logChannel <- nll + } + } + options.WaitGroup.Done() + }() + return nil +} diff --git a/libpod/define/config.go b/libpod/define/config.go index 10e00062a..17d764c65 100644 --- a/libpod/define/config.go +++ b/libpod/define/config.go @@ -57,3 +57,12 @@ type AttachStreams struct { // If false, stdout will not be attached AttachInput bool } + +// JournaldLogging is the string conmon expects to specify journald logging +const JournaldLogging = "journald" + +// KubernetesLogging is the string conmon expects when specifying to use the kubernetes logging format +const KubernetesLogging = "k8s-file" + +// JSONLogging is the string conmon expects when specifying to use the json logging format +const JSONLogging = "json-file" diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go index 0113f7d8e..da4b85067 100644 --- a/libpod/oci_conmon_linux.go +++ b/libpod/oci_conmon_linux.go @@ -1427,9 +1427,9 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p var logDriver string switch ctr.LogDriver() { - case JournaldLogging: - logDriver = JournaldLogging - case JSONLogging: + case define.JournaldLogging: + logDriver = define.JournaldLogging + case define.JSONLogging: fallthrough default: //nolint-stylecheck // No case here should happen except JSONLogging, but keep this here in case the options are extended @@ -1439,8 +1439,8 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p // to get here, either a user would specify `--log-driver ""`, or this came from another place in libpod // since the former case is obscure, and the latter case isn't an error, let's silently fallthrough fallthrough - case KubernetesLogging: - logDriver = fmt.Sprintf("%s:%s", KubernetesLogging, logPath) + case define.KubernetesLogging: + logDriver = fmt.Sprintf("%s:%s", define.KubernetesLogging, logPath) } args = append(args, "-l", logDriver) diff --git a/libpod/options.go b/libpod/options.go index 65a089131..b4e436b63 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -985,7 +985,7 @@ func WithLogDriver(driver string) CtrCreateOption { switch driver { case "": return errors.Wrapf(define.ErrInvalidArg, "log driver must be set") - case JournaldLogging, KubernetesLogging, JSONLogging: + case define.JournaldLogging, define.KubernetesLogging, define.JSONLogging: break default: return errors.Wrapf(define.ErrInvalidArg, "invalid log driver") diff --git a/libpod/pod_api.go b/libpod/pod_api.go index 200732652..ed4dc0727 100644 --- a/libpod/pod_api.go +++ b/libpod/pod_api.go @@ -431,9 +431,9 @@ func containerStatusFromContainers(allCtrs []*Container) (map[string]define.Cont } // Inspect returns a PodInspect struct to describe the pod -func (p *Pod) Inspect() (*PodInspect, error) { +func (p *Pod) Inspect() (*define.InspectPodData, error) { var ( - podContainers []PodContainerInfo + ctrs []define.InspectPodContainerInfo ) p.lock.Lock() @@ -443,14 +443,6 @@ func (p *Pod) Inspect() (*PodInspect, error) { } containers, err := p.runtime.state.PodContainers(p) - if err != nil { - return &PodInspect{}, err - } - ctrStatuses, err := containerStatusFromContainers(containers) - if err != nil { - return nil, err - } - status, err := CreatePodStatusResults(ctrStatuses) if err != nil { return nil, err } @@ -462,26 +454,29 @@ func (p *Pod) Inspect() (*PodInspect, error) { if err == nil { containerStatus = containerState.String() } - pc := PodContainerInfo{ + ctrs = append(ctrs, define.InspectPodContainerInfo{ ID: c.ID(), + Name: c.Name(), State: containerStatus, - } - podContainers = append(podContainers, pc) + }) + } + inspectData := define.InspectPodData{ + ID: p.ID(), + Name: p.Name(), + Namespace: p.Namespace(), + Created: p.CreatedTime(), + Hostname: "", + Labels: p.Labels(), + CreateCgroup: false, + CgroupParent: p.CgroupParent(), + CgroupPath: p.state.CgroupPath, + CreateInfra: false, + InfraContainerID: p.state.InfraContainerID, + InfraConfig: nil, + SharedNamespaces: nil, + NumContainers: uint(len(containers)), + Containers: ctrs, } - infraContainerID := p.state.InfraContainerID - config := new(PodConfig) - if err := JSONDeepCopy(p.config, config); err != nil { - return nil, err - } - inspectData := PodInspect{ - Config: config, - State: &PodInspectState{ - CgroupPath: p.state.CgroupPath, - InfraContainerID: infraContainerID, - Status: status, - }, - Containers: podContainers, - } return &inspectData, nil } diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 9d3e69d56..3dc8d3d0f 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -321,7 +321,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai ctrNamedVolumes = append(ctrNamedVolumes, newVol) } - if ctr.config.LogPath == "" && ctr.config.LogDriver != JournaldLogging { + if ctr.config.LogPath == "" && ctr.config.LogDriver != define.JournaldLogging { ctr.config.LogPath = filepath.Join(ctr.config.StaticDir, "ctr.log") } -- cgit v1.2.3-54-g00ecf