Merge pull request #2825 from baude/remotediff

add remote-client diff
This commit is contained in:
OpenShift Merge Robot
2019-04-03 11:16:42 -07:00
committed by GitHub
9 changed files with 76 additions and 6 deletions

16
API.md
View File

@ -31,6 +31,8 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in
[func DeleteUnusedImages() []string](#DeleteUnusedImages) [func DeleteUnusedImages() []string](#DeleteUnusedImages)
[func Diff(name: string) DiffInfo](#Diff)
[func ExportContainer(name: string, path: string) string](#ExportContainer) [func ExportContainer(name: string, path: string) string](#ExportContainer)
[func ExportImage(name: string, destination: string, compress: bool, tags: []string) string](#ExportImage) [func ExportImage(name: string, destination: string, compress: bool, tags: []string) string](#ExportImage)
@ -173,6 +175,8 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in
[type CreateResourceConfig](#CreateResourceConfig) [type CreateResourceConfig](#CreateResourceConfig)
[type DiffInfo](#DiffInfo)
[type Event](#Event) [type Event](#Event)
[type IDMap](#IDMap) [type IDMap](#IDMap)
@ -388,6 +392,11 @@ $ varlink call -m unix:/run/podman/io.podman/io.podman.DeleteUnusedImages
] ]
} }
~~~ ~~~
### <a name="Diff"></a>func Diff
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method Diff(name: [string](https://godoc.org/builtin#string)) [DiffInfo](#DiffInfo)</div>
### <a name="ExportContainer"></a>func ExportContainer ### <a name="ExportContainer"></a>func ExportContainer
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> <div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
@ -1431,6 +1440,13 @@ pids_limit [int](https://godoc.org/builtin#int)
shm_size [int](https://godoc.org/builtin#int) shm_size [int](https://godoc.org/builtin#int)
ulimit [[]string](#[]string) ulimit [[]string](#[]string)
### <a name="DiffInfo"></a>type DiffInfo
path [string](https://godoc.org/builtin#string)
changeType [string](https://godoc.org/builtin#string)
### <a name="Event"></a>type Event ### <a name="Event"></a>type Event
Event describes a libpod struct Event describes a libpod struct

View File

@ -14,7 +14,6 @@ func getMainCommands() []*cobra.Command {
_attachCommand, _attachCommand,
_commitCommand, _commitCommand,
_createCommand, _createCommand,
_diffCommand,
_execCommand, _execCommand,
_generateCommand, _generateCommand,
_playCommand, _playCommand,
@ -58,7 +57,6 @@ func getContainerSubCommands() []*cobra.Command {
_cleanupCommand, _cleanupCommand,
_commitCommand, _commitCommand,
_createCommand, _createCommand,
_diffCommand,
_execCommand, _execCommand,
_exportCommand, _exportCommand,
_killCommand, _killCommand,

View File

@ -52,6 +52,7 @@ var (
containerCommands = []*cobra.Command{ containerCommands = []*cobra.Command{
_containerExistsCommand, _containerExistsCommand,
_contInspectSubCommand, _contInspectSubCommand,
_diffCommand,
_listSubCommand, _listSubCommand,
_logsCommand, _logsCommand,
} }

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"github.com/containers/buildah/pkg/formats" "github.com/containers/buildah/pkg/formats"
"github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/pkg/adapter"
"github.com/containers/storage/pkg/archive" "github.com/containers/storage/pkg/archive"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -86,18 +86,17 @@ func diffCmd(c *cliconfig.DiffValues) error {
return errors.Errorf("container, image, or layer name must be specified: podman diff [options [...]] ID-NAME") return errors.Errorf("container, image, or layer name must be specified: podman diff [options [...]] ID-NAME")
} }
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get runtime") return errors.Wrapf(err, "could not get runtime")
} }
defer runtime.Shutdown(false) defer runtime.Shutdown(false)
to := c.InputArgs[0] to := c.InputArgs[0]
changes, err := runtime.GetDiff("", to) changes, err := runtime.Diff(c, to)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get changes for %q", to) return errors.Wrapf(err, "could not get changes for %q", to)
} }
diffOutput := []diffOutputParams{} diffOutput := []diffOutputParams{}
outputFormat := c.Format outputFormat := c.Format

View File

@ -36,6 +36,7 @@ var (
// implemented. // implemented.
var mainCommands = []*cobra.Command{ var mainCommands = []*cobra.Command{
_buildCommand, _buildCommand,
_diffCommand,
_eventsCommand, _eventsCommand,
_exportCommand, _exportCommand,
_historyCommand, _historyCommand,

View File

@ -461,6 +461,13 @@ type Event(
type: string type: string
) )
type DiffInfo(
# path that is different
path: string,
# Add, Delete, Modify
changeType: string
)
# GetVersion returns version and build information of the podman service # GetVersion returns version and build information of the podman service
method GetVersion() -> ( method GetVersion() -> (
version: string, version: string,
@ -1154,6 +1161,8 @@ method LoadImage(name: string, inputFile: string, quiet: bool, deleteFile: bool)
# GetEvents returns known libpod events filtered by the options provided. # GetEvents returns known libpod events filtered by the options provided.
method GetEvents(filter: []string, since: string, until: string) -> (events: Event) method GetEvents(filter: []string, since: string, until: string) -> (events: Event)
method Diff(name: string) -> (diffs: []DiffInfo)
# ImageNotFound means the image could not be found by the provided name or ID in local storage. # ImageNotFound means the image could not be found by the provided name or ID in local storage.
error ImageNotFound (id: string, reason: string) error ImageNotFound (id: string, reason: string)

View File

@ -23,6 +23,7 @@ import (
"github.com/containers/libpod/libpod/events" "github.com/containers/libpod/libpod/events"
"github.com/containers/libpod/libpod/image" "github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/rootless" "github.com/containers/libpod/pkg/rootless"
"github.com/containers/storage/pkg/archive"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -430,3 +431,8 @@ func (r *LocalRuntime) Events(c *cliconfig.EventValues) error {
} }
return nil return nil
} }
// Diff shows the difference in two objects
func (r *LocalRuntime) Diff(c *cliconfig.DiffValues, to string) ([]archive.Change, error) {
return r.Runtime.GetDiff("", to)
}

View File

@ -831,3 +831,30 @@ func (r *LocalRuntime) Events(c *cliconfig.EventValues) error {
} }
return nil return nil
} }
// Diff ...
func (r *LocalRuntime) Diff(c *cliconfig.DiffValues, to string) ([]archive.Change, error) {
var changes []archive.Change
reply, err := iopodman.Diff().Call(r.Conn, to)
if err != nil {
return nil, err
}
for _, change := range reply {
changes = append(changes, archive.Change{Path: change.Path, Kind: stringToChangeType(change.ChangeType)})
}
return changes, nil
}
func stringToChangeType(change string) archive.ChangeType {
switch change {
case "A":
return archive.ChangeAdd
case "D":
return archive.ChangeDelete
default:
logrus.Errorf("'%s' is unknown archive type", change)
fallthrough
case "C":
return archive.ChangeModify
}
}

View File

@ -910,3 +910,16 @@ func (i *LibpodAPI) LoadImage(call iopodman.VarlinkCall, name, inputFile string,
} }
return call.ReplyLoadImage(br) return call.ReplyLoadImage(br)
} }
// Diff ...
func (i *LibpodAPI) Diff(call iopodman.VarlinkCall, name string) error {
var response []iopodman.DiffInfo
changes, err := i.Runtime.GetDiff("", name)
if err != nil {
return call.ReplyErrorOccurred(err.Error())
}
for _, change := range changes {
response = append(response, iopodman.DiffInfo{Path: change.Path, ChangeType: change.Kind.String()})
}
return call.ReplyDiff(response)
}