mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Merge pull request #101116 from jsafrane/vsphere-validate-parameters
vSphere: Return useful errors from parameter validation
This commit is contained in:
commit
6e3a873674
@ -20,20 +20,18 @@ import "errors"
|
|||||||
|
|
||||||
// Error Messages
|
// Error Messages
|
||||||
const (
|
const (
|
||||||
FileAlreadyExistErrMsg = "File requested already exist"
|
FileAlreadyExistErrMsg = "File requested already exist"
|
||||||
NoDiskUUIDFoundErrMsg = "No disk UUID found"
|
NoDiskUUIDFoundErrMsg = "No disk UUID found"
|
||||||
NoDevicesFoundErrMsg = "No devices found"
|
NoDevicesFoundErrMsg = "No devices found"
|
||||||
DiskNotFoundErrMsg = "No vSphere disk ID found"
|
DiskNotFoundErrMsg = "No vSphere disk ID found"
|
||||||
InvalidVolumeOptionsErrMsg = "VolumeOptions verification failed"
|
NoVMFoundErrMsg = "No VM found"
|
||||||
NoVMFoundErrMsg = "No VM found"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error constants
|
// Error constants
|
||||||
var (
|
var (
|
||||||
ErrFileAlreadyExist = errors.New(FileAlreadyExistErrMsg)
|
ErrFileAlreadyExist = errors.New(FileAlreadyExistErrMsg)
|
||||||
ErrNoDiskUUIDFound = errors.New(NoDiskUUIDFoundErrMsg)
|
ErrNoDiskUUIDFound = errors.New(NoDiskUUIDFoundErrMsg)
|
||||||
ErrNoDevicesFound = errors.New(NoDevicesFoundErrMsg)
|
ErrNoDevicesFound = errors.New(NoDevicesFoundErrMsg)
|
||||||
ErrNoDiskIDFound = errors.New(DiskNotFoundErrMsg)
|
ErrNoDiskIDFound = errors.New(DiskNotFoundErrMsg)
|
||||||
ErrInvalidVolumeOptions = errors.New(InvalidVolumeOptionsErrMsg)
|
ErrNoVMFound = errors.New(NoVMFoundErrMsg)
|
||||||
ErrNoVMFound = errors.New(NoVMFoundErrMsg)
|
|
||||||
)
|
)
|
||||||
|
@ -64,9 +64,9 @@ func (virtualDisk *VirtualDisk) Create(ctx context.Context, datastore *vclib.Dat
|
|||||||
if virtualDisk.VolumeOptions.DiskFormat == "" {
|
if virtualDisk.VolumeOptions.DiskFormat == "" {
|
||||||
virtualDisk.VolumeOptions.DiskFormat = vclib.ThinDiskType
|
virtualDisk.VolumeOptions.DiskFormat = vclib.ThinDiskType
|
||||||
}
|
}
|
||||||
if !virtualDisk.VolumeOptions.VerifyVolumeOptions() {
|
if err := virtualDisk.VolumeOptions.VerifyVolumeOptions(); err != nil {
|
||||||
klog.Error("VolumeOptions verification failed. volumeOptions: ", virtualDisk.VolumeOptions)
|
klog.Errorf("VolumeOptions verification failed: %s (options: %+v)", err, virtualDisk.VolumeOptions)
|
||||||
return "", vclib.ErrInvalidVolumeOptions
|
return "", fmt.Errorf("validation of parameters failed: %s", err)
|
||||||
}
|
}
|
||||||
if virtualDisk.VolumeOptions.StoragePolicyID != "" && virtualDisk.VolumeOptions.StoragePolicyName != "" {
|
if virtualDisk.VolumeOptions.StoragePolicyID != "" && virtualDisk.VolumeOptions.StoragePolicyName != "" {
|
||||||
return "", fmt.Errorf("Storage Policy ID and Storage Policy Name both set, Please set only one parameter")
|
return "", fmt.Errorf("Storage Policy ID and Storage Policy Name both set, Please set only one parameter")
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package vclib
|
package vclib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
@ -90,21 +91,21 @@ func CheckControllerSupported(ctrlType string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// VerifyVolumeOptions checks if volumeOptions.SCIControllerType is valid controller type
|
// VerifyVolumeOptions checks if volumeOptions.SCIControllerType is valid controller type
|
||||||
func (volumeOptions VolumeOptions) VerifyVolumeOptions() bool {
|
func (volumeOptions VolumeOptions) VerifyVolumeOptions() error {
|
||||||
// Validate only if SCSIControllerType is set by user.
|
// Validate only if SCSIControllerType is set by user.
|
||||||
// Default value is set later in virtualDiskManager.Create and vmDiskManager.Create
|
// Default value is set later in virtualDiskManager.Create and vmDiskManager.Create
|
||||||
if volumeOptions.SCSIControllerType != "" {
|
if volumeOptions.SCSIControllerType != "" {
|
||||||
isValid := CheckControllerSupported(volumeOptions.SCSIControllerType)
|
isValid := CheckControllerSupported(volumeOptions.SCSIControllerType)
|
||||||
if !isValid {
|
if !isValid {
|
||||||
return false
|
return fmt.Errorf("invalid scsiControllerType: %s", volumeOptions.SCSIControllerType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ThinDiskType is the default, so skip the validation.
|
// ThinDiskType is the default, so skip the validation.
|
||||||
if volumeOptions.DiskFormat != ThinDiskType {
|
if volumeOptions.DiskFormat != ThinDiskType {
|
||||||
isValid := CheckDiskFormatSupported(volumeOptions.DiskFormat)
|
isValid := CheckDiskFormatSupported(volumeOptions.DiskFormat)
|
||||||
if !isValid {
|
if !isValid {
|
||||||
return false
|
return fmt.Errorf("invalid diskFormat: %s", volumeOptions.DiskFormat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user