Files
virtual-kubelet/providers/vic/operations/pod_starter.go
Loc Nguyen 513cebe7b7 VMware vSphere Integrated Containers provider (#206)
* Add Virtual Kubelet provider for VIC

Initial virtual kubelet provider for VMware VIC.  This provider currently
handles creating and starting of a pod VM via the VIC portlayer and persona
server.  Image store handling via the VIC persona server.  This provider
currently requires the feature/wolfpack branch of VIC.

* Added pod stop and delete.  Also added node capacity.

Added the ability to stop and delete pod VMs via VIC.  Also retrieve
node capacity information from the VCH.

* Cleanup and readme file

Some file clean up and added a Readme.md markdown file for the VIC
provider.

* Cleaned up errors, added function comments, moved operation code

1. Cleaned up error handling.  Set standard for creating errors.
2. Added method prototype comments for all interface functions.
3. Moved PodCreator, PodStarter, PodStopper, and PodDeleter to a new folder.

* Add mocking code and unit tests for podcache, podcreator, and podstarter

Used the unit test framework used in VIC to handle assertions in the provider's
unit test.  Mocking code generated using OSS project mockery, which is compatible
with the testify assertion framework.

* Vendored packages for the VIC provider

Requires feature/wolfpack branch of VIC and a few specific commit sha of
projects used within VIC.

* Implementation of POD Stopper and Deleter unit tests (#4)

* Updated files for initial PR
2018-06-04 15:41:32 -07:00

92 lines
2.2 KiB
Go

package operations
import (
"context"
"fmt"
"github.com/virtual-kubelet/virtual-kubelet/providers/vic/proxy"
"github.com/vmware/vic/lib/apiservers/portlayer/client"
"github.com/vmware/vic/pkg/trace"
)
type PodStarter interface {
Start(op trace.Operation, id, name string) error
}
type VicPodStarter struct {
client *client.PortLayer
isolationProxy proxy.IsolationProxy
imageStore proxy.ImageStore
}
type VicPodStarterError string
func (e VicPodStarterError) Error() string { return string(e) }
const (
PodStarterPortlayerClientError = VicPodStarterError("PodStarter called with an invalid portlayer client")
PodStarterIsolationProxyError = VicPodStarterError("PodStarter called with an invalid isolation proxy")
PodStarterInvalidPodIDError = VicPodStarterError("PodStarter called with invalid Pod ID")
PodStarterInvalidPodNameError = VicPodStarterError("PodStarter called with invalid Pod name")
)
func NewPodStarter(client *client.PortLayer, isolationProxy proxy.IsolationProxy) (PodStarter, error) {
defer trace.End(trace.Begin("", context.Background()))
if client == nil {
return nil, PodStarterPortlayerClientError
}
if isolationProxy == nil {
return nil, PodStarterIsolationProxyError
}
return &VicPodStarter{
client: client,
isolationProxy: isolationProxy,
}, nil
}
// Start starts up the pod vm
//
// arguments:
// op operation trace logger
// id pod id
// name pod name
// returns:
// error
func (v *VicPodStarter) Start(op trace.Operation, id, name string) error {
defer trace.End(trace.Begin(fmt.Sprintf("id(%s), name(%s)", id, name), op))
h, err := v.isolationProxy.Handle(op, id, name)
if err != nil {
return err
}
// Bind the container to the scope
h, ep, err := v.isolationProxy.BindScope(op, h, name)
if err != nil {
return err
}
op.Debugf("*** Scope bind returned endpoints %#v", ep)
defer func() {
if err != nil {
op.Debugf("Unbinding %s due to error - %s", id, err.Error())
v.isolationProxy.UnbindScope(op, h, name)
}
}()
h, err = v.isolationProxy.SetState(op, h, name, "RUNNING")
if err != nil {
return err
}
// map ports
err = v.isolationProxy.CommitHandle(op, h, id, -1)
return nil
}