diff --git a/controllers/che/backup.go b/controllers/che/backup.go index 0736907402..9a107f540f 100644 --- a/controllers/che/backup.go +++ b/controllers/che/backup.go @@ -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" @@ -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 { diff --git a/controllers/che/checluster_controller.go b/controllers/che/checluster_controller.go index 8e8aadb94e..8530714e3f 100644 --- a/controllers/che/checluster_controller.go +++ b/controllers/che/checluster_controller.go @@ -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