From 13d53dec65f9143234381418b4861d2c45ad8f1b Mon Sep 17 00:00:00 2001 From: Mateus Oliveira Date: Thu, 1 Aug 2024 15:02:32 -0300 Subject: [PATCH] fixup! fix: read ephemeral-storage in code Signed-off-by: Mateus Oliveira --- controllers/velero_test.go | 3279 ++++++++---------------------------- 1 file changed, 667 insertions(+), 2612 deletions(-) diff --git a/controllers/velero_test.go b/controllers/velero_test.go index 42b5e238b3..1dc1bedf00 100644 --- a/controllers/velero_test.go +++ b/controllers/velero_test.go @@ -2,6 +2,7 @@ package controllers import ( "context" + "fmt" "os" "reflect" "slices" @@ -33,12 +34,12 @@ import ( ) const ( - proxyEnvKey = "HTTP_PROXY" - proxyEnvValue = "http://proxy.example.com:8080" - argsMetricsPortTest int32 = 69420 - defaultFileSystemBackupTimeout = "--fs-backup-timeout=4h" - defaultRestoreResourcePriorities = "--restore-resource-priorities=securitycontextconstraints,customresourcedefinitions,klusterletconfigs.config.open-cluster-management.io,managedcluster.cluster.open-cluster-management.io,namespaces,roles,rolebindings,clusterrolebindings,klusterletaddonconfig.agent.open-cluster-management.io,managedclusteraddon.addon.open-cluster-management.io,storageclasses,volumesnapshotclass.snapshot.storage.k8s.io,volumesnapshotcontents.snapshot.storage.k8s.io,volumesnapshots.snapshot.storage.k8s.io,datauploads.velero.io,persistentvolumes,persistentvolumeclaims,serviceaccounts,secrets,configmaps,limitranges,pods,replicasets.apps,clusterclasses.cluster.x-k8s.io,endpoints,services,-,clusterbootstraps.run.tanzu.vmware.com,clusters.cluster.x-k8s.io,clusterresourcesets.addons.cluster.x-k8s.io" - defaultDisableInformerCache = "--disable-informer-cache=false" + proxyEnvKey = "HTTP_PROXY" + proxyEnvValue = "http://proxy.example.com:8080" + argsMetricsPortTest = 69420 + defaultFileSystemBackupTimeout = "--fs-backup-timeout=4h" + defaultRestoreResourcePriorities = "--restore-resource-priorities=securitycontextconstraints,customresourcedefinitions,klusterletconfigs.config.open-cluster-management.io,managedcluster.cluster.open-cluster-management.io,namespaces,roles,rolebindings,clusterrolebindings,klusterletaddonconfig.agent.open-cluster-management.io,managedclusteraddon.addon.open-cluster-management.io,storageclasses,volumesnapshotclass.snapshot.storage.k8s.io,volumesnapshotcontents.snapshot.storage.k8s.io,volumesnapshots.snapshot.storage.k8s.io,datauploads.velero.io,persistentvolumes,persistentvolumeclaims,serviceaccounts,secrets,configmaps,limitranges,pods,replicasets.apps,clusterclasses.cluster.x-k8s.io,endpoints,services,-,clusterbootstraps.run.tanzu.vmware.com,clusters.cluster.x-k8s.io,clusterresourcesets.addons.cluster.x-k8s.io" + defaultDisableInformerCache = "--disable-informer-cache=false" testNamespaceName = "test-ns" testDpaName = "test-DPA-CR" @@ -65,12 +66,27 @@ var ( Labels: veleroDeploymentMatchLabels, Annotations: veleroPodAnnotations, } + + baseObjectMeta = metav1.ObjectMeta{ + Name: testVeleroDeploymentName, + Namespace: testNamespaceName, + Labels: veleroDeploymentLabel, + } + + baseTypeMeta = metav1.TypeMeta{ + Kind: "Deployment", + APIVersion: appsv1.SchemeGroupVersion.String(), + } + baseEnvVars = []corev1.EnvVar{ {Name: common.VeleroScratchDirEnvKey, Value: "/scratch"}, { Name: common.VeleroNamespaceEnvKey, ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{FieldPath: "metadata.namespace"}, + FieldRef: &corev1.ObjectFieldSelector{ + APIVersion: "v1", + FieldPath: "metadata.namespace", + }, }, }, {Name: common.LDLibraryPathEnvKey, Value: "/plugins"}, @@ -128,11 +144,6 @@ var ( Name: testVeleroDeploymentName, Namespace: testNamespaceName, }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - }, } ) @@ -297,6 +308,18 @@ func pluginContainer(name, image string) corev1.Container { return container } +func deploymentVolumeSecret(name string) corev1.Volume { + return corev1.Volume{ + Name: name, + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: name, + DefaultMode: ptr.To(int32(420)), + }, + }, + } +} + func createTestDpaWith( dpaAnnotations map[string]string, dpaSpec oadpv1alpha1.DataProtectionApplicationSpec, @@ -311,6 +334,143 @@ func createTestDpaWith( } } +type TestBuiltVeleroDeploymentOptions struct { + args []string + customLabels map[string]string + labels map[string]string + annotations map[string]string + metricsPort int + initContainers []corev1.Container + volumes []corev1.Volume + volumeMounts []corev1.VolumeMount + env []corev1.EnvVar + dnsPolicy corev1.DNSPolicy + dnsConfig *corev1.PodDNSConfig + resourceLimits corev1.ResourceList + resourceRequests corev1.ResourceList + toleration []corev1.Toleration + nodeSelector map[string]string +} + +func createTestBuiltVeleroDeployment(options TestBuiltVeleroDeploymentOptions) *appsv1.Deployment { + testBuiltVeleroDeployment := &appsv1.Deployment{ + ObjectMeta: baseObjectMeta, + TypeMeta: baseTypeMeta, + Spec: appsv1.DeploymentSpec{ + Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, + Replicas: ptr.To(int32(1)), + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: &intstr.IntOrString{Type: intstr.String, StrVal: "25%"}, + MaxSurge: &intstr.IntOrString{Type: intstr.String, StrVal: "25%"}, + }, + }, + RevisionHistoryLimit: ptr.To(int32(10)), + ProgressDeadlineSeconds: ptr.To(int32(600)), + Template: corev1.PodTemplateSpec{ + ObjectMeta: veleroPodObjectMeta, + Spec: corev1.PodSpec{ + RestartPolicy: corev1.RestartPolicyAlways, + ServiceAccountName: common.Velero, + TerminationGracePeriodSeconds: ptr.To(int64(30)), + DNSPolicy: corev1.DNSClusterFirst, + DeprecatedServiceAccount: common.Velero, + SecurityContext: &corev1.PodSecurityContext{}, + SchedulerName: "default-scheduler", + Containers: []corev1.Container{ + { + Name: common.Velero, + Image: common.VeleroImage, + ImagePullPolicy: corev1.PullAlways, + TerminationMessagePath: "/dev/termination-log", + TerminationMessagePolicy: corev1.TerminationMessageReadFile, + Ports: []corev1.ContainerPort{{ + Name: "metrics", + ContainerPort: 8085, + Protocol: corev1.ProtocolTCP, + }}, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("128Mi"), + }, + }, + Command: []string{"/velero"}, + Args: append([]string{"server"}, options.args...), + VolumeMounts: baseVolumeMounts, + Env: baseEnvVars, + }, + }, + Volumes: baseVolumes, + InitContainers: []corev1.Container{}, + }, + }, + }, + } + + if options.customLabels != nil { + testBuiltVeleroDeployment.Labels = common.AppendTTMapAsCopy(testBuiltVeleroDeployment.Labels, options.customLabels) + testBuiltVeleroDeployment.Spec.Selector.MatchLabels = common.AppendTTMapAsCopy(testBuiltVeleroDeployment.Spec.Selector.MatchLabels, options.customLabels) + testBuiltVeleroDeployment.Spec.Template.Labels = common.AppendTTMapAsCopy(testBuiltVeleroDeployment.Spec.Template.Labels, options.customLabels) + } + + if options.labels != nil { + testBuiltVeleroDeployment.Spec.Template.Labels = common.AppendTTMapAsCopy(testBuiltVeleroDeployment.Spec.Template.Labels, options.labels) + } + + if options.annotations != nil { + testBuiltVeleroDeployment.Spec.Template.Annotations = common.AppendTTMapAsCopy(testBuiltVeleroDeployment.Spec.Template.Annotations, options.annotations) + } + + if options.initContainers != nil { + testBuiltVeleroDeployment.Spec.Template.Spec.InitContainers = options.initContainers + } + + if options.volumes != nil { + testBuiltVeleroDeployment.Spec.Template.Spec.Volumes = append(baseVolumes, options.volumes...) + } + + if options.volumeMounts != nil { + testBuiltVeleroDeployment.Spec.Template.Spec.Containers[0].VolumeMounts = append(baseVolumeMounts, options.volumeMounts...) + } + + if options.env != nil { + testBuiltVeleroDeployment.Spec.Template.Spec.Containers[0].Env = options.env + } + + if options.resourceLimits != nil { + testBuiltVeleroDeployment.Spec.Template.Spec.Containers[0].Resources.Limits = options.resourceLimits + } + + if options.resourceRequests != nil { + testBuiltVeleroDeployment.Spec.Template.Spec.Containers[0].Resources.Requests = options.resourceRequests + } + + if options.toleration != nil { + testBuiltVeleroDeployment.Spec.Template.Spec.Tolerations = options.toleration + } + + if options.nodeSelector != nil { + testBuiltVeleroDeployment.Spec.Template.Spec.NodeSelector = options.nodeSelector + } + + if options.metricsPort != 0 { + testBuiltVeleroDeployment.Spec.Template.Annotations = common.AppendTTMapAsCopy(testBuiltVeleroDeployment.Spec.Template.Annotations, map[string]string{"prometheus.io/port": strconv.Itoa(options.metricsPort)}) + testBuiltVeleroDeployment.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = int32(options.metricsPort) + } + + if len(options.dnsPolicy) > 0 { + testBuiltVeleroDeployment.Spec.Template.Spec.DNSPolicy = options.dnsPolicy + } + + if options.dnsConfig != nil { + testBuiltVeleroDeployment.Spec.Template.Spec.DNSConfig = options.dnsConfig + } + + return testBuiltVeleroDeployment +} + func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { tests := []struct { name string @@ -322,16 +482,16 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { errorMessage string }{ { - name: "DPA CR is nil", + name: "DPA CR is nil, error is returned", errorMessage: "DPA CR cannot be nil", }, { - name: "Velero Deployment is nil", + name: "Velero Deployment is nil, error is returned", dpa: &oadpv1alpha1.DataProtectionApplication{}, errorMessage: "velero deployment cannot be nil", }, { - name: "given valid DPA CR, appropriate Velero Deployment is built", + name: "valid DPA CR, Velero Deployment is built with default args", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -341,51 +501,16 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, }, - }, + }), }, { - name: "given valid DPA CR, appropriate Velero Deployment is built with custom labels", + name: "valid DPA CR, Velero Deployment is built with custom labels", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -400,60 +525,18 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { Namespace: testNamespaceName, Labels: map[string]string{"foo": "bar"}, }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - }, }, - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: common.AppendTTMapAsCopy(veleroDeploymentLabel, map[string]string{"foo": "bar"}), - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: common.AppendTTMapAsCopy(veleroDeploymentMatchLabels, map[string]string{"foo": "bar"})}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: common.AppendTTMapAsCopy(veleroDeploymentMatchLabels, map[string]string{"foo": "bar"}), - Annotations: veleroPodAnnotations, - }, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + customLabels: map[string]string{"foo": "bar"}, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, }, - }, + }), }, { - name: "given valid DPA CR with PodConfig Env, appropriate Velero Deployment is built", + name: "valid DPA CR with PodConfig Env, Velero Deployment is built with Container Env", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -469,234 +552,90 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: []corev1.EnvVar{ - {Name: common.VeleroScratchDirEnvKey, Value: "/scratch"}, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - {Name: common.LDLibraryPathEnvKey, Value: "/plugins"}, - {Name: "TEST_ENV", Value: "TEST_VALUE"}, - {Name: "OPENSHIFT_IMAGESTREAM_BACKUP", Value: "true"}, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + env: slices.Insert(baseEnvVars, 3, []corev1.EnvVar{{Name: "TEST_ENV", Value: "TEST_VALUE"}}...), + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, }, - }, + }), }, { - name: "given valid DPA CR, noDefaultBackupLocation, unsupportedOverrides operatorType MTC, vel deployment has secret volumes", + name: "valid DPA CR with proxy Env, Velero Deployment is built with Container Env", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ - Velero: &oadpv1alpha1.VeleroConfig{ - NoDefaultBackupLocation: true, - DefaultPlugins: allDefaultPluginsList, - }, - }, - UnsupportedOverrides: map[oadpv1alpha1.UnsupportedImageKey]string{ - oadpv1alpha1.OperatorTypeKey: oadpv1alpha1.OperatorTypeMTC, + Velero: &oadpv1alpha1.VeleroConfig{}, }, }, ), + testProxy: true, veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - "--features=EnableCSI", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: append(baseVolumeMounts, []corev1.VolumeMount{ - {Name: "cloud-credentials", MountPath: "/credentials"}, - {Name: "cloud-credentials-gcp", MountPath: "/credentials-gcp"}, - {Name: "cloud-credentials-azure", MountPath: "/credentials-azure"}, - }...), - Env: append(baseEnvVars, []corev1.EnvVar{ - {Name: common.AWSSharedCredentialsFileEnvKey, Value: "/credentials/cloud"}, - {Name: common.GCPCredentialsEnvKey, Value: "/credentials-gcp/cloud"}, - {Name: common.AzureCredentialsFileEnvKey, Value: "/credentials-azure/cloud"}, - }...), - }, - }, - Volumes: append(baseVolumes, []corev1.Volume{ - { - Name: "cloud-credentials", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "cloud-credentials", - }, - }, - }, - { - Name: "cloud-credentials-gcp", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "cloud-credentials-gcp", - }, - }, - }, - { - Name: "cloud-credentials-azure", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "cloud-credentials-azure", - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + env: slices.Insert(baseEnvVars, 3, []corev1.EnvVar{ + {Name: proxyEnvKey, Value: proxyEnvValue}, + {Name: strings.ToLower(proxyEnvKey), Value: proxyEnvValue}, + }...), + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), + }, + { + name: "valid DPA CR with podConfig label, Velero Deployment is built with template labels", + dpa: createTestDpaWith( + nil, + oadpv1alpha1.DataProtectionApplicationSpec{ + Configuration: &oadpv1alpha1.ApplicationConfig{ + Velero: &oadpv1alpha1.VeleroConfig{ + PodConfig: &oadpv1alpha1.PodConfig{ + Labels: map[string]string{ + "thisIsVelero": "yes", }, - }...), - InitContainers: []corev1.Container{ - pluginContainer(common.VeleroPluginForAWS, common.AWSPluginImage), - pluginContainer(common.VeleroPluginForGCP, common.GCPPluginImage), - pluginContainer(common.VeleroPluginForAzure, common.AzurePluginImage), - pluginContainer(common.KubeVirtPlugin, common.KubeVirtPluginImage), - pluginContainer(common.VeleroPluginForOpenshift, common.OpenshiftPluginImage), }, }, }, }, - }, + ), + veleroDeployment: testVeleroDeployment.DeepCopy(), + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + labels: map[string]string{"thisIsVelero": "yes"}, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, { - name: "given valid DPA CR with proxy env var, appropriate Velero Deployment is built", + name: "valid DPA CR with Pod annotations, Velero Deployment is built with template annotations", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{}, }, + PodAnnotations: map[string]string{ + "test-annotation": "awesome annotation", + }, }, ), - testProxy: true, veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - - Env: []corev1.EnvVar{ - {Name: common.VeleroScratchDirEnvKey, Value: "/scratch"}, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - {Name: common.LDLibraryPathEnvKey, Value: "/plugins"}, - {Name: proxyEnvKey, Value: proxyEnvValue}, - {Name: strings.ToLower(proxyEnvKey), Value: proxyEnvValue}, - {Name: "OPENSHIFT_IMAGESTREAM_BACKUP", Value: "true"}, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + annotations: map[string]string{"test-annotation": "awesome annotation"}, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, }, - }, + }), }, { - name: "given valid DPA CR with podConfig label, appropriate Velero Deployment has template labels", + name: "invalid DPA CR with podConfig label, error is returned", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -704,7 +643,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { Velero: &oadpv1alpha1.VeleroConfig{ PodConfig: &oadpv1alpha1.PodConfig{ Labels: map[string]string{ - "thisIsVelero": "yes", + "component": common.NodeAgent, }, }, }, @@ -712,61 +651,60 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: common.AppendTTMapAsCopy(veleroDeploymentMatchLabels, - map[string]string{ - "thisIsVelero": "yes", - }), - Annotations: veleroPodAnnotations, - }, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, + errorMessage: "velero deployment template custom label: conflicting key component with value node-agent may not override velero", + }, + { + name: "valid DPA CR with noDefaultBackupLocation, all default plugins and unsupportedOverrides operatorType MTC, Velero Deployment is built with secret volumes", + dpa: createTestDpaWith( + nil, + oadpv1alpha1.DataProtectionApplicationSpec{ + Configuration: &oadpv1alpha1.ApplicationConfig{ + Velero: &oadpv1alpha1.VeleroConfig{ + NoDefaultBackupLocation: true, + DefaultPlugins: allDefaultPluginsList, }, }, + UnsupportedOverrides: map[oadpv1alpha1.UnsupportedImageKey]string{ + oadpv1alpha1.OperatorTypeKey: oadpv1alpha1.OperatorTypeMTC, + }, }, - }, + ), + veleroDeployment: testVeleroDeployment.DeepCopy(), + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + initContainers: []corev1.Container{ + pluginContainer(common.VeleroPluginForAWS, common.AWSPluginImage), + pluginContainer(common.VeleroPluginForGCP, common.GCPPluginImage), + pluginContainer(common.VeleroPluginForAzure, common.AzurePluginImage), + pluginContainer(common.KubeVirtPlugin, common.KubeVirtPluginImage), + pluginContainer(common.VeleroPluginForOpenshift, common.OpenshiftPluginImage), + }, + volumes: []corev1.Volume{ + deploymentVolumeSecret("cloud-credentials"), + deploymentVolumeSecret("cloud-credentials-gcp"), + deploymentVolumeSecret("cloud-credentials-azure"), + }, + volumeMounts: []corev1.VolumeMount{ + {Name: "cloud-credentials", MountPath: "/credentials"}, + {Name: "cloud-credentials-gcp", MountPath: "/credentials-gcp"}, + {Name: "cloud-credentials-azure", MountPath: "/credentials-azure"}, + }, + env: append(baseEnvVars, []corev1.EnvVar{ + {Name: common.AWSSharedCredentialsFileEnvKey, Value: "/credentials/cloud"}, + {Name: common.GCPCredentialsEnvKey, Value: "/credentials-gcp/cloud"}, + {Name: common.AzureCredentialsFileEnvKey, Value: "/credentials-azure/cloud"}, + }...), + args: []string{ + "--features=EnableCSI", + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, { - name: "given valid DPA CR with Unsupported Server Args, appropriate Velero Deployment is built", + name: "valid DPA CR with Unsupported Server Args, Velero Deployment is built with Unsupported Server Args", dpa: createTestDpaWith( - map[string]string{ - "oadp.openshift.io/unsupported-velero-server-args": "unsupported-server-args-cm", - }, + map[string]string{"oadp.openshift.io/unsupported-velero-server-args": "unsupported-server-args-cm"}, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{}, @@ -786,139 +724,42 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, }, veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - "--unsupported-arg=value1", - "--unsupported-bool-arg=true", - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + "--unsupported-arg=value1", + "--unsupported-bool-arg=true", }, - }, + }), }, { - name: "given valid DPA CR with Empty String Unsupported Server Args Annotation, appropriate Velero Deployment is built", + name: "valid DPA CR with Empty String Unsupported Server Args Annotation, Velero Deployment is built with default args", dpa: createTestDpaWith( - map[string]string{ - "oadp.openshift.io/unsupported-velero-server-args": "", - }, + map[string]string{"oadp.openshift.io/unsupported-velero-server-args": ""}, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{}, }, }, ), - clientObjects: []client.Object{ - &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Name: "unsupported-server-args-cm", - Namespace: testNamespaceName, - }, - Data: map[string]string{ - "unsupported-arg": "value1", - "unsupported-bool-arg": "True", - }, - }, - }, veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, }, - }, + }), }, { - name: "given valid DPA CR with Unsupported Server Args and user added args, appropriate Velero Deployment is built", + name: "valid DPA CR with Unsupported Server Args and multiple options, Velero Deployment is built with Unsupported Server Args only", dpa: createTestDpaWith( - map[string]string{ - "oadp.openshift.io/unsupported-velero-server-args": "unsupported-server-args-cm", - }, + map[string]string{"oadp.openshift.io/unsupported-velero-server-args": "unsupported-server-args-cm"}, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - Args: &server.Args{ - ServerConfig: server.ServerConfig{ - BackupSyncPeriod: ptr.To(time.Duration(1)), - PodVolumeOperationTimeout: ptr.To(time.Duration(1)), - ResourceTerminatingTimeout: ptr.To(time.Duration(1)), - DefaultBackupTTL: ptr.To(time.Duration(1)), - StoreValidationFrequency: ptr.To(time.Duration(1)), - ItemOperationSyncFrequency: ptr.To(time.Duration(1)), - RepoMaintenanceFrequency: ptr.To(time.Duration(1)), - GarbageCollectionFrequency: ptr.To(time.Duration(1)), - DefaultItemOperationTimeout: ptr.To(time.Duration(1)), - ResourceTimeout: ptr.To(time.Duration(1)), - }, - }, + DisableInformerCache: ptr.To(true), + DefaultSnapshotMoveData: ptr.To(true), + ItemOperationSyncFrequency: "7m", }, }, }, @@ -936,54 +777,17 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, }, veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - "--unsupported-arg=value1", - "--unsupported-bool-arg=true", - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + "--unsupported-arg=value1", + "--unsupported-bool-arg=true", }, - }, + }), }, { - name: "given valid DPA CR with Unsupported Server Args and missing ConfigMap, error is returned", + name: "valid DPA CR with Unsupported Server Args and missing ConfigMap, error is returned", dpa: createTestDpaWith( - map[string]string{ - "oadp.openshift.io/unsupported-velero-server-args": "missing-unsupported-server-args-cm", - }, + map[string]string{"oadp.openshift.io/unsupported-velero-server-args": "missing-unsupported-server-args-cm"}, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{}, @@ -994,1303 +798,253 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { errorMessage: "configmaps \"missing-unsupported-server-args-cm\" not found", }, { - name: "given invalid DPA CR because invalid podConfig label, error is returned", + name: "valid DPA CR with ItemOperationSyncFrequency, Velero Deployment is built with ItemOperationSyncFrequency arg", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - PodConfig: &oadpv1alpha1.PodConfig{ - Labels: map[string]string{ - "component": common.NodeAgent, - }, - }, + ItemOperationSyncFrequency: "5m", }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - errorMessage: "velero deployment template custom label: conflicting key component with value node-agent may not override velero", + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + "--item-operation-sync-frequency=5m", + defaultDisableInformerCache, + }, + }), }, { - name: "given valid DPA CR and ItemOperationSyncFrequency is defined correctly, ItemOperationSyncFrequency is set", + name: "valid DPA CR with multiple options, Velero Deployment is built with multiple Args", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), - ItemOperationSyncFrequency: "5m", + LogLevel: logrus.InfoLevel.String(), + ItemOperationSyncFrequency: "5m", + DefaultItemOperationTimeout: "2h", + DefaultSnapshotMoveData: ptr.To(false), + NoDefaultBackupLocation: true, + DefaultVolumesToFSBackup: ptr.To(true), + DefaultPlugins: []oadpv1alpha1.DefaultPlugin{oadpv1alpha1.DefaultPluginCSI}, }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + "--features=EnableCSI", + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + "--log-level", + logrus.InfoLevel.String(), + "--item-operation-sync-frequency=5m", + "--default-item-operation-timeout=2h", + "--default-snapshot-move-data=false", + "--default-volumes-to-fs-backup=true", + defaultDisableInformerCache, + }, + }), + }, + { + name: "valid DPA CR with SnapshotMovedata false, Velero Deployment is built with SnapshotMovedata false", + dpa: createTestDpaWith( + nil, + oadpv1alpha1.DataProtectionApplicationSpec{ + Configuration: &oadpv1alpha1.ApplicationConfig{ + Velero: &oadpv1alpha1.VeleroConfig{ + DefaultSnapshotMoveData: ptr.To(false), + }, + }, }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), + ), + veleroDeployment: testVeleroDeployment.DeepCopy(), + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + "--default-snapshot-move-data=false", + defaultDisableInformerCache, }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{ - { - Name: "metrics", - ContainerPort: 8085, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - "--item-operation-sync-frequency=5m", - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "plugins", - MountPath: "/plugins", - }, - { - Name: "scratch", - MountPath: "/scratch", - }, - { - Name: "certs", - MountPath: "/etc/ssl/certs", - }, - }, - Env: []corev1.EnvVar{ - { - Name: common.VeleroScratchDirEnvKey, - Value: "/scratch", - }, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - { - Name: common.LDLibraryPathEnvKey, - Value: "/plugins", - }, - { - Name: "OPENSHIFT_IMAGESTREAM_BACKUP", - Value: "true", - }, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, - }, - }, - }, - { - name: "given valid DPA CR and Velero Config is defined correctly, SnapshotMovedata is set to false", - dpa: createTestDpaWith( - nil, - oadpv1alpha1.DataProtectionApplicationSpec{ - Configuration: &oadpv1alpha1.ApplicationConfig{ - Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), - ItemOperationSyncFrequency: "5m", - DefaultItemOperationTimeout: "2h", - DefaultSnapshotMoveData: ptr.To(false), - }, - }, - }, - ), - veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{ - { - Name: "metrics", - ContainerPort: 8085, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - "--item-operation-sync-frequency=5m", - "--default-item-operation-timeout=2h", - "--default-snapshot-move-data=false", - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "plugins", - MountPath: "/plugins", - }, - { - Name: "scratch", - MountPath: "/scratch", - }, - { - Name: "certs", - MountPath: "/etc/ssl/certs", - }, - }, - Env: []corev1.EnvVar{ - { - Name: common.VeleroScratchDirEnvKey, - Value: "/scratch", - }, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - { - Name: common.LDLibraryPathEnvKey, - Value: "/plugins", - }, - { - Name: "OPENSHIFT_IMAGESTREAM_BACKUP", - Value: "true", - }, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, - }, - }, - }, - { - name: "given valid DPA CR and Velero Config is defined correctly, defaultSnapshotMovedata is set to true", - dpa: createTestDpaWith( - nil, - oadpv1alpha1.DataProtectionApplicationSpec{ - Configuration: &oadpv1alpha1.ApplicationConfig{ - Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), - ItemOperationSyncFrequency: "5m", - DefaultItemOperationTimeout: "2h", - DefaultSnapshotMoveData: ptr.To(true), - }, - }, - }, - ), - veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{ - { - Name: "metrics", - ContainerPort: 8085, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - "--item-operation-sync-frequency=5m", - "--default-item-operation-timeout=2h", - "--default-snapshot-move-data=true", - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "plugins", - MountPath: "/plugins", - }, - { - Name: "scratch", - MountPath: "/scratch", - }, - { - Name: "certs", - MountPath: "/etc/ssl/certs", - }, - }, - Env: []corev1.EnvVar{ - { - Name: common.VeleroScratchDirEnvKey, - Value: "/scratch", - }, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - { - Name: common.LDLibraryPathEnvKey, - Value: "/plugins", - }, - { - Name: "OPENSHIFT_IMAGESTREAM_BACKUP", - Value: "true", - }, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, - }, - }, - }, - { - name: "given valid DPA CR and Velero Config is defined correctly, defaultVolumesToFSBackup is set to true", - dpa: createTestDpaWith( - nil, - oadpv1alpha1.DataProtectionApplicationSpec{ - Configuration: &oadpv1alpha1.ApplicationConfig{ - Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), - ItemOperationSyncFrequency: "5m", - DefaultItemOperationTimeout: "2h", - DefaultVolumesToFSBackup: ptr.To(true), - }, - }, - }, - ), - veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{ - { - Name: "metrics", - ContainerPort: 8085, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - "--item-operation-sync-frequency=5m", - "--default-item-operation-timeout=2h", - "--default-volumes-to-fs-backup=true", - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "plugins", - MountPath: "/plugins", - }, - { - Name: "scratch", - MountPath: "/scratch", - }, - { - Name: "certs", - MountPath: "/etc/ssl/certs", - }, - }, - Env: []corev1.EnvVar{ - { - Name: common.VeleroScratchDirEnvKey, - Value: "/scratch", - }, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - { - Name: common.LDLibraryPathEnvKey, - Value: "/plugins", - }, - { - Name: "OPENSHIFT_IMAGESTREAM_BACKUP", - Value: "true", - }, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, - }, - }, + }), }, { - name: "given valid DPA CR and Velero Config is defined correctly, disableInformerCache is nil and default behaviour of false is supplied to velero", + name: "valid DPA CR with SnapshotMovedata true, Velero Deployment is built with SnapshotMovedata true", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), - ItemOperationSyncFrequency: "5m", - DefaultItemOperationTimeout: "2h", - DefaultVolumesToFSBackup: ptr.To(false), + DefaultSnapshotMoveData: ptr.To(true), }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + "--default-snapshot-move-data=true", + defaultDisableInformerCache, }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{ - { - Name: "metrics", - ContainerPort: 8085, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - "--item-operation-sync-frequency=5m", - "--default-item-operation-timeout=2h", - "--default-volumes-to-fs-backup=false", - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "plugins", - MountPath: "/plugins", - }, - { - Name: "scratch", - MountPath: "/scratch", - }, - { - Name: "certs", - MountPath: "/etc/ssl/certs", - }, - }, - Env: []corev1.EnvVar{ - { - Name: common.VeleroScratchDirEnvKey, - Value: "/scratch", - }, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - { - Name: common.LDLibraryPathEnvKey, - Value: "/plugins", - }, - { - Name: "OPENSHIFT_IMAGESTREAM_BACKUP", - Value: "true", - }, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, - }, - }, + }), }, { - name: "given valid DPA CR and Velero Config is defined correctly, disableInformerCache is set to true", + name: "valid DPA CR with DefaultVolumesToFSBackup true, Velero Deployment is built with DefaultVolumesToFSBackup true", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), - ItemOperationSyncFrequency: "5m", - DefaultItemOperationTimeout: "2h", - DefaultVolumesToFSBackup: ptr.To(false), - DisableInformerCache: ptr.To(true), + DefaultVolumesToFSBackup: ptr.To(true), }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{ - { - Name: "metrics", - ContainerPort: 8085, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - "--item-operation-sync-frequency=5m", - "--default-item-operation-timeout=2h", - "--default-volumes-to-fs-backup=false", - "--disable-informer-cache=true", - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "plugins", - MountPath: "/plugins", - }, - { - Name: "scratch", - MountPath: "/scratch", - }, - { - Name: "certs", - MountPath: "/etc/ssl/certs", - }, - }, - Env: []corev1.EnvVar{ - { - Name: common.VeleroScratchDirEnvKey, - Value: "/scratch", - }, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - { - Name: common.LDLibraryPathEnvKey, - Value: "/plugins", - }, - { - Name: "OPENSHIFT_IMAGESTREAM_BACKUP", - Value: "true", - }, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + "--default-volumes-to-fs-backup=true", + defaultDisableInformerCache, }, - }, + }), }, { - name: "given valid DPA CR and Velero Config is defined correctly, disableInformerCache is set to false", + name: "valid DPA CR with DisableInformerCache true, Velero Deployment is built with DisableInformerCache true", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), - ItemOperationSyncFrequency: "5m", - DefaultItemOperationTimeout: "2h", - DefaultVolumesToFSBackup: ptr.To(false), - DisableInformerCache: ptr.To(false), + DisableInformerCache: ptr.To(true), }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{ - { - Name: "metrics", - ContainerPort: 8085, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - "--item-operation-sync-frequency=5m", - "--default-item-operation-timeout=2h", - "--default-volumes-to-fs-backup=false", - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "plugins", - MountPath: "/plugins", - }, - { - Name: "scratch", - MountPath: "/scratch", - }, - { - Name: "certs", - MountPath: "/etc/ssl/certs", - }, - }, - Env: []corev1.EnvVar{ - { - Name: common.VeleroScratchDirEnvKey, - Value: "/scratch", - }, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - { - Name: common.LDLibraryPathEnvKey, - Value: "/plugins", - }, - { - Name: "OPENSHIFT_IMAGESTREAM_BACKUP", - Value: "true", - }, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + "--disable-informer-cache=true", }, - }, + }), }, { - name: "given valid DPA CR and Velero Config is defined correctly, defaultVolumesToFSBackup is set to false", + name: "valid DPA CR with DisableInformerCache false, Velero Deployment is built with DisableInformerCache false", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), - ItemOperationSyncFrequency: "5m", - DefaultItemOperationTimeout: "2h", - DefaultVolumesToFSBackup: ptr.To(false), + DisableInformerCache: ptr.To(false), }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{ - { - Name: "metrics", - ContainerPort: 8085, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - "--item-operation-sync-frequency=5m", - "--default-item-operation-timeout=2h", - "--default-volumes-to-fs-backup=false", - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "plugins", - MountPath: "/plugins", - }, - { - Name: "scratch", - MountPath: "/scratch", - }, - { - Name: "certs", - MountPath: "/etc/ssl/certs", - }, - }, - Env: []corev1.EnvVar{ - { - Name: common.VeleroScratchDirEnvKey, - Value: "/scratch", - }, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - { - Name: common.LDLibraryPathEnvKey, - Value: "/plugins", - }, - { - Name: "OPENSHIFT_IMAGESTREAM_BACKUP", - Value: "true", - }, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, - }, - }, + }), }, { - name: "given valid DPA CR and Velero Config is defined correctly, defaultVolumesToFSBackup is set to false, snapshotMoveData is true", + name: "valid DPA CR with DefaultItemOperationTimeout, Velero Deployment is built with DefaultItemOperationTimeout arg", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), - ItemOperationSyncFrequency: "5m", DefaultItemOperationTimeout: "2h", - DefaultVolumesToFSBackup: ptr.To(false), - DefaultSnapshotMoveData: ptr.To(true), }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + "--default-item-operation-timeout=2h", + defaultDisableInformerCache, }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{ - { - Name: "metrics", - ContainerPort: 8085, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - "--item-operation-sync-frequency=5m", - "--default-item-operation-timeout=2h", - "--default-snapshot-move-data=true", - "--default-volumes-to-fs-backup=false", - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "plugins", - MountPath: "/plugins", - }, - { - Name: "scratch", - MountPath: "/scratch", - }, - { - Name: "certs", - MountPath: "/etc/ssl/certs", - }, - }, - Env: []corev1.EnvVar{ - { - Name: common.VeleroScratchDirEnvKey, - Value: "/scratch", - }, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - { - Name: common.LDLibraryPathEnvKey, - Value: "/plugins", - }, - { - Name: "OPENSHIFT_IMAGESTREAM_BACKUP", - Value: "true", - }, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, - }, - }, + }), }, { - name: "given valid DPA CR and DefaultItemOperationTimeout is defined correctly, DefaultItemOperationTimeout is set", + name: "valid DPA CR with log level, Velero Deployment is built with log level arg", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), - ItemOperationSyncFrequency: "5m", - DefaultItemOperationTimeout: "2h", + LogLevel: logrus.InfoLevel.String(), }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{ - { - Name: "metrics", - ContainerPort: 8085, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - "--item-operation-sync-frequency=5m", - "--default-item-operation-timeout=2h", - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "plugins", - MountPath: "/plugins", - }, - { - Name: "scratch", - MountPath: "/scratch", - }, - { - Name: "certs", - MountPath: "/etc/ssl/certs", - }, - }, - Env: []corev1.EnvVar{ - { - Name: common.VeleroScratchDirEnvKey, - Value: "/scratch", - }, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - { - Name: common.LDLibraryPathEnvKey, - Value: "/plugins", - }, - { - Name: "OPENSHIFT_IMAGESTREAM_BACKUP", - Value: "true", - }, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + "--log-level", + logrus.InfoLevel.String(), + defaultDisableInformerCache, }, - }, + }), }, { - name: "given valid DPA CR and log level is defined correctly, log level is set", + name: "invalid DPA CR with log level, error is returned", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), + LogLevel: logrus.InfoLevel.String() + "typo", }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, - }, - }, + errorMessage: "invalid log level infotypo, use: trace, debug, info, warning, error, fatal, or panic", }, { - name: "given valid DPA CR and ResourceTimeout is defined correctly, ResourceTimeout is set", + name: "valid DPA CR with ResourceTimeout, Velero Deployment is built with ResourceTimeout arg", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String(), ResourceTimeout: "5m", }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + "--resource-timeout=5m", + defaultDisableInformerCache, }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: veleroDeploymentMatchLabels, - }, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{ - { - Name: "metrics", - ContainerPort: 8085, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - "--log-level", - logrus.InfoLevel.String(), - "--resource-timeout=5m", - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "plugins", - MountPath: "/plugins", - }, - { - Name: "scratch", - MountPath: "/scratch", - }, - { - Name: "certs", - MountPath: "/etc/ssl/certs", - }, - }, - Env: []corev1.EnvVar{ - { - Name: common.VeleroScratchDirEnvKey, - Value: "/scratch", - }, - { - Name: common.VeleroNamespaceEnvKey, - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.namespace", - }, - }, - }, - { - Name: common.LDLibraryPathEnvKey, - Value: "/plugins", - }, - { - Name: "OPENSHIFT_IMAGESTREAM_BACKUP", - Value: "true", - }, - }, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, - }, - }, + }), }, { - name: "given valid DPA CR and log level is defined incorrectly error is returned", - dpa: createTestDpaWith( - nil, - oadpv1alpha1.DataProtectionApplicationSpec{ - Configuration: &oadpv1alpha1.ApplicationConfig{ - Velero: &oadpv1alpha1.VeleroConfig{ - LogLevel: logrus.InfoLevel.String() + "typo", - }, - }, - }, - ), - veleroDeployment: testVeleroDeployment.DeepCopy(), - errorMessage: "invalid log level infotypo, use: trace, debug, info, warning, error, fatal, or panic", - }, - { - name: "given valid DPA CR, velero deployment resource customization", + name: "valid DPA CR with Velero resource allocations, Velero Deployment is built with resource allocations", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -2306,6 +1060,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { corev1.ResourceCPU: resource.MustParse("1"), corev1.ResourceMemory: resource.MustParse("256Mi"), }, + // TODO storage and ephemeral-storage }, }, }, @@ -2313,197 +1068,24 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("2"), - corev1.ResourceMemory: resource.MustParse("700Mi"), - }, - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("1"), - corev1.ResourceMemory: resource.MustParse("256Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + resourceLimits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("2"), + corev1.ResourceMemory: resource.MustParse("700Mi"), }, - }, - }, - { - name: "given valid DPA CR, velero deployment resource customization only cpu limit", - dpa: createTestDpaWith( - nil, - oadpv1alpha1.DataProtectionApplicationSpec{ - Configuration: &oadpv1alpha1.ApplicationConfig{ - Velero: &oadpv1alpha1.VeleroConfig{ - PodConfig: &oadpv1alpha1.PodConfig{ - ResourceAllocations: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("2"), - }, - }, - }, - }, - }, - }, - ), - veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("2"), - }, - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, - }, - }, - }, - { - name: "given valid DPA CR, velero deployment resource customization only cpu request", - dpa: createTestDpaWith( - nil, - oadpv1alpha1.DataProtectionApplicationSpec{ - Configuration: &oadpv1alpha1.ApplicationConfig{ - Velero: &oadpv1alpha1.VeleroConfig{ - PodConfig: &oadpv1alpha1.PodConfig{ - ResourceAllocations: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("2"), - }, - }, - }, - }, - }, - }, - ), - veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("2"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + resourceRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("1"), + corev1.ResourceMemory: resource.MustParse("256Mi"), }, - }, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, { - name: "given valid DPA CR, velero deployment resource customization only memory request", + name: "valid DPA CR with Velero cpu limit, Velero Deployment is built with cpu limit", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -2511,8 +1093,8 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { Velero: &oadpv1alpha1.VeleroConfig{ PodConfig: &oadpv1alpha1.PodConfig{ ResourceAllocations: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceMemory: resource.MustParse("256Mi"), + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("2"), }, }, }, @@ -2521,56 +1103,19 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("256Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + resourceLimits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("2"), }, - }, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, { - name: "given valid DPA CR, velero deployment resource customization only memory limit", + name: "valid DPA CR with Velero cpu request, Velero Deployment is built with cpu request", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -2578,8 +1123,8 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { Velero: &oadpv1alpha1.VeleroConfig{ PodConfig: &oadpv1alpha1.PodConfig{ ResourceAllocations: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceMemory: resource.MustParse("128Mi"), + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("2"), }, }, }, @@ -2588,59 +1133,20 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("128Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + resourceRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("2"), + corev1.ResourceMemory: resource.MustParse("128Mi"), }, - }, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, { - name: "given valid DPA CR, velero deployment tolerations", + name: "valid DPA CR with Velero memory limit, Velero Deployment is built with memory limit", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -2649,20 +1155,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { PodConfig: &oadpv1alpha1.PodConfig{ ResourceAllocations: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("2"), - corev1.ResourceMemory: resource.MustParse("700Mi"), - }, - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("1"), - corev1.ResourceMemory: resource.MustParse("256Mi"), - }, - }, - Tolerations: []corev1.Toleration{ - { - Key: "key1", - Operator: "Equal", - Value: "value1", - Effect: "NoSchedule", + corev1.ResourceMemory: resource.MustParse("128Mi"), }, }, }, @@ -2671,71 +1164,19 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: veleroDeploymentMatchLabels, - Annotations: veleroPodAnnotations, - }, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Tolerations: []corev1.Toleration{ - { - Key: "key1", - Operator: "Equal", - Value: "value1", - Effect: "NoSchedule", - }, - }, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("2"), - corev1.ResourceMemory: resource.MustParse("700Mi"), - }, - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("1"), - corev1.ResourceMemory: resource.MustParse("256Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + resourceLimits: corev1.ResourceList{ + corev1.ResourceMemory: resource.MustParse("128Mi"), }, - }, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, { - name: "given valid DPA CR, velero deployment nodeselector", + name: "valid DPA CR with Velero memory request, Velero Deployment is built with memory request", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -2743,231 +1184,93 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { Velero: &oadpv1alpha1.VeleroConfig{ PodConfig: &oadpv1alpha1.PodConfig{ ResourceAllocations: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("2"), - corev1.ResourceMemory: resource.MustParse("700Mi"), - }, Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("1"), corev1.ResourceMemory: resource.MustParse("256Mi"), }, }, - NodeSelector: map[string]string{ - "foo": "bar", - }, }, }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: veleroDeploymentMatchLabels, - Annotations: veleroPodAnnotations, - }, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - NodeSelector: map[string]string{ - "foo": "bar", - }, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("2"), - corev1.ResourceMemory: resource.MustParse("700Mi"), - }, - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("1"), - corev1.ResourceMemory: resource.MustParse("256Mi"), - }, - }, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + resourceRequests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("256Mi"), }, - }, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, + // TODO storage and ephemeral-storage specific tests { - name: "given valid DPA CR, appropriate velero deployment is build with aws plugin specific specs", + name: "valid DPA CR with Velero tolerations, Velero Deployment is built with tolerations", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - DefaultPlugins: []oadpv1alpha1.DefaultPlugin{ - oadpv1alpha1.DefaultPluginAWS, + PodConfig: &oadpv1alpha1.PodConfig{ + Tolerations: []corev1.Toleration{ + { + Key: "key1", + Operator: "Equal", + Value: "value1", + Effect: "NoSchedule", + }, + }, }, }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: append(baseVolumeMounts, []corev1.VolumeMount{ - {Name: "cloud-credentials", MountPath: "/credentials"}, - }...), - Env: append(baseEnvVars, []corev1.EnvVar{ - {Name: common.AWSSharedCredentialsFileEnvKey, Value: "/credentials/cloud"}, - }...), - }, - }, - Volumes: append(baseVolumes, []corev1.Volume{{ - Name: "cloud-credentials", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "cloud-credentials", - }, - }, - }}...), - InitContainers: []corev1.Container{ - pluginContainer(common.VeleroPluginForAWS, common.AWSPluginImage), - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + toleration: []corev1.Toleration{ + { + Key: "key1", + Operator: "Equal", + Value: "value1", + Effect: "NoSchedule", }, }, - }, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, { - name: "given valid DPA CR, appropriate velero deployment is build with aws and kubevirt plugin specific specs", + name: "valid DPA CR with Velero nodeselector, Velero Deployment is built with nodeselector", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ Velero: &oadpv1alpha1.VeleroConfig{ - DefaultPlugins: []oadpv1alpha1.DefaultPlugin{ - oadpv1alpha1.DefaultPluginAWS, - oadpv1alpha1.DefaultPluginKubeVirt, + PodConfig: &oadpv1alpha1.PodConfig{ + NodeSelector: map[string]string{"foo": "bar"}, }, }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - {Name: "plugins", MountPath: "/plugins"}, - {Name: "scratch", MountPath: "/scratch"}, - {Name: "certs", MountPath: "/etc/ssl/certs"}, - {Name: "cloud-credentials", MountPath: "/credentials"}, - }, - Env: append(baseEnvVars, []corev1.EnvVar{ - {Name: common.AWSSharedCredentialsFileEnvKey, Value: "/credentials/cloud"}, - }...), - }, - }, - Volumes: append(baseVolumes, []corev1.Volume{{ - Name: "cloud-credentials", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "cloud-credentials", - }, - }, - }}...), - InitContainers: []corev1.Container{ - pluginContainer(common.VeleroPluginForAWS, common.AWSPluginImage), - pluginContainer(common.KubeVirtPlugin, common.KubeVirtPluginImage), - }, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + nodeSelector: map[string]string{"foo": "bar"}, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, }, - }, + }), }, { - name: "given valid DPA CR with annotations, appropriate velero deployment is build with aws plugin specific specs", + name: "valid DPA CR with aws plugin, Velero Deployment is built with aws plugin", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -2978,80 +1281,27 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, }, }, - PodAnnotations: map[string]string{ - "test-annotation": "awesome annotation", - }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: veleroDeploymentMatchLabels, - Annotations: common.AppendTTMapAsCopy(veleroPodAnnotations, - map[string]string{ - "test-annotation": "awesome annotation", - }, - ), - }, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - {Name: "plugins", MountPath: "/plugins"}, - {Name: "scratch", MountPath: "/scratch"}, - {Name: "certs", MountPath: "/etc/ssl/certs"}, - {Name: "cloud-credentials", MountPath: "/credentials"}, - }, - Env: append(baseEnvVars, []corev1.EnvVar{ - {Name: common.AWSSharedCredentialsFileEnvKey, Value: "/credentials/cloud"}, - }...), - }, - }, - Volumes: append(baseVolumes, []corev1.Volume{{ - Name: "cloud-credentials", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "cloud-credentials", - }, - }, - }}...), - InitContainers: []corev1.Container{ - pluginContainer(common.VeleroPluginForAWS, common.AWSPluginImage), - }, - }, - }, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + initContainers: []corev1.Container{pluginContainer(common.VeleroPluginForAWS, common.AWSPluginImage)}, + volumes: []corev1.Volume{deploymentVolumeSecret("cloud-credentials")}, + volumeMounts: []corev1.VolumeMount{ + {Name: "cloud-credentials", MountPath: "/credentials"}, + }, + env: append(baseEnvVars, []corev1.EnvVar{ + {Name: common.AWSSharedCredentialsFileEnvKey, Value: "/credentials/cloud"}, + }...), + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, { - name: "given valid DPA CR with PodDNS Policy/Config, annotations, appropriate velero deployment is build with aws plugin specific specs", + name: "valid DPA CR with aws and kubevirt plugin, Velero Deployment is built with aws and kubevirt plugin", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -3059,106 +1309,34 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { Velero: &oadpv1alpha1.VeleroConfig{ DefaultPlugins: []oadpv1alpha1.DefaultPlugin{ oadpv1alpha1.DefaultPluginAWS, - }, - }, - }, - PodAnnotations: map[string]string{ - "test-annotation": "awesome annotation", - }, - PodDnsPolicy: "None", - PodDnsConfig: corev1.PodDNSConfig{ - Nameservers: []string{ - "1.1.1.1", - "8.8.8.8", - }, - Options: []corev1.PodDNSConfigOption{ - {Name: "ndots", Value: ptr.To("2")}, - { - Name: "edns0", + oadpv1alpha1.DefaultPluginKubeVirt, }, }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: veleroDeploymentMatchLabels, - Annotations: common.AppendTTMapAsCopy(veleroPodAnnotations, - map[string]string{ - "test-annotation": "awesome annotation", - }, - ), - }, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - DNSPolicy: "None", - DNSConfig: &corev1.PodDNSConfig{ - Nameservers: []string{"1.1.1.1", "8.8.8.8"}, - Options: []corev1.PodDNSConfigOption{ - {Name: "ndots", Value: ptr.To("2")}, - { - Name: "edns0", - }, - }, - }, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - {Name: "plugins", MountPath: "/plugins"}, - {Name: "scratch", MountPath: "/scratch"}, - {Name: "certs", MountPath: "/etc/ssl/certs"}, - {Name: "cloud-credentials", MountPath: "/credentials"}, - }, - Env: append(baseEnvVars, []corev1.EnvVar{ - {Name: common.AWSSharedCredentialsFileEnvKey, Value: "/credentials/cloud"}, - }...), - }, - }, - Volumes: append(baseVolumes, []corev1.Volume{{ - Name: "cloud-credentials", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "cloud-credentials", - }, - }, - }}...), - InitContainers: []corev1.Container{ - pluginContainer(common.VeleroPluginForAWS, common.AWSPluginImage), - }, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + initContainers: []corev1.Container{ + pluginContainer(common.VeleroPluginForAWS, common.AWSPluginImage), + pluginContainer(common.KubeVirtPlugin, common.KubeVirtPluginImage), }, - }, + volumes: []corev1.Volume{deploymentVolumeSecret("cloud-credentials")}, + volumeMounts: []corev1.VolumeMount{ + {Name: "cloud-credentials", MountPath: "/credentials"}, + }, + env: append(baseEnvVars, []corev1.EnvVar{ + {Name: common.AWSSharedCredentialsFileEnvKey, Value: "/credentials/cloud"}, + }...), + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, { - name: "given valid Velero CR with with aws plugin from bucket", + name: "valid DPA CR with aws plugin from CloudStorage, Velero Deployment is built with aws plugin", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -3201,145 +1379,84 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, }, veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - defaultFileSystemBackupTimeout, - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: []corev1.VolumeMount{ - {Name: "plugins", MountPath: "/plugins"}, - {Name: "scratch", MountPath: "/scratch"}, - {Name: "certs", MountPath: "/etc/ssl/certs"}, - { - Name: "bound-sa-token", - MountPath: "/var/run/secrets/openshift/serviceaccount", - ReadOnly: true, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + initContainers: []corev1.Container{pluginContainer(common.VeleroPluginForAWS, common.AWSPluginImage)}, + volumes: []corev1.Volume{ + { + Name: "bound-sa-token", + VolumeSource: corev1.VolumeSource{ + Projected: &corev1.ProjectedVolumeSource{ + DefaultMode: ptr.To(int32(420)), + Sources: []corev1.VolumeProjection{ + { + ServiceAccountToken: &corev1.ServiceAccountTokenProjection{ + Audience: "openshift", + ExpirationSeconds: ptr.To(int64(3600)), + Path: "token", }, }, - Env: baseEnvVars, }, }, - Volumes: append(baseVolumes, []corev1.Volume{ - { - Name: "bound-sa-token", - VolumeSource: corev1.VolumeSource{ - Projected: &corev1.ProjectedVolumeSource{ - DefaultMode: ptr.To(int32(420)), - Sources: []corev1.VolumeProjection{ - { - ServiceAccountToken: &corev1.ServiceAccountTokenProjection{ - Audience: "openshift", - ExpirationSeconds: ptr.To(int64(3600)), - Path: "token", - }, - }, - }, - }, - }, - }}...), - InitContainers: []corev1.Container{ - pluginContainer(common.VeleroPluginForAWS, common.AWSPluginImage), - }, }, }, }, - }, + volumeMounts: []corev1.VolumeMount{ + {Name: "bound-sa-token", MountPath: "/var/run/secrets/openshift/serviceaccount", ReadOnly: true}, + }, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, { - name: "velero with custom metrics address", + name: "valid DPA CR with PodDNS Policy/Config, Velero Deployment is built with DNS Policy/Config", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ Configuration: &oadpv1alpha1.ApplicationConfig{ - Velero: &oadpv1alpha1.VeleroConfig{ - Args: &server.Args{ - ServerConfig: server.ServerConfig{ - MetricsAddress: ":" + strconv.Itoa(int(argsMetricsPortTest)), - }, + Velero: &oadpv1alpha1.VeleroConfig{}, + }, + PodDnsPolicy: "None", + PodDnsConfig: corev1.PodDNSConfig{ + Nameservers: []string{ + "1.1.1.1", + "8.8.8.8", + }, + Options: []corev1.PodDNSConfigOption{ + {Name: "ndots", Value: ptr.To("2")}, + { + Name: "edns0", }, }, }, }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: veleroDeploymentMatchLabels, - Annotations: common.AppendTTMapAsCopy(veleroPodAnnotations, map[string]string{ - "prometheus.io/port": strconv.Itoa(int(argsMetricsPortTest)), - }), - }, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: argsMetricsPortTest}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - "--metrics-address=:" + strconv.Itoa(int(argsMetricsPortTest)), - "--fs-backup-timeout=4h0m0s", - defaultRestoreResourcePriorities, - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + dnsPolicy: corev1.DNSNone, + dnsConfig: &corev1.PodDNSConfig{ + Nameservers: []string{ + "1.1.1.1", + "8.8.8.8", + }, + Options: []corev1.PodDNSConfigOption{ + {Name: "ndots", Value: ptr.To("2")}, + { + Name: "edns0", }, }, }, - }, + args: []string{ + defaultFileSystemBackupTimeout, + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), }, { - name: "Override restore resource priorities", + name: "valid DPA CR with metrics address, Velero Deployment is built with metrics address", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -3347,7 +1464,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { Velero: &oadpv1alpha1.VeleroConfig{ Args: &server.Args{ ServerConfig: server.ServerConfig{ - RestoreResourcePriorities: "securitycontextconstraints,test", + MetricsAddress: fmt.Sprintf(":%v", argsMetricsPortTest), }, }, }, @@ -3355,51 +1472,43 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - "--fs-backup-timeout=4h0m0s", - "--restore-resource-priorities=securitycontextconstraints,test", - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + metricsPort: argsMetricsPortTest, + args: []string{ + fmt.Sprintf("--metrics-address=:%v", argsMetricsPortTest), + "--fs-backup-timeout=4h0m0s", + defaultRestoreResourcePriorities, + defaultDisableInformerCache, + }, + }), + }, + { + name: "valid DPA CR with restore resource priorities, Velero Deployment is built with restore resource priorities", + dpa: createTestDpaWith( + nil, + oadpv1alpha1.DataProtectionApplicationSpec{ + Configuration: &oadpv1alpha1.ApplicationConfig{ + Velero: &oadpv1alpha1.VeleroConfig{ + Args: &server.Args{ + ServerConfig: server.ServerConfig{ + RestoreResourcePriorities: "securitycontextconstraints,test", }, }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, }, }, }, - }, + ), + veleroDeployment: testVeleroDeployment.DeepCopy(), + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + "--fs-backup-timeout=4h0m0s", + "--restore-resource-priorities=securitycontextconstraints,test", + defaultDisableInformerCache, + }, + }), }, { - name: "Check values of time fields in Velero args", + name: "valid DPA CR with Velero time fields, Velero Deployment is built with time fields args", dpa: createTestDpaWith( nil, oadpv1alpha1.DataProtectionApplicationSpec{ @@ -3424,57 +1533,22 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, ), veleroDeployment: testVeleroDeployment.DeepCopy(), - wantVeleroDeployment: &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: testVeleroDeploymentName, - Namespace: testNamespaceName, - Labels: veleroDeploymentLabel, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", - APIVersion: appsv1.SchemeGroupVersion.String(), - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{MatchLabels: veleroDeploymentMatchLabels}, - Replicas: ptr.To(int32(1)), - Template: corev1.PodTemplateSpec{ - ObjectMeta: veleroPodObjectMeta, - Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyAlways, - ServiceAccountName: common.Velero, - Containers: []corev1.Container{ - { - Name: common.Velero, - Image: common.VeleroImage, - ImagePullPolicy: corev1.PullAlways, - Ports: []corev1.ContainerPort{{Name: "metrics", ContainerPort: 8085}}, - Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi")}}, - Command: []string{"/velero"}, - Args: []string{ - "server", - "--backup-sync-period=1ns", - "--default-backup-ttl=1ns", - "--default-item-operation-timeout=1ns", - "--resource-timeout=1ns", - "--default-repo-maintain-frequency=1ns", - "--garbage-collection-frequency=1ns", - "--fs-backup-timeout=1ns", - "--item-operation-sync-frequency=1ns", - defaultRestoreResourcePriorities, - "--store-validation-frequency=1ns", - "--terminating-resource-timeout=1ns", - defaultDisableInformerCache, - }, - VolumeMounts: baseVolumeMounts, - Env: baseEnvVars, - }, - }, - Volumes: baseVolumes, - InitContainers: []corev1.Container{}, - }, - }, - }, - }, + wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{ + args: []string{ + "--backup-sync-period=1ns", + "--default-backup-ttl=1ns", + "--default-item-operation-timeout=1ns", + "--resource-timeout=1ns", + "--default-repo-maintain-frequency=1ns", + "--garbage-collection-frequency=1ns", + "--fs-backup-timeout=1ns", + "--item-operation-sync-frequency=1ns", + defaultRestoreResourcePriorities, + "--store-validation-frequency=1ns", + "--terminating-resource-timeout=1ns", + defaultDisableInformerCache, + }, + }), }, } for _, tt := range tests { @@ -3496,27 +1570,8 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { t.Errorf("buildVeleroDeployment() error = %v, errorMessage %v", err, tt.errorMessage) } } else { - setPodTemplateSpecDefaults(&tt.wantVeleroDeployment.Spec.Template) - if len(tt.wantVeleroDeployment.Spec.Template.Spec.Containers) > 0 { - setContainerDefaults(&tt.wantVeleroDeployment.Spec.Template.Spec.Containers[0]) - } - if tt.wantVeleroDeployment.Spec.Strategy.Type == "" { - tt.wantVeleroDeployment.Spec.Strategy.Type = appsv1.RollingUpdateDeploymentStrategyType - } - if tt.wantVeleroDeployment.Spec.Strategy.RollingUpdate == nil { - tt.wantVeleroDeployment.Spec.Strategy.RollingUpdate = &appsv1.RollingUpdateDeployment{ - MaxUnavailable: &intstr.IntOrString{Type: intstr.String, StrVal: "25%"}, - MaxSurge: &intstr.IntOrString{Type: intstr.String, StrVal: "25%"}, - } - } - if tt.wantVeleroDeployment.Spec.RevisionHistoryLimit == nil { - tt.wantVeleroDeployment.Spec.RevisionHistoryLimit = ptr.To(int32(10)) - } - if tt.wantVeleroDeployment.Spec.ProgressDeadlineSeconds == nil { - tt.wantVeleroDeployment.Spec.ProgressDeadlineSeconds = ptr.To(int32(600)) - } if !reflect.DeepEqual(tt.wantVeleroDeployment, tt.veleroDeployment) { - t.Errorf("expected velero deployment spec to be \n%#v, got \n%#v\nDIFF:%v", tt.wantVeleroDeployment, tt.veleroDeployment, cmp.Diff(tt.wantVeleroDeployment, tt.veleroDeployment)) + t.Errorf("expected velero deployment diffs.\nDIFF:%v", cmp.Diff(tt.wantVeleroDeployment, tt.veleroDeployment)) } } })