Move VirtualMachine to vm package

parent 7ffff557
......@@ -51,14 +51,14 @@ func (c *CleanupCommand) CustomExecute(ctx *cli.Context) error {
c.logger.Info("Executing the command")
vmCfg, err := c.provider.Get(ctx.Ctx, c.vmName)
vm, err := c.provider.Get(ctx.Ctx, c.vmName)
if err != nil {
return fmt.Errorf("couldn't get the VM %q details: %w", c.vmName, err)
}
fmt.Println("Deleting job's virtual machine...")
err = c.provider.Delete(ctx.Ctx, vmCfg)
err = c.provider.Delete(ctx.Ctx, vm)
if err != nil {
return fmt.Errorf("couldn't delete the VM %q: %w", c.vmName, err)
}
......
......@@ -53,13 +53,13 @@ func (c *PrepareCommand) CustomExecute(ctx *cli.Context) error {
c.logger.Info("Executing the command")
vmCfg := config.VirtualMachine{
vm := vm.VirtualMachine{
Name: c.vmName,
}
fmt.Println("Creating virtual machine for the job...")
err = c.provider.Create(ctx.Ctx, c.executor, &vmCfg)
err = c.provider.Create(ctx.Ctx, c.executor, &vm)
if err != nil {
return fmt.Errorf("couldn't create the Virtual Machine %q: %w", c.vmName, err)
}
......
......@@ -68,7 +68,7 @@ func (c *RunCommand) CustomExecute(ctx *cli.Context) error {
args := ctx.Cli.Args()
scriptPath := args.Get(0)
vmCfg, err := c.provider.Get(ctx.Ctx, c.vmName)
vm, err := c.provider.Get(ctx.Ctx, c.vmName)
if err != nil {
return fmt.Errorf("couldn't get the VM %q details: %w", c.vmName, err)
}
......@@ -78,7 +78,7 @@ func (c *RunCommand) CustomExecute(ctx *cli.Context) error {
return fmt.Errorf("couldn't load the %q script: %w", scriptPath, err)
}
err = c.executor.Execute(ctx.Ctx, vmCfg, script)
err = c.executor.Execute(ctx.Ctx, vm, script)
if err != nil {
return fmt.Errorf("couldn't execute the script on the Virtual Machine %q: %w", c.vmName, err)
}
......
......@@ -6,12 +6,13 @@ import (
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/config"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/factories"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/logging"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/vm"
)
const factoryType = "executor"
type Executor interface {
Execute(ctx context.Context, vm config.VirtualMachine, script []byte) error
Execute(ctx context.Context, vm vm.VirtualMachine, script []byte) error
ProvisionScript() string
}
......
......@@ -18,6 +18,7 @@ import (
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/executors/winrm/config"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/logging"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/runner"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/vm"
)
const (
......@@ -70,7 +71,7 @@ func New(cfg globalConfig.Global, logger logging.Logger) (executors.Executor, er
return e, nil
}
func (e *Executor) Execute(ctx context.Context, vm globalConfig.VirtualMachine, script []byte) error {
func (e *Executor) Execute(ctx context.Context, vm vm.VirtualMachine, script []byte) error {
endpoint := winrm.NewEndpoint(
vm.IPAddress,
e.port,
......@@ -159,7 +160,7 @@ func (e *Executor) executionMaxRetries() int {
return defaultExecutionMaxRetries
}
func (e *Executor) checkWinRMServiceAvailability(logger logging.Logger, vm globalConfig.VirtualMachine, client Client) error {
func (e *Executor) checkWinRMServiceAvailability(logger logging.Logger, vm vm.VirtualMachine, client Client) error {
for i := 0; i < e.executionMaxRetries(); i++ {
log := logger.WithField("retry-count", i)
log.Info("Checking availability of WinRM service...")
......@@ -183,7 +184,7 @@ func (e *Executor) checkWinRMServiceAvailability(logger logging.Logger, vm globa
return errWinRMServiceUnavailable
}
func (e *Executor) runScript(client Client, vm globalConfig.VirtualMachine, script []byte, stdout io.Writer, stderr io.Writer) error {
func (e *Executor) runScript(client Client, vm vm.VirtualMachine, script []byte, stdout io.Writer, stderr io.Writer) error {
// Appending `exit` command at the end, to be 100% sure that the script
// will close the shell - which means it will finish the execution - after
// the last defined user command is finishedW
......
......@@ -20,11 +20,12 @@ import (
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/logging"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/logging/test"
mocks "gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/mocks/executors/winrm"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/vm"
)
var (
testConfig = config.Global{}
testVMConfig = config.VirtualMachine{}
testConfig = config.Global{}
testVM = vm.VirtualMachine{}
)
func mockNewClient(t *testing.T, mockedError error) (*mocks.Client, func()) {
......@@ -147,7 +148,7 @@ func TestExecutor_Execute(t *testing.T) {
assert.NoError(t, err)
assert.IsType(t, &Executor{}, e)
vm := config.VirtualMachine{
vm := vm.VirtualMachine{
IPAddress: "127.0.0.1",
}
......
......@@ -2,23 +2,23 @@
package mocks
import config "gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/config"
import context "context"
import mock "github.com/stretchr/testify/mock"
import vm "gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/vm"
// Executor is an autogenerated mock type for the Executor type
type Executor struct {
mock.Mock
}
// Execute provides a mock function with given fields: ctx, vm, script
func (_m *Executor) Execute(ctx context.Context, vm config.VirtualMachine, script []byte) error {
ret := _m.Called(ctx, vm, script)
// Execute provides a mock function with given fields: ctx, _a1, script
func (_m *Executor) Execute(ctx context.Context, _a1 vm.VirtualMachine, script []byte) error {
ret := _m.Called(ctx, _a1, script)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, config.VirtualMachine, []byte) error); ok {
r0 = rf(ctx, vm, script)
if rf, ok := ret.Get(0).(func(context.Context, vm.VirtualMachine, []byte) error); ok {
r0 = rf(ctx, _a1, script)
} else {
r0 = ret.Error(0)
}
......
......@@ -2,21 +2,22 @@
package mocks
import config "gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/config"
import mock "github.com/stretchr/testify/mock"
import vm "gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/vm"
// CacheStore is an autogenerated mock type for the CacheStore type
type CacheStore struct {
mock.Mock
}
// Delete provides a mock function with given fields: vm
func (_m *CacheStore) Delete(vm config.VirtualMachine) error {
ret := _m.Called(vm)
// Delete provides a mock function with given fields: _a0
func (_m *CacheStore) Delete(_a0 vm.VirtualMachine) error {
ret := _m.Called(_a0)
var r0 error
if rf, ok := ret.Get(0).(func(config.VirtualMachine) error); ok {
r0 = rf(vm)
if rf, ok := ret.Get(0).(func(vm.VirtualMachine) error); ok {
r0 = rf(_a0)
} else {
r0 = ret.Error(0)
}
......@@ -25,14 +26,14 @@ func (_m *CacheStore) Delete(vm config.VirtualMachine) error {
}
// Read provides a mock function with given fields: vmName
func (_m *CacheStore) Read(vmName string) (config.VirtualMachine, error) {
func (_m *CacheStore) Read(vmName string) (vm.VirtualMachine, error) {
ret := _m.Called(vmName)
var r0 config.VirtualMachine
if rf, ok := ret.Get(0).(func(string) config.VirtualMachine); ok {
var r0 vm.VirtualMachine
if rf, ok := ret.Get(0).(func(string) vm.VirtualMachine); ok {
r0 = rf(vmName)
} else {
r0 = ret.Get(0).(config.VirtualMachine)
r0 = ret.Get(0).(vm.VirtualMachine)
}
var r1 error
......@@ -45,13 +46,13 @@ func (_m *CacheStore) Read(vmName string) (config.VirtualMachine, error) {
return r0, r1
}
// Write provides a mock function with given fields: vm
func (_m *CacheStore) Write(vm config.VirtualMachine) error {
ret := _m.Called(vm)
// Write provides a mock function with given fields: _a0
func (_m *CacheStore) Write(_a0 vm.VirtualMachine) error {
ret := _m.Called(_a0)
var r0 error
if rf, ok := ret.Get(0).(func(config.VirtualMachine) error); ok {
r0 = rf(vm)
if rf, ok := ret.Get(0).(func(vm.VirtualMachine) error); ok {
r0 = rf(_a0)
} else {
r0 = ret.Error(0)
}
......
......@@ -2,23 +2,24 @@
package mocks
import config "gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/config"
import context "context"
import executors "gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/executors"
import mock "github.com/stretchr/testify/mock"
import vm "gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/vm"
// Provider is an autogenerated mock type for the Provider type
type Provider struct {
mock.Mock
}
// Create provides a mock function with given fields: ctx, e, vm
func (_m *Provider) Create(ctx context.Context, e executors.Executor, vm *config.VirtualMachine) error {
ret := _m.Called(ctx, e, vm)
// Create provides a mock function with given fields: ctx, e, _a2
func (_m *Provider) Create(ctx context.Context, e executors.Executor, _a2 *vm.VirtualMachine) error {
ret := _m.Called(ctx, e, _a2)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, executors.Executor, *config.VirtualMachine) error); ok {
r0 = rf(ctx, e, vm)
if rf, ok := ret.Get(0).(func(context.Context, executors.Executor, *vm.VirtualMachine) error); ok {
r0 = rf(ctx, e, _a2)
} else {
r0 = ret.Error(0)
}
......@@ -26,13 +27,13 @@ func (_m *Provider) Create(ctx context.Context, e executors.Executor, vm *config
return r0
}
// Delete provides a mock function with given fields: ctx, vm
func (_m *Provider) Delete(ctx context.Context, vm config.VirtualMachine) error {
ret := _m.Called(ctx, vm)
// Delete provides a mock function with given fields: ctx, _a1
func (_m *Provider) Delete(ctx context.Context, _a1 vm.VirtualMachine) error {
ret := _m.Called(ctx, _a1)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, config.VirtualMachine) error); ok {
r0 = rf(ctx, vm)
if rf, ok := ret.Get(0).(func(context.Context, vm.VirtualMachine) error); ok {
r0 = rf(ctx, _a1)
} else {
r0 = ret.Error(0)
}
......@@ -41,14 +42,14 @@ func (_m *Provider) Delete(ctx context.Context, vm config.VirtualMachine) error
}
// Get provides a mock function with given fields: ctx, name
func (_m *Provider) Get(ctx context.Context, name string) (config.VirtualMachine, error) {
func (_m *Provider) Get(ctx context.Context, name string) (vm.VirtualMachine, error) {
ret := _m.Called(ctx, name)
var r0 config.VirtualMachine
if rf, ok := ret.Get(0).(func(context.Context, string) config.VirtualMachine); ok {
var r0 vm.VirtualMachine
if rf, ok := ret.Get(0).(func(context.Context, string) vm.VirtualMachine); ok {
r0 = rf(ctx, name)
} else {
r0 = ret.Get(0).(config.VirtualMachine)
r0 = ret.Get(0).(vm.VirtualMachine)
}
var r1 error
......
......@@ -13,6 +13,7 @@ import (
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/encoding"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/fs"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/logging"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/vm"
)
const (
......@@ -20,9 +21,9 @@ const (
)
type CacheStore interface {
Read(vmName string) (config.VirtualMachine, error)
Write(vm config.VirtualMachine) error
Delete(vm config.VirtualMachine) error
Read(vmName string) (vm.VirtualMachine, error)
Write(vm vm.VirtualMachine) error
Delete(vm vm.VirtualMachine) error
}
type fsCacheStore struct {
......@@ -39,8 +40,8 @@ func newFSCacheStorage(directory string, f fs.FS, e encoding.Encoder) CacheStore
}
}
func (d *fsCacheStore) Read(vmName string) (config.VirtualMachine, error) {
var newVM config.VirtualMachine
func (d *fsCacheStore) Read(vmName string) (vm.VirtualMachine, error) {
var newVM vm.VirtualMachine
path := d.vmFilePath(vmName)
......@@ -70,7 +71,7 @@ func (d *fsCacheStore) vmFilePath(vmName string) string {
return filepath.Join(d.directory, fmt.Sprintf("%s.json", vmName))
}
func (d *fsCacheStore) Write(vm config.VirtualMachine) error {
func (d *fsCacheStore) Write(vm vm.VirtualMachine) error {
buf := new(bytes.Buffer)
err := d.encoder.Encode(vm, buf)
......@@ -81,7 +82,7 @@ func (d *fsCacheStore) Write(vm config.VirtualMachine) error {
return d.fs.WriteFile(d.vmFilePath(vm.Name), buf.Bytes(), cacheFileMode)
}
func (d *fsCacheStore) Delete(vm config.VirtualMachine) error {
func (d *fsCacheStore) Delete(vm vm.VirtualMachine) error {
return d.fs.Remove(d.vmFilePath(vm.Name))
}
......@@ -105,10 +106,10 @@ func newCacheProviderDecorator(cfg config.Global, logger logging.Logger, interna
}
}
func (c *cacheProviderDecorator) Get(ctx context.Context, vmName string) (config.VirtualMachine, error) {
vm, err := c.store.Read(vmName)
func (c *cacheProviderDecorator) Get(ctx context.Context, vmName string) (vm.VirtualMachine, error) {
vmInst, err := c.store.Read(vmName)
if err == nil {
return vm, nil
return vmInst, nil
}
log := c.logger.WithField("vm-name", vmName)
......@@ -121,21 +122,21 @@ func (c *cacheProviderDecorator) Get(ctx context.Context, vmName string) (config
writeReadLog("Error while trying to read cache of the VM metadata")
vm, err = c.internal.Get(ctx, vmName)
vmInst, err = c.internal.Get(ctx, vmName)
if err != nil {
return config.VirtualMachine{}, err
return vm.VirtualMachine{}, err
}
err = c.store.Write(vm)
err = c.store.Write(vmInst)
if err != nil {
log.WithError(err).
Error("Error while trying to write cache of the VM metadata")
}
return vm, nil
return vmInst, nil
}
func (c *cacheProviderDecorator) Create(ctx context.Context, e executors.Executor, vm *config.VirtualMachine) error {
func (c *cacheProviderDecorator) Create(ctx context.Context, e executors.Executor, vm *vm.VirtualMachine) error {
err := c.internal.Create(ctx, e, vm)
if err != nil {
return err
......@@ -152,7 +153,7 @@ func (c *cacheProviderDecorator) Create(ctx context.Context, e executors.Executo
return nil
}
func (c *cacheProviderDecorator) Delete(ctx context.Context, vm config.VirtualMachine) error {
func (c *cacheProviderDecorator) Delete(ctx context.Context, vm vm.VirtualMachine) error {
err := c.internal.Delete(ctx, vm)
if err != nil {
return err
......
This diff is collapsed.
......@@ -8,10 +8,10 @@ import (
"google.golang.org/api/compute/v1"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/config"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/backoff"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/logging"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/providers/gcp/windows"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/vm"
)
const (
......@@ -20,7 +20,7 @@ const (
windowsFinishedStartupScripts = "GCEMetadataScripts: Finished running startup scripts"
)
func (p *Provider) provisionWindows(ctx context.Context, logger logging.Logger, vm *config.VirtualMachine, instance *compute.Instance) error {
func (p *Provider) provisionWindows(ctx context.Context, logger logging.Logger, vm *vm.VirtualMachine, instance *compute.Instance) error {
log := logger.WithField("os", osWindows)
log.Info("Provisioning Windows OS...")
......@@ -44,7 +44,7 @@ func (p *Provider) provisionWindows(ctx context.Context, logger logging.Logger,
return nil
}
func (p *Provider) getWindowsPassword(ctx context.Context, logger logging.Logger, vm *config.VirtualMachine, instance *compute.Instance) (string, error) {
func (p *Provider) getWindowsPassword(ctx context.Context, logger logging.Logger, vm *vm.VirtualMachine, instance *compute.Instance) (string, error) {
logger.Info("Getting Windows password...")
instances, err := p.getInstancesService(ctx)
......@@ -93,7 +93,7 @@ func (p *Provider) getWindowsPassword(ctx context.Context, logger logging.Logger
return credentials.DecodeAndDecryptPassword()
}
func (p *Provider) setWindowsPasswordMetadata(ctx context.Context, logger logging.Logger, vm *config.VirtualMachine, instance *compute.Instance, credentials *windows.Credentials) error {
func (p *Provider) setWindowsPasswordMetadata(ctx context.Context, logger logging.Logger, vm *vm.VirtualMachine, instance *compute.Instance, credentials *windows.Credentials) error {
windowsKey, err := credentials.WindowsKey()
if err != nil {
return fmt.Errorf("couldn't encode Windows key info: %w", err)
......@@ -124,7 +124,7 @@ func (p *Provider) setWindowsPasswordMetadata(ctx context.Context, logger loggin
return p.updateMetadata(ctx, logger, *vm, metadata)
}
func (p *Provider) readEncryptedPasswordFromSerialConsole(ctx context.Context, instances *compute.InstancesService, vm *config.VirtualMachine, credentials *windows.Credentials) error {
func (p *Provider) readEncryptedPasswordFromSerialConsole(ctx context.Context, instances *compute.InstancesService, vm *vm.VirtualMachine, credentials *windows.Credentials) error {
o, err := instances.
GetSerialPortOutput(p.config.Project, p.config.Zone, vm.Name).
Port(serialConsolePassword).
......@@ -149,7 +149,7 @@ func (p *Provider) readEncryptedPasswordFromSerialConsole(ctx context.Context, i
return errors.New("password not found in Serial Console output")
}
func (p *Provider) waitForWindowsReadiness(ctx context.Context, logger logging.Logger, vm *config.VirtualMachine) error {
func (p *Provider) waitForWindowsReadiness(ctx context.Context, logger logging.Logger, vm *vm.VirtualMachine) error {
instances, err := p.getInstancesService(ctx)
if err != nil {
return err
......
......@@ -17,6 +17,7 @@ import (
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/logging"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/providers"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/providers/gcp/config"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/vm"
)
const (
......@@ -36,7 +37,7 @@ const (
serialConsoleReadiness = 1
)
type osProvisioner func(ctx context.Context, logger logging.Logger, vm *globalConfig.VirtualMachine, instance *compute.Instance) error
type osProvisioner func(ctx context.Context, logger logging.Logger, vm *vm.VirtualMachine, instance *compute.Instance) error
type Provider struct {
config config.Provider
......@@ -68,8 +69,8 @@ func New(cfg globalConfig.Global, logger logging.Logger) (providers.Provider, er
return p, nil
}
func (p *Provider) Get(ctx context.Context, name string) (globalConfig.VirtualMachine, error) {
vm := globalConfig.VirtualMachine{
func (p *Provider) Get(ctx context.Context, name string) (vm.VirtualMachine, error) {
vmInst := vm.VirtualMachine{
Name: name,
GCP: config.VirtualMachine{
Project: p.config.Project,
......@@ -77,19 +78,19 @@ func (p *Provider) Get(ctx context.Context, name string) (globalConfig.VirtualMa
},
}
instance, err := p.getVM(ctx, vm.Name)
instance, err := p.getVM(ctx, vmInst.Name)
if err != nil {
return globalConfig.VirtualMachine{}, fmt.Errorf("couldn't get the instance details: %w", err)
return vm.VirtualMachine{}, fmt.Errorf("couldn't get the instance details: %w", err)
}
vm.IPAddress = instance.NetworkInterfaces[0].NetworkIP
vmInst.IPAddress = instance.NetworkInterfaces[0].NetworkIP
err = p.loadCredentialsFromMetadata(ctx, &vm, instance)
err = p.loadCredentialsFromMetadata(ctx, &vmInst, instance)
if err != nil {
p.logger.WithError(err).Warn("couldn't load the credentials")
}
return vm, nil
return vmInst, nil
}
type metadataCredentials struct {
......@@ -97,7 +98,7 @@ type metadataCredentials struct {
Password string `json:"password"`
}
func (p *Provider) loadCredentialsFromMetadata(ctx context.Context, vm *globalConfig.VirtualMachine, instance *compute.Instance) error {
func (p *Provider) loadCredentialsFromMetadata(ctx context.Context, vm *vm.VirtualMachine, instance *compute.Instance) error {
for _, item := range instance.Metadata.Items {
if item.Key != vmCredentialsMetadataKey {
continue
......@@ -122,7 +123,7 @@ func (p *Provider) loadCredentialsFromMetadata(ctx context.Context, vm *globalCo
return errors.New("couldn't find credentials in the VM metadata")
}
func (p *Provider) Create(ctx context.Context, e executors.Executor, vm *globalConfig.VirtualMachine) error {
func (p *Provider) Create(ctx context.Context, e executors.Executor, vm *vm.VirtualMachine) error {
log := p.logger.WithField("vm-name", vm.Name)
log.Info("Creating Virtual Machine...")
......@@ -176,7 +177,7 @@ func (p *Provider) Create(ctx context.Context, e executors.Executor, vm *globalC
return nil
}
func (p *Provider) getInstanceSpecs(e executors.Executor, vm *globalConfig.VirtualMachine) (compute.Instance, error) {
func (p *Provider) getInstanceSpecs(e executors.Executor, vm *vm.VirtualMachine) (compute.Instance, error) {
provisionScript := e.ProvisionScript()
region, err := zoneToRegion(p.config.Zone)
......@@ -331,7 +332,7 @@ func (p *Provider) getVM(ctx context.Context, name string) (*compute.Instance, e
return s.Get(p.config.Project, p.config.Zone, name).Do()
}
func (p *Provider) saveCredentialsInMetadata(ctx context.Context, logger logging.Logger, vm globalConfig.VirtualMachine) error {
func (p *Provider) saveCredentialsInMetadata(ctx context.Context, logger logging.Logger, vm vm.VirtualMachine) error {
instance, err := p.getVM(ctx, vm.Name)
if err != nil {
return fmt.Errorf("couldn't get the instance details: %w", err)
......@@ -375,7 +376,7 @@ func (p *Provider) saveCredentialsInMetadata(ctx context.Context, logger logging
return p.updateMetadata(ctx, logger, vm, metadata)
}
func (p *Provider) updateMetadata(ctx context.Context, logger logging.Logger, vm globalConfig.VirtualMachine, metadata *compute.Metadata) error {
func (p *Provider) updateMetadata(ctx context.Context, logger logging.Logger, vm vm.VirtualMachine, metadata *compute.Metadata) error {
logger.Info("Updating Virtual Machine metadata...")
instances, err := p.getInstancesService(ctx)
......@@ -401,7 +402,7 @@ func (p *Provider) updateMetadata(ctx context.Context, logger logging.Logger, vm
return nil
}
func (p *Provider) Delete(ctx context.Context, vm globalConfig.VirtualMachine) error {
func (p *Provider) Delete(ctx context.Context, vm vm.VirtualMachine) error {
log := p.logger.WithField("vm-name", vm.Name)
log.Info("Deleting Virtual Machine...")
......
......@@ -8,14 +8,15 @@ import (
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/executors"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/factories"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/internal/logging"
"gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/vm"
)
const factoryType = "provider"
type Provider interface {
Get(ctx context.Context, name string) (config.VirtualMachine, error)
Create(ctx context.Context, e executors.Executor, vm *config.VirtualMachine) error
Delete(ctx context.Context, vm config.VirtualMachine) error
Get(ctx context.Context, name string) (vm.VirtualMachine, error)
Create(ctx context.Context, e executors.Executor, vm *vm.VirtualMachine) error
Delete(ctx context.Context, vm vm.VirtualMachine) error
}
type Factory func(cfg config.Global, logger logging.Logger) (Provider, error)
......
package config
package vm
import (
gcp "gitlab.com/gitlab-org/ci-cd/custom-executor-drivers/autoscaler/providers/gcp/config"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment