Skip to content

Commit

Permalink
feature: add resize interface
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Wan <[email protected]>
  • Loading branch information
HusterWan committed Mar 13, 2018
1 parent 10d8a94 commit af05c15
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apis/server/container_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,24 @@ func (s *Server) upgradeContainer(ctx context.Context, rw http.ResponseWriter, r
rw.WriteHeader(http.StatusOK)
return nil
}

func (s *Server) resizeContainer(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
opts := types.ResizeOptions{}
// decode request body
if err := json.NewDecoder(req.Body).Decode(opts); err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}
// validate request body
if err := opts.Validate(strfmt.NewFormats()); err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

name := mux.Vars(req)["name"]

if err := s.ContainerMgr.Resize(ctx, name, opts); err != nil {
return err
}

rw.WriteHeader(http.StatusOK)
return nil
}
1 change: 1 addition & 0 deletions apis/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func initRoute(s *Server) http.Handler {
r.Path(versionMatcher + "/containers/{name:.*}/unpause").Methods(http.MethodPost).Handler(s.filter(s.unpauseContainer))
r.Path(versionMatcher + "/containers/{name:.*}/update").Methods(http.MethodPost).Handler(s.filter(s.updateContainer))
r.Path(versionMatcher + "/containers/{name:.*}/upgrade").Methods(http.MethodPost).Handler(s.filter(s.upgradeContainer))
r.Path(versionMatcher + "/containers/{name:.*}/resize").Methods(http.MethodPost).Handler(s.filter(s.resizeContainer))

// image
r.Path(versionMatcher + "/images/create").Methods(http.MethodPost).Handler(s.filter(s.pullImage))
Expand Down
32 changes: 32 additions & 0 deletions apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,29 @@ paths:
required: true
tags: ["Exec"]

/containers/{id}/resize:
post:
summary: "changes the size of the tty for a container"
operationId: "ContainerResize"
parameters:
- $ref: "#/parameters/id"
- name: "height"
in: "query"
description: "height of the tty"
type: "string"
- name: "width"
in: "query"
description: "width of the tty"
type: "string"
responses:
200:
description: "no error"
404:
$ref: "#/responses/404ErrorResponse"
500:
$ref: "#/responses/500ErrorResponse"
tags: ["Container"]

/exec/{id}/start:
post:
summary: "Start an exec instance"
Expand Down Expand Up @@ -2447,6 +2470,15 @@ definitions:
additionalProperties:
type: "string"

ResizeOptions:
description: "options of resizing container tty size"
type: "object"
properties:
Height:
type: "integer"
Width:
type: "integer"

parameters:
id:
name: id
Expand Down
57 changes: 57 additions & 0 deletions apis/types/resize_options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions client/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"net"
"net/url"
"strconv"

"github.com/alibaba/pouch/apis/types"
)
Expand Down Expand Up @@ -184,5 +185,18 @@ func (client *APIClient) ContainerUpdate(ctx context.Context, name string, confi

// ContainerUpgrade upgrade a container with new image and args.
func (client *APIClient) ContainerUpgrade(ctx context.Context, name string, config types.ContainerConfig, hostConfig *types.HostConfig) error {
// TODO
return nil
}

// ContainerResize resizes the size of container tty.
func (client *APIClient) ContainerResize(ctx context.Context, name string, opts types.ResizeOptions) error {
query := url.Values{}
query.Set("h", strconv.Itoa(int(opts.Height)))
query.Set("w", strconv.Itoa(int(opts.Width)))

resp, err := client.post(ctx, "/containers/"+name+"/resize", query, nil, nil)
ensureCloseReader(resp)

return err
}
1 change: 1 addition & 0 deletions client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ContainerAPIClient interface {
ContainerUnpause(ctx context.Context, name string) error
ContainerUpdate(ctx context.Context, name string, config *types.UpdateConfig) error
ContainerUpgrade(ctx context.Context, name string, config types.ContainerConfig, hostConfig *types.HostConfig) error
ContainerResize(ctx context.Context, name string, options types.ResizeOptions) error
}

// ImageAPIClient defines methods of Image client.
Expand Down
9 changes: 9 additions & 0 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type ContainerMgr interface {

// Upgrade upgrades a container with new image and args.
Upgrade(ctx context.Context, name string, config *types.ContainerUpgradeConfig) error

// Resize resizes the size of container tty.
Resize(ctx context.Context, name string, opts types.ResizeOptions) error
}

// ContainerManager is the default implement of interface ContainerMgr.
Expand Down Expand Up @@ -801,6 +804,12 @@ func (mgr *ContainerManager) Upgrade(ctx context.Context, name string, config *t
return nil
}

// Resize resizes the size of a container tty.
func (mgr *ContainerManager) Resize(ctx context.Context, name string, opts types.ResizeOptions) error {
// TODO
return nil
}

func (mgr *ContainerManager) openContainerIO(id string, attach *AttachConfig) (*containerio.IO, error) {
return mgr.openIO(id, attach, false)
}
Expand Down
22 changes: 22 additions & 0 deletions test/api_container_resize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"github.com/alibaba/pouch/test/environment"

"github.com/go-check/check"
)

// APIContainerResizeSuite is the test suite for container upgrade API.
type APIContainerResizeSuite struct{}

func init() {
check.Suite(&APIContainerResizeSuite{})
}

// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerResizeSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)

}

// TODO add test case.

0 comments on commit af05c15

Please sign in to comment.