Skip to content

Commit

Permalink
Skip creating/processing backup-session when backup-config is paused (#…
Browse files Browse the repository at this point in the history
…759)

* Skip creating/processing backup-session when backup-config is paused
* Add backup-session skipped event/status
* Ignore previously skipped backup session
  • Loading branch information
Dipta Das authored and tamalsaha committed Apr 30, 2019
1 parent 99753f7 commit 09af5d3
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions apis/stash/v1beta1/backup_session_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
BackupSessionRunning BackupSessionPhase = "Running"
BackupSessionSucceeded BackupSessionPhase = "Succeeded"
BackupSessionFailed BackupSessionPhase = "Failed"
BackupSessionSkipped BackupSessionPhase = "Skipped"
BackupSessionUnknown BackupSessionPhase = "Unknown"
)

Expand Down
11 changes: 9 additions & 2 deletions pkg/backup/backupsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ func (c *BackupSessionController) processBackupSession(key string) error {
return fmt.Errorf("can't get BackupConfiguration for BackupSession %s/%s, reason: %s", backupSession.Namespace, backupSession.Name, err)
}

// skip if BackupConfiguration paused
if backupConfiguration.Spec.Paused {
log.Infof("Skipping processing BackupSession %s/%s. Reason: Backup Configuration is paused.", backupSession.Namespace, backupSession.Name)
return nil
}

host, err := util.GetHostName(backupConfiguration.Spec.Target)
if err != nil {
return err
Expand Down Expand Up @@ -424,9 +430,10 @@ func (c *BackupSessionController) writeBackupFailureEvent(backupSession *api_v1b

func (c *BackupSessionController) isBackupTakenForThisHost(backupSession *api_v1beta1.BackupSession, host string) bool {

// if overall backupSession phase is "Succeeded" or "Failed" then it has been processed already
// if overall backupSession phase is "Succeeded" or "Failed" or "Skipped" then it has been processed already
if backupSession.Status.Phase == api_v1beta1.BackupSessionSucceeded ||
backupSession.Status.Phase == api_v1beta1.BackupSessionFailed {
backupSession.Status.Phase == api_v1beta1.BackupSessionFailed ||
backupSession.Status.Phase == api_v1beta1.BackupSessionSkipped {
return true
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/cmds/create_backupsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func (opt *options) createBackupSession() error {
if err != nil {
return err
}
// skip if BackupConfiguration paused
if backupConfiguration.Spec.Paused {
log.Infof("Skipping creating BackupSession. Reason: Backup Configuration %s/%s is paused.", backupConfiguration.Namespace, backupConfiguration.Name)
return nil
}
ref, err := reference.GetReference(stash_scheme.Scheme, backupConfiguration)
if err != nil {
return err
Expand Down
7 changes: 7 additions & 0 deletions pkg/controller/backup_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"fmt"

"github.com/appscode/go/log"
api_v1beta1 "github.com/appscode/stash/apis/stash/v1beta1"
stash_scheme "github.com/appscode/stash/client/clientset/versioned/scheme"
v1beta1_util "github.com/appscode/stash/client/clientset/versioned/typed/stash/v1beta1/util"
Expand Down Expand Up @@ -74,6 +75,12 @@ func (c *StashController) runBackupConfigurationProcessor(key string) error {
return err
}

// skip if BackupConfiguration paused
if backupConfiguration.Spec.Paused {
log.Infof("Skipping processing BackupConfiguration %s/%s. Reason: Backup Configuration is paused.", backupConfiguration.Namespace, backupConfiguration.Name)
return nil
}

if backupConfiguration.Spec.Target != nil &&
util.BackupModel(backupConfiguration.Spec.Target.Ref.Kind) == util.ModelSidecar {
if err := c.EnsureV1beta1Sidecar(backupConfiguration); err != nil {
Expand Down
32 changes: 32 additions & 0 deletions pkg/controller/backup_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func (c *StashController) runBackupSessionProcessor(key string) error {
} else if phase == api_v1beta1.BackupSessionRunning {
log.Infof("Skipping processing BackupSession %s/%s. Reason: phase is %q.", backupSession.Namespace, backupSession.Name, backupSession.Status.Phase)
return nil
} else if phase == api_v1beta1.BackupSessionSkipped {
log.Infof("Skipping processing BackupSession %s/%s. Reason: previously skipped.", backupSession.Namespace, backupSession.Name)
return nil
}

// backup process for this BackupSession has not started. so let's start backup process
Expand All @@ -110,6 +113,12 @@ func (c *StashController) runBackupSessionProcessor(key string) error {
return fmt.Errorf("can't get BackupConfiguration for BackupSession %s/%s, Reason: %s", backupSession.Namespace, backupSession.Name, err)
}

// skip if BackupConfiguration paused
if backupConfig.Spec.Paused {
log.Infof("Skipping processing BackupSession %s/%s. Reason: Backup Configuration is paused.", backupSession.Namespace, backupSession.Name)
return c.setBackupSessionSkipped(backupSession, "Backup Configuration is paused")
}

// skip if backup model is sidecar.
// for sidecar model controller inside sidecar will take care of it.
if backupConfig.Spec.Target != nil && util.BackupModel(backupConfig.Spec.Target.Ref.Kind) == util.ModelSidecar {
Expand Down Expand Up @@ -265,6 +274,29 @@ func (c *StashController) setBackupSessionFailed(backupSession *api_v1beta1.Back
return err
}

func (c *StashController) setBackupSessionSkipped(backupSession *api_v1beta1.BackupSession, reason string) error {
// set BackupSession phase to "Skipped"
_, err := stash_util.UpdateBackupSessionStatus(c.stashClient.StashV1beta1(), backupSession, func(in *api_v1beta1.BackupSessionStatus) *api_v1beta1.BackupSessionStatus {
in.Phase = api_v1beta1.BackupSessionSkipped
return in
}, apis.EnableStatusSubresource)
if err != nil {
return err
}

// write skip event
_, err = eventer.CreateEvent(
c.kubeClient,
eventer.BackupSessionEventComponent,
backupSession,
core.EventTypeWarning,
eventer.EventReasonBackupSessionSkipped,
reason,
)

return err
}

func (c *StashController) setBackupSessionRunning(backupSession *api_v1beta1.BackupSession) error {

backupConfig, err := c.stashClient.StashV1beta1().BackupConfigurations(backupSession.Namespace).Get(
Expand Down
1 change: 1 addition & 0 deletions pkg/eventer/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
EventReasonInvalidBackupSession = "InvalidBackupSession"
EventReasonBackupSessionSucceeded = "BackupSessionSucceeded"
EventReasonBackupSessionFailed = "BackupSessionFailedToExecute"
EventReasonBackupSessionSkipped = "BackupSessionSkipped"
EventReasonBackupSessionJobCreated = "BackupSessionJobCreated"
EventReasonHostBackupSucceded = "SuccessfulHostBackup"
EventReasonHostBackupFailed = "FailedHostBackup"
Expand Down

0 comments on commit 09af5d3

Please sign in to comment.