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:
Loc Nguyen
2018-06-04 15:41:32 -07:00
committed by Ria Bhatia
parent 98a111e8b7
commit 513cebe7b7
6296 changed files with 1123685 additions and 8 deletions

View File

@@ -0,0 +1,52 @@
// 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 flags
import (
"flag"
"strconv"
)
type optionalBool struct {
val **bool
}
func (b *optionalBool) Set(s string) error {
v, err := strconv.ParseBool(s)
*b.val = &v
return err
}
func (b *optionalBool) Get() interface{} {
if *b.val == nil {
return nil
}
return **b.val
}
func (b *optionalBool) String() string {
if b.val == nil || *b.val == nil {
return "<nil>"
}
return strconv.FormatBool(**b.val)
}
func (b *optionalBool) IsBoolFlag() bool { return true }
// NewOptionalString returns a flag.Value implementation where there is no default value.
// This avoids sending a default value over the wire as using flag.StringVar() would.
func NewOptionalBool(b **bool) flag.Value {
return &optionalBool{b}
}

View 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 flags
import (
"flag"
"testing"
)
func TestOptionalBool(t *testing.T) {
fs := flag.NewFlagSet("", flag.ContinueOnError)
var val *bool
fs.Var(NewOptionalBool(&val), "obool", "optional bool")
b := fs.Lookup("obool")
if b.DefValue != "<nil>" {
t.Fail()
}
if b.Value.String() != "<nil>" {
t.Fail()
}
if b.Value.(flag.Getter).Get() != nil {
t.Fail()
}
b.Value.Set("true")
if b.Value.String() != "true" {
t.Fail()
}
if b.Value.(flag.Getter).Get() != true {
t.Fail()
}
b.Value.Set("false")
if b.Value.String() != "false" {
t.Fail()
}
if b.Value.(flag.Getter).Get() != false {
t.Fail()
}
}

52
vendor/github.com/vmware/vic/pkg/flags/optional_int.go generated vendored Normal file
View File

@@ -0,0 +1,52 @@
// 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 flags
import (
"flag"
"strconv"
)
type optionalInt struct {
val **int
}
func (b *optionalInt) Set(s string) error {
v, err := strconv.Atoi(s)
*b.val = &v
return err
}
func (b *optionalInt) Get() interface{} {
if *b.val == nil {
return nil
}
return **b.val
}
func (b *optionalInt) String() string {
if b.val == nil || *b.val == nil {
return "<nil>"
}
return strconv.Itoa(**b.val)
}
func (b *optionalInt) IsBoolFlag() bool { return false }
// NewOptionalString returns a flag.Value implementation where there is no default value.
// This avoids sending a default value over the wire as using flag.StringVar() would.
func NewOptionalInt(i **int) flag.Value {
return &optionalInt{i}
}

View File

@@ -0,0 +1,51 @@
// 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 flags
import (
"flag"
"testing"
)
func TestOptionalInt(t *testing.T) {
fs := flag.NewFlagSet("", flag.ContinueOnError)
var val *int
fs.Var(NewOptionalInt(&val), "oint", "optional int")
b := fs.Lookup("oint")
if b.DefValue != "<nil>" {
t.Fail()
}
if b.Value.String() != "<nil>" {
t.Fail()
}
if b.Value.(flag.Getter).Get() != nil {
t.Fail()
}
b.Value.Set("1")
if b.Value.String() != "1" {
t.Fail()
}
if b.Value.(flag.Getter).Get() != 1 {
t.Fail()
}
}

View File

@@ -0,0 +1,50 @@
// Copyright 2016 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 flags
import (
"flag"
)
type optionalString struct {
val **string
}
func (b *optionalString) Set(s string) error {
*b.val = &s
return nil
}
func (b *optionalString) Get() interface{} {
if *b.val == nil {
return nil
}
return **b.val
}
func (b *optionalString) String() string {
if b.val == nil || *b.val == nil {
return "<nil>"
}
return **b.val
}
func (b *optionalString) IsBoolFlag() bool { return false }
// NewOptionalString returns a flag.Value implementation where there is no default value.
// This avoids sending a default value over the wire as using flag.StringVar() would.
func NewOptionalString(s **string) flag.Value {
return &optionalString{s}
}

View File

@@ -0,0 +1,51 @@
// Copyright 2016 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 flags
import (
"flag"
"testing"
)
func TestOptionalString(t *testing.T) {
fs := flag.NewFlagSet("", flag.ContinueOnError)
var val *string
fs.Var(NewOptionalString(&val), "obool", "optional bool")
b := fs.Lookup("obool")
if b.DefValue != "<nil>" {
t.Fail()
}
if b.Value.String() != "<nil>" {
t.Fail()
}
if b.Value.(flag.Getter).Get() != nil {
t.Fail()
}
b.Value.Set("test")
if b.Value.String() != "test" {
t.Fail()
}
if b.Value.(flag.Getter).Get() != "test" {
t.Fail()
}
}

