Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cmd/podman/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ func commitCmd(c *cliconfig.CommitValues) error {
return errors.Wrapf(err, "error looking up container %q", container)
}

sc := image.GetSystemContext(runtime.GetConfig().SignaturePolicyPath, "", false)
rtc, err := runtime.GetConfig()
if err != nil {
return err
}

sc := image.GetSystemContext(rtc.SignaturePolicyPath, "", false)
coptions := buildah.CommitOptions{
SignaturePolicyPath: runtime.GetConfig().SignaturePolicyPath,
SignaturePolicyPath: rtc.SignaturePolicyPath,
ReportWriter: writer,
SystemContext: sc,
PreferredManifestType: mimeType,
Expand Down
2 changes: 2 additions & 0 deletions cmd/podman/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/storage"
"github.com/fatih/camelcase"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var (
stores = make(map[storage.Store]struct{})
json = jsoniter.ConfigCompatibleWithStandardLibrary
)

const (
Expand Down
1 change: 0 additions & 1 deletion cmd/podman/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"strings"

"github.com/containers/buildah/pkg/formats"
Expand Down
6 changes: 5 additions & 1 deletion cmd/podman/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ func mountCmd(c *cliconfig.MountValues) error {
defer runtime.Shutdown(false)

if os.Geteuid() != 0 {
if driver := runtime.GetConfig().StorageConfig.GraphDriverName; driver != "vfs" {
rtc, err := runtime.GetConfig()
if err != nil {
return err
}
if driver := rtc.StorageConfig.GraphDriverName; driver != "vfs" {
// Do not allow to mount a graphdriver that is not vfs if we are creating the userns as part
// of the mount command.
return fmt.Errorf("cannot mount using driver %s in rootless mode", driver)
Expand Down
1 change: 0 additions & 1 deletion cmd/podman/pod_inspect.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"fmt"

"github.com/containers/libpod/cmd/podman/cliconfig"
Expand Down
6 changes: 3 additions & 3 deletions cmd/podman/pod_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import (
"text/tabwriter"
"time"

"encoding/json"
tm "github.com/buger/goterm"
"github.com/containers/buildah/pkg/formats"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/ulule/deepcopier"
)

var (
Expand Down Expand Up @@ -187,7 +185,9 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
}
time.Sleep(time.Second)
previousPodStats := new([]*libpod.PodContainerStats)
deepcopier.Copy(newStats).To(previousPodStats)
if err := libpod.JSONDeepCopy(newStats, previousPodStats); err != nil {
return err
}
pods, err = runtime.GetStatPods(c)
if err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/ps.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"fmt"
"html/template"
"os"
Expand Down Expand Up @@ -647,7 +646,7 @@ func printFormat(format string, containers []shared.PsContainerOutput) error {
}

func dumpJSON(containers []shared.PsContainerOutput) error {
b, err := json.MarshalIndent(containers, "", "\t")
b, err := json.MarshalIndent(containers, "", " ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh

if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/podman/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ func runCmd(c *cliconfig.RunValues) error {
if errors.Cause(err) == libpod.ErrNoSuchCtr {
// The container may have been removed
// Go looking for an exit file
ctrExitCode, err := readExitFile(runtime.GetConfig().TmpDir, ctr.ID())
rtc, err := runtime.GetConfig()
if err != nil {
return err
}
ctrExitCode, err := readExitFile(rtc.TmpDir, ctr.ID())
if err != nil {
logrus.Errorf("Cannot get exit code: %v", err)
exitCode = 127
Expand Down
15 changes: 11 additions & 4 deletions cmd/podman/shared/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,23 @@ func getContext() context.Context {
func CreateContainer(ctx context.Context, c *cliconfig.PodmanCommand, runtime *libpod.Runtime) (*libpod.Container, *cc.CreateConfig, error) {
var (
healthCheck *manifest.Schema2HealthConfig
err error
cidFile *os.File
)
if c.Bool("trace") {
span, _ := opentracing.StartSpanFromContext(ctx, "createContainer")
defer span.Finish()
}

rtc := runtime.GetConfig()
rtc, err := runtime.GetConfig()
if err != nil {
return nil, nil, err
}
rootfs := ""
if c.Bool("rootfs") {
rootfs = c.InputArgs[0]
}

var err error
var cidFile *os.File
if c.IsSet("cidfile") && os.Geteuid() == 0 {
cidFile, err = libpod.OpenExclusiveFile(c.String("cidfile"))
if err != nil && os.IsExist(err) {
Expand Down Expand Up @@ -721,7 +724,11 @@ func ParseCreateOpts(ctx context.Context, c *cliconfig.PodmanCommand, runtime *l
if c.Bool("init") {
initPath := c.String("init-path")
if initPath == "" {
initPath = runtime.GetConfig().InitPath
rtc, err := runtime.GetConfig()
if err != nil {
return nil, err
}
initPath = rtc.InitPath
}
if err := config.AddContainerInitBinary(initPath); err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion cmd/podman/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ func signCmd(c *cliconfig.SignValues) error {
}

// create the signstore file
newImage, err := runtime.ImageRuntime().New(getContext(), signimage, runtime.GetConfig().SignaturePolicyPath, "", os.Stderr, nil, image.SigningOptions{SignBy: signby}, false, nil)
rtc, err := runtime.GetConfig()
if err != nil {
return err
}
newImage, err := runtime.ImageRuntime().New(getContext(), signimage, rtc.SignaturePolicyPath, "", os.Stderr, nil, image.SigningOptions{SignBy: signby}, false, nil)
if err != nil {
return errors.Wrapf(err, "error pulling image %s", signimage)
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/podman/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ func startCmd(c *cliconfig.StartValues) error {
if errors.Cause(err) == libpod.ErrNoSuchCtr {
// The container may have been removed
// Go looking for an exit file
ctrExitCode, err := readExitFile(runtime.GetConfig().TmpDir, ctr.ID())
rtc, err := runtime.GetConfig()
if err != nil {
return err
}
ctrExitCode, err := readExitFile(rtc.TmpDir, ctr.ID())
if err != nil {
logrus.Errorf("Cannot get exit code: %v", err)
exitCode = 127
Expand Down
1 change: 0 additions & 1 deletion cmd/podman/trust_set_show.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"io/ioutil"
"os"
"sort"
Expand Down
3 changes: 0 additions & 3 deletions contrib/spec/podman.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ Provides: bundled(golang(github.com/stretchr/testify)) = 4d4bfba8f1d1027c4fdbe37
Provides: bundled(golang(github.com/syndtr/gocapability)) = e7cb7fa329f456b3855136a2642b197bad7366ba
Provides: bundled(golang(github.com/tchap/go-patricia)) = v2.2.6
Provides: bundled(golang(github.com/ulikunitz/xz)) = v0.5.4
Provides: bundled(golang(github.com/ulule/deepcopier)) = master
# "-" are not accepted in version strings, so comment out below line
#Provides: bundled(golang(github.com/urfave/cli)) = fix-short-opts-parsing
Provides: bundled(golang(github.com/varlink/go)) = master
Expand Down Expand Up @@ -237,7 +236,6 @@ BuildRequires: golang(github.com/opencontainers/selinux/go-selinux)
BuildRequires: golang(github.com/opencontainers/selinux/go-selinux/label)
BuildRequires: golang(github.com/pkg/errors)
BuildRequires: golang(github.com/sirupsen/logrus)
BuildRequires: golang(github.com/ulule/deepcopier)
BuildRequires: golang(golang.org/x/crypto/ssh/terminal)
BuildRequires: golang(golang.org/x/sys/unix)
BuildRequires: golang(k8s.io/apimachinery/pkg/util/wait)
Expand Down Expand Up @@ -290,7 +288,6 @@ Requires: golang(github.com/opencontainers/selinux/go-selinux)
Requires: golang(github.com/opencontainers/selinux/go-selinux/label)
Requires: golang(github.com/pkg/errors)
Requires: golang(github.com/sirupsen/logrus)
Requires: golang(github.com/ulule/deepcopier)
Requires: golang(golang.org/x/crypto/ssh/terminal)
Requires: golang(golang.org/x/sys/unix)
Requires: golang(k8s.io/apimachinery/pkg/util/wait)
Expand Down
13 changes: 9 additions & 4 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/cri-o/ocicni/pkg/ocicni"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/ulule/deepcopier"
)

// ContainerStatus represents the current state of a container
Expand Down Expand Up @@ -407,7 +406,9 @@ func (t ContainerStatus) String() string {
// Config returns the configuration used to create the container
func (c *Container) Config() *ContainerConfig {
returnConfig := new(ContainerConfig)
deepcopier.Copy(c.config).To(returnConfig)
if err := JSONDeepCopy(c.config, returnConfig); err != nil {
return nil
}

return returnConfig
}
Expand All @@ -417,7 +418,9 @@ func (c *Container) Config() *ContainerConfig {
// spec may differ slightly as mounts are added based on the image
func (c *Container) Spec() *spec.Spec {
returnSpec := new(spec.Spec)
deepcopier.Copy(c.config.Spec).To(returnSpec)
if err := JSONDeepCopy(c.config.Spec, returnSpec); err != nil {
return nil
}

return returnSpec
}
Expand Down Expand Up @@ -1094,7 +1097,9 @@ func (c *Container) ContainerState() (*ContainerState, error) {
}
}
returnConfig := new(ContainerState)
deepcopier.Copy(c.state).To(returnConfig)
if err := JSONDeepCopy(c.state, returnConfig); err != nil {
return nil, errors.Wrapf(err, "error copying container %s state", c.ID())
}
return c.state, nil
}

Expand Down
6 changes: 5 additions & 1 deletion libpod/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (v *Volume) newVolumeEvent(status events.Status) {
// Events is a wrapper function for everyone to begin tailing the events log
// with options
func (r *Runtime) Events(fromStart, stream bool, options []events.EventFilter, eventChannel chan *events.Event) error {
if !r.valid {
return ErrRuntimeStopped
}

t, err := r.getTail(fromStart, stream)
if err != nil {
return err
Expand All @@ -71,7 +75,7 @@ func (r *Runtime) Events(fromStart, stream bool, options []events.EventFilter, e
case events.Image, events.Volume, events.Pod, events.Container:
// no-op
default:
return errors.Errorf("event type %s is not valid in %s", event.Type.String(), r.GetConfig().EventsLogFilePath)
return errors.Errorf("event type %s is not valid in %s", event.Type.String(), r.config.EventsLogFilePath)
}
include := true
for _, filter := range options {
Expand Down
5 changes: 3 additions & 2 deletions libpod/pod_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/containers/libpod/libpod/events"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/ulule/deepcopier"
)

// Start starts all containers within a pod
Expand Down Expand Up @@ -441,7 +440,9 @@ func (p *Pod) Inspect() (*PodInspect, error) {
infraContainerID := p.state.InfraContainerID

config := new(PodConfig)
deepcopier.Copy(p.config).To(config)
if err := JSONDeepCopy(p.config, config); err != nil {
return nil, err
}
inspectData := PodInspect{
Config: config,
State: &PodInspectState{
Expand Down
15 changes: 9 additions & 6 deletions libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/docker/docker/pkg/namesgenerator"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/ulule/deepcopier"
)

// RuntimeStateStore is a constant indicating which state store implementation
Expand Down Expand Up @@ -355,7 +354,9 @@ func newRuntimeFromConfig(userConfigPath string, options ...RuntimeOption) (runt
if err != nil {
return nil, err
}
deepcopier.Copy(defaultRuntimeConfig).To(runtime.config)
if err := JSONDeepCopy(defaultRuntimeConfig, runtime.config); err != nil {
return nil, errors.Wrapf(err, "error copying runtime default config")
}
runtime.config.TmpDir = tmpDir

storageConf, err := util.GetDefaultStoreOptions()
Expand Down Expand Up @@ -923,20 +924,22 @@ func makeRuntime(runtime *Runtime) (err error) {
}

// GetConfig returns a copy of the configuration used by the runtime
func (r *Runtime) GetConfig() *RuntimeConfig {
func (r *Runtime) GetConfig() (*RuntimeConfig, error) {
r.lock.RLock()
defer r.lock.RUnlock()

if !r.valid {
return nil
return nil, ErrRuntimeStopped
}

config := new(RuntimeConfig)

// Copy so the caller won't be able to modify the actual config
deepcopier.Copy(r.config).To(config)
if err := JSONDeepCopy(r.config, config); err != nil {
return nil, errors.Wrapf(err, "error copying config")
}

return config
return config, nil
}

// Shutdown shuts down the runtime and associated containers and storage
Expand Down
5 changes: 3 additions & 2 deletions libpod/runtime_ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/ulule/deepcopier"
)

// CtrRemoveTimeout is the default number of seconds to wait after stopping a container
Expand Down Expand Up @@ -63,7 +62,9 @@ func (r *Runtime) newContainer(ctx context.Context, rSpec *spec.Spec, options ..
ctr.config.ID = stringid.GenerateNonCryptoID()

ctr.config.Spec = new(spec.Spec)
deepcopier.Copy(rSpec).To(ctr.config.Spec)
if err := JSONDeepCopy(rSpec, ctr.config.Spec); err != nil {
return nil, errors.Wrapf(err, "error copying runtime spec while creating container")
}
ctr.config.CreatedTime = time.Now()

ctr.config.ShmSize = DefaultShmSize
Expand Down
10 changes: 10 additions & 0 deletions libpod/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,13 @@ func validPodNSOption(p *Pod, ctrPod string) error {
}
return nil
}

// JSONDeepCopy performs a deep copy by performing a JSON encode/decode of the
// given structures. From and To should be identically typed structs.
func JSONDeepCopy(from, to interface{}) error {
tmp, err := json.Marshal(from)
if err != nil {
return err
}
return json.Unmarshal(tmp, to)
}
5 changes: 3 additions & 2 deletions pkg/adapter/pods_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/varlinkapi"
"github.com/pkg/errors"
"github.com/ulule/deepcopier"
)

// Pod ...
Expand Down Expand Up @@ -99,7 +98,9 @@ func (r *LocalRuntime) LookupPod(nameOrID string) (*Pod, error) {
// the data of a remotepod data struct
func (p *Pod) Inspect() (*libpod.PodInspect, error) {
config := new(libpod.PodConfig)
deepcopier.Copy(p.remotepod.config).To(config)
if err := libpod.JSONDeepCopy(p.remotepod.config, config); err != nil {
return nil, err
}
inspectData := libpod.PodInspect{
Config: config,
State: p.remotepod.state,
Expand Down
Loading