diff --git a/api/v1alpha1/nonadmin_types.go b/api/v1alpha1/nonadmin_types.go new file mode 100644 index 0000000..b3259ee --- /dev/null +++ b/api/v1alpha1/nonadmin_types.go @@ -0,0 +1,52 @@ +/* +Copyright 2024. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +// NonAdminPhase is a simple one high-level summary of the lifecycle of a NonAdminBackup or NonAdminRestore. +// +kubebuilder:validation:Enum=New;BackingOff;Created;Deleting +type NonAdminPhase string + +const ( + // NonAdminPhaseNew - NonAdmin object was accepted by the OpenShift cluster, but it has not yet been processed by the NonAdminController + NonAdminPhaseNew NonAdminPhase = "New" + // NonAdminPhaseBackingOff - Velero object was not created due to NonAdmin object error (configuration or similar) + NonAdminPhaseBackingOff NonAdminPhase = "BackingOff" + // NonAdminPhaseCreated - Velero object was created. The Phase will not have additional information about it. + NonAdminPhaseCreated NonAdminPhase = "Created" + // NonAdminPhaseDeleting - Velero object is pending deletion. The Phase will not have additional information about it. + NonAdminPhaseDeleting NonAdminPhase = "Deleting" +) + +// NonAdminCondition are used for more detailed information supporing NonAdminBackupPhase state. +// +kubebuilder:validation:Enum=Accepted;Queued;Deleting +type NonAdminCondition string + +// Predefined conditions for NonAdminController objects. +// One NonAdminController object may have multiple conditions. +// It is more granular knowledge of the NonAdminController object and represents the +// array of the conditions through which the NonAdminController has or has not passed +const ( + NonAdminConditionAccepted NonAdminCondition = "Accepted" + NonAdminConditionQueued NonAdminCondition = "Queued" + NonAdminConditionDeleting NonAdminCondition = "Deleting" +) + +// QueueInfo holds the queue position for a specific operation. +type QueueInfo struct { + // estimatedQueuePosition is the number of operations ahead in the queue (0 if not queued) + EstimatedQueuePosition int `json:"estimatedQueuePosition"` +} diff --git a/api/v1alpha1/nonadminbackup_types.go b/api/v1alpha1/nonadminbackup_types.go index 29d5010..a2fdbe3 100644 --- a/api/v1alpha1/nonadminbackup_types.go +++ b/api/v1alpha1/nonadminbackup_types.go @@ -21,21 +21,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// NonAdminPhase is a simple one high-level summary of the lifecycle of an NonAdminBackup. -// +kubebuilder:validation:Enum=New;BackingOff;Created;Deleting -type NonAdminPhase string - -const ( - // NonAdminPhaseNew - NonAdmin object was accepted by the OpenShift cluster, but it has not yet been processed by the NonAdminController - NonAdminPhaseNew NonAdminPhase = "New" - // NonAdminPhaseBackingOff - Velero object was not created due to NonAdmin object error (configuration or similar) - NonAdminPhaseBackingOff NonAdminPhase = "BackingOff" - // NonAdminPhaseCreated - Velero object was created. The Phase will not have additional information about it. - NonAdminPhaseCreated NonAdminPhase = "Created" - // NonAdminPhaseDeleting - Velero object is pending deletion. The Phase will not have additional information about it. - NonAdminPhaseDeleting NonAdminPhase = "Deleting" -) - // NonAdminBackupSpec defines the desired state of NonAdminBackup type NonAdminBackupSpec struct { // BackupSpec defines the specification for a Velero backup. @@ -98,6 +83,10 @@ type NonAdminBackupStatus struct { // +optional VeleroDeleteBackupRequest *VeleroDeleteBackupRequest `json:"veleroDeleteBackupRequest,omitempty"` + // queueInfo is used to estimate how many backups are scheduled before the given VeleroBackup in the OADP namespace. + // This number is not guaranteed to be accurate, but it should be close. It's inaccurate for cases when + // Velero pod is not running or being restarted after Backup object were created. + // It counts only VeleroBackups that are still subject to be handled by OADP/Velero. // +optional QueueInfo *QueueInfo `json:"queueInfo,omitempty"` @@ -107,15 +96,6 @@ type NonAdminBackupStatus struct { Conditions []metav1.Condition `json:"conditions,omitempty"` } -// QueueInfo holds the queue position for a specific VeleroBackup. -// It is used to estimate how many backups are scheduled before the given VeleroBackup in the OADP namespace. -// This number is not guaranteed to be accurate, but it should be close. It's inaccurate for cases when -// Velero pod is not running or being restarted after Backup object were created. -// It counts only VeleroBackups that are still subject to be handled by OADP/Velero. -type QueueInfo struct { - EstimatedQueuePosition int `json:"estimatedQueuePosition"` // Number of backups ahead in the queue (0 if not queued) -} - // +kubebuilder:object:root=true // +kubebuilder:subresource:status // +kubebuilder:resource:path=nonadminbackups,shortName=nab diff --git a/config/crd/bases/oadp.openshift.io_nonadminbackups.yaml b/config/crd/bases/oadp.openshift.io_nonadminbackups.yaml index 39aab8f..5ccd040 100644 --- a/config/crd/bases/oadp.openshift.io_nonadminbackups.yaml +++ b/config/crd/bases/oadp.openshift.io_nonadminbackups.yaml @@ -611,13 +611,14 @@ spec: type: string queueInfo: description: |- - QueueInfo holds the queue position for a specific VeleroBackup. - It is used to estimate how many backups are scheduled before the given VeleroBackup in the OADP namespace. + queueInfo is used to estimate how many backups are scheduled before the given VeleroBackup in the OADP namespace. This number is not guaranteed to be accurate, but it should be close. It's inaccurate for cases when Velero pod is not running or being restarted after Backup object were created. It counts only VeleroBackups that are still subject to be handled by OADP/Velero. properties: estimatedQueuePosition: + description: estimatedQueuePosition is the number of operations + ahead in the queue (0 if not queued) type: integer required: - estimatedQueuePosition diff --git a/internal/common/constant/constant.go b/internal/common/constant/constant.go index 6cada78..e9a1784 100644 --- a/internal/common/constant/constant.go +++ b/internal/common/constant/constant.go @@ -39,8 +39,8 @@ const ( NarOriginNameAnnotation = v1alpha1.OadpOperatorLabel + "-nar-origin-name" NarOriginNamespaceAnnotation = v1alpha1.OadpOperatorLabel + "-nar-origin-namespace" - NabFinalizerName = "nonadminbackup.oadp.openshift.io/finalizer" - NonAdminRestoreFinalizerName = "nonadminrestore.oadp.openshift.io/finalizer" + NabFinalizerName = "nonadminbackup.oadp.openshift.io/finalizer" + NarFinalizerName = "nonadminrestore.oadp.openshift.io/finalizer" ) // Common environment variables for the Non Admin Controller @@ -60,16 +60,15 @@ const TrueString = "True" // NamespaceString defines a constant for the Namespace string const NamespaceString = "Namespace" +// NameString defines a constant for the Name string +const NameString = "name" + +// CurrentPhaseString defines a constant for the Current Phase string +const CurrentPhaseString = "currentPhase" + +// UUIDString defines a constant for the UUID string +const UUIDString = "UUID" + // MaximumNacObjectNameLength represents Generated Non Admin Object Name and // must be below 63 characters, because it's used within object Label Value const MaximumNacObjectNameLength = validation.DNS1123LabelMaxLength - -// Predefined conditions for NonAdmin object. -// One NonAdmin object may have multiple conditions. -// It is more granular knowledge of the NonAdmin object and represents the -// array of the conditions through which the NonAdmin object has or has not passed -const ( - NonAdminConditionAccepted = "Accepted" - NonAdminConditionQueued = "Queued" - NonAdminConditionDeleting = "Deleting" -) diff --git a/internal/common/function/function.go b/internal/common/function/function.go index c26a7a4..aa774c8 100644 --- a/internal/common/function/function.go +++ b/internal/common/function/function.go @@ -350,7 +350,7 @@ func GetVeleroRestoreByLabel(ctx context.Context, clientInstance client.Client, case 1: return &veleroRestoreList.Items[0], nil default: - return nil, fmt.Errorf("multiple Velero Restore objects found with label %s=%s in namespace '%s'", constant.NabOriginNACUUIDLabel, labelValue, namespace) + return nil, fmt.Errorf("multiple Velero Restore objects found with label %s=%s in namespace '%s'", constant.NarOriginNACUUIDLabel, labelValue, namespace) } } diff --git a/internal/controller/nonadminbackup_controller.go b/internal/controller/nonadminbackup_controller.go index 253c55d..8841917 100644 --- a/internal/controller/nonadminbackup_controller.go +++ b/internal/controller/nonadminbackup_controller.go @@ -61,8 +61,6 @@ const ( statusUpdateError = "Failed to update NonAdminBackup Status" findSingleVBError = "Error encountered while retrieving VeleroBackup for NAB during the Delete operation" findSingleVDBRError = "Error encountered while retrieving DeleteBackupRequest for NAB during the Delete operation" - uuidString = "UUID" - nameString = "name" ) // +kubebuilder:rbac:groups=oadp.openshift.io,resources=nonadminbackups,verbs=get;list;watch;create;update;patch;delete @@ -165,7 +163,7 @@ func (r *NonAdminBackupReconciler) setStatusAndConditionForDeletionAndCallDelete updatedPhase := updateNonAdminPhase(&nab.Status.Phase, nacv1alpha1.NonAdminPhaseDeleting) updatedCondition := meta.SetStatusCondition(&nab.Status.Conditions, metav1.Condition{ - Type: string(constant.NonAdminConditionDeleting), + Type: string(nacv1alpha1.NonAdminConditionDeleting), Status: metav1.ConditionTrue, Reason: "DeletionPending", Message: "backup accepted for deletion", @@ -182,7 +180,7 @@ func (r *NonAdminBackupReconciler) setStatusAndConditionForDeletionAndCallDelete logger.V(1).Info("NonAdminBackup status unchanged during deletion") } if nab.ObjectMeta.DeletionTimestamp.IsZero() { - logger.V(1).Info("Marking NonAdminBackup for deletion", nameString, nab.Name) + logger.V(1).Info("Marking NonAdminBackup for deletion", constant.NameString, nab.Name) if err := r.Delete(ctx, nab); err != nil { logger.Error(err, "Failed to call Delete on the NonAdminBackup object") return false, err @@ -210,7 +208,7 @@ func (r *NonAdminBackupReconciler) setStatusForDirectKubernetesAPIDeletion(ctx c updatedPhase := updateNonAdminPhase(&nab.Status.Phase, nacv1alpha1.NonAdminPhaseDeleting) updatedCondition := meta.SetStatusCondition(&nab.Status.Conditions, metav1.Condition{ - Type: string(constant.NonAdminConditionDeleting), + Type: string(nacv1alpha1.NonAdminConditionDeleting), Status: metav1.ConditionTrue, Reason: "DeletionPending", Message: "backup deletion requires setting spec.deleteBackup or spec.forceDeleteBackup to true or finalizer removal", @@ -262,19 +260,19 @@ func (r *NonAdminBackupReconciler) createVeleroDeleteBackupRequest(ctx context.C if err != nil { // Log error if multiple VeleroBackup objects are found - logger.Error(err, findSingleVBError, uuidString, veleroBackupNACUUID) + logger.Error(err, findSingleVBError, constant.UUIDString, veleroBackupNACUUID) return false, err } if veleroBackup == nil { - logger.V(1).Info("VeleroBackup already deleted", "UUID", veleroBackupNACUUID) + logger.V(1).Info("VeleroBackup already deleted", constant.UUIDString, veleroBackupNACUUID) return false, nil } deleteBackupRequest, err := function.GetVeleroDeleteBackupRequestByLabel(ctx, r.Client, r.OADPNamespace, veleroBackupNACUUID) if err != nil { // Log error if multiple DeleteBackupRequest objects are found - logger.Error(err, findSingleVDBRError, uuidString, veleroBackupNACUUID) + logger.Error(err, findSingleVDBRError, constant.UUIDString, veleroBackupNACUUID) return false, err } @@ -346,16 +344,16 @@ func (r *NonAdminBackupReconciler) deleteVeleroBackupAndDeleteBackupRequestObjec if err != nil { // Case where more than one VeleroBackup is found with the same label UUID // TODO (migi): Determine if all objects with this UUID should be deleted - logger.Error(err, findSingleVBError, uuidString, veleroBackupNACUUID) + logger.Error(err, findSingleVBError, constant.UUIDString, veleroBackupNACUUID) return false, err } if veleroBackup != nil { if err = r.Delete(ctx, veleroBackup); err != nil { - logger.Error(err, "Failed to delete VeleroBackup", nameString, veleroBackup.Name) + logger.Error(err, "Failed to delete VeleroBackup", constant.NameString, veleroBackup.Name) return false, err } - logger.V(1).Info("VeleroBackup deletion initiated", nameString, veleroBackup.Name) + logger.V(1).Info("VeleroBackup deletion initiated", constant.NameString, veleroBackup.Name) } else { logger.V(1).Info("VeleroBackup already deleted") } @@ -363,15 +361,15 @@ func (r *NonAdminBackupReconciler) deleteVeleroBackupAndDeleteBackupRequestObjec deleteBackupRequest, err := function.GetVeleroDeleteBackupRequestByLabel(ctx, r.Client, r.OADPNamespace, veleroBackupNACUUID) if err != nil { // Log error if multiple DeleteBackupRequest objects are found - logger.Error(err, findSingleVDBRError, uuidString, veleroBackupNACUUID) + logger.Error(err, findSingleVDBRError, constant.UUIDString, veleroBackupNACUUID) return false, err } if deleteBackupRequest != nil { if err = r.Delete(ctx, deleteBackupRequest); err != nil { - logger.Error(err, "Failed to delete VeleroDeleteBackupRequest", nameString, deleteBackupRequest.Name) + logger.Error(err, "Failed to delete VeleroDeleteBackupRequest", constant.NameString, deleteBackupRequest.Name) return false, err } - logger.V(1).Info("VeleroDeleteBackupRequest deletion initiated", nameString, deleteBackupRequest.Name) + logger.V(1).Info("VeleroDeleteBackupRequest deletion initiated", constant.NameString, deleteBackupRequest.Name) } return false, nil // Continue so initNabDeletion can initialize deletion of an NonAdminBackup object } @@ -408,12 +406,12 @@ func (r *NonAdminBackupReconciler) removeNabFinalizerUponVeleroBackupDeletion(ct if err != nil { // Case in which more then one VeleroBackup is found with the same label UUID // TODO (migi): Should we delete all of the objects with such UUID ? - logger.Error(err, findSingleVBError, uuidString, veleroBackupNACUUID) + logger.Error(err, findSingleVBError, constant.UUIDString, veleroBackupNACUUID) return false, err } if veleroBackup != nil { - logger.V(1).Info("Waiting for VeleroBackup to be deleted", nameString, veleroBackupNACUUID) + logger.V(1).Info("Waiting for VeleroBackup to be deleted", constant.NameString, veleroBackupNACUUID) return true, nil // Requeue } } @@ -447,7 +445,7 @@ func (r *NonAdminBackupReconciler) removeNabFinalizerUponVeleroBackupDeletion(ct func (r *NonAdminBackupReconciler) initNabCreate(ctx context.Context, logger logr.Logger, nab *nacv1alpha1.NonAdminBackup) (bool, error) { // If phase is already set, nothing to do if nab.Status.Phase != constant.EmptyString { - logger.V(1).Info("NonAdminBackup Phase already initialized", "currentPhase", nab.Status.Phase) + logger.V(1).Info("NonAdminBackup Phase already initialized", constant.CurrentPhaseString, nab.Status.Phase) return false, nil } @@ -459,7 +457,7 @@ func (r *NonAdminBackupReconciler) initNabCreate(ctx context.Context, logger log } logger.V(1).Info("NonAdminBackup Phase set to New") } else { - logger.V(1).Info("NonAdminBackup Phase update skipped", "currentPhase", nab.Status.Phase) + logger.V(1).Info("NonAdminBackup Phase update skipped", constant.CurrentPhaseString, nab.Status.Phase) } return false, nil @@ -483,7 +481,7 @@ func (r *NonAdminBackupReconciler) validateSpec(ctx context.Context, logger logr updatedPhase := updateNonAdminPhase(&nab.Status.Phase, nacv1alpha1.NonAdminPhaseBackingOff) updatedCondition := meta.SetStatusCondition(&nab.Status.Conditions, metav1.Condition{ - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionFalse, Reason: "InvalidBackupSpec", Message: err.Error(), @@ -504,7 +502,7 @@ func (r *NonAdminBackupReconciler) validateSpec(ctx context.Context, logger logr updated := meta.SetStatusCondition(&nab.Status.Conditions, metav1.Condition{ - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", @@ -596,12 +594,12 @@ func (r *NonAdminBackupReconciler) createVeleroBackupAndSyncWithNonAdminBackup(c if err != nil { // Case in which more then one VeleroBackup is found with the same label UUID - logger.Error(err, findSingleVBError, uuidString, veleroBackupNACUUID) + logger.Error(err, findSingleVBError, constant.UUIDString, veleroBackupNACUUID) return false, err } if veleroBackup == nil { - logger.Info("VeleroBackup with label not found, creating one", uuidString, veleroBackupNACUUID) + logger.Info("VeleroBackup with label not found, creating one", constant.UUIDString, veleroBackupNACUUID) backupSpec := nab.Spec.BackupSpec.DeepCopy() backupSpec.IncludedNamespaces = []string{nab.Namespace} @@ -659,7 +657,7 @@ func (r *NonAdminBackupReconciler) createVeleroBackupAndSyncWithNonAdminBackup(c updatedCondition := meta.SetStatusCondition(&nab.Status.Conditions, metav1.Condition{ - Type: string(constant.NonAdminConditionQueued), + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", diff --git a/internal/controller/nonadminbackup_controller_test.go b/internal/controller/nonadminbackup_controller_test.go index 6814528..b44ba3a 100644 --- a/internal/controller/nonadminbackup_controller_test.go +++ b/internal/controller/nonadminbackup_controller_test.go @@ -380,7 +380,7 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseBackingOff, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionFalse, Reason: "InvalidBackupSpec", Message: "NonAdminBackup spec.backupSpec.includedNamespaces can not contain namespaces other than: ", @@ -400,7 +400,7 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseBackingOff, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionFalse, Reason: "InvalidBackupSpec", Message: "BackupSpec is not defined", @@ -421,14 +421,14 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseCreated, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", LastTransitionTime: metav1.NewTime(time.Now()), }, { - Type: string(constant.NonAdminConditionQueued), + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", @@ -440,19 +440,19 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseDeleting, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", }, { - Type: string(constant.NonAdminConditionQueued), + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", }, { - Type: string(constant.NonAdminConditionDeleting), + Type: string(nacv1alpha1.NonAdminConditionDeleting), Status: metav1.ConditionTrue, Reason: "DeletionPending", Message: "backup accepted for deletion", @@ -473,21 +473,21 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseDeleting, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", LastTransitionTime: metav1.NewTime(time.Now()), }, { - Type: string(constant.NonAdminConditionQueued), + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", LastTransitionTime: metav1.NewTime(time.Now()), }, { - Type: string(constant.NonAdminConditionDeleting), + Type: string(nacv1alpha1.NonAdminConditionDeleting), Status: metav1.ConditionTrue, Reason: "DeletionPending", Message: "backup accepted for deletion", @@ -499,19 +499,19 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseDeleting, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", }, { - Type: string(constant.NonAdminConditionQueued), + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", }, { - Type: string(constant.NonAdminConditionDeleting), + Type: string(nacv1alpha1.NonAdminConditionDeleting), Status: metav1.ConditionTrue, Reason: "DeletionPending", Message: "backup accepted for deletion", @@ -531,14 +531,14 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseCreated, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", LastTransitionTime: metav1.NewTime(time.Now()), }, { - Type: string(constant.NonAdminConditionQueued), + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", @@ -560,14 +560,14 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseCreated, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", LastTransitionTime: metav1.NewTime(time.Now()), }, { - Type: string(constant.NonAdminConditionQueued), + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", @@ -579,19 +579,19 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseDeleting, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", }, { - Type: string(constant.NonAdminConditionQueued), + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", }, { - Type: string(constant.NonAdminConditionDeleting), + Type: string(nacv1alpha1.NonAdminConditionDeleting), Status: metav1.ConditionTrue, Reason: "DeletionPending", Message: "backup accepted for deletion", @@ -612,21 +612,21 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseDeleting, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", LastTransitionTime: metav1.NewTime(time.Now()), }, { - Type: string(constant.NonAdminConditionQueued), + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", LastTransitionTime: metav1.NewTime(time.Now()), }, { - Type: string(constant.NonAdminConditionDeleting), + Type: string(nacv1alpha1.NonAdminConditionDeleting), Status: metav1.ConditionTrue, Reason: "DeletionPending", Message: "backup accepted for deletion", @@ -650,13 +650,13 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseCreated, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", }, { - Type: string(constant.NonAdminConditionQueued), + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", @@ -673,7 +673,7 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseNew, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", @@ -685,13 +685,13 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseCreated, Conditions: []metav1.Condition{ { - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", }, { - Type: "Queued", + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", @@ -710,7 +710,7 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseNew, Conditions: []metav1.Condition{ { - Type: "Accepted", + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", @@ -725,13 +725,13 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseCreated, Conditions: []metav1.Condition{ { - Type: "Accepted", + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", }, { - Type: "Queued", + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", @@ -755,14 +755,14 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func VeleroBackup: &nacv1alpha1.VeleroBackup{}, Conditions: []metav1.Condition{ { - Type: "Accepted", + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", LastTransitionTime: metav1.NewTime(time.Now()), }, { - Type: "Queued", + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", @@ -780,13 +780,13 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func }, Conditions: []metav1.Condition{ { - Type: "Accepted", + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "BackupAccepted", Message: "backup accepted", }, { - Type: "Queued", + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "BackupScheduled", Message: "Created Velero Backup object", @@ -809,7 +809,7 @@ var _ = ginkgo.Describe("Test single reconciles of NonAdminBackup Reconcile func Phase: nacv1alpha1.NonAdminPhaseBackingOff, Conditions: []metav1.Condition{ { - Type: "Accepted", + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionFalse, Reason: "InvalidBackupSpec", Message: "NonAdminBackup spec.backupSpec.includedNamespaces can not contain namespaces other than:", diff --git a/internal/controller/nonadminrestore_controller.go b/internal/controller/nonadminrestore_controller.go index 960c814..fa34257 100644 --- a/internal/controller/nonadminrestore_controller.go +++ b/internal/controller/nonadminrestore_controller.go @@ -132,7 +132,7 @@ func (r *NonAdminRestoreReconciler) setStatusAndConditionForDeletionAndCallDelet updatedPhase := updateNonAdminPhase(&nar.Status.Phase, nacv1alpha1.NonAdminPhaseDeleting) updatedCondition := meta.SetStatusCondition(&nar.Status.Conditions, metav1.Condition{ - Type: string(constant.NonAdminConditionDeleting), + Type: string(nacv1alpha1.NonAdminConditionDeleting), Status: metav1.ConditionTrue, Reason: "DeletionPending", Message: "restore accepted for deletion", @@ -149,7 +149,7 @@ func (r *NonAdminRestoreReconciler) setStatusAndConditionForDeletionAndCallDelet logger.V(1).Info("NonAdminRestore status unchanged during deletion") } if nar.ObjectMeta.DeletionTimestamp.IsZero() { - logger.V(1).Info("Marking NonAdminRestore for deletion", nameString, nar.Name) + logger.V(1).Info("Marking NonAdminRestore for deletion", constant.NameString, nar.Name) if err := r.Delete(ctx, nar); err != nil { logger.Error(err, "Failed to call Delete on the NonAdminRestore object") return false, err @@ -170,7 +170,7 @@ func (r *NonAdminRestoreReconciler) deleteVeleroRestore(ctx context.Context, log if err != nil { // Case in which more then one VeleroRestore is found with the same label NACUUID - logger.Error(err, findSingleVRError, uuidString, veleroRestoreNACUUID) + logger.Error(err, findSingleVRError, constant.UUIDString, veleroRestoreNACUUID) return false, err } @@ -179,10 +179,10 @@ func (r *NonAdminRestoreReconciler) deleteVeleroRestore(ctx context.Context, log // and it will get removed by the Velero cleanup process when the restore object gets deleted // https://github.com/vmware-tanzu/velero/blob/074f26539d3eb06c7b1a6af9b4975254e61b956c/pkg/cmd/cli/restore/delete.go#L122 if err = r.Delete(ctx, veleroRestore); err != nil { - logger.Error(err, "Failed to delete VeleroRestore", nameString, veleroRestore.Name) + logger.Error(err, "Failed to delete VeleroRestore", constant.NameString, veleroRestore.Name) return false, err } - logger.V(1).Info("VeleroRestore deletion initiated", nameString, veleroRestore.Name) + logger.V(1).Info("VeleroRestore deletion initiated", constant.NameString, veleroRestore.Name) } else { logger.V(1).Info("VeleroRestore already deleted") } @@ -197,19 +197,19 @@ func (r *NonAdminRestoreReconciler) removeNarFinalizerUponVeleroRestoreDeletion( veleroRestore, err := function.GetVeleroRestoreByLabel(ctx, r.Client, r.OADPNamespace, veleroRestoreNACUUID) if err != nil { // Case in which more then one VeleroRestore is found with the same label UUID - logger.Error(err, findSingleVRError, uuidString, veleroRestoreNACUUID) + logger.Error(err, findSingleVRError, constant.UUIDString, veleroRestoreNACUUID) return false, err } if veleroRestore != nil { - logger.V(1).Info("Waiting for VeleroRestore to be deleted", nameString, veleroRestoreNACUUID) + logger.V(1).Info("Waiting for VeleroRestore to be deleted", constant.NameString, veleroRestoreNACUUID) return true, nil // Requeue } } // VeleroRestore is deleted, proceed with deleting the NonAdminRestore logger.V(1).Info("VeleroRestore deleted, removing NonAdminRestore finalizer") - controllerutil.RemoveFinalizer(nar, constant.NonAdminRestoreFinalizerName) + controllerutil.RemoveFinalizer(nar, constant.NarFinalizerName) if err := r.Update(ctx, nar); err != nil { logger.Error(err, "Failed to remove finalizer from NonAdminRestore") @@ -242,7 +242,7 @@ func (r *NonAdminRestoreReconciler) validateSpec(ctx context.Context, logger log updatedPhase := updateNonAdminPhase(&nar.Status.Phase, nacv1alpha1.NonAdminPhaseBackingOff) updatedCondition := meta.SetStatusCondition(&nar.Status.Conditions, metav1.Condition{ - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionFalse, Reason: "InvalidRestoreSpec", Message: err.Error(), @@ -260,7 +260,7 @@ func (r *NonAdminRestoreReconciler) validateSpec(ctx context.Context, logger log updated := meta.SetStatusCondition(&nar.Status.Conditions, metav1.Condition{ - Type: string(constant.NonAdminConditionAccepted), + Type: string(nacv1alpha1.NonAdminConditionAccepted), Status: metav1.ConditionTrue, Reason: "RestoreAccepted", Message: "restore accepted", @@ -304,7 +304,7 @@ func (r *NonAdminRestoreReconciler) setUUID(ctx context.Context, logger logr.Log } func (r *NonAdminRestoreReconciler) setFinalizer(ctx context.Context, logger logr.Logger, nar *nacv1alpha1.NonAdminRestore) (bool, error) { - added := controllerutil.AddFinalizer(nar, constant.NonAdminRestoreFinalizerName) + added := controllerutil.AddFinalizer(nar, constant.NarFinalizerName) if added { if err := r.Update(ctx, nar); err != nil { logger.Error(err, "Failed to add finalizer") @@ -328,12 +328,12 @@ func (r *NonAdminRestoreReconciler) createVeleroRestore(ctx context.Context, log if err != nil { // Case in which more then one VeleroBackup is found with the same label UUID - logger.Error(err, findSingleVRError, uuidString, veleroRestoreNACUUID) + logger.Error(err, findSingleVRError, constant.UUIDString, veleroRestoreNACUUID) return false, err } if veleroRestore == nil { - logger.Info("VeleroRestore with label not found, creating one", uuidString, veleroRestoreNACUUID) + logger.Info("VeleroRestore with label not found, creating one", constant.UUIDString, veleroRestoreNACUUID) nab := &nacv1alpha1.NonAdminBackup{} err = r.Get(ctx, types.NamespacedName{Name: nar.Spec.RestoreSpec.BackupName, Namespace: nar.Namespace}, nab) if err != nil { @@ -382,7 +382,7 @@ func (r *NonAdminRestoreReconciler) createVeleroRestore(ctx context.Context, log updatedCondition := meta.SetStatusCondition(&nar.Status.Conditions, metav1.Condition{ - Type: string(constant.NonAdminConditionQueued), + Type: string(nacv1alpha1.NonAdminConditionQueued), Status: metav1.ConditionTrue, Reason: "RestoreScheduled", // TODO can this confuse user? scheduled -> queued? Message: "Created Velero Restore object", diff --git a/internal/handler/velerobackup_queue_handler.go b/internal/handler/velerobackup_queue_handler.go index 130a65b..853952c 100644 --- a/internal/handler/velerobackup_queue_handler.go +++ b/internal/handler/velerobackup_queue_handler.go @@ -74,13 +74,13 @@ func (h VeleroBackupQueueHandler) Update(ctx context.Context, evt event.UpdateEv // This object is within current queue, so there is no need to trigger changes to it. // The VeleroBackupHandler will serve for that. if nabOriginNamespace != nabEventOriginNamespace || nabOriginName != nabEventOriginName { - logger.V(1).Info("Processing Queue update for the NonAdmin Backup referenced by Velero Backup", "Name", backup.Name, constant.NamespaceString, backup.Namespace, "CreatedAt", backup.CreationTimestamp) + logger.V(1).Info("Processing Queue update for the NonAdmin Backup referenced by Velero Backup", constant.NameString, backup.Name, constant.NamespaceString, backup.Namespace, "CreatedAt", backup.CreationTimestamp) q.Add(reconcile.Request{NamespacedName: types.NamespacedName{ Name: nabOriginName, Namespace: nabOriginNamespace, }}) } else { - logger.V(1).Info("Ignoring Queue update for the NonAdmin Backup that triggered this event", "Name", backup.Name, constant.NamespaceString, backup.Namespace, "CreatedAt", backup.CreationTimestamp) + logger.V(1).Info("Ignoring Queue update for the NonAdmin Backup that triggered this event", constant.NameString, backup.Name, constant.NamespaceString, backup.Namespace, "CreatedAt", backup.CreationTimestamp) } } }