Add kpod diff command
kpod diff reports on differences between two layers, specified as layer IDs, containers, or images. In the case of containers or images, kpod diff produces a diff for the top layer Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
parent
fb2ee59225
commit
949268f958
6 changed files with 238 additions and 0 deletions
54
libkpod/diff.go
Normal file
54
libkpod/diff.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package libkpod
|
||||
|
||||
import (
|
||||
"github.com/containers/storage/pkg/archive"
|
||||
"github.com/kubernetes-incubator/cri-o/libkpod/image"
|
||||
"github.com/kubernetes-incubator/cri-o/libkpod/layer"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// GetDiff returns the differences betwen the two images, layers, or containers
|
||||
func (c *ContainerServer) GetDiff(from, to string) ([]archive.Change, error) {
|
||||
toLayer, err := c.getLayerID(to)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fromLayer := ""
|
||||
if from != "" {
|
||||
fromLayer, err = c.getLayerID(from)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return c.Store().Changes(fromLayer, toLayer)
|
||||
}
|
||||
|
||||
// GetLayerID gets a full layer id given a full or partial id
|
||||
// If the id matches a container or image, the id of the top layer is returned
|
||||
// If the id matches a layer, the top layer id is returned
|
||||
func (c *ContainerServer) getLayerID(id string) (string, error) {
|
||||
var toLayer string
|
||||
toImage, err := image.FindImage(c.store, id)
|
||||
if err != nil {
|
||||
toCtr, err := c.store.Container(id)
|
||||
if err != nil {
|
||||
toLayer, err = layer.FullID(c.store, id)
|
||||
if err != nil {
|
||||
return "", errors.Errorf("layer, image, or container %s does not exist", id)
|
||||
}
|
||||
} else {
|
||||
toLayer = toCtr.LayerID
|
||||
}
|
||||
} else {
|
||||
toLayer = toImage.TopLayer
|
||||
}
|
||||
return toLayer, nil
|
||||
}
|
||||
|
||||
func (c *ContainerServer) getLayerParent(layerID string) (string, error) {
|
||||
layer, err := c.store.Layer(layerID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return layer.Parent, nil
|
||||
}
|
12
libkpod/layer/layer.go
Normal file
12
libkpod/layer/layer.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package layer
|
||||
|
||||
import cstorage "github.com/containers/storage"
|
||||
|
||||
// FullID gets the full id of a layer given a partial id or name
|
||||
func FullID(store cstorage.Store, id string) (string, error) {
|
||||
layer, err := store.Layer(id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return layer.ID, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue