diff options
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container.go | 8 | ||||
-rw-r--r-- | libpod/container_api.go | 1 | ||||
-rw-r--r-- | libpod/container_attach_linux.go | 6 | ||||
-rw-r--r-- | libpod/container_internal.go | 3 | ||||
-rw-r--r-- | libpod/container_internal_linux.go | 6 | ||||
-rw-r--r-- | libpod/define/errors.go | 2 | ||||
-rw-r--r-- | libpod/healthcheck.go | 2 | ||||
-rw-r--r-- | libpod/image/image.go | 24 | ||||
-rw-r--r-- | libpod/image/prune.go | 2 | ||||
-rw-r--r-- | libpod/image/pull.go | 10 | ||||
-rw-r--r-- | libpod/image/search.go | 3 | ||||
-rw-r--r-- | libpod/kube.go | 1 | ||||
-rw-r--r-- | libpod/oci.go | 3 | ||||
-rw-r--r-- | libpod/oci_linux.go | 2 | ||||
-rw-r--r-- | libpod/runtime_ctr.go | 12 | ||||
-rw-r--r-- | libpod/runtime_pod_linux.go | 6 | ||||
-rw-r--r-- | libpod/stats.go | 2 |
17 files changed, 49 insertions, 44 deletions
diff --git a/libpod/container.go b/libpod/container.go index b71c0b2be..2d96b1120 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -445,7 +445,7 @@ func (c *Container) specFromState() (*spec.Spec, error) { if err != nil { return nil, errors.Wrapf(err, "error reading container config") } - if err := json.Unmarshal([]byte(content), &returnSpec); err != nil { + if err := json.Unmarshal(content, &returnSpec); err != nil { return nil, errors.Wrapf(err, "error unmarshalling container config") } } else { @@ -1030,7 +1030,7 @@ func (c *Container) StoppedByUser() (bool, error) { // NamespacePath returns the path of one of the container's namespaces // If the container is not running, an error will be returned -func (c *Container) NamespacePath(ns LinuxNS) (string, error) { +func (c *Container) NamespacePath(linuxNS LinuxNS) (string, error) { //nolint:interfacer if !c.batched { c.lock.Lock() defer c.lock.Unlock() @@ -1043,11 +1043,11 @@ func (c *Container) NamespacePath(ns LinuxNS) (string, error) { return "", errors.Wrapf(define.ErrCtrStopped, "cannot get namespace path unless container %s is running", c.ID()) } - if ns == InvalidNS { + if linuxNS == InvalidNS { return "", errors.Wrapf(define.ErrInvalidArg, "invalid namespace requested from container %s", c.ID()) } - return fmt.Sprintf("/proc/%d/ns/%s", c.state.PID, ns.String()), nil + return fmt.Sprintf("/proc/%d/ns/%s", c.state.PID, linuxNS.String()), nil } // CGroupPath returns a cgroups "path" for a given container. diff --git a/libpod/container_api.go b/libpod/container_api.go index 6f530f75f..50fa1759d 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -115,7 +115,6 @@ func (c *Container) StartAndAttach(ctx context.Context, streams *AttachStreams, if err := c.prepareToStart(ctx, recursive); err != nil { return nil, err } - attachChan := make(chan error) // We need to ensure that we don't return until start() fired in attach. diff --git a/libpod/container_attach_linux.go b/libpod/container_attach_linux.go index 43dd7d579..837cbf916 100644 --- a/libpod/container_attach_linux.go +++ b/libpod/container_attach_linux.go @@ -88,7 +88,11 @@ func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSi if err != nil { return errors.Wrapf(err, "failed to connect to container's attach socket: %v", socketPath) } - defer conn.Close() + defer func() { + if err := conn.Close(); err != nil { + logrus.Errorf("unable to close socket: %q", err) + } + }() // If starting was requested, start the container and notify when that's // done. diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 47b425c0a..ca27f5814 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1264,6 +1264,7 @@ func (c *Container) postDeleteHooks(ctx context.Context) (err error) { return err } for i, hook := range extensionHooks { + hook := hook logrus.Debugf("container %s: invoke poststop hook %d, path %s", c.ID(), i, hook.Path) var stderr, stdout bytes.Buffer hookErr, err := exec.Run(ctx, &hook, state, &stdout, &stderr, exec.DefaultPostKillTimeout) @@ -1513,7 +1514,7 @@ func (c *Container) prepareCheckpointExport() (err error) { logrus.Debugf("generating spec for container %q failed with %v", c.ID(), err) return err } - if err := c.writeJSONFile(g.Spec(), "spec.dump"); err != nil { + if err := c.writeJSONFile(g.Config, "spec.dump"); err != nil { return err } diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 399220b9a..3dfd4c9e9 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -686,8 +686,8 @@ func (c *Container) importCheckpoint(input string) (err error) { } // Make sure the newly created config.json exists on disk - g := generate.NewFromSpec(c.config.Spec) - if err = c.saveSpec(g.Spec()); err != nil { + g := generate.Generator{Config: c.config.Spec} + if err = c.saveSpec(g.Config); err != nil { return errors.Wrap(err, "Saving imported container specification for restore failed") } @@ -814,7 +814,7 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti } // Save the OCI spec to disk - if err := c.saveSpec(g.Spec()); err != nil { + if err := c.saveSpec(g.Config); err != nil { return err } diff --git a/libpod/define/errors.go b/libpod/define/errors.go index 14643ced1..3b8313855 100644 --- a/libpod/define/errors.go +++ b/libpod/define/errors.go @@ -95,7 +95,7 @@ var ( // ErrOSNotSupported indicates the function is not available on the particular // OS. - ErrOSNotSupported = errors.New("No support for this OS yet") + ErrOSNotSupported = errors.New("no support for this OS yet") // ErrOCIRuntime indicates an error from the OCI runtime ErrOCIRuntime = errors.New("OCI runtime error") diff --git a/libpod/healthcheck.go b/libpod/healthcheck.go index 8ed2b12e1..1a19b88bb 100644 --- a/libpod/healthcheck.go +++ b/libpod/healthcheck.go @@ -230,7 +230,7 @@ func (c *Container) updateHealthCheckLog(hcl HealthCheckLog, inStartPeriod bool) // increment failing streak healthCheck.FailingStreak = healthCheck.FailingStreak + 1 // if failing streak > retries, then status to unhealthy - if int(healthCheck.FailingStreak) >= c.HealthCheckConfig().Retries { + if healthCheck.FailingStreak >= c.HealthCheckConfig().Retries { healthCheck.Status = HealthCheckUnhealthy } } diff --git a/libpod/image/image.go b/libpod/image/image.go index f9879b85b..a057bc720 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -54,7 +54,6 @@ type Image struct { inspect.ImageResult inspectInfo *types.ImageInspectInfo InputName string - Local bool //runtime *libpod.Runtime image *storage.Image imageruntime *Runtime @@ -119,7 +118,6 @@ func setStore(options storage.StoreOptions) (storage.Store, error) { func (ir *Runtime) newFromStorage(img *storage.Image) *Image { image := Image{ InputName: img.ID, - Local: true, imageruntime: ir, image: img, } @@ -132,7 +130,6 @@ func (ir *Runtime) newFromStorage(img *storage.Image) *Image { func (ir *Runtime) NewFromLocal(name string) (*Image, error) { image := Image{ InputName: name, - Local: true, imageruntime: ir, } localImage, err := image.getLocalImage() @@ -153,13 +150,11 @@ func (ir *Runtime) New(ctx context.Context, name, signaturePolicyPath, authfile // We don't know if the image is local or not ... check local first newImage := Image{ InputName: name, - Local: false, imageruntime: ir, } if !forcePull { localImage, err := newImage.getLocalImage() if err == nil { - newImage.Local = true newImage.image = localImage return &newImage, nil } @@ -199,7 +194,6 @@ func (ir *Runtime) LoadFromArchiveReference(ctx context.Context, srcRef types.Im for _, name := range imageNames { newImage := Image{ InputName: name, - Local: true, imageruntime: ir, } img, err := newImage.getLocalImage() @@ -299,6 +293,11 @@ func (i *Image) ID() string { return i.image.ID } +// IsReadOnly returns whether the image ID comes from a local store +func (i *Image) IsReadOnly() bool { + return i.image.ReadOnly +} + // Digest returns the image's digest func (i *Image) Digest() digest.Digest { return i.image.Digest @@ -439,12 +438,25 @@ func (ir *Runtime) getImage(image string) (*Image, error) { // GetImages retrieves all images present in storage func (ir *Runtime) GetImages() ([]*Image, error) { + return ir.getImages(false) +} + +// GetRWImages retrieves all read/write images present in storage +func (ir *Runtime) GetRWImages() ([]*Image, error) { + return ir.getImages(true) +} + +// getImages retrieves all images present in storage +func (ir *Runtime) getImages(rwOnly bool) ([]*Image, error) { var newImages []*Image images, err := ir.store.Images() if err != nil { return nil, err } for _, i := range images { + if rwOnly && i.ReadOnly { + continue + } // iterating over these, be careful to not iterate on the literal // pointer. image := i diff --git a/libpod/image/prune.go b/libpod/image/prune.go index a4f8a0c9f..6ef5d321f 100644 --- a/libpod/image/prune.go +++ b/libpod/image/prune.go @@ -12,7 +12,7 @@ func (ir *Runtime) GetPruneImages(all bool) ([]*Image, error) { var ( pruneImages []*Image ) - allImages, err := ir.GetImages() + allImages, err := ir.GetRWImages() if err != nil { return nil, err } diff --git a/libpod/image/pull.go b/libpod/image/pull.go index 2f1d1e912..78cfe3626 100644 --- a/libpod/image/pull.go +++ b/libpod/image/pull.go @@ -240,6 +240,12 @@ func (ir *Runtime) pullImageFromReference(ctx context.Context, srcRef types.Imag return ir.doPullImage(ctx, sc, *goal, writer, signingOptions, dockerOptions, nil) } +func cleanErrorMessage(err error) string { + errMessage := strings.TrimPrefix(errors.Cause(err).Error(), "errors:\n") + errMessage = strings.Split(errMessage, "\n")[0] + return fmt.Sprintf(" %s\n", errMessage) +} + // doPullImage is an internal helper interpreting pullGoal. Almost everyone should call one of the callers of doPullImage instead. func (ir *Runtime) doPullImage(ctx context.Context, sc *types.SystemContext, goal pullGoal, writer io.Writer, signingOptions SigningOptions, dockerOptions *DockerRegistryOptions, label *string) ([]string, error) { span, _ := opentracing.StartSpanFromContext(ctx, "doPullImage") @@ -281,9 +287,9 @@ func (ir *Runtime) doPullImage(ctx context.Context, sc *types.SystemContext, goa _, err = cp.Image(ctx, policyContext, imageInfo.dstRef, imageInfo.srcRef, copyOptions) if err != nil { pullErrors = multierror.Append(pullErrors, err) - logrus.Errorf("Error pulling image ref %s: %v", imageInfo.srcRef.StringWithinTransport(), err) + logrus.Debugf("Error pulling image ref %s: %v", imageInfo.srcRef.StringWithinTransport(), err) if writer != nil { - _, _ = io.WriteString(writer, "Failed\n") + _, _ = io.WriteString(writer, cleanErrorMessage(err)) } } else { if !goal.pullAllPairs { diff --git a/libpod/image/search.go b/libpod/image/search.go index 9984e5234..e557431c6 100644 --- a/libpod/image/search.go +++ b/libpod/image/search.go @@ -217,21 +217,18 @@ func ParseSearchFilter(filter []string) (*SearchFilter, error) { return nil, errors.Wrapf(err, "incorrect value type for stars filter") } sFilter.Stars = stars - break case "is-automated": if len(arr) == 2 && arr[1] == "false" { sFilter.IsAutomated = types.OptionalBoolFalse } else { sFilter.IsAutomated = types.OptionalBoolTrue } - break case "is-official": if len(arr) == 2 && arr[1] == "false" { sFilter.IsOfficial = types.OptionalBoolFalse } else { sFilter.IsOfficial = types.OptionalBoolTrue } - break default: return nil, errors.Errorf("invalid filter type %q", f) } diff --git a/libpod/kube.go b/libpod/kube.go index b114cda72..084a3df4f 100644 --- a/libpod/kube.go +++ b/libpod/kube.go @@ -155,6 +155,7 @@ func (p *Pod) podWithContainers(containers []*Container, ports []v1.ContainerPor // Deduplicate volumes, so if containers in the pod share a volume, it's only // listed in the volumes section once for _, vol := range volumes { + vol := vol deDupPodVolumes[vol.Name] = &vol } } diff --git a/libpod/oci.go b/libpod/oci.go index 566cbd821..3daf9f834 100644 --- a/libpod/oci.go +++ b/libpod/oci.go @@ -169,7 +169,6 @@ func bindPorts(ports []ocicni.PortMapping) ([]*os.File, error) { return nil, errors.Wrapf(err, "cannot get file for UDP socket") } files = append(files, f) - break case "tcp": addr, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf("%s:%d", i.HostIP, i.HostPort)) @@ -186,13 +185,11 @@ func bindPorts(ports []ocicni.PortMapping) ([]*os.File, error) { return nil, errors.Wrapf(err, "cannot get file for TCP socket") } files = append(files, f) - break case "sctp": if !notifySCTP { notifySCTP = true logrus.Warnf("port reservation for SCTP is not supported") } - break default: return nil, fmt.Errorf("unknown protocol %s", i.Protocol) diff --git a/libpod/oci_linux.go b/libpod/oci_linux.go index 1182457f4..9ce836cb5 100644 --- a/libpod/oci_linux.go +++ b/libpod/oci_linux.go @@ -89,7 +89,7 @@ func makeAccessible(path string, uid, gid int) error { continue } if st.Mode()&0111 != 0111 { - if err := os.Chmod(path, os.FileMode(st.Mode()|0111)); err != nil { + if err := os.Chmod(path, st.Mode()|0111); err != nil { return err } } diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 4b3aeaa37..e57ab4634 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -432,20 +432,12 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool, // from the state elsewhere if !removePod { if err := r.state.RemoveContainerFromPod(pod, c); err != nil { - if cleanupErr == nil { - cleanupErr = err - } else { - logrus.Errorf("removing container from pod: %v", err) - } + cleanupErr = err } } } else { if err := r.state.RemoveContainer(c); err != nil { - if cleanupErr == nil { - cleanupErr = err - } else { - logrus.Errorf("removing container: %v", err) - } + cleanupErr = err } } diff --git a/libpod/runtime_pod_linux.go b/libpod/runtime_pod_linux.go index d667d3a25..f38e6e7c1 100644 --- a/libpod/runtime_pod_linux.go +++ b/libpod/runtime_pod_linux.go @@ -201,11 +201,7 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool) conmonCgroupPath := filepath.Join(p.state.CgroupPath, "conmon") conmonCgroup, err := cgroups.Load(conmonCgroupPath) if err != nil && err != cgroups.ErrCgroupDeleted { - if removalErr == nil { - removalErr = errors.Wrapf(err, "error retrieving pod %s conmon cgroup %s", p.ID(), conmonCgroupPath) - } else { - logrus.Errorf("Error retrieving pod %s conmon cgroup %s: %v", p.ID(), conmonCgroupPath, err) - } + removalErr = errors.Wrapf(err, "error retrieving pod %s conmon cgroup %s", p.ID(), conmonCgroupPath) } // New resource limits diff --git a/libpod/stats.go b/libpod/stats.go index 52af824bb..8101fbbbd 100644 --- a/libpod/stats.go +++ b/libpod/stats.go @@ -86,7 +86,7 @@ func getMemLimit(cgroupLimit uint64) uint64 { return cgroupLimit } - physicalLimit := uint64(si.Totalram) + physicalLimit := si.Totalram if cgroupLimit > physicalLimit { return physicalLimit } |