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:
26
vendor/github.com/vmware/vic/lib/portlayer/task/bind.go
generated
vendored
Normal file
26
vendor/github.com/vmware/vic/lib/portlayer/task/bind.go
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 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 task
|
||||
|
||||
import (
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
)
|
||||
|
||||
// Bind enables launching of the process in the container
|
||||
func Bind(op *trace.Operation, h interface{}, id string) (interface{}, error) {
|
||||
defer trace.End(trace.Begin(id))
|
||||
|
||||
return toggleActive(op, h, id, true)
|
||||
}
|
||||
78
vendor/github.com/vmware/vic/lib/portlayer/task/common.go
generated
vendored
Normal file
78
vendor/github.com/vmware/vic/lib/portlayer/task/common.go
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright 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 task
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
"github.com/vmware/vic/lib/migration/feature"
|
||||
"github.com/vmware/vic/lib/portlayer/exec"
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
)
|
||||
|
||||
// Toggle launching of the process in the container
|
||||
func toggleActive(op *trace.Operation, h interface{}, id string, active bool) (interface{}, error) {
|
||||
defer trace.End(trace.Begin(id))
|
||||
|
||||
handle, ok := h.(*exec.Handle)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Type assertion failed for %#+v", handle)
|
||||
}
|
||||
|
||||
stasks := handle.ExecConfig.Sessions
|
||||
etasks := handle.ExecConfig.Execs
|
||||
|
||||
taskS, okS := stasks[id]
|
||||
taskE, okE := etasks[id]
|
||||
|
||||
if !okS && !okE {
|
||||
return nil, fmt.Errorf("unknown task ID: %s", id)
|
||||
}
|
||||
|
||||
task := taskS
|
||||
if handle.Runtime != nil && handle.Runtime.PowerState != types.VirtualMachinePowerStatePoweredOff {
|
||||
op.Debugf("Task bind configuration applies to ephemeral set")
|
||||
task = taskE
|
||||
|
||||
if err := compatible(handle); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// if no task has been joined that can be manipulated in the container's current state
|
||||
if task == nil {
|
||||
return nil, fmt.Errorf("Cannot modify task %s in current state", id)
|
||||
}
|
||||
|
||||
op.Debugf("Toggling active state of task %s (%s): %t", id, task.Cmd.Path, active)
|
||||
|
||||
task.Active = active
|
||||
handle.Reload()
|
||||
|
||||
return handle, nil
|
||||
}
|
||||
|
||||
func compatible(h interface{}) error {
|
||||
if handle, ok := h.(*exec.Handle); ok {
|
||||
if handle.DataVersion < feature.TasksSupportedVersion {
|
||||
return fmt.Errorf("running tasks not supported for this container")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("Type assertion failed for %#+v", h)
|
||||
}
|
||||
76
vendor/github.com/vmware/vic/lib/portlayer/task/inspect.go
generated
vendored
Normal file
76
vendor/github.com/vmware/vic/lib/portlayer/task/inspect.go
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright 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 task
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
"github.com/vmware/vic/lib/config/executor"
|
||||
"github.com/vmware/vic/lib/portlayer/exec"
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
)
|
||||
|
||||
// Inspect the task configuration from the containerVM config
|
||||
func Inspect(op *trace.Operation, h interface{}, id string) (*executor.SessionConfig, error) {
|
||||
defer trace.End(trace.Begin(id))
|
||||
|
||||
handle, ok := h.(*exec.Handle)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Type assertion failed for %#+v", handle)
|
||||
}
|
||||
|
||||
stasks := handle.ExecConfig.Sessions
|
||||
etasks := handle.ExecConfig.Execs
|
||||
|
||||
_, okS := stasks[id]
|
||||
_, okE := etasks[id]
|
||||
|
||||
op.Debugf("target task ID: %s", id)
|
||||
op.Debugf("session tasks during inspect: %s", stasks)
|
||||
op.Debugf("exec tasks during inspect: %s", etasks)
|
||||
|
||||
if !okS && !okE {
|
||||
if handle.Runtime.PowerState == types.VirtualMachinePowerStatePoweredOff {
|
||||
powerStateError := TaskPowerStateError{
|
||||
msg: fmt.Sprintf("the operation cannot be completed, container(%s) has been shut down during the operations execution.", handle.ExecConfig.ID),
|
||||
}
|
||||
return nil, powerStateError
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unknown task ID: %s", id)
|
||||
}
|
||||
|
||||
tasks := stasks
|
||||
if handle.Runtime != nil && handle.Runtime.PowerState != types.VirtualMachinePowerStatePoweredOff {
|
||||
op.Debugf("Task configuration applies to ephemeral set")
|
||||
tasks = etasks
|
||||
}
|
||||
|
||||
if _, ok := tasks[id]; !ok {
|
||||
return nil, fmt.Errorf("Cannot find task %s", id)
|
||||
}
|
||||
|
||||
return tasks[id], nil
|
||||
}
|
||||
|
||||
// Special Error types for a task inspect
|
||||
type TaskPowerStateError struct {
|
||||
msg string
|
||||
}
|
||||
|
||||
func (e TaskPowerStateError) Error() string {
|
||||
return e.msg
|
||||
}
|
||||
65
vendor/github.com/vmware/vic/lib/portlayer/task/join.go
generated
vendored
Normal file
65
vendor/github.com/vmware/vic/lib/portlayer/task/join.go
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright 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 task
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
"github.com/vmware/vic/lib/config/executor"
|
||||
"github.com/vmware/vic/lib/portlayer/exec"
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
)
|
||||
|
||||
// Join adds the task configuration to the containerVM config
|
||||
func Join(op *trace.Operation, h interface{}, task *executor.SessionConfig) (interface{}, error) {
|
||||
defer trace.End(trace.Begin(task.ID))
|
||||
|
||||
handle, ok := h.(*exec.Handle)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Type assertion failed for %#+v", handle)
|
||||
}
|
||||
|
||||
// if the container isn't running then this is a persistent change
|
||||
var tasks map[string]*executor.SessionConfig
|
||||
if handle.Runtime == nil || handle.Runtime.PowerState == types.VirtualMachinePowerStatePoweredOff {
|
||||
if handle.ExecConfig.Sessions == nil {
|
||||
handle.ExecConfig.Sessions = make(map[string]*executor.SessionConfig)
|
||||
}
|
||||
tasks = handle.ExecConfig.Sessions
|
||||
task.Diagnostics.SysLogConfig = handle.ExecConfig.Diagnostics.SysLogConfig
|
||||
} else {
|
||||
op.Debugf("Task join configuration applies to ephemeral set")
|
||||
if handle.ExecConfig.Execs == nil {
|
||||
handle.ExecConfig.Execs = make(map[string]*executor.SessionConfig)
|
||||
}
|
||||
tasks = handle.ExecConfig.Execs
|
||||
|
||||
if err := compatible(h); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
_, ok = tasks[task.ID]
|
||||
if ok {
|
||||
return nil, fmt.Errorf("task ID collides: %s", task.ID)
|
||||
}
|
||||
|
||||
op.Debugf("Adding task (%s): %s", task.Cmd.Path, task.ID)
|
||||
|
||||
tasks[task.ID] = task
|
||||
|
||||
return handle, nil
|
||||
}
|
||||
63
vendor/github.com/vmware/vic/lib/portlayer/task/remove.go
generated
vendored
Normal file
63
vendor/github.com/vmware/vic/lib/portlayer/task/remove.go
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 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 task
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
"github.com/vmware/vic/lib/portlayer/exec"
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
)
|
||||
|
||||
// Remove the task configuration from the containerVM config
|
||||
func Remove(op *trace.Operation, h interface{}, id string) (interface{}, error) {
|
||||
defer trace.End(trace.Begin(id))
|
||||
|
||||
handle, ok := h.(*exec.Handle)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Type assertion failed for %#+v", handle)
|
||||
}
|
||||
|
||||
stasks := handle.ExecConfig.Sessions
|
||||
etasks := handle.ExecConfig.Execs
|
||||
|
||||
_, okS := stasks[id]
|
||||
_, okE := etasks[id]
|
||||
|
||||
if !okS && !okE {
|
||||
return nil, fmt.Errorf("unknown task ID: %s", id)
|
||||
}
|
||||
|
||||
tasks := stasks
|
||||
if handle.Runtime != nil && handle.Runtime.PowerState != types.VirtualMachinePowerStatePoweredOff {
|
||||
op.Debugf("Task configuration applies to ephemeral set")
|
||||
tasks = etasks
|
||||
|
||||
if err := compatible(h); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// if no task has been bound to the
|
||||
if _, ok := tasks[id]; !ok {
|
||||
return nil, fmt.Errorf("Cannot modify task %s in current state", id)
|
||||
}
|
||||
|
||||
delete(tasks, id)
|
||||
handle.Reload()
|
||||
|
||||
return handle, nil
|
||||
}
|
||||
26
vendor/github.com/vmware/vic/lib/portlayer/task/unbind.go
generated
vendored
Normal file
26
vendor/github.com/vmware/vic/lib/portlayer/task/unbind.go
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 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 task
|
||||
|
||||
import (
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
)
|
||||
|
||||
// Unbind disables launching of the process in the container
|
||||
func Unbind(op *trace.Operation, h interface{}, id string) (interface{}, error) {
|
||||
defer trace.End(trace.Begin(id))
|
||||
|
||||
return toggleActive(op, h, id, false)
|
||||
}
|
||||
61
vendor/github.com/vmware/vic/lib/portlayer/task/wait.go
generated
vendored
Normal file
61
vendor/github.com/vmware/vic/lib/portlayer/task/wait.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright 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 task
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
"github.com/vmware/vic/lib/constants"
|
||||
"github.com/vmware/vic/lib/portlayer/exec"
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
)
|
||||
|
||||
// Wait waits the task to start
|
||||
func Wait(op *trace.Operation, h interface{}, id string) error {
|
||||
defer trace.End(trace.Begin(id, op))
|
||||
|
||||
handle, ok := h.(*exec.Handle)
|
||||
if !ok {
|
||||
return fmt.Errorf("Type assertion failed for %#+v", handle)
|
||||
}
|
||||
|
||||
if handle.Runtime != nil && handle.Runtime.PowerState != types.VirtualMachinePowerStatePoweredOn {
|
||||
err := fmt.Errorf("Unable to wait for task when container %s is not running", id)
|
||||
op.Errorf("%s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
_, okS := handle.ExecConfig.Sessions[id]
|
||||
_, okE := handle.ExecConfig.Execs[id]
|
||||
|
||||
if !okS && !okE {
|
||||
return fmt.Errorf("Unknown task ID: %s", id)
|
||||
}
|
||||
|
||||
// wait task to set started field
|
||||
timeout, cancel := trace.WithTimeout(op, constants.PropertyCollectorTimeout, "Wait")
|
||||
defer cancel()
|
||||
|
||||
c := exec.Containers.Container(handle.ExecConfig.ID)
|
||||
if c == nil {
|
||||
return fmt.Errorf("Unknown container ID: %s", handle.ExecConfig.ID)
|
||||
}
|
||||
|
||||
if okS {
|
||||
return c.WaitForSession(timeout, id)
|
||||
}
|
||||
return c.WaitForExec(timeout, id)
|
||||
}
|
||||
Reference in New Issue
Block a user