Skip to content

Commit

Permalink
podman v2 remove bloat v2
Browse files Browse the repository at this point in the history
rid ourseleves of libpod references in v2 client

Signed-off-by: Brent Baude <[email protected]>
  • Loading branch information
baude committed Apr 16, 2020
1 parent 8857ba2 commit ba430bf
Show file tree
Hide file tree
Showing 36 changed files with 750 additions and 715 deletions.
3 changes: 2 additions & 1 deletion cmd/podman/shared/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/containers/image/v5/manifest"
"github.com/containers/libpod/cmd/podman/shared/parse"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/image"
ann "github.com/containers/libpod/pkg/annotations"
"github.com/containers/libpod/pkg/autoupdate"
Expand Down Expand Up @@ -715,7 +716,7 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
// both
memorySwappiness := c.Int64("memory-swappiness")

logDriver := libpod.KubernetesLogging
logDriver := define.KubernetesLogging
if c.Changed("log-driver") {
logDriver = c.String("log-driver")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podmanV2/common/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/containers/image/v5/manifest"
"github.com/containers/libpod/cmd/podmanV2/parse"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define"
ann "github.com/containers/libpod/pkg/annotations"
envLib "github.com/containers/libpod/pkg/env"
ns "github.com/containers/libpod/pkg/namespaces"
Expand Down Expand Up @@ -324,7 +324,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
if s.LogConfiguration == nil {
s.LogConfiguration = &specgen.LogConfig{}
}
s.LogConfiguration.Driver = libpod.KubernetesLogging
s.LogConfiguration.Driver = define.KubernetesLogging
if ld := c.LogDriver; len(ld) > 0 {
s.LogConfiguration.Driver = ld
}
Expand Down
50 changes: 48 additions & 2 deletions cmd/podmanV2/registry/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package registry

import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/containers/common/pkg/config"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

Expand All @@ -21,7 +25,7 @@ var (

// NewPodmanConfig creates a PodmanConfig from the environment
func NewPodmanConfig() entities.PodmanConfig {
if err := libpod.SetXdgDirs(); err != nil {
if err := setXdgDirs(); err != nil {
logrus.Errorf(err.Error())
os.Exit(1)
}
Expand Down Expand Up @@ -57,3 +61,45 @@ func NewPodmanConfig() entities.PodmanConfig {
}
return entities.PodmanConfig{Config: cfg, EngineMode: mode}
}

// SetXdgDirs ensures the XDG_RUNTIME_DIR env and XDG_CONFIG_HOME variables are set.
// containers/image uses XDG_RUNTIME_DIR to locate the auth file, XDG_CONFIG_HOME is
// use for the libpod.conf configuration file.
func setXdgDirs() error {
if !rootless.IsRootless() {
return nil
}

// Setup XDG_RUNTIME_DIR
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")

if runtimeDir == "" {
var err error
runtimeDir, err = util.GetRuntimeDir()
if err != nil {
return err
}
}
if err := os.Setenv("XDG_RUNTIME_DIR", runtimeDir); err != nil {
return errors.Wrapf(err, "cannot set XDG_RUNTIME_DIR")
}

if rootless.IsRootless() && os.Getenv("DBUS_SESSION_BUS_ADDRESS") == "" {
sessionAddr := filepath.Join(runtimeDir, "bus")
if _, err := os.Stat(sessionAddr); err == nil {
os.Setenv("DBUS_SESSION_BUS_ADDRESS", fmt.Sprintf("unix:path=%s", sessionAddr))
}
}

// Setup XDG_CONFIG_HOME
if cfgHomeDir := os.Getenv("XDG_CONFIG_HOME"); cfgHomeDir == "" {
cfgHomeDir, err := util.GetRootlessConfigHomeDir()
if err != nil {
return err
}
if err := os.Setenv("XDG_CONFIG_HOME", cfgHomeDir); err != nil {
return errors.Wrapf(err, "cannot set XDG_CONFIG_HOME")
}
}
return nil
}
9 changes: 0 additions & 9 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion libpod/container.log.go → libpod/container_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package libpod
import (
"os"

"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/logs"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand All @@ -22,7 +23,7 @@ func (r *Runtime) Log(containers []*Container, options *logs.LogOptions, logChan
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 {
if c.LogDriver() == define.JournaldLogging {
return c.readFromJournal(options, logChannel)
}
return c.readFromLogFile(options, logChannel)
Expand Down
9 changes: 9 additions & 0 deletions libpod/define/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 5 additions & 5 deletions libpod/oci_conmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libpod/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
49 changes: 22 additions & 27 deletions libpod/pod_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion libpod/runtime_ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Loading

0 comments on commit ba430bf

Please sign in to comment.