Skip to content

Commit

Permalink
validator and type updates
Browse files Browse the repository at this point in the history
Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
  • Loading branch information
kaovilai committed Aug 11, 2023
1 parent 27cccab commit 99b86dd
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions controllers/bsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

func (r *DPAReconciler) ValidateBackupStorageLocations(log logr.Logger) (bool, error) {
dpa := oadpv1alpha1.DataProtectionApplication{}
if err := r.Get(r.Context, r.NamespacedName, &dpa); err != nil {
return false, err
}
func (r *DPAReconciler) ValidateBackupStorageLocations(dpa oadpv1alpha1.DataProtectionApplication) (bool, error) {
if dpa.Spec.Configuration == nil || dpa.Spec.Configuration.Velero == nil {
return false, errors.New("DPA CR Velero configuration cannot be nil")
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/bsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ func TestDPAReconciler_ValidateBackupStorageLocations(t *testing.T) {
},
EventRecorder: record.NewFakeRecorder(10),
}
got, err := r.ValidateBackupStorageLocations(r.Log)
got, err := r.ValidateBackupStorageLocations(*tt.dpa)
if (err != nil) != tt.wantErr {
t.Errorf("ValidateBackupStorageLocations() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
4 changes: 2 additions & 2 deletions controllers/dpa_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ func (r *DPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
_, err := ReconcileBatch(r.Log,
r.ValidateDataProtectionCR,
r.ReconcileResticRestoreHelperConfig,
r.ValidateBackupStorageLocations,
r.ReconcileBackupStorageLocations,
r.ReconcileRegistrySecrets,
r.ReconcileRegistries,
r.ReconcileRegistrySVCs,
r.ReconcileRegistryRoutes,
r.ReconcileRegistryRouteConfigs,
r.ValidateVolumeSnapshotLocations,
r.LabelVSLSecrets,
r.ReconcileVolumeSnapshotLocations,
r.ReconcileVeleroDeployment,
Expand Down Expand Up @@ -214,6 +212,8 @@ type ReconcileFunc func(logr.Logger) (bool, error)
// reconcileBatch steps through a list of reconcile functions until one returns
// false or an error.
func ReconcileBatch(l logr.Logger, reconcileFuncs ...ReconcileFunc) (bool, error) {
// TODO: #1127 DPAReconciler already have a logger, use it instead of passing to each reconcile functions
// TODO: #1128 Right now each reconcile functions call get for DPA, we can do it once and pass it to each function
for _, f := range reconcileFuncs {
if cont, err := f(l); !cont || err != nil {
return cont, err
Expand Down
6 changes: 5 additions & 1 deletion controllers/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
"github.com/openshift/oadp-operator/pkg/credentials"
)

// ValidateDataProtectionCR function validates the DPA CR, returns true if valid, false otherwise
// it calls other validation functions to validate the DPA CR
// TODO: #1129 Clean up duplicate logic for validating backupstoragelocations and volumesnapshotlocations in dpa
func (r *DPAReconciler) ValidateDataProtectionCR(log logr.Logger) (bool, error) {
dpa := oadpv1alpha1.DataProtectionApplication{}
if err := r.Get(r.Context, r.NamespacedName, &dpa); err != nil {
Expand Down Expand Up @@ -99,7 +102,8 @@ func (r *DPAReconciler) ValidateDataProtectionCR(log logr.Logger) (bool, error)
if _, err := getResticResourceReqs(&dpa); err != nil {
return false, err
}

r.ValidateBackupStorageLocations(dpa)
r.ValidateVolumeSnapshotLocations(dpa)
return true, nil
}

Expand Down
9 changes: 3 additions & 6 deletions controllers/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,15 +995,13 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
Configuration: &oadpv1alpha1.ApplicationConfig{
Velero: &oadpv1alpha1.VeleroConfig{
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{
},
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{},
},
},
BackupImages: pointer.Bool(true),
},
},
objects: []client.Object{
},
objects: []client.Object{},
wantErr: true,
want: false,
},
Expand All @@ -1027,8 +1025,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
Configuration: &oadpv1alpha1.ApplicationConfig{
Velero: &oadpv1alpha1.VeleroConfig{
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{
},
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{},
},
},
BackupImages: pointer.Bool(true),
Expand Down
6 changes: 1 addition & 5 deletions controllers/vsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ func (r *DPAReconciler) LabelVSLSecrets(log logr.Logger) (bool, error) {
return true, nil
}

func (r *DPAReconciler) ValidateVolumeSnapshotLocations(log logr.Logger) (bool, error) {
dpa := oadpv1alpha1.DataProtectionApplication{}
if err := r.Get(r.Context, r.NamespacedName, &dpa); err != nil {
return false, err
}
func (r *DPAReconciler) ValidateVolumeSnapshotLocations(dpa oadpv1alpha1.DataProtectionApplication) (bool, error) {
if dpa.Spec.Configuration == nil {
return false, errors.New("application configuration not found")
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/vsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func TestDPAReconciler_ValidateVolumeSnapshotLocation(t *testing.T) {
},
EventRecorder: record.NewFakeRecorder(10),
}
got, err := r.ValidateVolumeSnapshotLocations(r.Log)
got, err := r.ValidateVolumeSnapshotLocations(*tt.dpa)
if (err != nil) != tt.wantErr {
t.Errorf("ValidateVolumeSnapshotLocations() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down

0 comments on commit 99b86dd

Please sign in to comment.