Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions controllers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ func (r *DPAReconciler) buildRegistryContainer(bsl *velerov1.BackupStorageLocati
Port: intstr.IntOrString{IntVal: 5000},
},
},
PeriodSeconds: 5,
TimeoutSeconds: 3,
PeriodSeconds: 10,
TimeoutSeconds: 10,
InitialDelaySeconds: 15,
},
ReadinessProbe: &corev1.Probe{
Expand All @@ -379,8 +379,8 @@ func (r *DPAReconciler) buildRegistryContainer(bsl *velerov1.BackupStorageLocati
Port: intstr.IntOrString{IntVal: 5000},
},
},
PeriodSeconds: 5,
TimeoutSeconds: 3,
PeriodSeconds: 10,
TimeoutSeconds: 10,
InitialDelaySeconds: 15,
},
},
Expand Down
16 changes: 8 additions & 8 deletions controllers/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,8 @@ func TestDPAReconciler_buildRegistryDeployment(t *testing.T) {
Port: intstr.IntOrString{IntVal: 5000},
},
},
PeriodSeconds: 5,
TimeoutSeconds: 3,
PeriodSeconds: 10,
TimeoutSeconds: 10,
InitialDelaySeconds: 15,
},
ReadinessProbe: &corev1.Probe{
Expand All @@ -627,8 +627,8 @@ func TestDPAReconciler_buildRegistryDeployment(t *testing.T) {
Port: intstr.IntOrString{IntVal: 5000},
},
},
PeriodSeconds: 5,
TimeoutSeconds: 3,
PeriodSeconds: 10,
TimeoutSeconds: 10,
InitialDelaySeconds: 15,
},
},
Expand Down Expand Up @@ -705,8 +705,8 @@ func TestDPAReconciler_buildRegistryContainer(t *testing.T) {
Port: intstr.IntOrString{IntVal: 5000},
},
},
PeriodSeconds: 5,
TimeoutSeconds: 3,
PeriodSeconds: 10,
TimeoutSeconds: 10,
InitialDelaySeconds: 15,
},
ReadinessProbe: &corev1.Probe{
Expand All @@ -716,8 +716,8 @@ func TestDPAReconciler_buildRegistryContainer(t *testing.T) {
Port: intstr.IntOrString{IntVal: 5000},
},
},
PeriodSeconds: 5,
TimeoutSeconds: 3,
PeriodSeconds: 10,
TimeoutSeconds: 10,
InitialDelaySeconds: 15,
},
}
Expand Down
63 changes: 11 additions & 52 deletions tests/e2e/backup_restore_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import (
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/openshift/oadp-operator/api/v1alpha1"
. "github.com/openshift/oadp-operator/tests/e2e/lib"
utils "github.com/openshift/oadp-operator/tests/e2e/utils"
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type VerificationFunction func(*DpaCustomResource, string) error
type VerificationFunction func(client.Client, string) error

var _ = Describe("AWS backup restore tests", func() {

Expand Down Expand Up @@ -55,20 +53,18 @@ var _ = Describe("AWS backup restore tests", func() {
PostRestoreVerify VerificationFunction
MaxK8SVersion *K8sVersion
MinK8SVersion *K8sVersion
dpaCrOpts []DpaCROption
backupOpts []BackupOpts
}

mongoReady := VerificationFunction(func(dpaCR *DpaCustomResource, namespace string) error {
Eventually(IsDCReady(dpaCR.Client, "mongo-persistent", "todolist"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
mongoReady := VerificationFunction(func(ocClient client.Client, namespace string) error {
Eventually(IsDCReady(ocClient, "mongo-persistent", "todolist"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
// err := VerifyBackupRestoreData(artifact_dir, namespace, "restify", "parks-app") // TODO: VERIFY PARKS APP DATA
return nil
})
mysqlReady := VerificationFunction(func(dpaCR *DpaCustomResource, namespace string) error {
mysqlReady := VerificationFunction(func(ocClient client.Client, namespace string) error {
// This test confirms that SCC restore logic in our plugin is working
//Eventually(IsDCReady(ocClient, "mssql-persistent", "mysql"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
Eventually(IsDeploymentReady(dpaCR.Client, "mysql-persistent", "mysql"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
exists, err := DoesSCCExist(dpaCR.Client, "mysql-persistent-scc")
Eventually(IsDeploymentReady(ocClient, "mysql-persistent", "mysql"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
exists, err := DoesSCCExist(ocClient, "mysql-persistent-scc")
if err != nil {
return err
}
Expand All @@ -90,7 +86,7 @@ var _ = Describe("AWS backup restore tests", func() {
Skip(reason)
}

err := dpaCR.Build(brCase.BackupRestoreType, brCase.dpaCrOpts...)
err := dpaCR.Build(brCase.BackupRestoreType)
Expect(err).NotTo(HaveOccurred())

updateLastInstallingNamespace(dpaCR.Namespace)
Expand Down Expand Up @@ -134,14 +130,14 @@ var _ = Describe("AWS backup restore tests", func() {

// Run optional custom verification
log.Printf("Running pre-backup function for case %s", brCase.Name)
err = brCase.PreBackupVerify(dpaCR, brCase.ApplicationNamespace)
err = brCase.PreBackupVerify(dpaCR.Client, brCase.ApplicationNamespace)
Expect(err).ToNot(HaveOccurred())

nsRequiresResticDCWorkaround, err := NamespaceRequiresResticDCWorkaround(dpaCR.Client, brCase.ApplicationNamespace)
Expect(err).ToNot(HaveOccurred())
// create backup
log.Printf("Creating backup %s for case %s", backupName, brCase.Name)
backup, err := CreateBackupForNamespaces(dpaCR.Client, namespace, backupName, []string{brCase.ApplicationNamespace}, brCase.backupOpts...)
backup, err := CreateBackupForNamespaces(dpaCR.Client, namespace, backupName, []string{brCase.ApplicationNamespace})
Expect(err).ToNot(HaveOccurred())

// wait for backup to not be running
Expand Down Expand Up @@ -223,7 +219,7 @@ var _ = Describe("AWS backup restore tests", func() {

// Run optional custom verification
log.Printf("Running post-restore function for case %s", brCase.Name)
err = brCase.PostRestoreVerify(dpaCR, brCase.ApplicationNamespace)
err = brCase.PostRestoreVerify(dpaCR.Client, brCase.ApplicationNamespace)
Expect(err).ToNot(HaveOccurred())

// Test is successful, clean up everything
Expand Down Expand Up @@ -266,42 +262,5 @@ var _ = Describe("AWS backup restore tests", func() {
PreBackupVerify: mysqlReady,
PostRestoreVerify: mysqlReady,
}, nil),
Entry("MySQL application NoDefaultBackupStorageLocation", BackupRestoreCase{
ApplicationTemplate: "./sample-applications/mysql-persistent/mysql-persistent-template.yaml",
ApplicationNamespace: "mysql-persistent",
Name: "mysql-e2e",
BackupRestoreType: RESTIC,
PreBackupVerify: VerificationFunction(func(dpaCR *DpaCustomResource, namespace string) error {
// create BSL
err := CreateBackupStorageLocation(dpaCR.Client, velerov1.BackupStorageLocation{
ObjectMeta: metav1.ObjectMeta{
Name: dpaCR.Name + "nobsl-1",
Namespace: dpaCR.Namespace,
},
Spec: *dpaCR.VeleroBSL(),
})
if err != nil {
return err
}
return mysqlReady(dpaCR, namespace)
}),
PostRestoreVerify: VerificationFunction(func(dpaCR *DpaCustomResource, namespace string) error {
// delete BSL
err := DeleteBackupStorageLocation(dpaCR.Client, velerov1.BackupStorageLocation{
ObjectMeta: metav1.ObjectMeta{
Name: dpaCR.Name + "nobsl-1",
Namespace: dpaCR.Namespace,
}})
if err != nil {
return err
}
return mysqlReady(dpaCR, namespace)
}),
dpaCrOpts: []DpaCROption{
WithVeleroConfig(&v1alpha1.VeleroConfig{NoDefaultBackupLocation: true}),
WithBackupImages(false),
},
backupOpts: []BackupOpts{WithBackupStorageLocation("ts-" + instanceName + "nobsl-1")}, // e2e_sute_test.go: dpaCR.name = "ts-" + instanceName
}, nil),
)
})
17 changes: 1 addition & 16 deletions tests/e2e/lib/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

type BackupOpts func(*velero.Backup) error

func WithBackupStorageLocation(name string) BackupOpts {
return func(backup *velero.Backup) error {
backup.Spec.StorageLocation = name
return nil
}
}

func CreateBackupForNamespaces(ocClient client.Client, veleroNamespace, backupName string, namespaces []string, backupOpts ...BackupOpts) (velero.Backup, error) {
func CreateBackupForNamespaces(ocClient client.Client, veleroNamespace, backupName string, namespaces []string) (velero.Backup, error) {

backup := velero.Backup{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -31,12 +22,6 @@ func CreateBackupForNamespaces(ocClient client.Client, veleroNamespace, backupNa
IncludedNamespaces: namespaces,
},
}
for _, opt := range backupOpts {
err := opt(&backup)
if err != nil {
return velero.Backup{}, err
}
}
err := ocClient.Create(context.Background(), &backup)
return backup, err
}
Expand Down
66 changes: 13 additions & 53 deletions tests/e2e/lib/dpa_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,55 +53,10 @@ type DpaCustomResource struct {
Provider string
}

type DpaCROption func(*oadpv1alpha1.DataProtectionApplication) error

func WithConfiguration(configuration *oadpv1alpha1.ApplicationConfig) DpaCROption {
return func(cr *oadpv1alpha1.DataProtectionApplication) error {
cr.Spec.Configuration = configuration
return nil
}
}

func WithVeleroConfig(config *oadpv1alpha1.VeleroConfig) DpaCROption {
return func(cr *oadpv1alpha1.DataProtectionApplication) error {
cr.Spec.Configuration.Velero = config
return nil
}
}

func WithResticConfig(config *oadpv1alpha1.ResticConfig) DpaCROption {
return func(cr *oadpv1alpha1.DataProtectionApplication) error {
cr.Spec.Configuration.Restic = config
return nil
}
}

func WithBackupImages(backupImage bool) DpaCROption {
return func(cr *oadpv1alpha1.DataProtectionApplication) error {
cr.Spec.BackupImages = pointer.Bool(backupImage)
return nil
}
}

var VeleroPrefix = "velero-e2e-" + string(uuid.NewUUID())
var Dpa *oadpv1alpha1.DataProtectionApplication

func (v *DpaCustomResource) VeleroBSL() *velero.BackupStorageLocationSpec {
return &velero.BackupStorageLocationSpec{
Provider: v.CustomResource.Spec.BackupLocations[0].Velero.Provider,
Default: true,
Config: v.CustomResource.Spec.BackupLocations[0].Velero.Config,
Credential: v.CustomResource.Spec.BackupLocations[0].Velero.Credential,
StorageType: velero.StorageType{
ObjectStorage: &velero.ObjectStorageLocation{
Bucket: v.CustomResource.Spec.BackupLocations[0].Velero.ObjectStorage.Bucket,
Prefix: VeleroPrefix,
},
},
}
}

func (v *DpaCustomResource) Build(backupRestoreType BackupRestoreType, dpaCrOpts ...DpaCROption) error {
func (v *DpaCustomResource) Build(backupRestoreType BackupRestoreType) error {
// Velero Instance creation spec with backupstorage location default to AWS. Would need to parameterize this later on to support multiple plugins.
dpaInstance := oadpv1alpha1.DataProtectionApplication{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -120,7 +75,18 @@ func (v *DpaCustomResource) Build(backupRestoreType BackupRestoreType, dpaCrOpts
SnapshotLocations: v.CustomResource.Spec.SnapshotLocations,
BackupLocations: []oadpv1alpha1.BackupLocation{
{
Velero: v.VeleroBSL(),
Velero: &velero.BackupStorageLocationSpec{
Provider: v.CustomResource.Spec.BackupLocations[0].Velero.Provider,
Default: true,
Config: v.CustomResource.Spec.BackupLocations[0].Velero.Config,
Credential: v.CustomResource.Spec.BackupLocations[0].Velero.Credential,
StorageType: velero.StorageType{
ObjectStorage: &velero.ObjectStorageLocation{
Bucket: v.CustomResource.Spec.BackupLocations[0].Velero.ObjectStorage.Bucket,
Prefix: VeleroPrefix,
},
},
},
},
},
},
Expand All @@ -137,12 +103,6 @@ func (v *DpaCustomResource) Build(backupRestoreType BackupRestoreType, dpaCrOpts
dpaInstance.Spec.Configuration.Velero.DefaultPlugins = append(dpaInstance.Spec.Configuration.Velero.DefaultPlugins, oadpv1alpha1.DefaultPluginCSI)
dpaInstance.Spec.Configuration.Velero.FeatureFlags = append(dpaInstance.Spec.Configuration.Velero.FeatureFlags, "EnableCSI")
}

for _, opt := range dpaCrOpts {
if err := opt(&dpaInstance); err != nil {
return err
}
}
v.CustomResource = &dpaInstance
return nil
}
Expand Down
31 changes: 0 additions & 31 deletions tests/e2e/lib/velero_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/vmware-tanzu/velero/pkg/label"
"github.com/vmware-tanzu/velero/pkg/restic"
appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -159,36 +158,6 @@ func RestoreErrorLogs(ocClient client.Client, restore velero.Restore) []string {
return logLines
}

func CreateBackupStorageLocation(ocClient client.Client, backupStorageLocation velero.BackupStorageLocation) error {
veleroClient, err := GetVeleroClient()
if err != nil {
return err
}
_, err = veleroClient.VeleroV1().BackupStorageLocations(backupStorageLocation.Namespace).Create(context.TODO(), &backupStorageLocation, metav1.CreateOptions{})
if err != nil {
if apierrors.IsAlreadyExists(err) {
return nil
}
return err
}
return nil
}

func DeleteBackupStorageLocation(ocClient client.Client, backupStorageLocation velero.BackupStorageLocation) error {
veleroClient, err := GetVeleroClient()
if err != nil {
return err
}
err = veleroClient.VeleroV1().BackupStorageLocations(backupStorageLocation.Namespace).Delete(context.TODO(), backupStorageLocation.Name, metav1.DeleteOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return err
}
return nil
}

func GetVeleroDeploymentList(namespace string) (*appsv1.DeploymentList, error) {
client, err := setUpClient()
if err != nil {
Expand Down