Skip to content

Commit 53069f9

Browse files
Fixing volume mount issue (#369)
* Fixing volume mount issue Adding logic to ignore openshift & csi default plugins * Refining code * testing with older commit * Using the existing plugin maps * changing function name and conditionl * Fixing typo and removing extra logic wrt secret name * Fixing unit tests * Breaking the loop once the plugin has been found * Refractoring code * adding unit tests
1 parent 0eab31d commit 53069f9

File tree

5 files changed

+155
-200
lines changed

5 files changed

+155
-200
lines changed

controllers/restic_test.go

Lines changed: 10 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func TestVeleroReconciler_buildResticDaemonset(t *testing.T) {
387387
},
388388
},
389389
{
390-
name: "Valid velero and daemonset for aws as bsl with non-default secret name",
390+
name: "Valid velero with annotation and daemonset for aws as bsl with default secret name",
391391
args: args{
392392
&oadpv1alpha1.Velero{
393393
Spec: oadpv1alpha1.VeleroSpec{
@@ -409,178 +409,7 @@ func TestVeleroReconciler_buildResticDaemonset(t *testing.T) {
409409
},
410410
Credential: &corev1.SecretKeySelector{
411411
LocalObjectReference: corev1.LocalObjectReference{
412-
Name: "aws-creds",
413-
},
414-
},
415-
},
416-
},
417-
},
418-
}, &appsv1.DaemonSet{
419-
ObjectMeta: getResticObjectMeta(r),
420-
},
421-
},
422-
wantErr: false,
423-
want: &appsv1.DaemonSet{
424-
ObjectMeta: getResticObjectMeta(r),
425-
TypeMeta: metav1.TypeMeta{
426-
Kind: "DaemonSet",
427-
APIVersion: appsv1.SchemeGroupVersion.String(),
428-
},
429-
Spec: appsv1.DaemonSetSpec{
430-
UpdateStrategy: appsv1.DaemonSetUpdateStrategy{
431-
Type: appsv1.RollingUpdateDaemonSetStrategyType,
432-
},
433-
Selector: resticLabelSelector,
434-
Template: corev1.PodTemplateSpec{
435-
ObjectMeta: metav1.ObjectMeta{
436-
Labels: map[string]string{
437-
"component": common.Velero,
438-
"name": common.Restic,
439-
},
440-
},
441-
Spec: corev1.PodSpec{
442-
NodeSelector: velero.Spec.ResticNodeSelector,
443-
ServiceAccountName: common.Velero,
444-
SecurityContext: &corev1.PodSecurityContext{
445-
RunAsUser: pointer.Int64(0),
446-
SupplementalGroups: velero.Spec.ResticSupplementalGroups,
447-
},
448-
Volumes: []corev1.Volume{
449-
// Cloud Provider volumes are dynamically added in the for loop below
450-
{
451-
Name: HostPods,
452-
VolumeSource: corev1.VolumeSource{
453-
HostPath: &corev1.HostPathVolumeSource{
454-
Path: resticPvHostPath,
455-
},
456-
},
457-
},
458-
{
459-
Name: "scratch",
460-
VolumeSource: corev1.VolumeSource{
461-
EmptyDir: &corev1.EmptyDirVolumeSource{},
462-
},
463-
},
464-
{
465-
Name: "certs",
466-
VolumeSource: corev1.VolumeSource{
467-
EmptyDir: &corev1.EmptyDirVolumeSource{},
468-
},
469-
},
470-
{
471-
Name: "aws-creds",
472-
VolumeSource: corev1.VolumeSource{
473-
Secret: &corev1.SecretVolumeSource{
474-
SecretName: "aws-creds",
475-
},
476-
},
477-
},
478-
},
479-
Tolerations: velero.Spec.ResticTolerations,
480-
Containers: []corev1.Container{
481-
{
482-
Name: common.Restic,
483-
SecurityContext: &corev1.SecurityContext{
484-
Privileged: pointer.Bool(true),
485-
},
486-
Image: getVeleroImage(&velero),
487-
ImagePullPolicy: corev1.PullAlways,
488-
Resources: r.getVeleroResourceReqs(&velero), //setting default.
489-
Command: []string{
490-
"/velero",
491-
},
492-
Args: []string{
493-
"restic",
494-
"server",
495-
},
496-
VolumeMounts: []corev1.VolumeMount{
497-
{
498-
Name: "host-pods",
499-
MountPath: "/host_pods",
500-
MountPropagation: &mountPropagationToHostContainer,
501-
},
502-
{
503-
Name: "scratch",
504-
MountPath: "/scratch",
505-
},
506-
{
507-
Name: "certs",
508-
MountPath: "/etc/ssl/certs",
509-
},
510-
{
511-
Name: "aws-creds",
512-
MountPath: "/credentials",
513-
},
514-
},
515-
Env: []corev1.EnvVar{
516-
{
517-
Name: "NODE_NAME",
518-
ValueFrom: &corev1.EnvVarSource{
519-
FieldRef: &corev1.ObjectFieldSelector{
520-
FieldPath: "spec.nodeName",
521-
},
522-
},
523-
},
524-
{
525-
Name: "VELERO_NAMESPACE",
526-
ValueFrom: &corev1.EnvVarSource{
527-
FieldRef: &corev1.ObjectFieldSelector{
528-
FieldPath: "metadata.namespace",
529-
},
530-
},
531-
},
532-
{
533-
Name: "VELERO_SCRATCH_DIR",
534-
Value: "/scratch",
535-
},
536-
{
537-
Name: "HTTP_PROXY",
538-
Value: os.Getenv("HTTP_PROXY"),
539-
},
540-
{
541-
Name: "HTTPS_PROXY",
542-
Value: os.Getenv("HTTPS_PROXY"),
543-
},
544-
{
545-
Name: "NO_PROXY",
546-
Value: os.Getenv("NO_PROXY"),
547-
},
548-
{
549-
Name: common.AWSSharedCredentialsFileEnvKey,
550-
Value: "/credentials/cloud",
551-
},
552-
},
553-
},
554-
},
555-
},
556-
},
557-
},
558-
},
559-
},
560-
{
561-
name: "Valid velero with annotation and daemonset for aws as bsl with non-default secret name",
562-
args: args{
563-
&oadpv1alpha1.Velero{
564-
Spec: oadpv1alpha1.VeleroSpec{
565-
DefaultVeleroPlugins: []oadpv1alpha1.DefaultPlugin{
566-
oadpv1alpha1.DefaultPluginAWS,
567-
},
568-
BackupStorageLocations: []velerov1.BackupStorageLocationSpec{
569-
{
570-
Provider: AWSProvider,
571-
StorageType: velerov1.StorageType{
572-
ObjectStorage: &velerov1.ObjectStorageLocation{
573-
Bucket: "aws-bucket",
574-
},
575-
},
576-
Config: map[string]string{
577-
Region: "aws-region",
578-
S3URL: "https://sr-url-aws-domain.com",
579-
InsecureSkipTLSVerify: "false",
580-
},
581-
Credential: &corev1.SecretKeySelector{
582-
LocalObjectReference: corev1.LocalObjectReference{
583-
Name: "aws-creds",
412+
Name: "cloud-credentials",
584413
},
585414
},
586415
},
@@ -645,10 +474,10 @@ func TestVeleroReconciler_buildResticDaemonset(t *testing.T) {
645474
},
646475
},
647476
{
648-
Name: "aws-creds",
477+
Name: "cloud-credentials",
649478
VolumeSource: corev1.VolumeSource{
650479
Secret: &corev1.SecretVolumeSource{
651-
SecretName: "aws-creds",
480+
SecretName: "cloud-credentials",
652481
},
653482
},
654483
},
@@ -685,7 +514,7 @@ func TestVeleroReconciler_buildResticDaemonset(t *testing.T) {
685514
MountPath: "/etc/ssl/certs",
686515
},
687516
{
688-
Name: "aws-creds",
517+
Name: "cloud-credentials",
689518
MountPath: "/credentials",
690519
},
691520
},
@@ -735,7 +564,7 @@ func TestVeleroReconciler_buildResticDaemonset(t *testing.T) {
735564
},
736565
},
737566
{
738-
name: "Valid velero with DNS Policy/Config with annotation and daemonset for aws as bsl with non-default secret name",
567+
name: "Valid velero with DNS Policy/Config with annotation and daemonset for aws as bsl with default secret name",
739568
args: args{
740569
&oadpv1alpha1.Velero{
741570
Spec: oadpv1alpha1.VeleroSpec{
@@ -757,7 +586,7 @@ func TestVeleroReconciler_buildResticDaemonset(t *testing.T) {
757586
},
758587
Credential: &corev1.SecretKeySelector{
759588
LocalObjectReference: corev1.LocalObjectReference{
760-
Name: "aws-creds",
589+
Name: "cloud-credentials",
761590
},
762591
},
763592
},
@@ -854,10 +683,10 @@ func TestVeleroReconciler_buildResticDaemonset(t *testing.T) {
854683
},
855684
},
856685
{
857-
Name: "aws-creds",
686+
Name: "cloud-credentials",
858687
VolumeSource: corev1.VolumeSource{
859688
Secret: &corev1.SecretVolumeSource{
860-
SecretName: "aws-creds",
689+
SecretName: "cloud-credentials",
861690
},
862691
},
863692
},
@@ -894,7 +723,7 @@ func TestVeleroReconciler_buildResticDaemonset(t *testing.T) {
894723
MountPath: "/etc/ssl/certs",
895724
},
896725
{
897-
Name: "aws-creds",
726+
Name: "cloud-credentials",
898727
MountPath: "/credentials",
899728
},
900729
},

controllers/velero.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ func (r *VeleroReconciler) ReconcileVeleroDeployment(log logr.Logger) (bool, err
264264
if err != nil {
265265
return err
266266
}
267-
268267
// update the Deployment template
269268
return r.buildVeleroDeployment(veleroDeployment, &velero)
270269
})
@@ -532,3 +531,26 @@ func (r *VeleroReconciler) getVeleroResourceReqs(velero *oadpv1alpha1.Velero) co
532531

533532
return ResourcesReqs
534533
}
534+
535+
// For later: Move this code into validator.go when more need for validation arises
536+
// TODO: if multiple default plugins exist, ensure we validate all of them.
537+
// Right now its sequential validation
538+
func (r *VeleroReconciler) ValidateVeleroPlugins(log logr.Logger) (bool, error) {
539+
velero := oadpv1alpha1.Velero{}
540+
if err := r.Get(r.Context, r.NamespacedName, &velero); err != nil {
541+
return false, err
542+
}
543+
544+
var defaultPlugin oadpv1alpha1.DefaultPlugin
545+
for _, plugin := range velero.Spec.DefaultVeleroPlugins {
546+
if pluginSpecificMap, ok := credentials.PluginSpecificFields[plugin]; ok && pluginSpecificMap.IsCloudProvider {
547+
secretName := pluginSpecificMap.SecretName
548+
_, err := r.getProviderSecret(secretName)
549+
if err != nil {
550+
r.Log.Info(fmt.Sprintf("error validating %s provider secret: %s/%s", defaultPlugin, r.NamespacedName.Namespace, secretName))
551+
return false, err
552+
}
553+
}
554+
}
555+
return true, nil
556+
}

controllers/velero_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
2122
routev1 "github.com/openshift/api/route/v1"
2223
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
2324

@@ -73,13 +74,15 @@ func (r *VeleroReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
7374
// Set reconciler context + name
7475
r.Context = ctx
7576
r.NamespacedName = req.NamespacedName
76-
7777
velero := oadpv1alpha1.Velero{}
78+
7879
if err := r.Get(ctx, req.NamespacedName, &velero); err != nil {
7980
log.Error(err, "unable to fetch velero CR")
8081
return result, client.IgnoreNotFound(err)
8182
}
83+
8284
_, err := ReconcileBatch(r.Log,
85+
r.ValidateVeleroPlugins,
8386
r.ReconcileVeleroSecurityContextConstraint,
8487
r.ReconcileResticRestoreHelperConfig,
8588
r.ValidateBackupStorageLocations,
@@ -103,6 +106,7 @@ func (r *VeleroReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
103106
Message: err.Error(),
104107
},
105108
)
109+
106110
} else {
107111
apimeta.SetStatusCondition(&velero.Status.Conditions,
108112
metav1.Condition{

0 commit comments

Comments
 (0)