Skip to content

Commit

Permalink
Added backup test-case with s3 storage
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekdwivedi3060 committed Jul 29, 2024
1 parent 975274e commit 2c2b437
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 129 deletions.
4 changes: 2 additions & 2 deletions config/samples/aerospikebackup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ spec:
source-cluster: test-cluster
storage: local
test-routine1:
backup-policy: test-policy
backup-policy: test-policy1
interval-cron: "@daily"
incr-interval-cron: "@hourly"
namespaces: [ "test" ]
source-cluster: test-cluster
storage: local
storage: s3Storage
14 changes: 11 additions & 3 deletions config/samples/aerospikebackupservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ spec:
local:
path: /localStorage
type: local
s3Storage:
type: aws-s3
path: "s3://aerospike-kubernetes-operator-test"
s3-region: us-east-1
s3-profile: default

secrets:
- secretName: auth-secret
- secretName: aws-secret
volumeMount:
name: auth-secret
mountPath: /etc/aerospike-backup-service/auth-secret
name: aws-secret
mountPath: /root/.aws/credentials
subPath: credentials

service:
type: LoadBalancer

13 changes: 5 additions & 8 deletions controllers/backup-service/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ import (
"github.com/aerospike/aerospike-kubernetes-operator/pkg/utils"
)

// BackupServiceConfigYAML is the backup service configuration yaml file
const BackupServiceConfigYAML = "aerospike-backup-service.yml"

