Skip to content

Commit

Permalink
Merge pull request #5374 from baude/create
Browse files Browse the repository at this point in the history
add default network for apiv2 create
  • Loading branch information
openshift-merge-robot authored Mar 7, 2020
2 parents 43bf4f6 + 8b5e2a6 commit c8de26f
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 190 deletions.
1 change: 1 addition & 0 deletions cmd/podman/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func before(cmd *cobra.Command, args []string) error {
logrus.Info("running as rootless")
}
setUMask()

return profileOn(cmd)
}

Expand Down
2 changes: 1 addition & 1 deletion contrib/cirrus/setup_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exithandler() {
echo "$(basename $0) exit status: $RET"
[[ "$RET" -eq "0" ]] && date +%s >> "$SETUP_MARKER_FILEPATH"
show_env_vars
[ "$RET" -eq "0" ]] || warn "Non-zero exit caused by error ABOVE env. var. display."
[[ "$RET" -eq "0" ]] || warn "Non-zero exit caused by error ABOVE env. var. display."
}
trap exithandler EXIT

Expand Down
10 changes: 9 additions & 1 deletion libpod/runtime_ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/events"
"github.com/containers/libpod/pkg/cgroups"
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/storage/pkg/stringid"
spec "github.com/opencontainers/runtime-spec/specs-go"
Expand Down Expand Up @@ -438,9 +439,16 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool,
if err := c.ociRuntime.KillContainer(c, 9, false); err != nil {
return err
}
if err := c.unpause(); err != nil {
isV2, err := cgroups.IsCgroup2UnifiedMode()
if err != nil {
return err
}
// cgroups v1 and v2 handle signals on paused processes differently
if !isV2 {
if err := c.unpause(); err != nil {
return err
}
}
// Need to update container state to make sure we know it's stopped
if err := c.waitForExitFileAndSync(); err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion pkg/api/handlers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func UnpauseContainer(w http.ResponseWriter, r *http.Request) {
return
}

// the api does not error if the Container is already paused, so just into it
if err := con.Unpause(); err != nil {
utils.InternalServerError(w, err)
return
Expand Down
46 changes: 45 additions & 1 deletion pkg/api/server/register_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,50 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/libpod/images/{name:.*}/tag"), s.APIHandler(handlers.TagImage)).Methods(http.MethodPost)

// swagger:operation POST /commit libpod libpodCommitContainer
// ---
// tags:
// - containers
// summary: Commit
// description: Create a new image from a container
// parameters:
// - in: query
// name: container
// type: string
// description: the name or ID of a container
// - in: query
// name: repo
// type: string
// description: the repository name for the created image
// - in: query
// name: tag
// type: string
// description: tag name for the created image
// - in: query
// name: comment
// type: string
// description: commit message
// - in: query
// name: author
// type: string
// description: author of the image
// - in: query
// name: pause
// type: boolean
// description: pause the container before committing it
// - in: query
// name: changes
// type: string
// description: instructions to apply while committing in Dockerfile format
// produces:
// - application/json
// responses:
// 201:
// description: no error
// 404:
// $ref: '#/responses/NoSuchImage'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/commit"), s.APIHandler(generic.CommitContainer)).Methods(http.MethodPost)
return nil
}
2 changes: 1 addition & 1 deletion pkg/bindings/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
jsoniter "github.com/json-iterator/go"
)

func CreateWithSpec(ctx context.Context, s specgen.SpecGenerator) (utils.ContainerCreateResponse, error) {
func CreateWithSpec(ctx context.Context, s *specgen.SpecGenerator) (utils.ContainerCreateResponse, error) {
var ccr utils.ContainerCreateResponse
conn, err := bindings.GetClient(ctx)
if err != nil {
Expand Down
44 changes: 34 additions & 10 deletions pkg/bindings/test/common_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package test_bindings

import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"

. "github.com/containers/libpod/pkg/bindings"
"github.com/containers/libpod/pkg/bindings/containers"
"github.com/containers/libpod/pkg/specgen"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega/gexec"
"github.com/pkg/errors"
Expand Down Expand Up @@ -55,6 +59,16 @@ type bindingTest struct {
tempDirPath string
runRoot string
crioRoot string
conn context.Context
}

func (b *bindingTest) NewConnection() error {
connText, err := NewConnection(context.Background(), b.sock)
if err != nil {
return err
}
b.conn = connText
return nil
}

func (b *bindingTest) runPodman(command []string) *gexec.Session {
Expand Down Expand Up @@ -173,17 +187,27 @@ func (b *bindingTest) restoreImageFromCache(i testImage) {

// Run a container within or without a pod
// and add or append the alpine image to it
func (b *bindingTest) RunTopContainer(containerName *string, insidePod *bool, podName *string) {
cmd := []string{"run", "-dt"}
func (b *bindingTest) RunTopContainer(containerName *string, insidePod *bool, podName *string) (string, error) {
s := specgen.NewSpecGenerator(alpine.name)
s.Terminal = false
s.Command = []string{"top"}
if containerName != nil {
s.Name = *containerName
}
if insidePod != nil && podName != nil {
pName := *podName
cmd = append(cmd, "--pod", pName)
} else if containerName != nil {
cName := *containerName
cmd = append(cmd, "--name", cName)
}
cmd = append(cmd, alpine.name, "top")
b.runPodman(cmd).Wait(45)
s.Pod = *podName
}
ctr, err := containers.CreateWithSpec(b.conn, s)
if err != nil {
return "", nil
}
err = containers.Start(b.conn, ctr.ID, nil)
if err != nil {
return "", err
}
waiting := "running"
_, err = containers.Wait(b.conn, ctr.ID, &waiting)
return ctr.ID, err
}

// This method creates a pod with the given pod name.
Expand Down
Loading

0 comments on commit c8de26f

Please sign in to comment.