mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
vSphere provider - Adding config for working dir
This allows the user the set "working-dir" in their vsphere.cfg file. The value should be a path in the vSphere datastore in which the provider will look for vms.
This commit is contained in:
parent
653bce30ee
commit
49436012ba
@ -22,6 +22,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi"
|
||||
@ -71,6 +72,7 @@ type VSphereConfig struct {
|
||||
InsecureFlag bool `gcfg:"insecure-flag"`
|
||||
Datacenter string `gcfg:"datacenter"`
|
||||
Datastore string `gcfg:"datastore"`
|
||||
WorkingDir string `gcfg:"working-dir"`
|
||||
}
|
||||
|
||||
Network struct {
|
||||
@ -171,6 +173,9 @@ func newVSphere(cfg VSphereConfig) (*VSphere, error) {
|
||||
glog.Errorf("%v is not a supported SCSI Controller type. Please configure 'lsilogic-sas' OR 'pvscsi'", cfg.Disk.SCSIControllerType)
|
||||
return nil, errors.New("Controller type not supported. Please configure 'lsilogic-sas' OR 'pvscsi'")
|
||||
}
|
||||
if cfg.Global.WorkingDir != "" {
|
||||
cfg.Global.WorkingDir = path.Clean(cfg.Global.WorkingDir) + "/"
|
||||
}
|
||||
vs := VSphere{
|
||||
cfg: &cfg,
|
||||
localInstanceID: id,
|
||||
@ -217,9 +222,11 @@ func getVirtualMachineByName(cfg *VSphereConfig, ctx context.Context, c *govmomi
|
||||
}
|
||||
f.SetDatacenter(dc)
|
||||
|
||||
vmRegex := cfg.Global.WorkingDir + name
|
||||
|
||||
// Retrieve vm by name
|
||||
//TODO: also look for vm inside subfolders
|
||||
vm, err := f.VirtualMachine(ctx, name)
|
||||
vm, err := f.VirtualMachine(ctx, vmRegex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -247,8 +254,10 @@ func getInstances(cfg *VSphereConfig, ctx context.Context, c *govmomi.Client, fi
|
||||
|
||||
f.SetDatacenter(dc)
|
||||
|
||||
vmRegex := cfg.Global.WorkingDir + filter
|
||||
|
||||
//TODO: get all vms inside subfolders
|
||||
vms, err := f.VirtualMachineList(ctx, filter)
|
||||
vms, err := f.VirtualMachineList(ctx, vmRegex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -492,7 +501,9 @@ func getVirtualMachineDevices(cfg *VSphereConfig, ctx context.Context, c *govmom
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
vm, err := f.VirtualMachine(ctx, name)
|
||||
vmRegex := cfg.Global.WorkingDir + name
|
||||
|
||||
vm, err := f.VirtualMachine(ctx, vmRegex)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ func configFromEnv() (cfg VSphereConfig, ok bool) {
|
||||
cfg.Network.PublicNetwork = os.Getenv("VSPHERE_PUBLIC_NETWORK")
|
||||
cfg.Global.Datastore = os.Getenv("VSPHERE_DATASTORE")
|
||||
cfg.Disk.SCSIControllerType = os.Getenv("VSPHERE_SCSICONTROLLER_TYPE")
|
||||
cfg.Global.WorkingDir = os.Getenv("VSPHERE_WORKING_DIR")
|
||||
if os.Getenv("VSPHERE_INSECURE") != "" {
|
||||
InsecureFlag, err = strconv.ParseBool(os.Getenv("VSPHERE_INSECURE"))
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user