Add ability to exclude Presets from VM's
@@ -50,6 +50,7 @@ type VirtualMachinePresetController struct {
}
const initializerMarking = "presets.virtualmachines." + kubev1.GroupName + "/presets-applied"
+const exclusionMarking = "presets.virtualmachines." + kubev1.GroupName + "/exclude"
func NewVirtualMachinePresetController(vmPresetInformer cache.SharedIndexInformer, vmInitInformer cache.SharedIndexInformer, queue workqueue.RateLimitingInterface, vmInitCache cache.Store, clientset kubecli.KubevirtClient, recorder record.EventRecorder) *VirtualMachinePresetController {
vmi := VirtualMachinePresetController{
@@ -133,6 +134,7 @@ func (c *VirtualMachinePresetController) initializeVirtualMachine(vm *kubev1.Vir
var err error
success := true
+ if !arePresetsExcluded(vm) {
logger.Object(vm).Info("Initializing VirtualMachine")
allPresets, err := listPresets(c.vmPresetInformer, vm.GetNamespace())
@@ -151,6 +153,9 @@ func (c *VirtualMachinePresetController) initializeVirtualMachine(vm *kubev1.Vir
logger.Object(vm).Warning("Marking VM as failed")
vm.Status.Phase = kubev1.Failed
}
+ } else {
+ logger.Object(vm).Infof("VirtualMachinePresets are excluded")
+ }
// Even failed VM's need to be marked as initialized so they're
// not re-processed by this controller
logger.Object(vm).Info("Marking VM as initialized")
@@ -374,6 +379,14 @@ func isVirtualMachineInitialized(vm *kubev1.VirtualMachine) bool {
return false
}
+func arePresetsExcluded(vm *kubev1.VirtualMachine) bool {
+ if vm.Annotations != nil {
+ excluded, ok := vm.Annotations[exclusionMarking]
+ return ok && (excluded == "true")
+ }
+ return false
+}
+
func addInitializedAnnotation(vm *kubev1.VirtualMachine) {
if vm.Annotations == nil {
vm.Annotations = map[string]string{}
