* 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
78 lines
1.5 KiB
Go
78 lines
1.5 KiB
Go
package vic
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
"strings"
|
|
|
|
"github.com/vmware/vic/pkg/trace"
|
|
)
|
|
|
|
type VicConfig struct {
|
|
PersonaAddr string `yaml:"persona-server"`
|
|
PortlayerAddr string `yaml:"portlayer-server"`
|
|
HostUUID string `yaml:"host-uuid"`
|
|
}
|
|
|
|
const (
|
|
personaAddrEnv = "PERSONA_ADDR"
|
|
portlayerAddrEnv = "PORTLAYER_ADDR"
|
|
hostUUIDEnv = "HOST_UUID"
|
|
localVirtualKubelet = "LOCAL_VIRTUAL_KUBELET"
|
|
)
|
|
|
|
func LocalInstance() bool {
|
|
value := strings.ToLower(os.Getenv(localVirtualKubelet))
|
|
|
|
if value == "1" || value == "t" || value == "true" {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func NewVicConfig(op trace.Operation, configFile string) VicConfig {
|
|
var config VicConfig
|
|
|
|
if configFile == "" {
|
|
config.loadConfigFromEnv()
|
|
} else {
|
|
config.loadConfigFile(configFile)
|
|
}
|
|
|
|
return config
|
|
}
|
|
|
|
func (v *VicConfig) loadConfigFile(configFile string) error {
|
|
op := trace.NewOperation(context.Background(), "LoadConfigFile - %s", configFile)
|
|
defer trace.End(trace.Begin("", op))
|
|
|
|
contents, err := ioutil.ReadFile(configFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var config VicConfig
|
|
err = yaml.Unmarshal(contents, &config)
|
|
if err != nil {
|
|
err = fmt.Errorf("Unable to unmarshal vic virtual kubelet configfile: %s", err.Error())
|
|
op.Error(err)
|
|
return err
|
|
}
|
|
|
|
*v = config
|
|
|
|
return nil
|
|
}
|
|
|
|
func (v *VicConfig) loadConfigFromEnv() {
|
|
v.PersonaAddr = os.Getenv(personaAddrEnv)
|
|
v.PortlayerAddr = os.Getenv(portlayerAddrEnv)
|
|
v.HostUUID = os.Getenv(hostUUIDEnv)
|
|
}
|