64
vendor/github.com/vmware/vic/pkg/flags/shares_flag.go generated vendored Normal file
View File

@@ -0,0 +1,64 @@
// Copyright 2016 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 flags
import (
"fmt"
"strconv"
"strings"
"github.com/vmware/govmomi/vim25/types"
)
type ShareFlag struct {
shares **types.SharesInfo
}
func (s *ShareFlag) Set(val string) error {
if *s.shares == nil {
*s.shares = &types.SharesInfo{}
}
switch val = strings.ToLower(val); val {
case string(types.SharesLevelNormal), string(types.SharesLevelLow), string(types.SharesLevelHigh):
(*s.shares).Level = types.SharesLevel(val)
(*s.shares).Shares = 0
default:
n, err := strconv.Atoi(val)
if err != nil {
return err
}
(*s.shares).Level = types.SharesLevelCustom
(*s.shares).Shares = int32(n)
}
return nil
}
func (s *ShareFlag) String() string {
if s.shares == nil || *s.shares == nil {
return "<nil>"
}
switch (*s.shares).Level {
case types.SharesLevelCustom:
return fmt.Sprintf("%v", (*s.shares).Shares)
default:
return string((*s.shares).Level)
}
}
func NewSharesFlag(shares **types.SharesInfo) *ShareFlag {
return &ShareFlag{shares}
}

View File

@@ -0,0 +1,75 @@
// Copyright 2016 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 flags
import (
"flag"
"strings"
"testing"
"github.com/vmware/govmomi/vim25/types"
)
func TestShareFlag(t *testing.T) {
fs := flag.NewFlagSet("", flag.ContinueOnError)
var val *types.SharesInfo
fs.Var(NewSharesFlag(&val), "shares", "memory shares")
u := fs.Lookup("shares")
if u.DefValue != "<nil>" {
t.Errorf("DefValue: %s", u.DefValue)
}
if u.Value.String() != "<nil>" {
t.Errorf("Value: %s", u.Value)
}
ref := "2000"
u.Value.Set(ref)
if u.Value.String() != strings.ToLower(ref) {
t.Errorf("Value after set: %q", u.Value)
}
if val == nil {
t.Errorf("val is not set")
}
if val.Level != types.SharesLevelCustom {
t.Errorf("shares level is not set correctly: %s", val.Level)
}
if val.Shares != 2000 {
t.Errorf("shares Share is not set correctly: %d", val.Shares)
}
ref = "HIGH"
u.Value.Set(ref)
if u.Value.String() != strings.ToLower(ref) {
t.Errorf("Value after set: %q", u.Value)
}
if val == nil {
t.Errorf("val is not set")
}
if val.Level != types.SharesLevelHigh {
t.Errorf("shares level is not set correctly: %s", val.Level)
}
if val.Shares != 0 {
t.Errorf("shares Share is not set correctly: %d", val.Shares)
}
}

60
vendor/github.com/vmware/vic/pkg/flags/url_flag.go generated vendored Normal file
View File

@@ -0,0 +1,60 @@
// Copyright 2016 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 flags
import (
"flag"
"net/url"
"regexp"
)
var schemeMatch = regexp.MustCompile(`^\w+://`)
type URLFlag struct {
u **url.URL
}
// Set will add a protocol (https) if there isn't a :// match. This
// ensures tha url.Parse can correctly extract user:password from
// raw URLs such as user:password@hostname
func (f *URLFlag) Set(s string) error {
var err error
// Default the scheme to https
if !schemeMatch.MatchString(s) {
s = "https://" + s
}
url, err := url.Parse(s)
*f.u = url
return err
}
func (f *URLFlag) Get() interface{} {
return *f.u
}
func (f *URLFlag) String() string {
if f.u == nil || *f.u == nil {
return "<nil>"
}
return (*f.u).String()
}
func (f *URLFlag) IsBoolFlag() bool { return false }
// NewURLFlag returns a flag.Value.
func NewURLFlag(u **url.URL) flag.Value {
return &URLFlag{u}
}

View File

@@ -0,0 +1,60 @@
// Copyright 2016 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 flags
import (
"flag"
"net/url"
"testing"
)
func TestURLFlag(t *testing.T) {
fs := flag.NewFlagSet("", flag.ContinueOnError)
var val *url.URL
fs.Var(NewURLFlag(&val), "url", "url flag")
u := fs.Lookup("url")
if u.DefValue != "<nil>" {
t.Errorf("DefValue: %s", u.DefValue)
}
if u.Value.String() != "<nil>" {
t.Errorf("Value: %s", u.Value)
}
ref := "http://x:y@127.0.0.1"
u.Value.Set(ref)
if u.Value.String() != ref {
t.Errorf("Value after set: %s", u.Value)
}
if val == nil {
t.Errorf("val is not set")
}
if val.String() != ref {
t.Errorf("val is not set correctly: %s", val.String())
}
if val.User == nil {
t.Fatalf("Expected user info to be parsed from url")
}
if val.User.Username() != "x" {
t.Errorf("user was not extracted correctly")
}
}