Skip to content

Commit

Permalink
feature-gates: add VolumeMigration feature gate
Browse files Browse the repository at this point in the history
Signed-off-by: Alice Frosi <[email protected]>
  • Loading branch information
alicefr committed Jun 1, 2024
1 parent cfcea6f commit 3f80dec
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,13 @@ func validateLiveUpdateFeatures(field *k8sfield.Path, spec *v1.VirtualMachineSpe
Field: "updateVolumesStrategy",
})
}
if spec.UpdateVolumesStrategy != nil && *spec.UpdateVolumesStrategy == v1.UpdateVolumesStrategyMigration && !config.VolumeMigrationEnabled() {
causes = append(causes, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueInvalid,
Message: fmt.Sprintf("%s feature gate is not enabled in kubevirt-config", virtconfig.VolumeMigration),
Field: "updateVolumesStrategy",
})
}

return causes
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,24 @@ var _ = Describe("Validating VM Admitter", func() {
Message: fmt.Sprintf("%s feature gate is not enabled in kubevirt-config", virtconfig.VolumesUpdateStrategy),
}))
})
It("should accept the VM with the feature gate enabled for volume migration", func() {
enableFeatureGate(virtconfig.VMLiveUpdateFeaturesGate, virtconfig.VolumesUpdateStrategy, virtconfig.VolumeMigration)
vm.Spec.UpdateVolumesStrategy = virtpointer.P(v1.UpdateVolumesStrategyMigration)
resp := admitVm(vmsAdmitter, vm)
Expect(resp.Allowed).To(BeTrue())
Expect(resp.Result).To(BeNil())
})
It("should reject the VM creation if the volume migration feature gate isn't enabled", func() {
enableFeatureGate(virtconfig.VMLiveUpdateFeaturesGate, virtconfig.VolumesUpdateStrategy)
vm.Spec.UpdateVolumesStrategy = virtpointer.P(v1.UpdateVolumesStrategyMigration)
resp := admitVm(vmsAdmitter, vm)
Expect(resp.Allowed).To(BeFalse())
Expect(resp.Result.Details.Causes).To(ContainElement(metav1.StatusCause{
Type: metav1.CauseTypeFieldValueInvalid,
Field: "updateVolumesStrategy",
Message: fmt.Sprintf("%s feature gate is not enabled in kubevirt-config", virtconfig.VolumeMigration),
}))
})
})
})

Expand Down
6 changes: 6 additions & 0 deletions pkg/virt-config/feature-gates.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ const (

// VolumesUpdateStrategy enables to specify the strategy on the volume updates.
VolumesUpdateStrategy = "VolumesUpdateStrategy"
// VolumeMigration enables to migrate the storage. It depends on the VolumesUpdateStrategy feature.
VolumeMigration = "VolumeMigration"
)

func (config *ClusterConfig) isFeatureGateEnabled(featureGate string) bool {
Expand Down Expand Up @@ -248,3 +250,7 @@ func (config *ClusterConfig) AlignCPUsEnabled() bool {
func (config *ClusterConfig) VolumesUpdateStrategyEnabled() bool {
return config.isFeatureGateEnabled(VolumesUpdateStrategy)
}

func (config *ClusterConfig) VolumeMigrationEnabled() bool {
return config.isFeatureGateEnabled(VolumeMigration)
}
3 changes: 3 additions & 0 deletions pkg/virt-controller/watch/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,9 @@ func (c *VMController) handleVolumeUpdateRequest(vm *virtv1.VirtualMachine, vmi
})
}
case *vm.Spec.UpdateVolumesStrategy == virtv1.UpdateVolumesStrategyMigration:
if !c.clusterConfig.VolumeMigrationEnabled() {
return nil
}
// Validate if the update volumes can be migrated
if err := volumemig.ValidateVolumes(vmi, vm); err != nil {
vmConditions.UpdateCondition(vm, &virtv1.VirtualMachineCondition{
Expand Down

0 comments on commit 3f80dec

Please sign in to comment.