type serviceConfig struct {
portInfo map[string]int32
contextPath string
Expand Down Expand Up @@ -157,7 +154,7 @@ func (r *SingleBackupServiceReconciler) reconcileConfigMap() error {
return err
}

data := cm.Data[BackupServiceConfigYAML]
data := cm.Data[common.BackupServiceConfigYAML]

if err := yaml.Unmarshal([]byte(data), &currentDataMap); err != nil {
return err
Expand All @@ -173,7 +170,7 @@ func (r *SingleBackupServiceReconciler) reconcileConfigMap() error {
return err
}

cm.Data[BackupServiceConfigYAML] = string(updatedConfig)
cm.Data[common.BackupServiceConfigYAML] = string(updatedConfig)

if err = r.Client.Update(
context.TODO(), cm, common.UpdateOption,
Expand All @@ -192,7 +189,7 @@ func (r *SingleBackupServiceReconciler) reconcileConfigMap() error {

func (r *SingleBackupServiceReconciler) getConfigMapData() map[string]string {
data := make(map[string]string)
data[BackupServiceConfigYAML] = string(r.aeroBackupService.Spec.Config.Raw)
data[common.BackupServiceConfigYAML] = string(r.aeroBackupService.Spec.Config.Raw)

return data
}
Expand Down Expand Up @@ -419,8 +416,8 @@ func (r *SingleBackupServiceReconciler) getVolumeAndMounts() ([]corev1.VolumeMou
// Backup service configMap mountPath
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "backup-service-config",
MountPath: fmt.Sprintf("/etc/aerospike-backup-service/%s", BackupServiceConfigYAML),
SubPath: BackupServiceConfigYAML,
MountPath: fmt.Sprintf("/etc/aerospike-backup-service/%s", common.BackupServiceConfigYAML),
SubPath: common.BackupServiceConfigYAML,
})

// Backup service configMap
Expand Down
10 changes: 4 additions & 6 deletions controllers/backup/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"github.com/aerospike/aerospike-kubernetes-operator/pkg/utils"
)

const BackupConfigYAML = "aerospike-backup-service.yml"

// SingleBackupReconciler reconciles a single AerospikeBackup object
type SingleBackupReconciler struct {
client.Client
Expand Down Expand Up @@ -139,7 +137,7 @@ func (r *SingleBackupReconciler) reconcileConfigMap() error {
return err
}

data := cm.Data[BackupConfigYAML]
data := cm.Data[common.BackupServiceConfigYAML]

if err := yaml.Unmarshal([]byte(data), &cmDataMap); err != nil {
return err
Expand Down Expand Up @@ -184,7 +182,7 @@ func (r *SingleBackupReconciler) reconcileConfigMap() error {
return err
}

cm.Data[BackupConfigYAML] = string(updatedConfig)
cm.Data[common.BackupServiceConfigYAML] = string(updatedConfig)

if err := r.Client.Update(
context.TODO(), cm, common.UpdateOption,
Expand Down Expand Up @@ -231,7 +229,7 @@ func (r *SingleBackupReconciler) removeBackupInfoFromConfigMap() error {
return err
}

data := cm.Data[BackupConfigYAML]
data := cm.Data[common.BackupServiceConfigYAML]

if err := yaml.Unmarshal([]byte(data), &cmDataMap); err != nil {
return err
Expand Down Expand Up @@ -264,7 +262,7 @@ func (r *SingleBackupReconciler) removeBackupInfoFromConfigMap() error {
return err
}

cm.Data[BackupConfigYAML] = string(updatedConfig)
cm.Data[common.BackupServiceConfigYAML] = string(updatedConfig)

if err := r.Client.Update(
context.TODO(), cm, common.UpdateOption,
Expand Down
15 changes: 8 additions & 7 deletions controllers/common/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package common

// Backup Config relate keys
const (
ServiceKey = "service"
AerospikeClustersKey = "aerospike-clusters"
AerospikeClusterKey = "aerospike-cluster"
StorageKey = "storage"
BackupRoutinesKey = "backup-routines"
BackupPoliciesKey = "backup-policies"
SecretAgentsKey = "secret-agent"
ServiceKey = "service"
AerospikeClustersKey = "aerospike-clusters"
AerospikeClusterKey = "aerospike-cluster"
StorageKey = "storage"
BackupRoutinesKey = "backup-routines"
BackupPoliciesKey = "backup-policies"
SecretAgentsKey = "secret-agent"
BackupServiceConfigYAML = "aerospike-backup-service.yml"
)

const (
Expand Down
51 changes: 41 additions & 10 deletions test/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ var _ = Describe(
)

Context("When doing Valid operations", func() {
It("Should trigger backup when correct backup config is given", func() {
It("Should trigger backup when correct backup config with local storage is given", func() {
backup, err = newBackup()
Expect(err).ToNot(HaveOccurred())
err = deployBackup(k8sClient, backup)
Expand All @@ -259,6 +259,25 @@ var _ = Describe(

})

It("Should trigger backup when correct backup config with s3 storage is given", func() {
config := getBackupConfigInMap()
backupRoutines := config[common.BackupRoutinesKey].(map[string]interface{})
backupRoutines["test-routine"].(map[string]interface{})[common.StorageKey] = "s3Storage"

config[common.BackupRoutinesKey] = backupRoutines

configBytes, mErr := json.Marshal(config)
Expect(mErr).ToNot(HaveOccurred())

backup = newBackupWithConfig(configBytes)

err = deployBackup(k8sClient, backup)
Expect(err).ToNot(HaveOccurred())

err = validateTriggeredBackup(k8sClient, backupServiceName, backupServiceNamespace, backup)
Expect(err).ToNot(HaveOccurred())
})

It("Should trigger on-demand backup when given", func() {
backup, err = newBackup()
Expect(err).ToNot(HaveOccurred())
Expand All @@ -275,16 +294,31 @@ var _ = Describe(
},
}

err = k8sClient.Update(testCtx, backup)
err = updateBackup(k8sClient, backup)
Expect(err).ToNot(HaveOccurred())

err = validateTriggeredBackup(k8sClient, backupServiceName, backupServiceNamespace, backup)
Expect(err).ToNot(HaveOccurred())
})

It("Should unregister backup-routines when removed from backup CR", func() {
backup, err = newBackup()
backupConfig := getBackupConfigInMap()
backupRoutines := backupConfig[common.BackupRoutinesKey].(map[string]interface{})
backupRoutines["test-routine1"] = map[string]interface{}{
"backup-policy": "test-policy1",
"interval-cron": "@daily",
"incr-interval-cron": "@hourly",
"namespaces": []string{"test"},
"source-cluster": "test-cluster",
"storage": "local",
}

backupConfig[common.BackupRoutinesKey] = backupRoutines

configBytes, err := json.Marshal(backupConfig)
Expect(err).ToNot(HaveOccurred())

backup = newBackupWithConfig(configBytes)
err = deployBackup(k8sClient, backup)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -295,17 +329,14 @@ var _ = Describe(
Expect(err).ToNot(HaveOccurred())

By("Removing 1 backup-routine from backup CR")
backupConfig := getBackupConfigInMap()
routines := backupConfig[common.BackupRoutinesKey].(map[string]interface{})
delete(routines, "test-routine1")
backupConfig[common.BackupRoutinesKey] = routines
backupConfig = getBackupConfigInMap()

configBytes, mErr := json.Marshal(backupConfig)
Expect(mErr).ToNot(HaveOccurred())
configBytes, err = json.Marshal(backupConfig)
Expect(err).ToNot(HaveOccurred())

backup.Spec.Config.Raw = configBytes

err = k8sClient.Update(testCtx, backup)
err = updateBackup(k8sClient, backup)
Expect(err).ToNot(HaveOccurred())

err = validateTriggeredBackup(k8sClient, backupServiceName, backupServiceNamespace, backup)
Expand Down
Loading

0 comments on commit 2c2b437

Please sign in to comment.