From b133e0f906d410047304c98d4828662babac21db Mon Sep 17 00:00:00 2001 From: Nahshon Unna-Tsameret Date: Thu, 8 Aug 2024 15:44:07 +0300 Subject: [PATCH] KubeVirt: add label to DataVolume Added the `hypershift.openshift.io/nodepool-name` label to the rhcos datavolume, to allow easy access to these datavolumes, e.g. for backup. Signed-off-by: Nahshon Unna-Tsameret --- api/hypershift/v1beta1/hostedcluster_types.go | 3 +++ .../controllers/nodepool/kubevirt/imagecacher.go | 5 +++-- .../controllers/nodepool/kubevirt/kubevirt.go | 3 +++ .../controllers/nodepool/kubevirt/kubevirt_test.go | 5 ++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/api/hypershift/v1beta1/hostedcluster_types.go b/api/hypershift/v1beta1/hostedcluster_types.go index a95ba980d8..fdb5ef98ee 100644 --- a/api/hypershift/v1beta1/hostedcluster_types.go +++ b/api/hypershift/v1beta1/hostedcluster_types.go @@ -326,6 +326,9 @@ const ( // This annotation signals to the NodePool controller that it is safe to use TopologySpreadConstraints on a NodePool // without triggering an unexpected update of KubeVirt VMs. NodePoolSupportsKubevirtTopologySpreadConstraintsAnnotation = "hypershift.openshift.io/nodepool-supports-kubevirt-topology-spread-constraints" + + // IsKubeVirtRHCOSVolumeLabelName labels rhcos DataVolumes and PVCs, to be able to filter them, e.g. for backup + IsKubeVirtRHCOSVolumeLabelName = "hypershift.openshift.io/is-kubevirt-rhcos" ) // HostedClusterSpec is the desired behavior of a HostedCluster. diff --git a/hypershift-operator/controllers/nodepool/kubevirt/imagecacher.go b/hypershift-operator/controllers/nodepool/kubevirt/imagecacher.go index b686ddefef..346e499511 100644 --- a/hypershift-operator/controllers/nodepool/kubevirt/imagecacher.go +++ b/hypershift-operator/controllers/nodepool/kubevirt/imagecacher.go @@ -222,8 +222,9 @@ func (qi *cachedBootImage) buildDVForCache(nodePool *hyperv1.NodePool, uid strin GenerateName: bootImageNamePrefix, Namespace: qi.namespace, Labels: map[string]string{ - bootImageDVLabelRoleName: bootImageDVLabelRoleValue, - bootImageDVLabelUID: uid, + bootImageDVLabelRoleName: bootImageDVLabelRoleValue, + bootImageDVLabelUID: uid, + hyperv1.IsKubeVirtRHCOSVolumeLabelName: "true", }, Annotations: map[string]string{ bootImageDVAnnotationHash: qi.hash, diff --git a/hypershift-operator/controllers/nodepool/kubevirt/kubevirt.go b/hypershift-operator/controllers/nodepool/kubevirt/kubevirt.go index e7ff623a11..d36c36e117 100644 --- a/hypershift-operator/controllers/nodepool/kubevirt/kubevirt.go +++ b/hypershift-operator/controllers/nodepool/kubevirt/kubevirt.go @@ -236,6 +236,9 @@ func virtualMachineTemplateBase(nodePool *hyperv1.NodePool, bootImage BootImage) TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ Name: rootVolumeName, + Labels: map[string]string{ + hyperv1.IsKubeVirtRHCOSVolumeLabelName: "true", + }, }, Spec: v1beta1.DataVolumeSpec{ Source: dvSource, diff --git a/hypershift-operator/controllers/nodepool/kubevirt/kubevirt_test.go b/hypershift-operator/controllers/nodepool/kubevirt/kubevirt_test.go index 3bfeb1d1af..3af4ba7997 100644 --- a/hypershift-operator/controllers/nodepool/kubevirt/kubevirt_test.go +++ b/hypershift-operator/controllers/nodepool/kubevirt/kubevirt_test.go @@ -10,7 +10,6 @@ import ( "github.com/go-logr/zapr" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" - suppconfig "github.com/openshift/hypershift/support/config" "go.uber.org/zap/zaptest" corev1 "k8s.io/api/core/v1" apiresource "k8s.io/apimachinery/pkg/api/resource" @@ -24,6 +23,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1" + suppconfig "github.com/openshift/hypershift/support/config" ) const ( @@ -1328,6 +1328,9 @@ func generateNodeTemplate(options ...nodeTemplateOption) *capikubevirt.VirtualMa TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ Name: "rhcos", + Labels: map[string]string{ + hyperv1.IsKubeVirtRHCOSVolumeLabelName: "true", + }, }, Spec: v1beta1.DataVolumeSpec{ Source: &v1beta1.DataVolumeSource{