Merge pull request #4719 from ywk253100/220225_bsl
Update BSL CR as long as there is any errorpull/4729/head
commit
208d250ddc
|
@ -0,0 +1 @@
|
|||
Mark the BSL as "Unavailable" when gets any error and add a new field "Message" to the status to record the error message
|
|
@ -158,6 +158,10 @@ spec:
|
|||
format: date-time
|
||||
nullable: true
|
||||
type: string
|
||||
message:
|
||||
description: Message is a message about the backup storage location's
|
||||
status.
|
||||
type: string
|
||||
phase:
|
||||
description: Phase is the current state of the BackupStorageLocation.
|
||||
enum:
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -74,6 +74,10 @@ type BackupStorageLocationStatus struct {
|
|||
// +nullable
|
||||
LastValidationTime *metav1.Time `json:"lastValidationTime,omitempty"`
|
||||
|
||||
// Message is a message about the backup storage location's status.
|
||||
// +optional
|
||||
Message string `json:"message,omitempty"`
|
||||
|
||||
// LastSyncedRevision is the value of the `metadata/revision` file in the backup
|
||||
// storage location the last time the BSL's contents were synced into the cluster.
|
||||
//
|
||||
|
|
|
@ -23,8 +23,8 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"sigs.k8s.io/cluster-api/util/patch"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
|
@ -95,37 +95,45 @@ func (r *BackupStorageLocationReconciler) Reconcile(ctx context.Context, req ctr
|
|||
continue
|
||||
}
|
||||
|
||||
backupStore, err := r.BackupStoreGetter.Get(location, pluginManager, log)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Error getting a backup store")
|
||||
continue
|
||||
}
|
||||
|
||||
// Initialize the patch helper.
|
||||
patchHelper, err := patch.NewHelper(location, r.Client)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Error getting a patch helper to update this resource")
|
||||
continue
|
||||
}
|
||||
|
||||
// updates the default backup location
|
||||
location.Spec.Default = isDefault
|
||||
|
||||
log.Info("Validating backup storage location")
|
||||
anyVerified = true
|
||||
if err := backupStore.IsValid(); err != nil {
|
||||
log.Info("Backup storage location is invalid, marking as unavailable")
|
||||
unavailableErrors = append(unavailableErrors, errors.Wrapf(err, "Backup storage location %q is unavailable", location.Name).Error())
|
||||
location.Status.Phase = velerov1api.BackupStorageLocationPhaseUnavailable
|
||||
} else {
|
||||
log.Info("Backup storage location valid, marking as available")
|
||||
location.Status.Phase = velerov1api.BackupStorageLocationPhaseAvailable
|
||||
}
|
||||
location.Status.LastValidationTime = &metav1.Time{Time: time.Now().UTC()}
|
||||
|
||||
if err := patchHelper.Patch(r.Ctx, location); err != nil {
|
||||
log.WithError(err).Error("Error updating backup storage location phase")
|
||||
}
|
||||
func() {
|
||||
// Initialize the patch helper.
|
||||
patchHelper, err := patch.NewHelper(location, r.Client)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Error getting a patch helper to update this resource")
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
location.Status.LastValidationTime = &metav1.Time{Time: time.Now().UTC()}
|
||||
if err != nil {
|
||||
log.Info("Backup storage location is invalid, marking as unavailable")
|
||||
err = errors.Wrapf(err, "Backup storage location %q is unavailable", location.Name)
|
||||
unavailableErrors = append(unavailableErrors, err.Error())
|
||||
location.Status.Phase = velerov1api.BackupStorageLocationPhaseUnavailable
|
||||
location.Status.Message = err.Error()
|
||||
} else {
|
||||
log.Info("Backup storage location valid, marking as available")
|
||||
location.Status.Phase = velerov1api.BackupStorageLocationPhaseAvailable
|
||||
location.Status.Message = ""
|
||||
}
|
||||
if err := patchHelper.Patch(r.Ctx, location); err != nil {
|
||||
log.WithError(err).Error("Error updating backup storage location phase")
|
||||
}
|
||||
}()
|
||||
|
||||
backupStore, err := r.BackupStoreGetter.Get(location, pluginManager, log)
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "Error getting a backup store")
|
||||
return
|
||||
}
|
||||
|
||||
// updates the default backup location
|
||||
location.Spec.Default = isDefault
|
||||
|
||||
log.Info("Validating backup storage location")
|
||||
err = backupStore.IsValid()
|
||||
}()
|
||||
}
|
||||
|
||||
if !anyVerified {
|
||||
|
|
Loading…
Reference in New Issue