diff --git a/controllers/validator.go b/controllers/validator.go index 075312c5b8..66a4ce316d 100644 --- a/controllers/validator.go +++ b/controllers/validator.go @@ -3,12 +3,10 @@ package controllers import ( "errors" "fmt" - "strings" "github.com/go-logr/logr" oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1" "github.com/openshift/oadp-operator/pkg/credentials" - "k8s.io/apimachinery/pkg/types" ) func (r *DPAReconciler) ValidateDataProtectionCR(log logr.Logger) (bool, error) { @@ -57,35 +55,9 @@ func (r *DPAReconciler) ValidateVeleroPlugins(log logr.Logger) (bool, error) { return false, err } - providerNeedsDefaultCreds := map[string]bool{} - hasCloudStorage := false - - for _, bsl := range dpa.Spec.BackupLocations { - if bsl.Velero != nil && bsl.Velero.Credential == nil { - providerNeedsDefaultCreds[strings.TrimPrefix(bsl.Velero.Provider, "velero.io/")] = true - } - if bsl.CloudStorage != nil { - hasCloudStorage = true - if bsl.CloudStorage.Credential == nil { - cloudStroage := oadpv1alpha1.CloudStorage{} - err := r.Get(r.Context, types.NamespacedName{Name: bsl.CloudStorage.CloudStorageRef.Name, Namespace: dpa.Namespace}, &cloudStroage) - if err != nil { - return false, err - } - providerNeedsDefaultCreds[string(cloudStroage.Spec.Provider)] = true - } - } - } - - for _, vsl := range dpa.Spec.SnapshotLocations { - if vsl.Velero != nil { - // To handle the case where we want to manually hand the credentials for a cloud storage created - // Bucket credententials via configuration. Only AWS is supported - provider := strings.TrimPrefix(vsl.Velero.Provider, "velero.io") - if provider != string(oadpv1alpha1.AWSBucketProvider) { - providerNeedsDefaultCreds[provider] = true - } - } + providerNeedsDefaultCreds, hasCloudStorage, err := r.noDefaultCredentials(dpa) + if err != nil { + return false, err } var defaultPlugin oadpv1alpha1.DefaultPlugin diff --git a/controllers/velero.go b/controllers/velero.go index 8ac665eace..3652ab3cc4 100644 --- a/controllers/velero.go +++ b/controllers/velero.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "reflect" + "strings" "github.com/openshift/oadp-operator/pkg/credentials" "github.com/operator-framework/operator-lib/proxy" @@ -468,7 +469,12 @@ func (r *DPAReconciler) customizeVeleroDeployment(dpa *oadpv1alpha1.DataProtecti if err := r.customizeVeleroContainer(dpa, veleroDeployment, veleroContainer, isSTSNeeded); err != nil { return err } - return credentials.AppendPluginSpecificSpecs(dpa, veleroDeployment, veleroContainer) + + providerNeedsDefaultCreds, hasCloudStorage, err := r.noDefaultCredentials(*dpa) + if err != nil { + return err + } + return credentials.AppendPluginSpecificSpecs(dpa, veleroDeployment, veleroContainer, providerNeedsDefaultCreds, hasCloudStorage) } func (r *DPAReconciler) customizeVeleroContainer(dpa *oadpv1alpha1.DataProtectionApplication, veleroDeployment *appsv1.Deployment, veleroContainer *corev1.Container, isSTSNeeded bool) error { @@ -611,3 +617,39 @@ func (r *DPAReconciler) getResticResourceReqs(dpa *oadpv1alpha1.DataProtectionAp return ResourcesReqs } + +func (r DPAReconciler) noDefaultCredentials(dpa oadpv1alpha1.DataProtectionApplication) (map[string]bool, bool, error) { + providerNeedsDefaultCreds := map[string]bool{} + hasCloudStorage := false + + for _, bsl := range dpa.Spec.BackupLocations { + if bsl.Velero != nil && bsl.Velero.Credential == nil { + providerNeedsDefaultCreds[strings.TrimPrefix(bsl.Velero.Provider, "velero.io/")] = true + } + if bsl.CloudStorage != nil { + hasCloudStorage = true + if bsl.CloudStorage.Credential == nil { + cloudStroage := oadpv1alpha1.CloudStorage{} + err := r.Get(r.Context, types.NamespacedName{Name: bsl.CloudStorage.CloudStorageRef.Name, Namespace: dpa.Namespace}, &cloudStroage) + if err != nil { + return nil, false, err + } + providerNeedsDefaultCreds[string(cloudStroage.Spec.Provider)] = true + } + } + } + + for _, vsl := range dpa.Spec.SnapshotLocations { + if vsl.Velero != nil { + // To handle the case where we want to manually hand the credentials for a cloud storage created + // Bucket credententials via configuration. Only AWS is supported + provider := strings.TrimPrefix(vsl.Velero.Provider, "velero.io") + if provider != string(oadpv1alpha1.AWSBucketProvider) { + providerNeedsDefaultCreds[provider] = true + } + } + } + + return providerNeedsDefaultCreds, hasCloudStorage, nil + +} diff --git a/controllers/velero_test.go b/controllers/velero_test.go index 992476a704..d3264be914 100644 --- a/controllers/velero_test.go +++ b/controllers/velero_test.go @@ -40,899 +40,899 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { wantVeleroDeployment *appsv1.Deployment clientObjects []client.Object }{ - // { - // name: "DPA CR is nil", - // veleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // }, - // }, - // dpa: nil, - // wantErr: true, - // wantVeleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // }, - // }, - // }, + { + name: "DPA CR is nil", + veleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + }, + }, + dpa: nil, + wantErr: true, + wantVeleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + }, + }, + }, - // { - // name: "Velero Deployment is nil", - // veleroDeployment: nil, - // dpa: &oadpv1alpha1.DataProtectionApplication{}, - // wantErr: true, - // wantVeleroDeployment: nil, - // }, - // { - // name: "given valid DPA CR, appropriate Velero Deployment is built", - // veleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // }, - // }, - // dpa: &oadpv1alpha1.DataProtectionApplication{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-Velero-CR", - // Namespace: "test-ns", - // }, - // Spec: oadpv1alpha1.DataProtectionApplicationSpec{ - // Configuration: &oadpv1alpha1.ApplicationConfig{ - // Velero: &oadpv1alpha1.VeleroConfig{}, - // }, - // }, - // }, - // wantErr: false, - // wantVeleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // Labels: map[string]string{ - // "app.kubernetes.io/name": common.Velero, - // "app.kubernetes.io/instance": "test-Velero-CR", - // "app.kubernetes.io/managed-by": common.OADPOperator, - // "app.kubernetes.io/component": Server, - // oadpv1alpha1.OadpOperatorLabel: "True", - // }, - // }, - // TypeMeta: metav1.TypeMeta{ - // Kind: "Deployment", - // APIVersion: appsv1.SchemeGroupVersion.String(), - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // Replicas: pointer.Int32(1), - // Template: corev1.PodTemplateSpec{ - // ObjectMeta: metav1.ObjectMeta{ - // Labels: veleroLabelSelector.MatchLabels, - // Annotations: map[string]string{ - // "prometheus.io/scrape": "true", - // "prometheus.io/port": "8085", - // "prometheus.io/path": "/metrics", - // }, - // }, - // 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("1"), - // corev1.ResourceMemory: resource.MustParse("512Mi"), - // }, - // Requests: corev1.ResourceList{ - // corev1.ResourceCPU: resource.MustParse("500m"), - // corev1.ResourceMemory: resource.MustParse("128Mi"), - // }, - // }, - // Command: []string{"/velero"}, - // Args: []string{ - // "server", - // "--restic-timeout=1h", - // }, - // 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", - // }, - // }, - // }, - // }, - // Volumes: []corev1.Volume{ - // { - // Name: "plugins", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "scratch", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "certs", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // }, - // InitContainers: []corev1.Container{}, - // }, - // }, - // }, - // }, - // }, - // { - // name: "given valid DPA CR, velero deployment resource customization", - // veleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // }, - // TypeMeta: metav1.TypeMeta{ - // Kind: "Deployment", - // APIVersion: appsv1.SchemeGroupVersion.String(), - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // }, - // }, - // dpa: &oadpv1alpha1.DataProtectionApplication{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-Velero-CR", - // Namespace: "test-ns", - // }, - // Spec: oadpv1alpha1.DataProtectionApplicationSpec{ - // Configuration: &oadpv1alpha1.ApplicationConfig{ - // 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"), - // }, - // }, - // }, - // }, - // }, - // }, - // }, - // wantErr: false, - // wantVeleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // Labels: map[string]string{ - // "app.kubernetes.io/name": common.Velero, - // "app.kubernetes.io/instance": "test-Velero-CR", - // "app.kubernetes.io/managed-by": common.OADPOperator, - // "app.kubernetes.io/component": Server, - // oadpv1alpha1.OadpOperatorLabel: "True", - // }, - // }, - // TypeMeta: metav1.TypeMeta{ - // Kind: "Deployment", - // APIVersion: appsv1.SchemeGroupVersion.String(), - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // Replicas: pointer.Int32(1), - // Template: corev1.PodTemplateSpec{ - // ObjectMeta: metav1.ObjectMeta{ - // Labels: veleroLabelSelector.MatchLabels, - // Annotations: map[string]string{ - // "prometheus.io/scrape": "true", - // "prometheus.io/port": "8085", - // "prometheus.io/path": "/metrics", - // }, - // }, - // 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", - // "--restic-timeout=1h", - // }, - // 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", - // }, - // }, - // }, - // }, - // Volumes: []corev1.Volume{ - // { - // Name: "plugins", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "scratch", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "certs", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // }, - // InitContainers: []corev1.Container{}, - // }, - // }, - // }, - // }, - // }, - // { - // name: "given valid DPA CR, appropriate velero deployment is build with aws plugin specific specs", - // veleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // }, - // }, - // dpa: &oadpv1alpha1.DataProtectionApplication{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-Velero-CR", - // Namespace: "test-ns", - // }, - // Spec: oadpv1alpha1.DataProtectionApplicationSpec{ - // Configuration: &oadpv1alpha1.ApplicationConfig{ - // Velero: &oadpv1alpha1.VeleroConfig{ - // DefaultPlugins: []oadpv1alpha1.DefaultPlugin{ - // oadpv1alpha1.DefaultPluginAWS, - // }, - // }, - // }, - // }, - // }, - // wantErr: false, - // wantVeleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // Labels: map[string]string{ - // "app.kubernetes.io/name": common.Velero, - // "app.kubernetes.io/instance": "test-Velero-CR", - // "app.kubernetes.io/managed-by": common.OADPOperator, - // "app.kubernetes.io/component": Server, - // oadpv1alpha1.OadpOperatorLabel: "True", - // }, - // }, - // TypeMeta: metav1.TypeMeta{ - // Kind: "Deployment", - // APIVersion: appsv1.SchemeGroupVersion.String(), - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // Replicas: pointer.Int32(1), - // Template: corev1.PodTemplateSpec{ - // ObjectMeta: metav1.ObjectMeta{ - // Labels: veleroLabelSelector.MatchLabels, - // Annotations: map[string]string{ - // "prometheus.io/scrape": "true", - // "prometheus.io/port": "8085", - // "prometheus.io/path": "/metrics", - // }, - // }, - // 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("1"), - // corev1.ResourceMemory: resource.MustParse("512Mi"), - // }, - // Requests: corev1.ResourceList{ - // corev1.ResourceCPU: resource.MustParse("500m"), - // corev1.ResourceMemory: resource.MustParse("128Mi"), - // }, - // }, - // Command: []string{"/velero"}, - // Args: []string{ - // "server", - // "--restic-timeout=1h", - // }, - // VolumeMounts: []corev1.VolumeMount{ - // { - // Name: "plugins", - // MountPath: "/plugins", - // }, - // { - // Name: "scratch", - // MountPath: "/scratch", - // }, - // { - // Name: "certs", - // MountPath: "/etc/ssl/certs", - // }, - // { - // Name: "cloud-credentials", - // MountPath: "/credentials", - // }, - // }, - // 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: common.AWSSharedCredentialsFileEnvKey, - // Value: "/credentials/cloud", - // }, - // }, - // }, - // }, - // Volumes: []corev1.Volume{ - // { - // Name: "plugins", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "scratch", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "certs", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "cloud-credentials", - // VolumeSource: corev1.VolumeSource{ - // Secret: &corev1.SecretVolumeSource{ - // SecretName: "cloud-credentials", - // }, - // }, - // }, - // }, - // InitContainers: []corev1.Container{ - // { - // Image: common.AWSPluginImage, - // Name: common.VeleroPluginForAWS, - // ImagePullPolicy: corev1.PullAlways, - // Resources: corev1.ResourceRequirements{}, - // TerminationMessagePath: "/dev/termination-log", - // TerminationMessagePolicy: "File", - // VolumeMounts: []corev1.VolumeMount{ - // { - // MountPath: "/target", - // Name: "plugins", - // }, - // }, - // }, - // }, - // }, - // }, - // }, - // }, - // }, - // { - // name: "given valid DPA CR with annotations, appropriate velero deployment is build with aws plugin specific specs", - // veleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // }, - // }, - // dpa: &oadpv1alpha1.DataProtectionApplication{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-Velero-CR", - // Namespace: "test-ns", - // }, - // Spec: oadpv1alpha1.DataProtectionApplicationSpec{ - // Configuration: &oadpv1alpha1.ApplicationConfig{ - // Velero: &oadpv1alpha1.VeleroConfig{ - // DefaultPlugins: []oadpv1alpha1.DefaultPlugin{ - // oadpv1alpha1.DefaultPluginAWS, - // }, - // }, - // }, - // PodAnnotations: map[string]string{ - // "test-annotation": "awesome annotation", - // }, - // }, - // }, - // wantErr: false, - // wantVeleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // Labels: map[string]string{ - // "app.kubernetes.io/name": common.Velero, - // "app.kubernetes.io/instance": "test-Velero-CR", - // "app.kubernetes.io/managed-by": common.OADPOperator, - // "app.kubernetes.io/component": Server, - // oadpv1alpha1.OadpOperatorLabel: "True", - // }, - // }, - // TypeMeta: metav1.TypeMeta{ - // Kind: "Deployment", - // APIVersion: appsv1.SchemeGroupVersion.String(), - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // Replicas: pointer.Int32(1), - // Template: corev1.PodTemplateSpec{ - // ObjectMeta: metav1.ObjectMeta{ - // Labels: veleroLabelSelector.MatchLabels, - // Annotations: map[string]string{ - // "prometheus.io/scrape": "true", - // "prometheus.io/port": "8085", - // "prometheus.io/path": "/metrics", - // "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{ - // Limits: corev1.ResourceList{ - // corev1.ResourceCPU: resource.MustParse("1"), - // corev1.ResourceMemory: resource.MustParse("512Mi"), - // }, - // Requests: corev1.ResourceList{ - // corev1.ResourceCPU: resource.MustParse("500m"), - // corev1.ResourceMemory: resource.MustParse("128Mi"), - // }, - // }, - // Command: []string{"/velero"}, - // Args: []string{ - // "server", - // "--restic-timeout=1h", - // }, - // VolumeMounts: []corev1.VolumeMount{ - // { - // Name: "plugins", - // MountPath: "/plugins", - // }, - // { - // Name: "scratch", - // MountPath: "/scratch", - // }, - // { - // Name: "certs", - // MountPath: "/etc/ssl/certs", - // }, - // { - // Name: "cloud-credentials", - // MountPath: "/credentials", - // }, - // }, - // 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: common.AWSSharedCredentialsFileEnvKey, - // Value: "/credentials/cloud", - // }, - // }, - // }, - // }, - // Volumes: []corev1.Volume{ - // { - // Name: "plugins", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "scratch", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "certs", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "cloud-credentials", - // VolumeSource: corev1.VolumeSource{ - // Secret: &corev1.SecretVolumeSource{ - // SecretName: "cloud-credentials", - // }, - // }, - // }, - // }, - // InitContainers: []corev1.Container{ - // { - // Image: common.AWSPluginImage, - // Name: common.VeleroPluginForAWS, - // ImagePullPolicy: corev1.PullAlways, - // Resources: corev1.ResourceRequirements{}, - // TerminationMessagePath: "/dev/termination-log", - // TerminationMessagePolicy: "File", - // VolumeMounts: []corev1.VolumeMount{ - // { - // MountPath: "/target", - // Name: "plugins", - // }, - // }, - // }, - // }, - // }, - // }, - // }, - // }, - // }, - // { - // name: "given valid DPA CR with PodDNS Policy/Config, annotations, appropriate velero deployment is build with aws plugin specific specs", - // veleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // }, - // }, - // dpa: &oadpv1alpha1.DataProtectionApplication{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-Velero-CR", - // Namespace: "test-ns", - // }, - // Spec: oadpv1alpha1.DataProtectionApplicationSpec{ - // Configuration: &oadpv1alpha1.ApplicationConfig{ - // 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: pointer.String("2"), - // }, - // { - // Name: "edns0", - // }, - // }, - // }, - // }, - // }, - // wantErr: false, - // wantVeleroDeployment: &appsv1.Deployment{ - // ObjectMeta: metav1.ObjectMeta{ - // Name: "test-velero-deployment", - // Namespace: "test-ns", - // Labels: map[string]string{ - // "app.kubernetes.io/name": common.Velero, - // "app.kubernetes.io/instance": "test-Velero-CR", - // "app.kubernetes.io/managed-by": common.OADPOperator, - // "app.kubernetes.io/component": Server, - // oadpv1alpha1.OadpOperatorLabel: "True", - // }, - // }, - // TypeMeta: metav1.TypeMeta{ - // Kind: "Deployment", - // APIVersion: appsv1.SchemeGroupVersion.String(), - // }, - // Spec: appsv1.DeploymentSpec{ - // Selector: veleroLabelSelector, - // Replicas: pointer.Int32(1), - // Template: corev1.PodTemplateSpec{ - // ObjectMeta: metav1.ObjectMeta{ - // Labels: veleroLabelSelector.MatchLabels, - // Annotations: map[string]string{ - // "prometheus.io/scrape": "true", - // "prometheus.io/port": "8085", - // "prometheus.io/path": "/metrics", - // "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: pointer.String("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{ - // Limits: corev1.ResourceList{ - // corev1.ResourceCPU: resource.MustParse("1"), - // corev1.ResourceMemory: resource.MustParse("512Mi"), - // }, - // Requests: corev1.ResourceList{ - // corev1.ResourceCPU: resource.MustParse("500m"), - // corev1.ResourceMemory: resource.MustParse("128Mi"), - // }, - // }, - // Command: []string{"/velero"}, - // Args: []string{ - // "server", - // "--restic-timeout=1h", - // }, - // VolumeMounts: []corev1.VolumeMount{ - // { - // Name: "plugins", - // MountPath: "/plugins", - // }, - // { - // Name: "scratch", - // MountPath: "/scratch", - // }, - // { - // Name: "certs", - // MountPath: "/etc/ssl/certs", - // }, - // { - // Name: "cloud-credentials", - // MountPath: "/credentials", - // }, - // }, - // 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: common.AWSSharedCredentialsFileEnvKey, - // Value: "/credentials/cloud", - // }, - // }, - // }, - // }, - // Volumes: []corev1.Volume{ - // { - // Name: "plugins", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "scratch", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "certs", - // VolumeSource: corev1.VolumeSource{ - // EmptyDir: &corev1.EmptyDirVolumeSource{}, - // }, - // }, - // { - // Name: "cloud-credentials", - // VolumeSource: corev1.VolumeSource{ - // Secret: &corev1.SecretVolumeSource{ - // SecretName: "cloud-credentials", - // }, - // }, - // }, - // }, - // InitContainers: []corev1.Container{ - // { - // Image: common.AWSPluginImage, - // Name: common.VeleroPluginForAWS, - // ImagePullPolicy: corev1.PullAlways, - // Resources: corev1.ResourceRequirements{}, - // TerminationMessagePath: "/dev/termination-log", - // TerminationMessagePolicy: "File", - // VolumeMounts: []corev1.VolumeMount{ - // { - // MountPath: "/target", - // Name: "plugins", - // }, - // }, - // }, - // }, - // }, - // }, - // }, - // }, - // }, + { + name: "Velero Deployment is nil", + veleroDeployment: nil, + dpa: &oadpv1alpha1.DataProtectionApplication{}, + wantErr: true, + wantVeleroDeployment: nil, + }, + { + name: "given valid DPA CR, appropriate Velero Deployment is built", + veleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + }, + }, + dpa: &oadpv1alpha1.DataProtectionApplication{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-Velero-CR", + Namespace: "test-ns", + }, + Spec: oadpv1alpha1.DataProtectionApplicationSpec{ + Configuration: &oadpv1alpha1.ApplicationConfig{ + Velero: &oadpv1alpha1.VeleroConfig{}, + }, + }, + }, + wantErr: false, + wantVeleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + Labels: map[string]string{ + "app.kubernetes.io/name": common.Velero, + "app.kubernetes.io/instance": "test-Velero-CR", + "app.kubernetes.io/managed-by": common.OADPOperator, + "app.kubernetes.io/component": Server, + oadpv1alpha1.OadpOperatorLabel: "True", + }, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "Deployment", + APIVersion: appsv1.SchemeGroupVersion.String(), + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + Replicas: pointer.Int32(1), + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: veleroLabelSelector.MatchLabels, + Annotations: map[string]string{ + "prometheus.io/scrape": "true", + "prometheus.io/port": "8085", + "prometheus.io/path": "/metrics", + }, + }, + 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("1"), + corev1.ResourceMemory: resource.MustParse("512Mi"), + }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("128Mi"), + }, + }, + Command: []string{"/velero"}, + Args: []string{ + "server", + "--restic-timeout=1h", + }, + 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", + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "plugins", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "scratch", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "certs", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + }, + InitContainers: []corev1.Container{}, + }, + }, + }, + }, + }, + { + name: "given valid DPA CR, velero deployment resource customization", + veleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + }, + TypeMeta: metav1.TypeMeta{ + Kind: "Deployment", + APIVersion: appsv1.SchemeGroupVersion.String(), + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + }, + }, + dpa: &oadpv1alpha1.DataProtectionApplication{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-Velero-CR", + Namespace: "test-ns", + }, + Spec: oadpv1alpha1.DataProtectionApplicationSpec{ + Configuration: &oadpv1alpha1.ApplicationConfig{ + 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"), + }, + }, + }, + }, + }, + }, + }, + wantErr: false, + wantVeleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + Labels: map[string]string{ + "app.kubernetes.io/name": common.Velero, + "app.kubernetes.io/instance": "test-Velero-CR", + "app.kubernetes.io/managed-by": common.OADPOperator, + "app.kubernetes.io/component": Server, + oadpv1alpha1.OadpOperatorLabel: "True", + }, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "Deployment", + APIVersion: appsv1.SchemeGroupVersion.String(), + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + Replicas: pointer.Int32(1), + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: veleroLabelSelector.MatchLabels, + Annotations: map[string]string{ + "prometheus.io/scrape": "true", + "prometheus.io/port": "8085", + "prometheus.io/path": "/metrics", + }, + }, + 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", + "--restic-timeout=1h", + }, + 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", + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "plugins", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "scratch", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "certs", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + }, + InitContainers: []corev1.Container{}, + }, + }, + }, + }, + }, + { + name: "given valid DPA CR, appropriate velero deployment is build with aws plugin specific specs", + veleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + }, + }, + dpa: &oadpv1alpha1.DataProtectionApplication{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-Velero-CR", + Namespace: "test-ns", + }, + Spec: oadpv1alpha1.DataProtectionApplicationSpec{ + Configuration: &oadpv1alpha1.ApplicationConfig{ + Velero: &oadpv1alpha1.VeleroConfig{ + DefaultPlugins: []oadpv1alpha1.DefaultPlugin{ + oadpv1alpha1.DefaultPluginAWS, + }, + }, + }, + }, + }, + wantErr: false, + wantVeleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + Labels: map[string]string{ + "app.kubernetes.io/name": common.Velero, + "app.kubernetes.io/instance": "test-Velero-CR", + "app.kubernetes.io/managed-by": common.OADPOperator, + "app.kubernetes.io/component": Server, + oadpv1alpha1.OadpOperatorLabel: "True", + }, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "Deployment", + APIVersion: appsv1.SchemeGroupVersion.String(), + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + Replicas: pointer.Int32(1), + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: veleroLabelSelector.MatchLabels, + Annotations: map[string]string{ + "prometheus.io/scrape": "true", + "prometheus.io/port": "8085", + "prometheus.io/path": "/metrics", + }, + }, + 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("1"), + corev1.ResourceMemory: resource.MustParse("512Mi"), + }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("128Mi"), + }, + }, + Command: []string{"/velero"}, + Args: []string{ + "server", + "--restic-timeout=1h", + }, + VolumeMounts: []corev1.VolumeMount{ + { + Name: "plugins", + MountPath: "/plugins", + }, + { + Name: "scratch", + MountPath: "/scratch", + }, + { + Name: "certs", + MountPath: "/etc/ssl/certs", + }, + { + Name: "cloud-credentials", + MountPath: "/credentials", + }, + }, + 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: common.AWSSharedCredentialsFileEnvKey, + Value: "/credentials/cloud", + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "plugins", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "scratch", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "certs", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "cloud-credentials", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "cloud-credentials", + }, + }, + }, + }, + InitContainers: []corev1.Container{ + { + Image: common.AWSPluginImage, + Name: common.VeleroPluginForAWS, + ImagePullPolicy: corev1.PullAlways, + Resources: corev1.ResourceRequirements{}, + TerminationMessagePath: "/dev/termination-log", + TerminationMessagePolicy: "File", + VolumeMounts: []corev1.VolumeMount{ + { + MountPath: "/target", + Name: "plugins", + }, + }, + }, + }, + }, + }, + }, + }, + }, + { + name: "given valid DPA CR with annotations, appropriate velero deployment is build with aws plugin specific specs", + veleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + }, + }, + dpa: &oadpv1alpha1.DataProtectionApplication{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-Velero-CR", + Namespace: "test-ns", + }, + Spec: oadpv1alpha1.DataProtectionApplicationSpec{ + Configuration: &oadpv1alpha1.ApplicationConfig{ + Velero: &oadpv1alpha1.VeleroConfig{ + DefaultPlugins: []oadpv1alpha1.DefaultPlugin{ + oadpv1alpha1.DefaultPluginAWS, + }, + }, + }, + PodAnnotations: map[string]string{ + "test-annotation": "awesome annotation", + }, + }, + }, + wantErr: false, + wantVeleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + Labels: map[string]string{ + "app.kubernetes.io/name": common.Velero, + "app.kubernetes.io/instance": "test-Velero-CR", + "app.kubernetes.io/managed-by": common.OADPOperator, + "app.kubernetes.io/component": Server, + oadpv1alpha1.OadpOperatorLabel: "True", + }, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "Deployment", + APIVersion: appsv1.SchemeGroupVersion.String(), + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + Replicas: pointer.Int32(1), + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: veleroLabelSelector.MatchLabels, + Annotations: map[string]string{ + "prometheus.io/scrape": "true", + "prometheus.io/port": "8085", + "prometheus.io/path": "/metrics", + "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{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("1"), + corev1.ResourceMemory: resource.MustParse("512Mi"), + }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("128Mi"), + }, + }, + Command: []string{"/velero"}, + Args: []string{ + "server", + "--restic-timeout=1h", + }, + VolumeMounts: []corev1.VolumeMount{ + { + Name: "plugins", + MountPath: "/plugins", + }, + { + Name: "scratch", + MountPath: "/scratch", + }, + { + Name: "certs", + MountPath: "/etc/ssl/certs", + }, + { + Name: "cloud-credentials", + MountPath: "/credentials", + }, + }, + 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: common.AWSSharedCredentialsFileEnvKey, + Value: "/credentials/cloud", + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "plugins", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "scratch", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "certs", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "cloud-credentials", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "cloud-credentials", + }, + }, + }, + }, + InitContainers: []corev1.Container{ + { + Image: common.AWSPluginImage, + Name: common.VeleroPluginForAWS, + ImagePullPolicy: corev1.PullAlways, + Resources: corev1.ResourceRequirements{}, + TerminationMessagePath: "/dev/termination-log", + TerminationMessagePolicy: "File", + VolumeMounts: []corev1.VolumeMount{ + { + MountPath: "/target", + Name: "plugins", + }, + }, + }, + }, + }, + }, + }, + }, + }, + { + name: "given valid DPA CR with PodDNS Policy/Config, annotations, appropriate velero deployment is build with aws plugin specific specs", + veleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + }, + }, + dpa: &oadpv1alpha1.DataProtectionApplication{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-Velero-CR", + Namespace: "test-ns", + }, + Spec: oadpv1alpha1.DataProtectionApplicationSpec{ + Configuration: &oadpv1alpha1.ApplicationConfig{ + 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: pointer.String("2"), + }, + { + Name: "edns0", + }, + }, + }, + }, + }, + wantErr: false, + wantVeleroDeployment: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-velero-deployment", + Namespace: "test-ns", + Labels: map[string]string{ + "app.kubernetes.io/name": common.Velero, + "app.kubernetes.io/instance": "test-Velero-CR", + "app.kubernetes.io/managed-by": common.OADPOperator, + "app.kubernetes.io/component": Server, + oadpv1alpha1.OadpOperatorLabel: "True", + }, + }, + TypeMeta: metav1.TypeMeta{ + Kind: "Deployment", + APIVersion: appsv1.SchemeGroupVersion.String(), + }, + Spec: appsv1.DeploymentSpec{ + Selector: veleroLabelSelector, + Replicas: pointer.Int32(1), + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: veleroLabelSelector.MatchLabels, + Annotations: map[string]string{ + "prometheus.io/scrape": "true", + "prometheus.io/port": "8085", + "prometheus.io/path": "/metrics", + "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: pointer.String("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{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("1"), + corev1.ResourceMemory: resource.MustParse("512Mi"), + }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("128Mi"), + }, + }, + Command: []string{"/velero"}, + Args: []string{ + "server", + "--restic-timeout=1h", + }, + VolumeMounts: []corev1.VolumeMount{ + { + Name: "plugins", + MountPath: "/plugins", + }, + { + Name: "scratch", + MountPath: "/scratch", + }, + { + Name: "certs", + MountPath: "/etc/ssl/certs", + }, + { + Name: "cloud-credentials", + MountPath: "/credentials", + }, + }, + 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: common.AWSSharedCredentialsFileEnvKey, + Value: "/credentials/cloud", + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "plugins", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "scratch", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "certs", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + { + Name: "cloud-credentials", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "cloud-credentials", + }, + }, + }, + }, + InitContainers: []corev1.Container{ + { + Image: common.AWSPluginImage, + Name: common.VeleroPluginForAWS, + ImagePullPolicy: corev1.PullAlways, + Resources: corev1.ResourceRequirements{}, + TerminationMessagePath: "/dev/termination-log", + TerminationMessagePolicy: "File", + VolumeMounts: []corev1.VolumeMount{ + { + MountPath: "/target", + Name: "plugins", + }, + }, + }, + }, + }, + }, + }, + }, + }, { name: "given valid Velero CR with with aws plugin from bucket", veleroDeployment: &appsv1.Deployment{ @@ -1053,10 +1053,6 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { MountPath: "/var/run/secrets/openshift/serviceaccount", ReadOnly: true, }, - { - Name: "cloud-credentials", - MountPath: "/credentials", - }, }, Env: []corev1.EnvVar{ { @@ -1075,10 +1071,6 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { Name: common.LDLibraryPathEnvKey, Value: "/plugins", }, - { - Name: common.AWSSharedCredentialsFileEnvKey, - Value: "/credentials/cloud", - }, }, }, }, @@ -1118,14 +1110,6 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { }, }, }, - { - Name: "cloud-credentials", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "cloud-credentials", - }, - }, - }, }, InitContainers: []corev1.Container{ { @@ -1173,7 +1157,7 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) { t.Errorf("buildVeleroDeployment() error = %v, wantErr %v", err, tt.wantErr) } if !reflect.DeepEqual(tt.wantVeleroDeployment, tt.veleroDeployment) { - t.Errorf("expected registry deployment spec to be %#v, got %#v", tt.wantVeleroDeployment, tt.veleroDeployment) + t.Errorf("expected registry deployment spec to be %#v, got %#v", tt.wantVeleroDeployment.Spec.Template.Spec.Volumes, tt.veleroDeployment.Spec.Template.Spec.Volumes) } }) } diff --git a/go.sum b/go.sum index 7cef5dab9b..37e39befb5 100644 --- a/go.sum +++ b/go.sum @@ -13,7 +13,6 @@ cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bP cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= -cloud.google.com/go v0.65.0 h1:Dg9iHVQfrhq82rUNu9ZxUDrJLaxFUe/HlCVaLyRruq8= cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= @@ -583,7 +582,6 @@ github.com/openshift/api v0.0.0-20210805075156-d8fab4513288 h1:Yw96Z8gygCXxjeMTm github.com/openshift/api v0.0.0-20210805075156-d8fab4513288/go.mod h1:x81TFA31x1OMT9SYWukQqJ/KbmeveRN6fo+XeGRK8g0= github.com/openshift/build-machinery-go v0.0.0-20210712174854-1bb7fd1518d3/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/operator-framework/api v0.10.0 h1:TaxbgbrV8D3wnKNyrImZ2zjQVVHMQRc7piWLDmlGoEE= github.com/operator-framework/api v0.10.0/go.mod h1:tV0BUNvly7szq28ZPBXhjp1Sqg5yHCOeX19ui9K4vjI= github.com/operator-framework/api v0.10.7 h1:GlZJ6m+0WSVdSsSjTbhKKAvHXamWJXhwXHUhVwL8LBE= github.com/operator-framework/api v0.10.7/go.mod h1:PtQSNSuVrhSC6YE6JJJZv3nnZJc32osKX8FmFUZK05U= @@ -643,7 +641,6 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= @@ -653,15 +650,14 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= +github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= -github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M= github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw= github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t68Nk= @@ -760,8 +756,6 @@ go.uber.org/zap v1.8.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= -go.uber.org/zap v1.18.1 h1:CSUJ2mjFszzEWt4CdKISEuChVIXGBn3lAPwkRGyVrc4= -go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.19.0 h1:mZQZefskPPCMIBCSEH0v2/iUqqLrYtaeqwD6FUGUnFE= go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= golang.org/x/arch v0.0.0-20180920145803-b19384d3c130/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8= @@ -804,9 +798,9 @@ golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -880,7 +874,6 @@ golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4Iltr golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 h1:ld7aEMNHoBnnDAX15v1T6z31v8HwR2A9FYOuAhWqkwc= golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= @@ -978,8 +971,6 @@ golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2 h1:c8PlLMqBbOHoqtjteWm5/kbe6rNY2pbRfbIMVnepueo= golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -1069,8 +1060,8 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1144,7 +1135,6 @@ google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a h1:pOwg4OoaRYScjmR4LlLgdtnyoHYTSAVhhqe5uPdpII8= google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= @@ -1169,7 +1159,6 @@ google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI= google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= @@ -1248,15 +1237,12 @@ k8s.io/api v0.20.9/go.mod h1:wTKbf3LIlu+vuXqOk4Bi5drnSUtB10ou5XYrlgOuCdQ= k8s.io/api v0.21.1/go.mod h1:FstGROTmsSHBarKc8bylzXih8BLNYTiS3TZcsoEDg2s= k8s.io/api v0.21.3/go.mod h1:hUgeYHUbBp23Ue4qdX9tR8/ANi/g3ehylAqDn9NWVOg= k8s.io/api v0.22.0-rc.0/go.mod h1:EUcKB6RvpW74HMRUSSNwpUzrIHBdGT1FeAvOV+txic0= -k8s.io/api v0.22.0 h1:elCpMZ9UE8dLdYxr55E06TmSeji9I3KH494qH70/y+c= -k8s.io/api v0.22.0/go.mod h1:0AoXXqst47OI/L0oGKq9DG61dvGRPXs7X4/B7KyjBCU= k8s.io/api v0.22.1/go.mod h1:bh13rkTp3F1XEaLGykbyRD2QaTTzPm0e/BMd8ptFONY= k8s.io/api v0.22.2 h1:M8ZzAD0V6725Fjg53fKeTJxGsJvRbk4TEm/fexHMtfw= k8s.io/api v0.22.2/go.mod h1:y3ydYpLJAaDI+BbSe2xmGcqxiWHmWjkEeIbiwHvnPR8= k8s.io/apiextensions-apiserver v0.19.2/go.mod h1:EYNjpqIAvNZe+svXVx9j4uBaVhTB4C94HkY3w058qcg= k8s.io/apiextensions-apiserver v0.19.12/go.mod h1:LXHRkG+7v33P+IzTKYVuqffGlB7Xg7K0VgfObTacbQg= k8s.io/apiextensions-apiserver v0.21.1/go.mod h1:KESQFCGjqVcVsZ9g0xX5bacMjyX5emuWcS2arzdEouA= -k8s.io/apiextensions-apiserver v0.21.3 h1:+B6biyUWpqt41kz5x6peIsljlsuwvNAp/oFax/j2/aY= k8s.io/apiextensions-apiserver v0.21.3/go.mod h1:kl6dap3Gd45+21Jnh6utCx8Z2xxLm8LGDkprcd+KbsE= k8s.io/apiextensions-apiserver v0.22.1/go.mod h1:HeGmorjtRmRLE+Q8dJu6AYRoZccvCMsghwS8XTUYb2c= k8s.io/apiextensions-apiserver v0.22.2 h1:zK7qI8Ery7j2CaN23UCFaC1hj7dMiI87n01+nKuewd4= @@ -1269,8 +1255,6 @@ k8s.io/apimachinery v0.20.9/go.mod h1:kQa//VOAwyVwJ2+L9kOREbsnryfsGSkSM1przND4+m k8s.io/apimachinery v0.21.1/go.mod h1:jbreFvJo3ov9rj7eWT7+sYiRx+qZuCYXwWT1bcDswPY= k8s.io/apimachinery v0.21.3/go.mod h1:H/IM+5vH9kZRNJ4l3x/fXP/5bOPJaVP/guptnZPeCFI= k8s.io/apimachinery v0.22.0-rc.0/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0= -k8s.io/apimachinery v0.22.0 h1:CqH/BdNAzZl+sr3tc0D3VsK3u6ARVSo3GWyLmfIjbP0= -k8s.io/apimachinery v0.22.0/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0= k8s.io/apimachinery v0.22.1/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0= k8s.io/apimachinery v0.22.2 h1:ejz6y/zNma8clPVfNDLnPbleBo6MpoFy/HBiBqCouVk= k8s.io/apimachinery v0.22.2/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0= @@ -1288,8 +1272,6 @@ k8s.io/client-go v0.19.12/go.mod h1:BAGKQraZ6fDmXhT46pGXWZQQqN7P4E0BJux0+9O6Gt0= k8s.io/client-go v0.20.9/go.mod h1:SjslwSB3f2wb/RwvGMfPIwsiBTPnD/Hp1xBGlz6U3t8= k8s.io/client-go v0.21.1/go.mod h1:/kEw4RgW+3xnBGzvp9IWxKSNA+lXn3A7AuH3gdOAzLs= k8s.io/client-go v0.21.3/go.mod h1:+VPhCgTsaFmGILxR/7E1N0S+ryO010QBeNCv5JwRGYU= -k8s.io/client-go v0.22.0 h1:sD6o9O6tCwUKCENw8v+HFsuAbq2jCu8cWC61/ydwA50= -k8s.io/client-go v0.22.0/go.mod h1:GUjIuXR5PiEv/RVK5OODUsm6eZk7wtSWZSaSJbpFdGg= k8s.io/client-go v0.22.1/go.mod h1:BquC5A4UOo4qVDUtoc04/+Nxp1MeHcVc1HJm1KmG8kk= k8s.io/client-go v0.22.2 h1:DaSQgs02aCC1QcwUdkKZWOeaVsQjYvWv8ZazcZ6JcHc= k8s.io/client-go v0.22.2/go.mod h1:sAlhrkVDf50ZHx6z4K0S40wISNTarf1r800F+RlCF6U= @@ -1305,7 +1287,6 @@ k8s.io/code-generator v0.22.2/go.mod h1:eV77Y09IopzeXOJzndrDyCI88UBok2h6WxAlBwpx k8s.io/component-base v0.19.2/go.mod h1:g5LrsiTiabMLZ40AR6Hl45f088DevyGY+cCE2agEIVo= k8s.io/component-base v0.19.12/go.mod h1:tpwExE0sY3A7CwtlxGL7SnQOdQfUlnFybT6GmAD+z/s= k8s.io/component-base v0.21.1/go.mod h1:NgzFZ2qu4m1juby4TnrmpR8adRk6ka62YdH5DkIIyKA= -k8s.io/component-base v0.21.3 h1:4WuuXY3Npa+iFfi2aDRiOz+anhNvRfye0859ZgfC5Og= k8s.io/component-base v0.21.3/go.mod h1:kkuhtfEHeZM6LkX0saqSK8PbdO7A0HigUngmhhrwfGQ= k8s.io/component-base v0.22.1/go.mod h1:0D+Bl8rrnsPN9v0dyYvkqFfBeAd4u7n77ze+p8CMiPo= k8s.io/component-base v0.22.2 h1:vNIvE0AIrLhjX8drH0BgCNJcR4QZxMXcJzBsDplDx9M= @@ -1337,8 +1318,6 @@ k8s.io/utils v0.0.0-20200912215256-4140de9c8800/go.mod h1:jPW/WVKK9YHAvNhRxK0md/ k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210527160623-6fdb442a123b/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -k8s.io/utils v0.0.0-20210722164352-7f3ee0f31471 h1:DnzUXII7sVg1FJ/4JX6YDRJfLNAC7idRatPwe07suiI= -k8s.io/utils v0.0.0-20210722164352-7f3ee0f31471/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a h1:8dYfu/Fc9Gz2rNJKB9IQRGgQOh2clmRzNIPPY1xLY5g= k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= @@ -1352,8 +1331,6 @@ sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.22/go.mod h1:LEScyz sigs.k8s.io/cluster-api v0.3.11-0.20210106212952-b6c1b5b3db3d/go.mod h1:HwDMTKYusSK0SnTAr/P3htrxdiykBADqffkamkiUXhk= sigs.k8s.io/controller-runtime v0.7.1-0.20201215171748-096b2e07c091/go.mod h1:pJ3YBrJiAqMAZKi6UVGuE98ZrroV1p+pIhoHsMm9wdU= sigs.k8s.io/controller-runtime v0.9.0/go.mod h1:TgkfvrhhEw3PlI0BRL/5xM+89y3/yc0ZDfdbTl84si8= -sigs.k8s.io/controller-runtime v0.9.5 h1:WThcFE6cqctTn2jCZprLICO6BaKZfhsT37uAapTNfxc= -sigs.k8s.io/controller-runtime v0.9.5/go.mod h1:q6PpkM5vqQubEKUKOM6qr06oXGzOBcCby1DA9FbyZeA= sigs.k8s.io/controller-runtime v0.10.0/go.mod h1:GCdh6kqV6IY4LK0JLwX0Zm6g233RtVGdb/f0+KSfprg= sigs.k8s.io/controller-runtime v0.10.3 h1:s5Ttmw/B4AuIbwrXD3sfBkXwnPMMWrqpVj4WRt1dano= sigs.k8s.io/controller-runtime v0.10.3/go.mod h1:CQp8eyUQZ/Q7PJvnIrB6/hgfTC1kBkGylwsLgOQi1WY= diff --git a/pkg/credentials/credentials.go b/pkg/credentials/credentials.go index c956eb1041..54303f8471 100644 --- a/pkg/credentials/credentials.go +++ b/pkg/credentials/credentials.go @@ -193,7 +193,7 @@ func AppendCloudProviderVolumes(dpa *oadpv1alpha1.DataProtectionApplication, ds } // add plugin specific specs to velero deployment -func AppendPluginSpecificSpecs(dpa *oadpv1alpha1.DataProtectionApplication, veleroDeployment *appsv1.Deployment, veleroContainer *corev1.Container) error { +func AppendPluginSpecificSpecs(dpa *oadpv1alpha1.DataProtectionApplication, veleroDeployment *appsv1.Deployment, veleroContainer *corev1.Container, providerNeedsDefaultCreds map[string]bool, hasCloudStorage bool) error { for _, plugin := range dpa.Spec.Configuration.Velero.DefaultPlugins { if pluginSpecificMap, ok := PluginSpecificFields[plugin]; ok { veleroDeployment.Spec.Template.Spec.InitContainers = append( @@ -212,7 +212,14 @@ func AppendPluginSpecificSpecs(dpa *oadpv1alpha1.DataProtectionApplication, vele }, }, }) - if !pluginSpecificMap.IsCloudProvider { + + pluginNeedsCheck, foundInBSLorVSL := providerNeedsDefaultCreds[string(plugin)] + + if !foundInBSLorVSL && !hasCloudStorage { + pluginNeedsCheck = true + } + + if !pluginSpecificMap.IsCloudProvider || !pluginNeedsCheck { continue } // set default secret name to use