kubevirt.io/api@v1.2.0/migrations/v1alpha1/types.go (about) 1 /* 2 * This file is part of the KubeVirt project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 * Copyright 2020 Red Hat, Inc. 17 * 18 */ 19 20 package v1alpha1 21 22 import ( 23 "k8s.io/apimachinery/pkg/api/resource" 24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 26 k6tv1 "kubevirt.io/api/core/v1" 27 ) 28 29 // MigrationPolicy holds migration policy (i.e. configurations) to apply to a VM or group of VMs 30 // 31 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 32 // +k8s:openapi-gen=true 33 // +genclient 34 // +genclient:nonNamespaced 35 type MigrationPolicy struct { 36 metav1.TypeMeta `json:",inline"` 37 metav1.ObjectMeta `json:"metadata,omitempty"` 38 Spec MigrationPolicySpec `json:"spec" valid:"required"` 39 // +nullable 40 Status MigrationPolicyStatus `json:"status,omitempty"` 41 } 42 43 type MigrationPolicySpec struct { 44 Selectors *Selectors `json:"selectors"` 45 46 //+optional 47 AllowAutoConverge *bool `json:"allowAutoConverge,omitempty"` 48 //+optional 49 BandwidthPerMigration *resource.Quantity `json:"bandwidthPerMigration,omitempty"` 50 //+optional 51 CompletionTimeoutPerGiB *int64 `json:"completionTimeoutPerGiB,omitempty"` 52 //+optional 53 AllowPostCopy *bool `json:"allowPostCopy,omitempty"` 54 } 55 56 type LabelSelector map[string]string 57 58 type Selectors struct { 59 //+optional 60 NamespaceSelector LabelSelector `json:"namespaceSelector,omitempty"` 61 //+optional 62 VirtualMachineInstanceSelector LabelSelector `json:"virtualMachineInstanceSelector,omitempty"` 63 } 64 65 type MigrationPolicyStatus struct { 66 } 67 68 // MigrationPolicyList is a list of MigrationPolicy 69 // 70 // +k8s:openapi-gen=true 71 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 72 type MigrationPolicyList struct { 73 metav1.TypeMeta `json:",inline"` 74 metav1.ListMeta `json:"metadata,omitempty"` 75 // +listType=atomic 76 Items []MigrationPolicy `json:"items"` 77 } 78 79 // GetMigrationConfByPolicy returns a new migration configuration. The new configuration attributes will be overridden 80 // by the migration policy if the specified attributes were defined for this policy. Otherwise they wouldn't change. 81 // The boolean returned value indicates if any changes were made to the configurations. 82 func (m *MigrationPolicy) GetMigrationConfByPolicy(clusterMigrationConfigurations *k6tv1.MigrationConfiguration) (changed bool, err error) { 83 policySpec := m.Spec 84 changed = false 85 86 if policySpec.AllowAutoConverge != nil { 87 changed = true 88 *clusterMigrationConfigurations.AllowAutoConverge = *policySpec.AllowAutoConverge 89 } 90 if policySpec.BandwidthPerMigration != nil { 91 changed = true 92 *clusterMigrationConfigurations.BandwidthPerMigration = *policySpec.BandwidthPerMigration 93 } 94 if policySpec.CompletionTimeoutPerGiB != nil { 95 changed = true 96 *clusterMigrationConfigurations.CompletionTimeoutPerGiB = *policySpec.CompletionTimeoutPerGiB 97 } 98 if policySpec.AllowPostCopy != nil { 99 changed = true 100 *clusterMigrationConfigurations.AllowPostCopy = *policySpec.AllowPostCopy 101 } 102 103 return changed, nil 104 }