aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/api/handlers/compat/images.go2
-rw-r--r--pkg/api/handlers/libpod/images.go2
-rw-r--r--pkg/api/server/register_images.go4
-rw-r--r--pkg/bindings/containers/types.go1
-rw-r--r--pkg/bindings/containers/types_commit_options.go15
-rw-r--r--pkg/domain/entities/containers.go1
-rw-r--r--pkg/domain/infra/abi/containers.go1
-rw-r--r--pkg/domain/infra/tunnel/containers.go2
-rw-r--r--pkg/specgen/generate/kube/kube.go16
-rw-r--r--pkg/specgen/generate/kube/kube_test.go42
10 files changed, 83 insertions, 3 deletions
diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go
index 3546f88a0..edefce010 100644
--- a/pkg/api/handlers/compat/images.go
+++ b/pkg/api/handlers/compat/images.go
@@ -102,6 +102,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
Comment string `schema:"comment"`
Container string `schema:"container"`
Pause bool `schema:"pause"`
+ Squash bool `schema:"squash"`
Repo string `schema:"repo"`
Tag string `schema:"tag"`
// fromSrc string # fromSrc is currently unused
@@ -138,6 +139,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
options.Message = query.Comment
options.Author = query.Author
options.Pause = query.Pause
+ options.Squash = query.Squash
for _, change := range query.Changes {
options.Changes = append(options.Changes, strings.Split(change, "\n")...)
}
diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go
index f078c13cc..eb9fb12a6 100644
--- a/pkg/api/handlers/libpod/images.go
+++ b/pkg/api/handlers/libpod/images.go
@@ -497,6 +497,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
Container string `schema:"container"`
Format string `schema:"format"`
Pause bool `schema:"pause"`
+ Squash bool `schema:"squash"`
Repo string `schema:"repo"`
Tag string `schema:"tag"`
}{
@@ -543,6 +544,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
options.Message = query.Comment
options.Author = query.Author
options.Pause = query.Pause
+ options.Squash = query.Squash
options.Changes = query.Changes
ctr, err := runtime.LookupContainer(query.Container)
if err != nil {
diff --git a/pkg/api/server/register_images.go b/pkg/api/server/register_images.go
index d7bc17093..017310f12 100644
--- a/pkg/api/server/register_images.go
+++ b/pkg/api/server/register_images.go
@@ -460,6 +460,10 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// name: changes
// type: string
// description: instructions to apply while committing in Dockerfile format
+ // - in: query
+ // name: squash
+ // type: boolean
+ // description: squash newly built layers into a single new layer
// produces:
// - application/json
// responses:
diff --git a/pkg/bindings/containers/types.go b/pkg/bindings/containers/types.go
index 4915e3e23..66b90af9b 100644
--- a/pkg/bindings/containers/types.go
+++ b/pkg/bindings/containers/types.go
@@ -30,6 +30,7 @@ type CommitOptions struct {
Comment *string
Format *string
Pause *bool
+ Squash *bool
Repo *string
Tag *string
}
diff --git a/pkg/bindings/containers/types_commit_options.go b/pkg/bindings/containers/types_commit_options.go
index 7eb04198f..7b4745eb8 100644
--- a/pkg/bindings/containers/types_commit_options.go
+++ b/pkg/bindings/containers/types_commit_options.go
@@ -92,6 +92,21 @@ func (o *CommitOptions) GetPause() bool {
return *o.Pause
}
+// WithSquash set field Squash to given value
+func (o *CommitOptions) WithSquash(value bool) *CommitOptions {
+ o.Squash = &value
+ return o
+}
+
+// GetSquash returns value of field Squash
+func (o *CommitOptions) GetSquash() bool {
+ if o.Squash == nil {
+ var z bool
+ return z
+ }
+ return *o.Squash
+}
+
// WithRepo set field Repo to given value
func (o *CommitOptions) WithRepo(value string) *CommitOptions {
o.Repo = &value
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go
index e9bce0eb7..79795a221 100644
--- a/pkg/domain/entities/containers.go
+++ b/pkg/domain/entities/containers.go
@@ -154,6 +154,7 @@ type CommitOptions struct {
Message string
Pause bool
Quiet bool
+ Squash bool
Writer io.Writer
}
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 92f5b1a80..e6feb7c82 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -529,6 +529,7 @@ func (ic *ContainerEngine) ContainerCommit(ctx context.Context, nameOrID string,
Message: options.Message,
Changes: options.Changes,
Author: options.Author,
+ Squash: options.Squash,
}
newImage, err := ctr.Commit(ctx, options.ImageName, opts)
if err != nil {
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go
index aa4baf846..fe986361b 100644
--- a/pkg/domain/infra/tunnel/containers.go
+++ b/pkg/domain/infra/tunnel/containers.go
@@ -302,7 +302,7 @@ func (ic *ContainerEngine) ContainerCommit(ctx context.Context, nameOrID string,
return nil, errors.Errorf("invalid image name %q", opts.ImageName)
}
}
- options := new(containers.CommitOptions).WithAuthor(opts.Author).WithChanges(opts.Changes).WithComment(opts.Message)
+ options := new(containers.CommitOptions).WithAuthor(opts.Author).WithChanges(opts.Changes).WithComment(opts.Message).WithSquash(opts.Squash)
options.WithFormat(opts.Format).WithPause(opts.Pause).WithRepo(repo).WithTag(tag)
response, err := containers.Commit(ic.ClientCtx, nameOrID, options)
if err != nil {
diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go
index a8f17e2b6..5e6671231 100644
--- a/pkg/specgen/generate/kube/kube.go
+++ b/pkg/specgen/generate/kube/kube.go
@@ -324,7 +324,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
continue
}
- dest, options, err := parseMountPath(volume.MountPath, volume.ReadOnly)
+ dest, options, err := parseMountPath(volume.MountPath, volume.ReadOnly, volume.MountPropagation)
if err != nil {
return nil, err
}
@@ -390,7 +390,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
return s, nil
}
-func parseMountPath(mountPath string, readOnly bool) (string, []string, error) {
+func parseMountPath(mountPath string, readOnly bool, propagationMode *v1.MountPropagationMode) (string, []string, error) {
options := []string{}
splitVol := strings.Split(mountPath, ":")
if len(splitVol) > 2 {
@@ -410,6 +410,18 @@ func parseMountPath(mountPath string, readOnly bool) (string, []string, error) {
if err != nil {
return "", opts, errors.Wrapf(err, "parsing MountOptions")
}
+ if propagationMode != nil {
+ switch *propagationMode {
+ case v1.MountPropagationNone:
+ opts = append(opts, "private")
+ case v1.MountPropagationHostToContainer:
+ opts = append(opts, "rslave")
+ case v1.MountPropagationBidirectional:
+ opts = append(opts, "rshared")
+ default:
+ return "", opts, errors.Errorf("unknown propagation mode %q", *propagationMode)
+ }
+ }
return dest, opts, nil
}
diff --git a/pkg/specgen/generate/kube/kube_test.go b/pkg/specgen/generate/kube/kube_test.go
new file mode 100644
index 000000000..62793ebb6
--- /dev/null
+++ b/pkg/specgen/generate/kube/kube_test.go
@@ -0,0 +1,42 @@
+package kube
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ v1 "k8s.io/api/core/v1"
+ //"github.com/stretchr/testify/require"
+)
+
+func testPropagation(t *testing.T, propagation v1.MountPropagationMode, expected string) {
+ dest, options, err := parseMountPath("/to", false, &propagation)
+ assert.NoError(t, err)
+ assert.Equal(t, dest, "/to")
+ assert.Contains(t, options, expected)
+}
+
+func TestParseMountPathPropagation(t *testing.T) {
+ testPropagation(t, v1.MountPropagationNone, "private")
+ testPropagation(t, v1.MountPropagationHostToContainer, "rslave")
+ testPropagation(t, v1.MountPropagationBidirectional, "rshared")
+
+ prop := v1.MountPropagationMode("SpaceWave")
+ _, _, err := parseMountPath("/to", false, &prop)
+ assert.Error(t, err)
+
+ _, options, err := parseMountPath("/to", false, nil)
+ assert.NoError(t, err)
+ assert.NotContains(t, options, "private")
+ assert.NotContains(t, options, "rslave")
+ assert.NotContains(t, options, "rshared")
+}
+
+func TestParseMountPathRO(t *testing.T) {
+ _, options, err := parseMountPath("/to", true, nil)
+ assert.NoError(t, err)
+ assert.Contains(t, options, "ro")
+
+ _, options, err = parseMountPath("/to", false, nil)
+ assert.NoError(t, err)
+ assert.NotContains(t, options, "ro")
+}