Skip to content

Commit 9099b3c

Browse files
author
Valeriy Khorunzhin
committed
support legacy
Signed-off-by: Valeriy Khorunzhin <valeriy.khorunzhin@flant.com>
1 parent d9d9c25 commit 9099b3c

9 files changed

Lines changed: 95 additions & 15 deletions

File tree

images/virtualization-artifact/pkg/common/annotations/annotations.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,33 @@ const (
4040

4141
// AnnAPIGroup is the APIGroup for virtualization-controller.
4242
AnnAPIGroup = "internal.virtualization.deckhouse.io"
43+
// AnnAPIGroupLegacy is the legacy APIGroup for virtualization-controller annotations.
44+
AnnAPIGroupLegacy = "virt.deckhouse.io"
4345

4446
// AnnCreatedBy is a pod annotation indicating if the pod was created by the PVC.
4547
AnnCreatedBy = AnnAPIGroup + "/storage.createdByController"
4648

4749
// AnnPodRetainAfterCompletion is PVC annotation for retaining transfer pods after completion
4850
AnnPodRetainAfterCompletion = AnnAPIGroup + "/storage.pod.retainAfterCompletion"
4951

52+
// AnnPodRetainAfterCompletionLegacy is the legacy PVC annotation for retaining transfer pods after completion.
53+
AnnPodRetainAfterCompletionLegacy = AnnAPIGroupLegacy + "/storage.pod.retainAfterCompletion"
54+
5055
// AnnUploadURLDeprecated provides a const for CVMI/VMI/VMD uploadURL annotation.
5156
// TODO remove annotation and its usages after version 1.0 becomes Stable.
52-
AnnUploadURLDeprecated = AnnAPIGroup + "/upload.url"
57+
AnnUploadURLDeprecated = AnnAPIGroupLegacy + "/upload.url"
5358

5459
// AnnTolerationsHash provides a const for annotation with hash of applied tolerations.
5560
AnnTolerationsHash = AnnAPIGroup + "/tolerations-hash"
61+
// AnnTolerationsHashLegacy provides a const for legacy annotation with hash of applied tolerations.
62+
AnnTolerationsHashLegacy = AnnAPIGroupLegacy + "/tolerations-hash"
63+
5664
// AnnProvisionerTolerations provides a const for tolerations to use for provisioners.
5765
AnnProvisionerTolerations = AnnAPIGroup + "/provisioner-tolerations"
5866
// AnnProvisionerName provides a name of data volume provisioner.
5967
AnnProvisionerName = AnnAPIGroup + "/provisioner-name"
68+
// AnnProvisionerNameLegacy provides a legacy name of data volume provisioner.
69+
AnnProvisionerNameLegacy = AnnAPIGroupLegacy + "/provisioner-name"
6070

6171
// AnnDefaultStorageClass is the annotation indicating that a storage class is the default one.
6272
AnnDefaultStorageClass = "storageclass.kubernetes.io/is-default-class"
@@ -72,14 +82,22 @@ const (
7282

7383
// AnnVMLastAppliedSpec is an annotation on KVVM. It contains a JSON with VM spec.
7484
AnnVMLastAppliedSpec = AnnAPIGroup + "/vm.last-applied-spec"
85+
// AnnVMLastAppliedSpecLegacy is a legacy annotation on KVVM. It contains a JSON with VM spec.
86+
AnnVMLastAppliedSpecLegacy = AnnAPIGroupLegacy + "/vm.last-applied-spec"
7587

7688
// AnnVMClassLastAppliedSpec is an annotation on KVVM. It contains a JSON with VM spec.
7789
AnnVMClassLastAppliedSpec = AnnAPIGroup + "/vmclass.last-applied-spec"
90+
// AnnVMClassLastAppliedSpecLegacy is a legacy annotation on KVVM. It contains a JSON with VMClass spec.
91+
AnnVMClassLastAppliedSpecLegacy = AnnAPIGroupLegacy + "/vmclass.last-applied-spec"
7892

7993
// LastPropagatedVMAnnotationsAnnotation is a marshalled map of previously applied virtual machine annotations.
8094
LastPropagatedVMAnnotationsAnnotation = AnnAPIGroup + "/last-propagated-vm-annotations"
95+
// LastPropagatedVMAnnotationsAnnotationLegacy is a legacy marshalled map of previously applied virtual machine annotations.
96+
LastPropagatedVMAnnotationsAnnotationLegacy = AnnAPIGroupLegacy + "/last-propagated-vm-annotations"
8197
// LastPropagatedVMLabelsAnnotation is a marshalled map of previously applied virtual machine labels.
8298
LastPropagatedVMLabelsAnnotation = AnnAPIGroup + "/last-propagated-vm-labels"
99+
// LastPropagatedVMLabelsAnnotationLegacy is a legacy marshalled map of previously applied virtual machine labels.
100+
LastPropagatedVMLabelsAnnotationLegacy = AnnAPIGroupLegacy + "/last-propagated-vm-labels"
83101

84102
AnnOsType = AnnAPIGroupV + "/os-type"
85103

images/virtualization-artifact/pkg/common/object/object.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ func GetAge(obj client.Object) time.Duration {
133133
// - CVMI, VMI has no annotation to retain pod after import
134134
// - CVMI, VMI is deleted
135135
func ShouldCleanupSubResources(obj metav1.Object) bool {
136-
return obj.GetAnnotations()[annotations.AnnPodRetainAfterCompletion] != "true" || obj.GetDeletionTimestamp() != nil
136+
return (obj.GetAnnotations()[annotations.AnnPodRetainAfterCompletion] != "true" &&
137+
obj.GetAnnotations()[annotations.AnnPodRetainAfterCompletionLegacy] != "true") ||
138+
obj.GetDeletionTimestamp() != nil
137139
}
138140

139141
func IsTerminating(obj client.Object) bool {

images/virtualization-artifact/pkg/common/provisioner/node_placement.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ type NodePlacement struct {
3636
func IsNodePlacementChanged(nodePlacement *NodePlacement, obj client.Object) (bool, error) {
3737
oldHash, exists := obj.GetAnnotations()[annotations.AnnTolerationsHash]
3838

39+
if !exists {
40+
oldHash, exists = obj.GetAnnotations()[annotations.AnnTolerationsHashLegacy]
41+
}
42+
3943
if nodePlacement == nil && exists {
4044
return true, nil
4145
}
@@ -59,11 +63,17 @@ func KeepNodePlacementTolerations(nodePlacement *NodePlacement, obj client.Objec
5963

6064
if nodePlacement == nil || len(nodePlacement.Tolerations) == 0 {
6165
_, ok := anno[annotations.AnnTolerationsHash]
66+
67+
if !ok {
68+
_, ok = anno[annotations.AnnTolerationsHashLegacy]
69+
}
70+
6271
if !ok {
6372
return nil
6473
}
6574

6675
delete(anno, annotations.AnnTolerationsHash)
76+
delete(anno, annotations.AnnTolerationsHashLegacy)
6777

6878
obj.SetAnnotations(anno)
6979

images/virtualization-artifact/pkg/common/vm/vm.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ func RemoveNonPropagatableAnnotations(anno map[string]string) map[string]string
131131
res := make(map[string]string)
132132

133133
for k, v := range anno {
134-
if k == annotations.LastPropagatedVMAnnotationsAnnotation || k == annotations.LastPropagatedVMLabelsAnnotation {
134+
if k == annotations.LastPropagatedVMAnnotationsAnnotation ||
135+
k == annotations.LastPropagatedVMAnnotationsAnnotationLegacy ||
136+
k == annotations.LastPropagatedVMLabelsAnnotation ||
137+
k == annotations.LastPropagatedVMLabelsAnnotationLegacy {
135138
continue
136139
}
137140

images/virtualization-artifact/pkg/controller/importer/importer_pod.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ const (
3939
// CABundleVolName is the name of the volume containing certs from dataSource.http.caBundle field.
4040
caBundleVolName = "ca-bundle-vol"
4141

42-
// AnnOwnerRef is used when owner is in a different namespace
43-
AnnOwnerRef = annotations.AnnAPIGroup + "/storage.ownerRef"
44-
4542
// PodRunningReason is const that defines the pod was started as a reason
4643
// PodRunningReason = "Pod is running"
4744

images/virtualization-artifact/pkg/controller/kvbuilder/last_applied_spec.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ import (
2929

3030
// LoadLastAppliedSpec loads VM spec from JSON in the last-applied-spec annotation.
3131
func LoadLastAppliedSpec(kvvm *virtv1.VirtualMachine) (*v1alpha2.VirtualMachineSpec, error) {
32-
lastSpecJSON := kvvm.GetAnnotations()[annotations.AnnVMLastAppliedSpec]
32+
lastSpecJSON, ok := kvvm.GetAnnotations()[annotations.AnnVMLastAppliedSpec]
33+
34+
if !ok {
35+
lastSpecJSON = kvvm.GetAnnotations()[annotations.AnnVMLastAppliedSpecLegacy]
36+
}
37+
3338
if strings.TrimSpace(lastSpecJSON) == "" {
3439
return nil, nil
3540
}
@@ -55,7 +60,12 @@ func SetLastAppliedSpec(kvvm *virtv1.VirtualMachine, vm *v1alpha2.VirtualMachine
5560

5661
// LoadLastAppliedClassSpec loads VMClass spec from JSON in the last-applied-spec annotation.
5762
func LoadLastAppliedClassSpec(kvvm *virtv1.VirtualMachine) (*v1alpha2.VirtualMachineClassSpec, error) {
58-
lastSpecJSON := kvvm.GetAnnotations()[annotations.AnnVMClassLastAppliedSpec]
63+
lastSpecJSON, ok := kvvm.GetAnnotations()[annotations.AnnVMClassLastAppliedSpec]
64+
65+
if !ok {
66+
lastSpecJSON = kvvm.GetAnnotations()[annotations.AnnVMClassLastAppliedSpecLegacy]
67+
}
68+
5969
if strings.TrimSpace(lastSpecJSON) == "" {
6070
return nil, nil
6171
}

images/virtualization-artifact/pkg/controller/service/disk_service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ func (s DiskService) CheckProvisioning(ctx context.Context, pvc *corev1.Persiste
172172
}
173173

174174
podName, ok := pvc.Annotations[annotations.AnnProvisionerName]
175+
176+
if !ok || podName == "" {
177+
podName, ok = pvc.Annotations[annotations.AnnProvisionerNameLegacy]
178+
}
179+
175180
if !ok || podName == "" {
176181
return nil
177182
}

images/virtualization-artifact/pkg/controller/vm/internal/sync_kvvm.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,29 @@ func MakeKVVMFromVMSpec(ctx context.Context, s state.VirtualMachineState) (*virt
585585

586586
// IsKVVMChanged returns whether kvvm spec or special annotations are changed.
587587
func IsKVVMChanged(prevKVVM, newKVVM *virtv1.VirtualMachine) bool {
588-
if prevKVVM.Annotations[annotations.AnnVMLastAppliedSpec] != newKVVM.Annotations[annotations.AnnVMLastAppliedSpec] {
588+
prevKVVMLastAppliedSpecAnnotations, ok := prevKVVM.Annotations[annotations.AnnVMLastAppliedSpec]
589+
if !ok {
590+
prevKVVMLastAppliedSpecAnnotations = prevKVVM.Annotations[annotations.AnnVMLastAppliedSpecLegacy]
591+
}
592+
newKVVMLastAppliedSpecAnnotations, ok := newKVVM.Annotations[annotations.AnnVMLastAppliedSpec]
593+
if !ok {
594+
newKVVMLastAppliedSpecAnnotations = newKVVM.Annotations[annotations.AnnVMLastAppliedSpecLegacy]
595+
}
596+
597+
if prevKVVMLastAppliedSpecAnnotations != newKVVMLastAppliedSpecAnnotations {
589598
return true
590599
}
591600

592-
if prevKVVM.Annotations[annotations.AnnVMClassLastAppliedSpec] != newKVVM.Annotations[annotations.AnnVMClassLastAppliedSpec] {
601+
prevKVVMClassLastAppliedSpecAnnotations, ok := prevKVVM.Annotations[annotations.AnnVMClassLastAppliedSpec]
602+
if !ok {
603+
prevKVVMClassLastAppliedSpecAnnotations = prevKVVM.Annotations[annotations.AnnVMClassLastAppliedSpecLegacy]
604+
}
605+
newKVVMClassLastAppliedSpecAnnotations, ok := newKVVM.Annotations[annotations.AnnVMClassLastAppliedSpec]
606+
if !ok {
607+
newKVVMClassLastAppliedSpecAnnotations = newKVVM.Annotations[annotations.AnnVMClassLastAppliedSpecLegacy]
608+
}
609+
610+
if prevKVVMClassLastAppliedSpecAnnotations != newKVVMClassLastAppliedSpecAnnotations {
593611
return true
594612
}
595613

images/virtualization-artifact/pkg/controller/vm/internal/sync_metadata.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ func (h *SyncMetadataHandler) updateKVVMSpecTemplateMetadataAnnotations(currAnno
204204
res := make(map[string]string, len(newAnno))
205205

206206
for k, v := range newAnno {
207-
if k == annotations.AnnVMLastAppliedSpec || k == annotations.AnnVMClassLastAppliedSpec {
207+
if k == annotations.AnnVMLastAppliedSpec ||
208+
k == annotations.AnnVMLastAppliedSpecLegacy ||
209+
k == annotations.AnnVMClassLastAppliedSpec ||
210+
k == annotations.AnnVMClassLastAppliedSpecLegacy {
208211
continue
209212
}
210213

@@ -294,8 +297,15 @@ func PropagateVMMetadata(vm *v1alpha2.VirtualMachine, kvvm *virtv1.VirtualMachin
294297
func GetLastPropagatedLabels(kvvm *virtv1.VirtualMachine) (map[string]string, error) {
295298
var lastPropagatedLabels map[string]string
296299

297-
if kvvm.Annotations[annotations.LastPropagatedVMLabelsAnnotation] != "" {
298-
err := json.Unmarshal([]byte(kvvm.Annotations[annotations.LastPropagatedVMLabelsAnnotation]), &lastPropagatedLabels)
300+
key := annotations.LastPropagatedVMLabelsAnnotation
301+
lastPropagatedVMLabelsAnnotation, ok := kvvm.Annotations[key]
302+
if !ok {
303+
key = annotations.LastPropagatedVMLabelsAnnotationLegacy
304+
lastPropagatedVMLabelsAnnotation = kvvm.Annotations[key]
305+
}
306+
307+
if lastPropagatedVMLabelsAnnotation != "" {
308+
err := json.Unmarshal([]byte(lastPropagatedVMLabelsAnnotation), &lastPropagatedLabels)
299309
if err != nil {
300310
return nil, err
301311
}
@@ -323,8 +333,15 @@ func SetLastPropagatedLabels(metadata *metav1.ObjectMeta, vm *v1alpha2.VirtualMa
323333
func GetLastPropagatedAnnotations(kvvm *virtv1.VirtualMachine) (map[string]string, error) {
324334
var lastPropagatedAnno map[string]string
325335

326-
if kvvm.Annotations[annotations.LastPropagatedVMAnnotationsAnnotation] != "" {
327-
err := json.Unmarshal([]byte(kvvm.Annotations[annotations.LastPropagatedVMAnnotationsAnnotation]), &lastPropagatedAnno)
336+
key := annotations.LastPropagatedVMAnnotationsAnnotation
337+
lastPropagatedAnnotations, ok := kvvm.Annotations[key]
338+
if !ok {
339+
key = annotations.LastPropagatedVMAnnotationsAnnotationLegacy
340+
lastPropagatedAnnotations = kvvm.Annotations[key]
341+
}
342+
343+
if lastPropagatedAnnotations != "" {
344+
err := json.Unmarshal([]byte(lastPropagatedAnnotations), &lastPropagatedAnno)
328345
if err != nil {
329346
return nil, err
330347
}

0 commit comments

Comments
 (0)