Skip to content

Commit 326acad

Browse files
committed
add validation for datastore and storagePolicyName
Signed-off-by: Yassine TIJANI <[email protected]>
1 parent 7dd17ca commit 326acad

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

api/v1alpha3/vspheremachine_webhook.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (r *VSphereMachine) ValidateCreate() error {
5252
}
5353
}
5454
}
55+
56+
if spec.Datastore != "" && spec.StoragePolicyName != "" {
57+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "Datastore"), spec.Datastore, "cannot be set when spec.StoragePolicyName is also set"))
58+
}
5559
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
5660
}
5761

api/v1alpha3/vspheremachinetemplate_webhook.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ func (r *VSphereMachineTemplate) ValidateCreate() error {
5353
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "template", "spec", "network", "devices", "ipAddrs"), "cannot be set in templates"))
5454
}
5555
}
56+
57+
if spec.Datastore != "" && spec.StoragePolicyName != "" {
58+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "Datastore"), spec.Datastore, "cannot be set when spec.StoragePolicyName is also set"))
59+
}
5660
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
5761
}
5862

api/v1alpha3/vspherevm_webhook.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (r *VSphereVM) ValidateCreate() error {
5252
}
5353
}
5454
}
55+
56+
if spec.Datastore != "" && spec.StoragePolicyName != "" {
57+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "Datastore"), spec.Datastore, "cannot be set when spec.StoragePolicyName is also set"))
58+
}
5559
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
5660
}
5761

pkg/services/govmomi/vcenter/clone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ func Clone(ctx *context.VMContext, bootstrapData []byte) error {
163163
MemoryMB: memMiB,
164164
},
165165
Location: types.VirtualMachineRelocateSpec{
166-
// Datastore: types.NewReference(datastore.Reference()),
167166
DiskMoveType: string(diskMoveType),
168167
Folder: types.NewReference(folder.Reference()),
169168
Pool: types.NewReference(pool.Reference()),
@@ -202,6 +201,7 @@ func Clone(ctx *context.VMContext, bootstrapData []byte) error {
202201
if err != nil {
203202
return errors.Wrapf(err, "error trigging clone op for machine %s", ctx)
204203
}
204+
205205
ctx.VSphereVM.Status.TaskRef = task.Reference().Value
206206

207207
// patch the vsphereVM early to ensure that the task is

0 commit comments

Comments
 (0)