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/migration/plugins/init.go
generated
vendored
Normal file
26
vendor/github.com/vmware/vic/lib/migration/plugins/init.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 plugins
|
||||
|
||||
// import all plugin packages here to register plugins
|
||||
import (
|
||||
// imported for the side effect
|
||||
_ "github.com/vmware/vic/lib/migration/plugins/plugin1"
|
||||
_ "github.com/vmware/vic/lib/migration/plugins/plugin2"
|
||||
_ "github.com/vmware/vic/lib/migration/plugins/plugin5"
|
||||
_ "github.com/vmware/vic/lib/migration/plugins/plugin7"
|
||||
_ "github.com/vmware/vic/lib/migration/plugins/plugin8"
|
||||
_ "github.com/vmware/vic/lib/migration/plugins/plugin9"
|
||||
)
|
||||
128
vendor/github.com/vmware/vic/lib/migration/plugins/plugin1/commonSpecForVCH.go
generated
vendored
Normal file
128
vendor/github.com/vmware/vic/lib/migration/plugins/plugin1/commonSpecForVCH.go
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
// 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 plugin1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
||||
"github.com/vmware/vic/lib/migration/errors"
|
||||
"github.com/vmware/vic/lib/migration/feature"
|
||||
"github.com/vmware/vic/lib/migration/manager"
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
"github.com/vmware/vic/pkg/vsphere/extraconfig"
|
||||
"github.com/vmware/vic/pkg/vsphere/session"
|
||||
)
|
||||
|
||||
const (
|
||||
target = manager.ApplianceConfigure
|
||||
)
|
||||
|
||||
func init() {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, feature.AddCommonSpecForVCHVersion)))
|
||||
if err := manager.Migrator.Register(feature.AddCommonSpecForVCHVersion, target, &AddCommonSpecForVCH{}); err != nil {
|
||||
log.Errorf("Failed to register plugin %s:%d, %s", target, feature.AddCommonSpecForVCHVersion, err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// AddCommonSpecForVCH is plugin for vic 0.8.0-GA version upgrade
|
||||
type AddCommonSpecForVCH struct {
|
||||
}
|
||||
|
||||
type VirtualContainerHostConfigSpec struct {
|
||||
ExecutorConfig `vic:"0.1" scope:"read-only" key:"init"`
|
||||
}
|
||||
|
||||
type ExecutorConfig struct {
|
||||
Common `vic:"0.1" scope:"read-only" key:"common"`
|
||||
}
|
||||
|
||||
type Common struct {
|
||||
// A reference to the components hosting execution environment, if any
|
||||
ExecutionEnvironment string
|
||||
|
||||
// Unambiguous ID with meaning in the context of its hosting execution environment
|
||||
ID string `vic:"0.1" scope:"read-only" key:"id"`
|
||||
|
||||
// Convenience field to record a human readable name
|
||||
Name string `vic:"0.1" scope:"read-only" key:"name"`
|
||||
|
||||
// Freeform notes related to the entity
|
||||
Notes string `vic:"0.1" scope:"hidden" key:"notes"`
|
||||
}
|
||||
|
||||
type UpdatedVCHConfigSpec struct {
|
||||
UpdatedExecutorConfig `vic:"0.1" scope:"read-only" key:"init"`
|
||||
}
|
||||
|
||||
type UpdatedExecutorConfig struct {
|
||||
UpdatedCommon `vic:"0.1" scope:"read-only" key:"common"`
|
||||
}
|
||||
|
||||
type UpdatedCommon struct {
|
||||
// A reference to the components hosting execution environment, if any
|
||||
ExecutionEnvironment string
|
||||
|
||||
// Unambiguous ID with meaning in the context of its hosting execution environment
|
||||
ID string `vic:"0.1" scope:"read-only" key:"id"`
|
||||
|
||||
// Convenience field to record a human readable name
|
||||
Name string `vic:"0.1" scope:"hidden" key:"name"`
|
||||
|
||||
// Freeform notes related to the entity
|
||||
Notes string `vic:"0.1" scope:"hidden" key:"notes"`
|
||||
}
|
||||
|
||||
func (p *AddCommonSpecForVCH) Migrate(ctx context.Context, s *session.Session, data interface{}) error {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("AddCommonSpecForVCH version: %d", feature.AddCommonSpecForVCHVersion)))
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
mapData, ok := data.(map[string]string)
|
||||
if !ok {
|
||||
// Log the error here and return nil so that other plugins can proceed
|
||||
log.Errorf("Migration data format is not map: %+v", data)
|
||||
return nil
|
||||
}
|
||||
oldStruct := &VirtualContainerHostConfigSpec{}
|
||||
result := extraconfig.Decode(extraconfig.MapSource(mapData), oldStruct)
|
||||
log.Debugf("The oldStruct is %+v", oldStruct)
|
||||
if result == nil {
|
||||
return &errors.DecodeError{Err: fmt.Errorf("decode oldStruct %+v failed", oldStruct)}
|
||||
}
|
||||
|
||||
newStruct := &UpdatedVCHConfigSpec{
|
||||
UpdatedExecutorConfig: UpdatedExecutorConfig{
|
||||
UpdatedCommon: UpdatedCommon{
|
||||
Name: oldStruct.Name,
|
||||
ID: oldStruct.ID,
|
||||
ExecutionEnvironment: oldStruct.ExecutionEnvironment,
|
||||
Notes: oldStruct.Notes,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cfg := make(map[string]string)
|
||||
extraconfig.Encode(extraconfig.MapSink(cfg), newStruct)
|
||||
|
||||
for k, v := range cfg {
|
||||
log.Debugf("New data: %s:%s", k, v)
|
||||
mapData[k] = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
117
vendor/github.com/vmware/vic/lib/migration/plugins/plugin2/commonSpecForContainer.go
generated
vendored
Normal file
117
vendor/github.com/vmware/vic/lib/migration/plugins/plugin2/commonSpecForContainer.go
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
// 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 plugin2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
||||
"github.com/vmware/vic/lib/migration/errors"
|
||||
"github.com/vmware/vic/lib/migration/feature"
|
||||
"github.com/vmware/vic/lib/migration/manager"
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
"github.com/vmware/vic/pkg/vsphere/extraconfig"
|
||||
"github.com/vmware/vic/pkg/vsphere/session"
|
||||
)
|
||||
|
||||
const (
|
||||
target = manager.ContainerConfigure
|
||||
)
|
||||
|
||||
func init() {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, feature.AddCommonSpecForContainerVersion)))
|
||||
if err := manager.Migrator.Register(feature.AddCommonSpecForContainerVersion, target, &AddCommonSpecForContainer{}); err != nil {
|
||||
log.Errorf("Failed to register plugin %s:%d, %s", target, feature.AddCommonSpecForContainerVersion, err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// AddCommonSpecForContainer is plugin for vic 0.8.0-GA version upgrade
|
||||
type AddCommonSpecForContainer struct {
|
||||
}
|
||||
|
||||
type ExecutorConfig struct {
|
||||
Common `vic:"0.1" scope:"read-only" key:"common"`
|
||||
}
|
||||
|
||||
type Common struct {
|
||||
// A reference to the components hosting execution environment, if any
|
||||
ExecutionEnvironment string
|
||||
|
||||
// Unambiguous ID with meaning in the context of its hosting execution environment
|
||||
ID string `vic:"0.1" scope:"read-only" key:"id"`
|
||||
|
||||
// Convenience field to record a human readable name
|
||||
Name string `vic:"0.1" scope:"read-only" key:"name"`
|
||||
|
||||
// Freeform notes related to the entity
|
||||
Notes string `vic:"0.1" scope:"hidden" key:"notes"`
|
||||
}
|
||||
|
||||
type UpdatedExecutorConfig struct {
|
||||
UpdatedCommon `vic:"0.1" scope:"read-only" key:"common"`
|
||||
}
|
||||
|
||||
type UpdatedCommon struct {
|
||||
// A reference to the components hosting execution environment, if any
|
||||
ExecutionEnvironment string
|
||||
|
||||
// Unambiguous ID with meaning in the context of its hosting execution environment
|
||||
ID string `vic:"0.1" scope:"read-only" key:"id"`
|
||||
|
||||
// Convenience field to record a human readable name
|
||||
Name string `vic:"0.1" scope:"hidden" key:"name"`
|
||||
|
||||
// Freeform notes related to the entity
|
||||
Notes string `vic:"0.1" scope:"hidden" key:"notes"`
|
||||
}
|
||||
|
||||
func (p *AddCommonSpecForContainer) Migrate(ctx context.Context, s *session.Session, data interface{}) error {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("AddCommonSpecForContainer version %d", feature.AddCommonSpecForContainerVersion)))
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
mapData, ok := data.(map[string]string)
|
||||
if !ok {
|
||||
// Log the error here and return nil so that other plugins can proceed
|
||||
log.Errorf("Migration data format is not map: %+v", data)
|
||||
return nil
|
||||
}
|
||||
oldStruct := &ExecutorConfig{}
|
||||
result := extraconfig.Decode(extraconfig.MapSource(mapData), oldStruct)
|
||||
log.Debugf("The oldStruct is %+v", oldStruct)
|
||||
if result == nil {
|
||||
return &errors.DecodeError{Err: fmt.Errorf("decode oldStruct %+v failed", oldStruct)}
|
||||
}
|
||||
|
||||
newStruct := &UpdatedExecutorConfig{
|
||||
UpdatedCommon: UpdatedCommon{
|
||||
Name: oldStruct.Name,
|
||||
ID: oldStruct.ID,
|
||||
Notes: oldStruct.Notes,
|
||||
ExecutionEnvironment: oldStruct.ExecutionEnvironment,
|
||||
}}
|
||||
|
||||
cfg := make(map[string]string)
|
||||
extraconfig.Encode(extraconfig.MapSink(cfg), newStruct)
|
||||
|
||||
for k, v := range cfg {
|
||||
log.Debugf("New data: %s:%s", k, v)
|
||||
mapData[k] = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
120
vendor/github.com/vmware/vic/lib/migration/plugins/plugin5/migrate_registry.go
generated
vendored
Normal file
120
vendor/github.com/vmware/vic/lib/migration/plugins/plugin5/migrate_registry.go
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
// 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 plugin5 Plugin to migrate urls from go1.7 to go1.8
|
||||
// Issue# https://github.com/vmware/vic/issues/4388
|
||||
package plugin5
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
||||
"github.com/vmware/vic/lib/migration/errors"
|
||||
"github.com/vmware/vic/lib/migration/feature"
|
||||
"github.com/vmware/vic/lib/migration/manager"
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
"github.com/vmware/vic/pkg/vsphere/extraconfig"
|
||||
"github.com/vmware/vic/pkg/vsphere/session"
|
||||
)
|
||||
|
||||
const (
|
||||
target = manager.ApplianceConfigure
|
||||
)
|
||||
|
||||
// VirtualContainerHostConfigSpec holds the metadata for a
|
||||
// Virtual Container Host that should be visible inside the appliance VM.
|
||||
type VirtualContainerHostConfigSpec struct {
|
||||
// Registry configuration for Imagec
|
||||
Registry `vic:"0.1" scope:"read-only" key:"registry"`
|
||||
}
|
||||
|
||||
// Registry defines the registries virtual container host can talk to
|
||||
type Registry struct {
|
||||
// Insecure registries
|
||||
InsecureRegistries []url.URL `vic:"0.1" scope:"read-only" key:"insecure_registries"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, feature.MigrateRegistryVersion)))
|
||||
if err := manager.Migrator.Register(feature.MigrateRegistryVersion, target, &MigrateRegistry{}); err != nil {
|
||||
log.Errorf("Failed to register plugin %s:%d, %s", target, feature.MigrateRegistryVersion, err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// MigrateRegistry is plugin for vic 0.9.0-GA version upgrade
|
||||
type MigrateRegistry struct {
|
||||
}
|
||||
|
||||
func (p *MigrateRegistry) Migrate(ctx context.Context, s *session.Session, data interface{}) error {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("MigrateRegistry version %d", feature.MigrateRegistryVersion)))
|
||||
if data == nil {
|
||||
log.Debugf("No data received plugin %s:%d", target, feature.MigrateRegistryVersion)
|
||||
return nil
|
||||
}
|
||||
|
||||
mapData, ok := data.(map[string]string)
|
||||
if !ok {
|
||||
// Log the error here and return nil so that other plugins can proceed
|
||||
log.Errorf("Migration data format is not map: %+v", data)
|
||||
return nil
|
||||
}
|
||||
|
||||
oldVCHSpec := &VirtualContainerHostConfigSpec{}
|
||||
|
||||
result := extraconfig.Decode(extraconfig.MapSource(mapData), oldVCHSpec)
|
||||
if result == nil {
|
||||
log.Errorf("Error decoding vchspec: %+v", oldVCHSpec)
|
||||
return &errors.DecodeError{}
|
||||
}
|
||||
|
||||
log.Debugf("The oldVCHSpec is %+v", oldVCHSpec)
|
||||
|
||||
newVCHSpec := &VirtualContainerHostConfigSpec{}
|
||||
|
||||
for _, registry := range oldVCHSpec.InsecureRegistries {
|
||||
log.Debugf("Checking insecure registry url: %v", registry.String())
|
||||
if registry.Host == "" {
|
||||
log.Debugf("Fixing insecure registry url: %v", registry.String())
|
||||
|
||||
// split host:port/path
|
||||
sp := strings.SplitN(registry.Path, "/", 2)
|
||||
|
||||
// Fix host from the first index of split
|
||||
registry.Host = sp[0]
|
||||
// if a path was present, in the second index of split
|
||||
if len(sp) > 1 {
|
||||
registry.Path = sp[1]
|
||||
} else {
|
||||
// else set path as empty
|
||||
registry.Path = ""
|
||||
}
|
||||
}
|
||||
newVCHSpec.InsecureRegistries = append(newVCHSpec.InsecureRegistries, registry)
|
||||
}
|
||||
|
||||
cfg := make(map[string]string)
|
||||
extraconfig.Encode(extraconfig.MapSink(cfg), newVCHSpec)
|
||||
|
||||
for k, v := range cfg {
|
||||
log.Debugf("New data: %s:%s", k, v)
|
||||
mapData[k] = v
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
65
vendor/github.com/vmware/vic/lib/migration/plugins/plugin5/migrate_registry_test.go
generated
vendored
Normal file
65
vendor/github.com/vmware/vic/lib/migration/plugins/plugin5/migrate_registry_test.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 plugin5
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/vmware/vic/pkg/vsphere/extraconfig"
|
||||
)
|
||||
|
||||
func TestMigrateRegistry(t *testing.T) {
|
||||
|
||||
inConfig := []url.URL{
|
||||
{Path: "1.1.1.1:5000"},
|
||||
{Path: "2.2.2.2"},
|
||||
{Host: "3.3.3.3:6000"},
|
||||
{Host: "3.3.3.3"},
|
||||
{Host: "vic.vmware.com"},
|
||||
{Path: "[1234:1234:0:1234::11]:7000"},
|
||||
{Host: "[1234:1234:0:1234::11]:7000"},
|
||||
{Path: "3.3.3.3/foo/bar"},
|
||||
}
|
||||
|
||||
outConfig := []url.URL{
|
||||
{Host: "1.1.1.1:5000"},
|
||||
{Host: "2.2.2.2"},
|
||||
{Host: "3.3.3.3:6000"},
|
||||
{Host: "3.3.3.3"},
|
||||
{Host: "vic.vmware.com"},
|
||||
{Host: "[1234:1234:0:1234::11]:7000"},
|
||||
{Host: "[1234:1234:0:1234::11]:7000"},
|
||||
{Host: "3.3.3.3", Path: "foo/bar"},
|
||||
}
|
||||
|
||||
m := MigrateRegistry{}
|
||||
|
||||
vch := VirtualContainerHostConfigSpec{
|
||||
Registry{
|
||||
InsecureRegistries: inConfig,
|
||||
}}
|
||||
|
||||
mapData := make(map[string]string)
|
||||
extraconfig.Encode(extraconfig.MapSink(mapData), vch)
|
||||
|
||||
err := m.Migrate(nil, nil, mapData)
|
||||
assert.NoError(t, err)
|
||||
|
||||
vchMigrated := extraconfig.Decode(extraconfig.MapSource(mapData), vch)
|
||||
assert.Equal(t, outConfig, vchMigrated.(VirtualContainerHostConfigSpec).InsecureRegistries)
|
||||
}
|
||||
111
vendor/github.com/vmware/vic/lib/migration/plugins/plugin7/vicadminProxyVarRename.go
generated
vendored
Normal file
111
vendor/github.com/vmware/vic/lib/migration/plugins/plugin7/vicadminProxyVarRename.go
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
// 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 plugin7
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
||||
"github.com/vmware/vic/lib/migration/errors"
|
||||
"github.com/vmware/vic/lib/migration/feature"
|
||||
"github.com/vmware/vic/lib/migration/manager"
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
"github.com/vmware/vic/pkg/vsphere/extraconfig"
|
||||
"github.com/vmware/vic/pkg/vsphere/session"
|
||||
)
|
||||
|
||||
// Translates the proxy environment variables from the old appliance to the new appliance for vic admin
|
||||
const (
|
||||
target = manager.ApplianceConfigure
|
||||
oldHProxy = "HTTP_PROXY"
|
||||
newHProxy = "VICADMIN_HTTP_PROXY"
|
||||
oldSProxy = "HTTPS_PROXY"
|
||||
newSProxy = "VICADMIN_HTTPS_PROXY"
|
||||
sessionName = "vicadmin"
|
||||
)
|
||||
|
||||
func init() {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, feature.VicadminProxyVarRenameVersion)))
|
||||
if err := manager.Migrator.Register(feature.VicadminProxyVarRenameVersion, target, &VicadminProxyVarRename{}); err != nil {
|
||||
log.Errorf("Failed to register plugin %s:%d, %s", target, feature.VicadminProxyVarRenameVersion, err)
|
||||
}
|
||||
}
|
||||
|
||||
// VicadminProxyVarRename is plugin for vic 0.8.0-GA version upgrade
|
||||
type VicadminProxyVarRename struct {
|
||||
}
|
||||
|
||||
type VCHConfig struct {
|
||||
ExecutorConfig `vic:"0.1" scope:"read-only" key:"init"`
|
||||
}
|
||||
|
||||
type ExecutorConfig struct {
|
||||
Sessions map[string]*SessionConfig `vic:"0.1" scope:"read-only" key:"sessions"`
|
||||
}
|
||||
|
||||
type SessionConfig struct {
|
||||
Cmd Cmd `vic:"0.1" scope:"read-only" key:"cmd"`
|
||||
}
|
||||
|
||||
type Cmd struct {
|
||||
Env []string `vic:"0.1" scope:"read-only" key:"Env"`
|
||||
}
|
||||
|
||||
func (p *VicadminProxyVarRename) Migrate(ctx context.Context, s *session.Session, data interface{}) error {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("%d", feature.VicadminProxyVarRenameVersion)))
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
mapData := data.(map[string]string)
|
||||
oldStruct := &VCHConfig{}
|
||||
result := extraconfig.Decode(extraconfig.MapSource(mapData), oldStruct)
|
||||
if result == nil {
|
||||
return &errors.DecodeError{}
|
||||
}
|
||||
|
||||
// translate old proxy env var keys into to proxy env var keys
|
||||
// skip upgrading if the proxy isn't defined or something is wrong with the the vicadmin executor
|
||||
if oldStruct.Sessions == nil || oldStruct.Sessions[sessionName] == nil || oldStruct.Sessions[sessionName].Cmd.Env == nil {
|
||||
log.Debugln("vicadmin session not found. skipping proxy rename")
|
||||
} else {
|
||||
var newEnvs []string
|
||||
for _, envVar := range oldStruct.Sessions[sessionName].Cmd.Env {
|
||||
envVarArgs := strings.Split(envVar, "=")
|
||||
envVarValue := ""
|
||||
if len(envVarArgs) > 1 {
|
||||
envVarValue = envVarArgs[1]
|
||||
}
|
||||
if strings.Contains(envVar, oldHProxy) {
|
||||
newEnvs = append(newEnvs, fmt.Sprintf("%s=%s", newHProxy, envVarValue))
|
||||
} else if strings.Contains(envVar, oldSProxy) {
|
||||
newEnvs = append(newEnvs, fmt.Sprintf("%s=%s", newSProxy, envVarValue))
|
||||
} else {
|
||||
newEnvs = append(newEnvs, envVar)
|
||||
}
|
||||
}
|
||||
oldStruct.Sessions[sessionName].Cmd.Env = newEnvs
|
||||
}
|
||||
|
||||
cfg := make(map[string]string)
|
||||
extraconfig.Encode(extraconfig.MapSink(cfg), oldStruct)
|
||||
for k, v := range cfg {
|
||||
log.Debugf("New data: %s:%s", k, v)
|
||||
mapData[k] = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
90
vendor/github.com/vmware/vic/lib/migration/plugins/plugin8/insecure_registries_type_change.go
generated
vendored
Normal file
90
vendor/github.com/vmware/vic/lib/migration/plugins/plugin8/insecure_registries_type_change.go
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
// 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 plugin8
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
||||
"github.com/vmware/vic/lib/migration/errors"
|
||||
"github.com/vmware/vic/lib/migration/feature"
|
||||
"github.com/vmware/vic/lib/migration/manager"
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
"github.com/vmware/vic/pkg/vsphere/extraconfig"
|
||||
"github.com/vmware/vic/pkg/vsphere/session"
|
||||
)
|
||||
|
||||
// Translates the proxy environment variables from the old appliance to the new appliance for vic admin
|
||||
const (
|
||||
target = manager.ApplianceConfigure
|
||||
)
|
||||
|
||||
func init() {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, feature.InsecureRegistriesTypeChangeVersion)))
|
||||
if err := manager.Migrator.Register(feature.InsecureRegistriesTypeChangeVersion, target, &InsecureRegistriesTypeChange{}); err != nil {
|
||||
log.Errorf("Failed to register plugin %s:%d, %s", target, feature.InsecureRegistriesTypeChangeVersion, err)
|
||||
}
|
||||
}
|
||||
|
||||
// InsecureRegistriesTypeChange
|
||||
type InsecureRegistriesTypeChange struct {
|
||||
}
|
||||
|
||||
type OldVCHConfig struct {
|
||||
OldRegistry `vic:"0.1" scope:"read-only" key:"registry"`
|
||||
}
|
||||
|
||||
type OldRegistry struct {
|
||||
InsecureRegistries []url.URL `vic:"0.1" scope:"read-only" key:"insecure_registries"`
|
||||
}
|
||||
|
||||
type VCHConfig struct {
|
||||
Registry `vic:"0.1" scope:"read-only" key:"registry"`
|
||||
}
|
||||
|
||||
type Registry struct {
|
||||
InsecureRegistries []string `vic:"0.1" scope:"read-only" key:"insecure_registries"`
|
||||
}
|
||||
|
||||
func (p *InsecureRegistriesTypeChange) Migrate(ctx context.Context, s *session.Session, data interface{}) error {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("%d", feature.InsecureRegistriesTypeChangeVersion)))
|
||||
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
mapData := data.(map[string]string)
|
||||
oldStruct := &OldVCHConfig{}
|
||||
result := extraconfig.Decode(extraconfig.MapSource(mapData), oldStruct)
|
||||
if result == nil {
|
||||
return &errors.DecodeError{}
|
||||
}
|
||||
|
||||
vchConfig := &VCHConfig{}
|
||||
for _, r := range oldStruct.InsecureRegistries {
|
||||
vchConfig.InsecureRegistries = append(vchConfig.InsecureRegistries, strings.TrimPrefix(r.String(), r.Scheme+"://"))
|
||||
}
|
||||
|
||||
cfg := make(map[string]string)
|
||||
extraconfig.Encode(extraconfig.MapSink(cfg), vchConfig)
|
||||
for k, v := range cfg {
|
||||
log.Debugf("New data: %s:%s", k, v)
|
||||
mapData[k] = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
81
vendor/github.com/vmware/vic/lib/migration/plugins/plugin9/container_create_timestamp.go
generated
vendored
Normal file
81
vendor/github.com/vmware/vic/lib/migration/plugins/plugin9/container_create_timestamp.go
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
// 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 plugin9
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
||||
"github.com/vmware/vic/lib/migration/errors"
|
||||
"github.com/vmware/vic/lib/migration/feature"
|
||||
"github.com/vmware/vic/lib/migration/manager"
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
"github.com/vmware/vic/pkg/vsphere/extraconfig"
|
||||
"github.com/vmware/vic/pkg/vsphere/session"
|
||||
)
|
||||
|
||||
const target = manager.ContainerConfigure
|
||||
|
||||
func init() {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("Registering plugin %s:%d", target, feature.ContainerCreateTimestampVersion)))
|
||||
if err := manager.Migrator.Register(feature.ContainerCreateTimestampVersion, target, &ContainerCreateTimestampVersion{}); err != nil {
|
||||
log.Errorf("Failed to register plugin %s:%d, %s", target, feature.ContainerCreateTimestampVersion, err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ContainerCreateTimestampVersion is a plugin to convert stored container create timestamps
|
||||
// in seconds to nanoseconds in the container configuration.
|
||||
type ContainerCreateTimestampVersion struct {
|
||||
}
|
||||
|
||||
// ExecutorConfig is used to update the container create time from seconds to nanoseconds.
|
||||
type ExecutorConfig struct {
|
||||
CreateTime int64 `vic:"0.1" scope:"read-write" key:"createtime"`
|
||||
}
|
||||
|
||||
// Migrate converts the stored container create timestamp (in seconds) to nanoseconds.
|
||||
func (c *ContainerCreateTimestampVersion) Migrate(ctx context.Context, s *session.Session, data interface{}) error {
|
||||
defer trace.End(trace.Begin(fmt.Sprintf("ContainerCreateTimestampVersion version %d", feature.ContainerCreateTimestampVersion)))
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
mapData, ok := data.(map[string]string)
|
||||
if !ok {
|
||||
// Log the error here and return nil so that other plugins can proceed.
|
||||
log.Errorf("Migration data format is not map: %+v", data)
|
||||
return nil
|
||||
}
|
||||
oldStruct := &ExecutorConfig{}
|
||||
result := extraconfig.Decode(extraconfig.MapSource(mapData), oldStruct)
|
||||
log.Debugf("The oldStruct is %+v", oldStruct)
|
||||
if result == nil {
|
||||
return &errors.DecodeError{Err: fmt.Errorf("decode oldStruct %+v failed", oldStruct)}
|
||||
}
|
||||
|
||||
// Convert create timestamp to nanoseconds for older containers that use seconds.
|
||||
oldStruct.CreateTime *= 1e9
|
||||
|
||||
cfg := make(map[string]string)
|
||||
extraconfig.Encode(extraconfig.MapSink(cfg), oldStruct)
|
||||
|
||||
for k, v := range cfg {
|
||||
log.Debugf("New data: %s:%s", k, v)
|
||||
mapData[k] = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
49
vendor/github.com/vmware/vic/lib/migration/plugins/plugin9/container_create_timestamp_test.go
generated
vendored
Normal file
49
vendor/github.com/vmware/vic/lib/migration/plugins/plugin9/container_create_timestamp_test.go
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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 plugin9
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/vmware/vic/lib/config/executor"
|
||||
"github.com/vmware/vic/pkg/vsphere/extraconfig"
|
||||
)
|
||||
|
||||
// TestMigrateContainerCreateTimestamp tests this package's ContainerCreateTimestampVersion.Migrate.
|
||||
func TestMigrateContainerCreateTimestamp(t *testing.T) {
|
||||
secSinceEpoch := int64(1510950922)
|
||||
oldCreateTime := secSinceEpoch
|
||||
newCreateTime := secSinceEpoch * 1e9
|
||||
layerID := "abcdefg"
|
||||
execConfig := executor.ExecutorConfig{
|
||||
CreateTime: oldCreateTime,
|
||||
// Supply an extra field that's not accessed in the plugin9 migrator to
|
||||
// ensure that unneeded fields aren't dropped from the returned data.
|
||||
LayerID: layerID,
|
||||
}
|
||||
|
||||
c := ContainerCreateTimestampVersion{}
|
||||
mapData := make(map[string]string)
|
||||
extraconfig.Encode(extraconfig.MapSink(mapData), execConfig)
|
||||
|
||||
err := c.Migrate(nil, nil, mapData)
|
||||
assert.NoError(t, err)
|
||||
|
||||
newConf := extraconfig.Decode(extraconfig.MapSource(mapData), execConfig)
|
||||
assert.Equal(t, newCreateTime, newConf.(executor.ExecutorConfig).CreateTime)
|
||||
assert.Equal(t, layerID, newConf.(executor.ExecutorConfig).LayerID)
|
||||
}
|
||||
45
vendor/github.com/vmware/vic/lib/migration/plugins/plugins.md
generated
vendored
Normal file
45
vendor/github.com/vmware/vic/lib/migration/plugins/plugins.md
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
# Developer guideline to write a data migration plugin
|
||||
|
||||
## Who and When to develop a data migration plugin
|
||||
|
||||
As [upgrade design](../../../doc/design/vic-machine/upgrade.md) mentioned, every developer who changed configuration from VCH appliance configuration, container vm configuration, or key/value store, whatever it is, they should add data migration plugin here.
|
||||
|
||||
## How to develop a data migration plugin
|
||||
|
||||
### VM guestinfo changes including VCH appliance and container VM
|
||||
|
||||
- Check if there is a file conflict with someone else's commit. If there is a conflict, that means there's another plugin being developed at the time - ensure that you do not use same plugin version number.
|
||||
- Create a new package in the _lib/migration/plugins_ directory for your new plugin, say _pluginX_.
|
||||
- Add a new constant for the plugin version in _lib/migration/feature/feature.go_.
|
||||
- Add plugin files to the new package.
|
||||
- Your plugin might rely on previous version and current version, if you need the whole VCH appliance or container configuration definition, copy them to package lib/migration/config, with correct new package created. For example, if you are working on migration from version 4 to version 5, create a package named v4 if there is no one existing, and copy all old configuration files to there, and create a new package v5, copy all new configuration files to v5 package. Remember to update package name.
|
||||
- If only a few attributes are touched, you could define that piece of attribute definition in your plugin package, without whole configuration files copied in the above step. Which can save binary size, and also configuration encodeing/decoding time.
|
||||
- Develop plugin based on your specific change, read the input data, decoding to acceptable format, and change value inside of them. stop_singal_rename_sample.go is one VCH appliance configuration change sample, you can follow that to write your own plugin.
|
||||
- Register your plugin to data migration framework, and put the function in package _pluginX_'s init() method.
|
||||
* Register appliance data migration plugin to manager.ApplianceConfigure category
|
||||
* Register container data migration plugin to manager.ContainerConfigure category
|
||||
* The two plugin targets are for different data, ensure that the type is selected correctly in registration.
|
||||
- *Important:* add import of your _pluginX_ package in init.go of the _plugin_ package to ensure that _pluginX_ is registered dynamically.
|
||||
|
||||
### key/value store changes
|
||||
|
||||
- Check if there is a file conflict with someone else's commit. If there is a conflict, that means there's another plugin being developed at the time - ensure that you do not use same plugin version number.
|
||||
- Create a new package in the _lib/migration/plugins_ directory for your new plugin, say _pluginX_.
|
||||
- Add a new constant for the plugin version in _lib/migration/feature/feature.go_.
|
||||
- Add your plugin files to the new package.
|
||||
- Develop plugin based on your specific change.
|
||||
* Create new key/value store file in datastore, instead of change in existing file. The new file for new version, e.g. v4, could use file name as XXX.v4, to differentiate with old version's file.
|
||||
* Copy all existing key/values to the new file, and update to the new file directly.
|
||||
* Write to new datastore file only, because old file is still correct if migration failed eventually.
|
||||
- Register your plugin to data migration framework, and put the function in package _pluginX_'s init() method.
|
||||
* Register key/value store data migration plugin to manager.ApplianceConfigure category.
|
||||
- *Important:* add import of your _pluginX_ package in init.go of the _plugin_ package to ensure that _pluginX_ is registered dynamically.
|
||||
|
||||
Note:
|
||||
- Plugin version should be greater than 0
|
||||
- If you changed both key/value store and VCH appliance configuration, please add two separate plugins for them. Eventually, data migration framework will execute both of them, but separation will make the code easy to read.
|
||||
- While copy configuration files, remove unnecessary methods from that file, to reduce binary file size
|
||||
|
||||
## Add integration test
|
||||
|
||||
Be sure to add test scenario into upgrade test group, to cover your changes, to make sure after upgrade, your function works well
|
||||
Reference in New Issue
Block a user