Skip to content

Commit d936f14

Browse files
committed
Do not allow empty StorageClass profile ID
This patch prevents a bug in the VMIC controller where an empty profile ID slipped into locations due to the VM provider not verifying the profile ID from a StorageClass is non-empty. The VMIC API has also been updated to require a min-length of 1 for required fields.
1 parent 1094519 commit d936f14

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

api/v1alpha5/virtualmachineimagecache_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,26 @@ const (
2323
)
2424

2525
type VirtualMachineImageCacheLocationSpec struct {
26+
27+
// +required
28+
// +kubebuilder:validation:MinLength=1
29+
2630
// DatacenterID describes the ID of the datacenter to which the image should
2731
// be cached.
2832
DatacenterID string `json:"datacenterID"`
2933

34+
// +required
35+
// +kubebuilder:validation:MinLength=1
36+
3037
// ProfileID describes the ID of the storage profile used to cache the
3138
// image.
3239
// Please note, this profile *must* include the datastore specified by the
3340
// datastoreID field.
3441
ProfileID string `json:"profileID"`
3542

43+
// +required
44+
// +kubebuilder:validation:MinLength=1
45+
3646
// DatastoreID describes the ID of the datastore to which the image should
3747
// be cached.
3848
DatastoreID string `json:"datastoreID"`

config/crd/bases/vmoperator.vmware.com_virtualmachineimagecaches.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,18 +664,21 @@ spec:
664664
description: |-
665665
DatacenterID describes the ID of the datacenter to which the image should
666666
be cached.
667+
minLength: 1
667668
type: string
668669
datastoreID:
669670
description: |-
670671
DatastoreID describes the ID of the datastore to which the image should
671672
be cached.
673+
minLength: 1
672674
type: string
673675
profileID:
674676
description: |-
675677
ProfileID describes the ID of the storage profile used to cache the
676678
image.
677679
Please note, this profile *must* include the datastore specified by the
678680
datastoreID field.
681+
minLength: 1
679682
type: string
680683
required:
681684
- datacenterID

pkg/util/kube/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ func (e ErrMissingParameter) Error() string {
146146
// GetStoragePolicyID returns the storage policy ID for a given StorageClass.
147147
// If no ID is found, an error is returned.
148148
func GetStoragePolicyID(obj storagev1.StorageClass) (string, error) {
149-
policyID, ok := obj.Parameters[internal.StoragePolicyIDParameter]
150-
if !ok {
149+
policyID := obj.Parameters[internal.StoragePolicyIDParameter]
150+
if policyID == "" {
151151
return "", ErrMissingParameter{
152152
StorageClassName: obj.Name,
153153
ParameterName: internal.StoragePolicyIDParameter,

0 commit comments

Comments
 (0)