Skip to content

Commit

Permalink
Do not automatically backup to internal backup server if it doesn't e…
Browse files Browse the repository at this point in the history
…xist

Signed-off-by: Mykola Morhun <[email protected]>
  • Loading branch information
mmorhun committed Sep 24, 2021
1 parent d7e925d commit 04057d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
8 changes: 6 additions & 2 deletions controllers/che/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

chev1 "github.com/eclipse-che/che-operator/api/v1"
"github.com/eclipse-che/che-operator/pkg/deploy"
Expand Down Expand Up @@ -105,10 +106,13 @@ func getBackupCRSpec(deployContext *deploy.DeployContext) (*chev1.CheClusterBack
// getBackupServerConfigurationNameForBackupBeforeUpdate searches for backup server configuration.
// If there is only one, then it is used.
// If there are two or more, then one with 'che.eclipse.org/default-backup-server-configuration' annotation is used.
// If there is none, then empty string returned (internal backup server should be used).
// If there is none, then empty string is returned.
func getBackupServerConfigurationNameForBackupBeforeUpdate(deployContext *deploy.DeployContext) (string, error) {
backupServerConfigsList := &chev1.CheBackupServerConfigurationList{}
if err := deployContext.ClusterAPI.Client.List(context.TODO(), backupServerConfigsList); err != nil {
listOptions := &client.ListOptions{
Namespace: deployContext.CheCluster.GetNamespace(),
}
if err := deployContext.ClusterAPI.Client.List(context.TODO(), backupServerConfigsList, listOptions); err != nil {
return "", err
}
if len(backupServerConfigsList.Items) == 1 {
Expand Down
38 changes: 23 additions & 15 deletions controllers/che/checluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,33 @@ func (r *CheClusterReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)

if isCheGoingToBeUpdated(instance) {
// Current operator is newer than deployed Che
backupCR, err := getBackupCRForUpdate(deployContext)
// Check if any backup server configured
configName, err := getBackupServerConfigurationNameForBackupBeforeUpdate(deployContext)
if err != nil {
if errors.IsNotFound(err) {
// Create a backup before updating current installation
if err := requestBackup(deployContext); err != nil {
return ctrl.Result{}, err
}
// Backup request is successfully submitted
// Give some time for the backup
return ctrl.Result{RequeueAfter: time.Second * 15}, nil
}
return ctrl.Result{}, err
}
if backupCR.Status.State == orgv1.STATE_IN_PROGRESS {
// Backup is still in progress
return ctrl.Result{RequeueAfter: time.Second * 5}, nil
if configName != "" {
// Backup server configured
backupCR, err := getBackupCRForUpdate(deployContext)
if err != nil {
if errors.IsNotFound(err) {
// Create a backup before updating current installation
if err := requestBackup(deployContext); err != nil {
return ctrl.Result{}, err
}
// Backup request is successfully submitted
// Give some time for the backup
return ctrl.Result{RequeueAfter: time.Second * 15}, nil
}
return ctrl.Result{}, err
}
if backupCR.Status.State == orgv1.STATE_IN_PROGRESS {
// Backup is still in progress
return ctrl.Result{RequeueAfter: time.Second * 5}, nil
}
// Backup is done or failed
// Proceed anyway
}
// Backup is done or failed
// Proceed anyway
}

// Reconcile finalizers before CR is deleted
Expand Down

0 comments on commit 04057d7

Please sign in to comment.