Skip to content

Check the NaBSL status and conditions before creating Velero Backup#249

Merged
openshift-merge-bot[bot] merged 3 commits into
migtools:masterfrom
mpryc:issue_246_nabsl-backingoff
Apr 14, 2025
Merged

Check the NaBSL status and conditions before creating Velero Backup#249
openshift-merge-bot[bot] merged 3 commits into
migtools:masterfrom
mpryc:issue_246_nabsl-backingoff

Conversation

@mpryc
Copy link
Copy Markdown
Collaborator

@mpryc mpryc commented Mar 4, 2025

Fixes #246

Ensure the state of the NaBSL is satisfying the Backup operation, in a case the admin redefined enforcement the NaBSL state was correctly synced back from the enforcement, however we disallowed real updated of the Velero BSL object causing NaBSL being in not allowed state, however previous Velero BSL fully functional.

This logic fixes that issue.

Why the changes were made

To fix #246

How to test the changes made

  1. As described in the Able to perform Backup successsfully using NABSL in phase: BackingOff #246 issue:
  2. Create enforcements for the NaBSL in the DPA
  3. Create NaBSL to satisfy enforcements
  4. Change the NaBSL enforcements in the DPA
  5. Try to perform Backup operation using the NaBSL

Expected result: Backup can not be created.

Comment thread internal/common/function/function.go Outdated
return fmt.Errorf("NonAdminBackupStorageLocation is not in created state and can not be used for the NonAdminBackup")
}

for _, condition := range nonAdminBsl.Status.Conditions {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like this approach. If a new condition is added, this can break us

If there is a certain condition that is important to check, we can check it, but checking all seems the wrong approach

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpryc the bug should be fixed via only checking the phase, right ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Condition contains details for one aspect of the current state of this API Resource.
// ---
// This struct is intended for direct use as an array at the field path .status.conditions.  For example,
//
//	type FooStatus struct{
//	    // Represents the observations of a foo's current state.
//	    // Known .status.conditions.type are: "Available", "Progressing", and "Degraded"
//	    // +patchMergeKey=type
//	    // +patchStrategy=merge
//	    // +listType=map
//	    // +listMapKey=type
//	    Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
//
//	    // other fields
//	}

condition is not always something that needs to be true to be satisfied.

We are establishing that all conditions in this repo if true is considered an unsatisfied condition. Is that what we want?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your concern about checking all conditions, but in our specific case, I believe it's a safer approach. I can rework this logic to check for 4 conditions individually:

NonAdminBSLConditionSecretSynced NonAdminBSLCondition = "SecretSynced"
NonAdminBSLConditionBSLSynced NonAdminBSLCondition = "BackupStorageLocationSynced"
NonAdminBSLConditionApproved NonAdminBSLCondition = "ClusterAdminApproved"
NonAdminBSLConditionSpecUpdateApproved NonAdminBSLCondition = "SpecUpdateApproved"

Each of these conditions must be satisfied to ensure that a NaBSL is actually usable. Relying solely on the status field could lead to situations where an NaBSL is marked as "OK" but is still not in a functional state.

By explicitly checking these conditions, we reduce potential issues that could arise if a new phase or status logic is introduced in the future. I believe this approach is a safeguard rather than an unnecessary restriction, but as I wrote I can change this to explicitly check for the above 4 conditions instead of iterating through all of them.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added only 3 conditions which in my opinion are a must to be met here before continuing backup and none of those 3 conditions can be false.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think logic is not correct

current we iterate through NABSL status conditions, if that condition is one of the 3 and is false, we error, right?

but if for example NABSL status conditions has no conditions, no problem happens, but it should report a problem, no?

would change logic to iterate through required conditions types, check if that condition is present in NABSL status (error if not) and if it true (error if not). Example implementation

		requiredConditions := []string{
			string(nacv1alpha1.NonAdminBSLConditionSecretSynced),
			string(nacv1alpha1.NonAdminBSLConditionBSLSynced),
			string(nacv1alpha1.NonAdminBSLConditionApproved),
		}
		for _, condition := range requiredConditions {
			conditionInNABSL := meta.FindStatusCondition(nonAdminBsl.Status.Conditions, condition)
			if conditionInNABSL == nil {
				return fmt.Errorf("TODO")
			}
			if conditionInNABSL.Status != metav1.ConditionTrue {
				return fmt.Errorf("TODO")
			}
		}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#249 (comment) Something wrong with only checking phase ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shubham-pampattiwar updated the implementation to relay only on phase, which should be sufficient.

mpryc added 2 commits April 14, 2025 12:00
Fixes migtools#246

Ensure the state of the NaBSL is satisfying the Backup operation,
in a case the admin redefined enforcement the NaBSL state was
correctly synced back from the enforcement, however we disallowed
real updated of the Velero BSL object causing NaBSL being in
not allowed state, however previous Velero BSL fully functional.

This logic fixes that issue.

Signed-off-by: Michal Pryc <mpryc@redhat.com>
We should faily only when specific conditions are False,
not all of them.

Signed-off-by: Michal Pryc <mpryc@redhat.com>
@mpryc mpryc force-pushed the issue_246_nabsl-backingoff branch from e9dce0e to fc54ae3 Compare April 14, 2025 10:16
Remove conditions check for the NaBSL check prior to creating backup.
This is enough as the NaBSL must be in created state after satisfying
all the conditions.

Signed-off-by: Michal Pryc <mpryc@redhat.com>
Copy link
Copy Markdown
Member

@shubham-pampattiwar shubham-pampattiwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 14, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mateusoliveira43, mpryc, shubham-pampattiwar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [mateusoliveira43,mpryc,shubham-pampattiwar]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot Bot merged commit abf428e into migtools:master Apr 14, 2025
8 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for Review to Merged / Ready for build in OADP Apr 14, 2025
@mpryc
Copy link
Copy Markdown
Collaborator Author

mpryc commented May 16, 2025

/cherry-pick oadp-1.5

@openshift-cherrypick-robot
Copy link
Copy Markdown

@mpryc: new pull request created: #284

Details

In response to this:

/cherry-pick oadp-1.5

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged / Ready for build

Development

Successfully merging this pull request may close these issues.

Able to perform Backup successsfully using NABSL in phase: BackingOff

5 participants