Skip to content

Commit

Permalink
Dropped 2.0.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekdwivedi3060 committed Dec 16, 2024
1 parent c35ddac commit 6dc8f10
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 22 deletions.
34 changes: 30 additions & 4 deletions api/v1beta1/aerospikebackup_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
Expand Down Expand Up @@ -59,11 +60,23 @@ func (r *AerospikeBackup) ValidateCreate() (admission.Warnings, error) {

abLog.Info("Validate create")

k8sClient, gErr := getK8sClient()
if gErr != nil {
return nil, gErr
}

if err := validateBackupSvcSupportedVersion(k8sClient,
r.Spec.BackupService.Name,
r.Spec.BackupService.Namespace,
); err != nil {
return nil, err
}

if len(r.Spec.OnDemandBackups) != 0 {
return nil, fmt.Errorf("onDemand backups config cannot be specified while creating backup")
}

if err := r.validateBackupConfig(); err != nil {
if err := r.validateBackupConfig(k8sClient); err != nil {
return nil, err
}

Expand All @@ -78,11 +91,23 @@ func (r *AerospikeBackup) ValidateUpdate(old runtime.Object) (admission.Warnings

oldObj := old.(*AerospikeBackup)

k8sClient, gErr := getK8sClient()
if gErr != nil {
return nil, gErr
}

if err := validateBackupSvcSupportedVersion(k8sClient,
r.Spec.BackupService.Name,
r.Spec.BackupService.Namespace,
); err != nil {
return nil, err
}

if !reflect.DeepEqual(r.Spec.BackupService, oldObj.Spec.BackupService) {
return nil, fmt.Errorf("backup service cannot be updated")
}

if err := r.validateBackupConfig(); err != nil {
if err := r.validateBackupConfig(k8sClient); err != nil {
return nil, err
}

Expand All @@ -107,7 +132,7 @@ func (r *AerospikeBackup) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}

func (r *AerospikeBackup) validateBackupConfig() error {
func (r *AerospikeBackup) validateBackupConfig(k8sClient client.Client) error {
backupConfig := make(map[string]interface{})

if err := yaml.Unmarshal(r.Spec.Config.Raw, &backupConfig); err != nil {
Expand All @@ -130,7 +155,8 @@ func (r *AerospikeBackup) validateBackupConfig() error {
return fmt.Errorf("secret-agent field cannot be specified in backup config")
}

backupSvcConfig, err := getBackupServiceFullConfig(r.Spec.BackupService.Name, r.Spec.BackupService.Namespace)
backupSvcConfig, err := getBackupServiceFullConfig(k8sClient, r.Spec.BackupService.Name,
r.Spec.BackupService.Namespace)
if err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions api/v1beta1/aerospikebackupservice_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/aerospike/aerospike-backup-service/v2/pkg/validation"
)

const minSupportedVersion = "3.0.0"

func (r *AerospikeBackupService) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Expand Down Expand Up @@ -58,6 +60,10 @@ func (r *AerospikeBackupService) ValidateCreate() (admission.Warnings, error) {

absLog.Info("Validate create")

if err := ValidateBackupSvcVersion(r.Spec.Image); err != nil {
return nil, err
}

if err := r.validateBackupServiceConfig(); err != nil {
return nil, err
}
Expand All @@ -75,6 +81,10 @@ func (r *AerospikeBackupService) ValidateUpdate(_ runtime.Object) (admission.War

absLog.Info("Validate update")

if err := ValidateBackupSvcVersion(r.Spec.Image); err != nil {
return nil, err
}

if err := r.validateBackupServiceConfig(); err != nil {
return nil, err
}
Expand Down
20 changes: 17 additions & 3 deletions api/v1beta1/aerospikerestore_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
Expand Down Expand Up @@ -67,7 +68,19 @@ func (r *AerospikeRestore) ValidateCreate() (admission.Warnings, error) {

arLog.Info("Validate create")

if err := r.validateRestoreConfig(); err != nil {
k8sClient, gErr := getK8sClient()
if gErr != nil {
return nil, gErr
}

if err := validateBackupSvcSupportedVersion(k8sClient,
r.Spec.BackupService.Name,
r.Spec.BackupService.Namespace,
); err != nil {
return nil, err
}

if err := r.validateRestoreConfig(k8sClient); err != nil {
return nil, err
}

Expand Down Expand Up @@ -99,14 +112,15 @@ func (r *AerospikeRestore) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}

func (r *AerospikeRestore) validateRestoreConfig() error {
func (r *AerospikeRestore) validateRestoreConfig(k8sClient client.Client) error {
restoreConfig := make(map[string]interface{})

if err := yaml.Unmarshal(r.Spec.Config.Raw, &restoreConfig); err != nil {
return err
}

backupSvcConfig, err := getBackupServiceFullConfig(r.Spec.BackupService.Name, r.Spec.BackupService.Namespace)
backupSvcConfig, err := getBackupServiceFullConfig(k8sClient, r.Spec.BackupService.Name,
r.Spec.BackupService.Namespace)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const (
StorageKey = "storage"
BackupRoutinesKey = "backup-routines"
BackupPoliciesKey = "backup-policies"
SecretAgentsKey = "secret-agent"
SecretAgentsKey = "secret-agents"
SourceClusterKey = "source-cluster"
BackupServiceConfigYAML = "aerospike-backup-service.yml"
)
Expand Down
45 changes: 37 additions & 8 deletions api/v1beta1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1beta1

import (
"context"
"fmt"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -14,6 +15,7 @@ import (

"github.com/aerospike/aerospike-backup-service/v2/pkg/dto"
asdbv1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1"
lib "github.com/aerospike/aerospike-management-lib"
)

func namespacedName(obj client.Object) string {
Expand Down Expand Up @@ -42,26 +44,53 @@ func getK8sClient() (client.Client, error) {
return cl, nil
}

func getBackupServiceFullConfig(name, namespace string) (*dto.Config, error) {
func getBackupServiceFullConfig(k8sClient client.Client, name, namespace string) (*dto.Config, error) {
var backupSvcConfigMap corev1.ConfigMap

cl, gErr := getK8sClient()
if gErr != nil {
return nil, gErr
}

if err := cl.Get(context.TODO(),
if err := k8sClient.Get(context.TODO(),
types.NamespacedName{Name: name, Namespace: namespace},
&backupSvcConfigMap); err != nil {
return nil, err
}

var backupSvcConfig dto.Config

if err := yaml.UnmarshalStrict([]byte(backupSvcConfigMap.Data[BackupServiceConfigYAML]),
if err := yaml.Unmarshal([]byte(backupSvcConfigMap.Data[BackupServiceConfigYAML]),
&backupSvcConfig); err != nil {
return nil, err
}

return &backupSvcConfig, nil
}

func ValidateBackupSvcVersion(image string) error {
version, err := asdbv1.GetImageVersion(image)
if err != nil {
return err
}

val, err := lib.CompareVersions(version, minSupportedVersion)
if err != nil {
return fmt.Errorf("failed to check backup service image version: %v", err)
}

if val < 0 {
return fmt.Errorf("backup service version %s is not supported. Minimum supported version is %s",
version, minSupportedVersion)
}

return nil
}

func validateBackupSvcSupportedVersion(k8sClient client.Client, name, namespace string) error {
var backupSvc AerospikeBackupService

if err := k8sClient.Get(context.TODO(),
types.NamespacedName{Name: name, Namespace: namespace},
&backupSvc,
); err != nil {
return err
}

return ValidateBackupSvcVersion(backupSvc.Spec.Image)
}
34 changes: 28 additions & 6 deletions internal/controller/backup-service/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ func (r *SingleBackupServiceReconciler) Reconcile() (result ctrl.Result, recErr
}
}()

// Skip reconcile if the backup service version is less thatn 2.0.0.
// This is to avoid rolling restart of the backup service pods after AKO upgrade
if err := asdbv1beta1.ValidateBackupSvcVersion(r.aeroBackupService.Spec.Image); err != nil {
r.Log.Info("Skipping reconcile as backup service version is less than 2.0.0")
return reconcile.Result{}, nil
}

if !r.aeroBackupService.ObjectMeta.DeletionTimestamp.IsZero() {
// Stop reconciliation as the Aerospike Backup service is being deleted
return reconcile.Result{}, nil
Expand Down Expand Up @@ -109,7 +116,7 @@ func (r *SingleBackupServiceReconciler) reconcileConfigMap() error {
return err
}

r.Log.Info("Create Backup Service ConfigMap",
r.Log.Info("Creating new Backup Service ConfigMap",
"name", getBackupServiceName(r.aeroBackupService))

cm = &corev1.ConfigMap{
Expand All @@ -133,7 +140,7 @@ func (r *SingleBackupServiceReconciler) reconcileConfigMap() error {
context.TODO(), cm, common.CreateOption,
); err != nil {
return fmt.Errorf(
"failed to create ConfigMap: %v",
"failed to create ConfigMap: %w",
err,
)
}
Expand Down Expand Up @@ -162,10 +169,25 @@ func (r *SingleBackupServiceReconciler) reconcileConfigMap() error {
return err
}

currentDataMap[asdbv1beta1.ServiceKey] = desiredDataMap[asdbv1beta1.ServiceKey]
currentDataMap[asdbv1beta1.BackupPoliciesKey] = desiredDataMap[asdbv1beta1.BackupPoliciesKey]
currentDataMap[asdbv1beta1.StorageKey] = desiredDataMap[asdbv1beta1.StorageKey]
currentDataMap[asdbv1beta1.SecretAgentsKey] = desiredDataMap[asdbv1beta1.SecretAgentsKey]
// Sync keys
keys := []string{
asdbv1beta1.ServiceKey,
asdbv1beta1.BackupPoliciesKey,
asdbv1beta1.StorageKey,
asdbv1beta1.SecretAgentsKey,
}

for _, key := range keys {
if value, ok := desiredDataMap[key]; ok {
currentDataMap[key] = value
} else {
delete(currentDataMap, key)
}
}

// Remove old "secret-agent: null" from configMap
// This was added internally in AKO (3.4) during backup service configMap update
delete(currentDataMap, "secret-agent")

updatedConfig, err := yaml.Marshal(currentDataMap)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions internal/controller/restore/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func (r *SingleRestoreReconciler) Reconcile() (result ctrl.Result, recErr error)
return reconcile.Result{}, nil
}

if r.aeroRestore.Status.Phase == asdbv1beta1.AerospikeRestoreCompleted {
// Stop reconciliation as the Aerospike restore is already completed
r.Log.Info("Restore already completed, skipping reconciliation")
return reconcile.Result{}, nil
}

if err := r.setStatusPhase(asdbv1beta1.AerospikeRestoreInProgress); err != nil {
return ctrl.Result{}, err
}
Expand Down

0 comments on commit 6dc8f10

Please sign in to comment.