mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #27513 from hpcloud/hpe/vsphere-vm-dir
Automatic merge from submit-queue 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 should help compartmentalize workloads in vSphere.
This commit is contained in:
commit
bf54cd40f3
@ -22,6 +22,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/vmware/govmomi"
|
"github.com/vmware/govmomi"
|
||||||
@ -71,6 +72,7 @@ type VSphereConfig struct {
|
|||||||
InsecureFlag bool `gcfg:"insecure-flag"`
|
InsecureFlag bool `gcfg:"insecure-flag"`
|
||||||
Datacenter string `gcfg:"datacenter"`
|
Datacenter string `gcfg:"datacenter"`
|
||||||
Datastore string `gcfg:"datastore"`
|
Datastore string `gcfg:"datastore"`
|
||||||
|
WorkingDir string `gcfg:"working-dir"`
|
||||||
}
|
}
|
||||||
|
|
||||||
Network struct {
|
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)
|
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'")
|
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{
|
vs := VSphere{
|
||||||
cfg: &cfg,
|
cfg: &cfg,
|
||||||
localInstanceID: id,
|
localInstanceID: id,
|
||||||
@ -217,9 +222,11 @@ func getVirtualMachineByName(cfg *VSphereConfig, ctx context.Context, c *govmomi
|
|||||||
}
|
}
|
||||||
f.SetDatacenter(dc)
|
f.SetDatacenter(dc)
|
||||||
|
|
||||||
|
vmRegex := cfg.Global.WorkingDir + name
|
||||||
|
|
||||||
// Retrieve vm by name
|
// Retrieve vm by name
|
||||||
//TODO: also look for vm inside subfolders
|
//TODO: also look for vm inside subfolders
|
||||||
vm, err := f.VirtualMachine(ctx, name)
|
vm, err := f.VirtualMachine(ctx, vmRegex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -247,8 +254,10 @@ func getInstances(cfg *VSphereConfig, ctx context.Context, c *govmomi.Client, fi
|
|||||||
|
|
||||||
f.SetDatacenter(dc)
|
f.SetDatacenter(dc)
|
||||||
|
|
||||||
|
vmRegex := cfg.Global.WorkingDir + filter
|
||||||
|
|
||||||
//TODO: get all vms inside subfolders
|
//TODO: get all vms inside subfolders
|
||||||
vms, err := f.VirtualMachineList(ctx, filter)
|
vms, err := f.VirtualMachineList(ctx, vmRegex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -492,7 +501,9 @@ func getVirtualMachineDevices(cfg *VSphereConfig, ctx context.Context, c *govmom
|
|||||||
return nil, nil, nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ func configFromEnv() (cfg VSphereConfig, ok bool) {
|
|||||||
cfg.Network.PublicNetwork = os.Getenv("VSPHERE_PUBLIC_NETWORK")
|
cfg.Network.PublicNetwork = os.Getenv("VSPHERE_PUBLIC_NETWORK")
|
||||||
cfg.Global.Datastore = os.Getenv("VSPHERE_DATASTORE")
|
cfg.Global.Datastore = os.Getenv("VSPHERE_DATASTORE")
|
||||||
cfg.Disk.SCSIControllerType = os.Getenv("VSPHERE_SCSICONTROLLER_TYPE")
|
cfg.Disk.SCSIControllerType = os.Getenv("VSPHERE_SCSICONTROLLER_TYPE")
|
||||||
|
cfg.Global.WorkingDir = os.Getenv("VSPHERE_WORKING_DIR")
|
||||||
if os.Getenv("VSPHERE_INSECURE") != "" {
|
if os.Getenv("VSPHERE_INSECURE") != "" {
|
||||||
InsecureFlag, err = strconv.ParseBool(os.Getenv("VSPHERE_INSECURE"))
|
InsecureFlag, err = strconv.ParseBool(os.Getenv("VSPHERE_INSECURE"))
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user