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
This commit is contained in:
76
vendor/github.com/vmware/govmomi/event/history_collector.go
generated
vendored
Normal file
76
vendor/github.com/vmware/govmomi/event/history_collector.go
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package event
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type HistoryCollector struct {
|
||||
*object.HistoryCollector
|
||||
}
|
||||
|
||||
func NewHistoryCollector(c *vim25.Client, ref types.ManagedObjectReference) *HistoryCollector {
|
||||
return &HistoryCollector{
|
||||
HistoryCollector: object.NewHistoryCollector(c, ref),
|
||||
}
|
||||
}
|
||||
|
||||
func (h HistoryCollector) LatestPage(ctx context.Context) ([]types.BaseEvent, error) {
|
||||
var o mo.EventHistoryCollector
|
||||
|
||||
err := h.Properties(ctx, h.Reference(), []string{"latestPage"}, &o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return o.LatestPage, nil
|
||||
}
|
||||
|
||||
func (h HistoryCollector) ReadNextEvents(ctx context.Context, maxCount int32) ([]types.BaseEvent, error) {
|
||||
req := types.ReadNextEvents{
|
||||
This: h.Reference(),
|
||||
MaxCount: maxCount,
|
||||
}
|
||||
|
||||
res, err := methods.ReadNextEvents(ctx, h.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res.Returnval, nil
|
||||
}
|
||||
|
||||
func (h HistoryCollector) ReadPreviousEvents(ctx context.Context, maxCount int32) ([]types.BaseEvent, error) {
|
||||
req := types.ReadPreviousEvents{
|
||||
This: h.Reference(),
|
||||
MaxCount: maxCount,
|
||||
}
|
||||
|
||||
res, err := methods.ReadPreviousEvents(ctx, h.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res.Returnval, nil
|
||||
}
|
||||
186
vendor/github.com/vmware/govmomi/event/manager.go
generated
vendored
Normal file
186
vendor/github.com/vmware/govmomi/event/manager.go
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package event
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
object.Common
|
||||
|
||||
eventCategory map[string]string
|
||||
eventCategoryMu *sync.Mutex
|
||||
maxObjects int
|
||||
}
|
||||
|
||||
func NewManager(c *vim25.Client) *Manager {
|
||||
m := Manager{
|
||||
Common: object.NewCommon(c, *c.ServiceContent.EventManager),
|
||||
|
||||
eventCategory: make(map[string]string),
|
||||
eventCategoryMu: new(sync.Mutex),
|
||||
maxObjects: 10,
|
||||
}
|
||||
|
||||
return &m
|
||||
}
|
||||
|
||||
func (m Manager) CreateCollectorForEvents(ctx context.Context, filter types.EventFilterSpec) (*HistoryCollector, error) {
|
||||
req := types.CreateCollectorForEvents{
|
||||
This: m.Common.Reference(),
|
||||
Filter: filter,
|
||||
}
|
||||
|
||||
res, err := methods.CreateCollectorForEvents(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewHistoryCollector(m.Client(), res.Returnval), nil
|
||||
}
|
||||
|
||||
func (m Manager) LogUserEvent(ctx context.Context, entity types.ManagedObjectReference, msg string) error {
|
||||
req := types.LogUserEvent{
|
||||
This: m.Common.Reference(),
|
||||
Entity: entity,
|
||||
Msg: msg,
|
||||
}
|
||||
|
||||
_, err := methods.LogUserEvent(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m Manager) PostEvent(ctx context.Context, eventToPost types.BaseEvent, taskInfo types.TaskInfo) error {
|
||||
req := types.PostEvent{
|
||||
This: m.Common.Reference(),
|
||||
EventToPost: eventToPost,
|
||||
TaskInfo: &taskInfo,
|
||||
}
|
||||
|
||||
_, err := methods.PostEvent(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m Manager) QueryEvents(ctx context.Context, filter types.EventFilterSpec) ([]types.BaseEvent, error) {
|
||||
req := types.QueryEvents{
|
||||
This: m.Common.Reference(),
|
||||
Filter: filter,
|
||||
}
|
||||
|
||||
res, err := methods.QueryEvents(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res.Returnval, nil
|
||||
}
|
||||
|
||||
func (m Manager) RetrieveArgumentDescription(ctx context.Context, eventTypeID string) ([]types.EventArgDesc, error) {
|
||||
req := types.RetrieveArgumentDescription{
|
||||
This: m.Common.Reference(),
|
||||
EventTypeId: eventTypeID,
|
||||
}
|
||||
|
||||
res, err := methods.RetrieveArgumentDescription(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res.Returnval, nil
|
||||
}
|
||||
|
||||
func (m Manager) eventCategoryMap(ctx context.Context) (map[string]string, error) {
|
||||
m.eventCategoryMu.Lock()
|
||||
defer m.eventCategoryMu.Unlock()
|
||||
|
||||
if len(m.eventCategory) != 0 {
|
||||
return m.eventCategory, nil
|
||||
}
|
||||
|
||||
var o mo.EventManager
|
||||
|
||||
ps := []string{"description.eventInfo"}
|
||||
err := property.DefaultCollector(m.Client()).RetrieveOne(ctx, m.Common.Reference(), ps, &o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, info := range o.Description.EventInfo {
|
||||
m.eventCategory[info.Key] = info.Category
|
||||
}
|
||||
|
||||
return m.eventCategory, nil
|
||||
}
|
||||
|
||||
// EventCategory returns the category for an event, such as "info" or "error" for example.
|
||||
func (m Manager) EventCategory(ctx context.Context, event types.BaseEvent) (string, error) {
|
||||
// Most of the event details are included in the Event.FullFormattedMessage, but the category
|
||||
// is only available via the EventManager description.eventInfo property. The value of this
|
||||
// property is static, so we fetch and once and cache.
|
||||
eventCategory, err := m.eventCategoryMap(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
switch e := event.(type) {
|
||||
case *types.EventEx:
|
||||
if e.Severity == "" {
|
||||
return "info", nil
|
||||
}
|
||||
return e.Severity, nil
|
||||
}
|
||||
|
||||
class := reflect.TypeOf(event).Elem().Name()
|
||||
|
||||
return eventCategory[class], nil
|
||||
}
|
||||
|
||||
// Get the events from the specified object(s) and optionanlly tail the event stream
|
||||
func (m Manager) Events(ctx context.Context, objects []types.ManagedObjectReference, pageSize int32, tail bool, force bool, f func(types.ManagedObjectReference, []types.BaseEvent) error, kind ...string) error {
|
||||
// TODO: deprecated this method and add one that uses a single config struct, so we can extend further without breaking the method signature.
|
||||
if len(objects) >= m.maxObjects && !force {
|
||||
return fmt.Errorf("Maximum number of objects to monitor (%d) exceeded, refine search", m.maxObjects)
|
||||
}
|
||||
|
||||
proc := newEventProcessor(m, pageSize, f, kind)
|
||||
for _, o := range objects {
|
||||
proc.addObject(ctx, o)
|
||||
}
|
||||
|
||||
defer proc.destroy()
|
||||
|
||||
return proc.run(ctx, tail)
|
||||
}
|
||||
192
vendor/github.com/vmware/govmomi/event/processor.go
generated
vendored
Normal file
192
vendor/github.com/vmware/govmomi/event/processor.go
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
Copyright (c) 2016-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package event
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type tailInfo struct {
|
||||
t *eventTailer
|
||||
obj types.ManagedObjectReference
|
||||
collector *HistoryCollector
|
||||
}
|
||||
|
||||
type eventProcessor struct {
|
||||
mgr Manager
|
||||
pageSize int32
|
||||
kind []string
|
||||
tailers map[types.ManagedObjectReference]*tailInfo // tailers by collector ref
|
||||
callback func(types.ManagedObjectReference, []types.BaseEvent) error
|
||||
}
|
||||
|
||||
func newEventProcessor(mgr Manager, pageSize int32, callback func(types.ManagedObjectReference, []types.BaseEvent) error, kind []string) *eventProcessor {
|
||||
return &eventProcessor{
|
||||
mgr: mgr,
|
||||
tailers: make(map[types.ManagedObjectReference]*tailInfo),
|
||||
callback: callback,
|
||||
pageSize: pageSize,
|
||||
kind: kind,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *eventProcessor) addObject(ctx context.Context, obj types.ManagedObjectReference) error {
|
||||
filter := types.EventFilterSpec{
|
||||
Entity: &types.EventFilterSpecByEntity{
|
||||
Entity: obj,
|
||||
Recursion: types.EventFilterSpecRecursionOptionAll,
|
||||
},
|
||||
EventTypeId: p.kind,
|
||||
}
|
||||
|
||||
collector, err := p.mgr.CreateCollectorForEvents(ctx, filter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("[%#v] %s", obj, err)
|
||||
}
|
||||
|
||||
err = collector.SetPageSize(ctx, p.pageSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.tailers[collector.Reference()] = &tailInfo{
|
||||
t: newEventTailer(),
|
||||
obj: obj,
|
||||
collector: collector,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *eventProcessor) destroy() {
|
||||
for _, info := range p.tailers {
|
||||
_ = info.collector.Destroy(context.Background())
|
||||
}
|
||||
}
|
||||
|
||||
func (p *eventProcessor) run(ctx context.Context, tail bool) error {
|
||||
if len(p.tailers) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var collectors []types.ManagedObjectReference
|
||||
for ref := range p.tailers {
|
||||
collectors = append(collectors, ref)
|
||||
}
|
||||
|
||||
c := property.DefaultCollector(p.mgr.Client())
|
||||
props := []string{"latestPage"}
|
||||
|
||||
if len(collectors) == 1 {
|
||||
// only one object to follow, don't bother creating a view
|
||||
return property.Wait(ctx, c, collectors[0], props, func(pc []types.PropertyChange) bool {
|
||||
if err := p.process(collectors[0], pc); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return !tail
|
||||
})
|
||||
}
|
||||
|
||||
// create and populate a ListView
|
||||
m := view.NewManager(p.mgr.Client())
|
||||
|
||||
list, err := m.CreateListView(ctx, collectors)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer list.Destroy(context.Background())
|
||||
|
||||
ref := list.Reference()
|
||||
filter := new(property.WaitFilter).Add(ref, collectors[0].Type, props, list.TraversalSpec())
|
||||
|
||||
return property.WaitForUpdates(ctx, c, filter, func(updates []types.ObjectUpdate) bool {
|
||||
for _, update := range updates {
|
||||
if err := p.process(update.Obj, update.ChangeSet); err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return !tail
|
||||
})
|
||||
}
|
||||
|
||||
func (p *eventProcessor) process(c types.ManagedObjectReference, pc []types.PropertyChange) error {
|
||||
t := p.tailers[c]
|
||||
if t == nil {
|
||||
return fmt.Errorf("unknown collector %s", c.String())
|
||||
}
|
||||
|
||||
for _, u := range pc {
|
||||
evs := t.t.newEvents(u.Val.(types.ArrayOfEvent).Event)
|
||||
if len(evs) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := p.callback(t.obj, evs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
const invalidKey = int32(-1)
|
||||
|
||||
type eventTailer struct {
|
||||
lastKey int32
|
||||
}
|
||||
|
||||
func newEventTailer() *eventTailer {
|
||||
return &eventTailer{
|
||||
lastKey: invalidKey,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *eventTailer) newEvents(evs []types.BaseEvent) []types.BaseEvent {
|
||||
var ret []types.BaseEvent
|
||||
if t.lastKey == invalidKey {
|
||||
ret = evs
|
||||
} else {
|
||||
found := false
|
||||
for i := range evs {
|
||||
if evs[i].GetEvent().Key != t.lastKey {
|
||||
continue
|
||||
}
|
||||
|
||||
found = true
|
||||
ret = evs[:i]
|
||||
break
|
||||
}
|
||||
|
||||
if !found {
|
||||
ret = evs
|
||||
}
|
||||
}
|
||||
|
||||
if len(ret) > 0 {
|
||||
t.lastKey = ret[0].GetEvent().Key
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
45
vendor/github.com/vmware/govmomi/event/sort.go
generated
vendored
Normal file
45
vendor/github.com/vmware/govmomi/event/sort.go
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package event
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
// Sort events in ascending order base on Key
|
||||
// From the EventHistoryCollector.latestPage sdk docs:
|
||||
// The "oldest event" is the one with the smallest key (event ID).
|
||||
// The events in the returned page are unordered.
|
||||
func Sort(events []types.BaseEvent) {
|
||||
sort.Sort(baseEvent(events))
|
||||
}
|
||||
|
||||
type baseEvent []types.BaseEvent
|
||||
|
||||
func (d baseEvent) Len() int {
|
||||
return len(d)
|
||||
}
|
||||
|
||||
func (d baseEvent) Less(i, j int) bool {
|
||||
return d[i].GetEvent().Key < d[j].GetEvent().Key
|
||||
}
|
||||
|
||||
func (d baseEvent) Swap(i, j int) {
|
||||
d[i], d[j] = d[j], d[i]
|
||||
}
|
||||
Reference in New Issue
Block a user