Skip to content

Commit

Permalink
Merge pull request #905 from katiewasnothere/gcs_update_container
Browse files Browse the repository at this point in the history
Add support for issuing a container update to gcs
  • Loading branch information
katiewasnothere authored Dec 22, 2020
2 parents d3e5deb + 6e87c0c commit bf55dad
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/cow/cow.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ type Container interface {
// container to be terminated by some error condition (including calling
// Close).
Wait() error
// Modify sends a request to modify container resources
Modify(ctx context.Context, config interface{}) error
}
19 changes: 19 additions & 0 deletions internal/gcs/guestconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,25 @@ func (gc *GuestConnection) DeleteContainerState(ctx context.Context, cid string)
return gc.brdg.RPC(ctx, rpcDeleteContainerState, &req, &resp, false)
}

func (gc *GuestConnection) UpdateContainer(ctx context.Context, cid string, resources interface{}) (err error) {
ctx, span := trace.StartSpan(ctx, "gcs::GuestConnection::UpdateContainer")
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(trace.StringAttribute("cid", cid))

resourcesJSON, err := json.Marshal(resources)
if err != nil {
return err
}

req := updateContainerRequest{
requestBase: makeRequest(ctx, cid),
Resources: string(resourcesJSON),
}
var resp responseBase
return gc.brdg.RPC(ctx, rpcUpdateContainer, &req, &resp, false)
}

// Close terminates the guest connection. It is undefined to call any other
// methods on the connection after this is called.
func (gc *GuestConnection) Close() error {
Expand Down
8 changes: 8 additions & 0 deletions internal/gcs/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
rpcNegotiateProtocol
rpcDumpStacks
rpcDeleteContainerState
rpcUpdateContainer
rpcLifecycleNotification
)

Expand Down Expand Up @@ -118,6 +119,8 @@ func (typ msgType) String() string {
s += "DumpStacks"
case rpcDeleteContainerState:
s += "DeleteContainerState"
case rpcUpdateContainer:
s += "UpdateContainer"
case rpcLifecycleNotification:
s += "LifecycleNotification"
default:
Expand Down Expand Up @@ -358,3 +361,8 @@ type containerGetPropertiesResponseV2 struct {
responseBase
Properties containerPropertiesV2
}

type updateContainerRequest struct {
requestBase
Resources string
}
10 changes: 10 additions & 0 deletions internal/gcs/resourcepaths.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package gcs

const (
// silo container resources paths
siloDeviceResourcePath string = "Container/Devices/Generic"
siloMappedDirectoryResourcePath string = "Container/MappedDirectories"
siloMappedPipeResourcePath string = "Container/MappedPipes"
siloMemoryResourcePath string = "Container/Memory/SizeInMB"
siloRegistryFlushStatePath string = "Container/RegistryFlushState"
)
1 change: 1 addition & 0 deletions internal/schema1/schema1.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ type GuestDefinedCapabilities struct {
SignalProcessSupported bool `json:",omitempty"`
DumpStacksSupported bool `json:",omitempty"`
DeleteContainerStateSupported bool `json:",omitempty"`
UpdateContainerSupported bool `json:",omitempty"`
}

// GuestConnectionInfo is the structure of an iterm return by a GuestConnection call on a utility VM
Expand Down
12 changes: 12 additions & 0 deletions internal/uvm/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package uvm

import (
"context"
)

func (uvm *UtilityVM) UpdateContainer(ctx context.Context, cid string, resources interface{}) error {
if uvm.gc == nil || !uvm.guestCaps.UpdateContainerSupported {
return nil
}
return uvm.gc.UpdateContainer(ctx, cid, resources)
}

0 comments on commit bf55dad

Please sign in to comment.