Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not automatically backup to internal backup server if it doesn't exist #1090

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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