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

feat: implement clusterStagedUpdateRun validation #991

Merged
merged 3 commits into from
Dec 18, 2024

Conversation

jwtty
Copy link
Contributor

@jwtty jwtty commented Dec 16, 2024

Description of your changes

This PR implements the clusterStagedUpdateRun validation

Fixes #

I have:

  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

Special notes for your reviewer

@jwtty jwtty force-pushed the stagerun-validation branch 2 times, most recently from d52ec3b to 06a2156 Compare December 16, 2024 03:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • pkg/controllers/updaterun/controller.go: Evaluated as low risk
Comments suppressed due to low confidence (13)

pkg/controllers/updaterun/validation.go:44

  • [nitpick] The error message uses %v to print the ApplyStrategy, which might not provide a clear and readable output. Consider using a more specific format or converting the ApplyStrategy to a string.
mismatchErr := fmt.Errorf("the applyStrategy in the clusterStagedUpdateRun is outdated, latest: %v, recorded: %v", updateRunCopy.Status.ApplyStrategy, updateRun.Status.ApplyStrategy)

pkg/controllers/updaterun/validation.go:56

  • Include the placementName in the error message for better context.
mismatchErr := fmt.Errorf("the policy snapshot index used in the clusterStagedUpdateRun is outdated, latest: %s, recorded: %s", latestPolicySnapshot.Name, updateRun.Status.PolicySnapshotIndexUsed)

pkg/controllers/updaterun/validation.go:62

  • Include the placementName in the error message for better context.
mismatchErr := fmt.Errorf("the cluster count initialized in the clusterStagedUpdateRun is outdated, latest: %d, recorded: %d", clusterCount, updateRun.Status.PolicyObservedClusterCount)

pkg/controllers/updaterun/validation.go:210

  • [nitpick] The error message should be more descriptive. Consider including more context about the failure.
failedErr := fmt.Errorf("the stage `%s` has failed, err: %s", stageStatus.StageName, stageSucceedCond.Message)

pkg/controllers/updaterun/validation_test.go:222

  • The 'validateDeleteStageStatus' function has several branches that are not covered by tests. Ensure that all possible paths are tested.
func TestValidateDeleteStageStatus(t *testing.T) {

pkg/controllers/updaterun/controller_integration_test.go:472

  • The 'condType' parameter uses the 'any' type, which could lead to runtime errors if an unsupported type is passed. Ensure that only supported types are passed to this function.
func generateTrueCondition(updateRun *placementv1alpha1.ClusterStagedUpdateRun, condType any) metav1.Condition {

pkg/controllers/updaterun/controller_integration_test.go:510

  • The 'condType' parameter uses the 'any' type, which could lead to runtime errors if an unsupported type is passed. Ensure that only supported types are passed to this function.
func generateFalseCondition(updateRun *placementv1alpha1.ClusterStagedUpdateRun, condType any) metav1.Condition {

pkg/controllers/updaterun/initialization_integration_test.go:255

  • The comment should be 'Setting the latest policy snapshot condition as fully scheduled'.
By("Set the latest policy snapshot condition as fully scheduled")

pkg/controllers/updaterun/initialization_integration_test.go:288

  • The comment should be 'Setting the latest policy snapshot condition as fully scheduled'.
By("Set the latest policy snapshot condition as fully scheduled")

pkg/controllers/updaterun/initialization_integration_test.go:320

  • The comment should be 'Setting the latest policy snapshot condition as fully scheduled'.
By("Set the latest policy snapshot condition as fully scheduled")

pkg/controllers/updaterun/initialization_integration_test.go:356

  • The comment should be 'Setting the latest policy snapshot condition as fully scheduled'.
By("Set the latest policy snapshot condition as fully scheduled")

pkg/controllers/updaterun/initialization_integration_test.go:413

  • The comment should be 'Setting the latest policy snapshot condition as fully scheduled'.
By("Set the latest policy snapshot condition as fully scheduled")

pkg/controllers/updaterun/initialization_integration_test.go:554

  • The comment should be 'Setting the latest policy snapshot condition as fully scheduled'.
By("Set the latest policy snapshot condition as fully scheduled")

@jwtty jwtty force-pushed the stagerun-validation branch from 06a2156 to fd9a057 Compare December 16, 2024 18:15
pkg/controllers/updaterun/controller.go Show resolved Hide resolved
pkg/controllers/updaterun/controller.go Show resolved Hide resolved
pkg/controllers/updaterun/initialization.go Show resolved Hide resolved
pkg/controllers/updaterun/initialization.go Show resolved Hide resolved
pkg/controllers/updaterun/validation.go Outdated Show resolved Hide resolved
pkg/controllers/updaterun/validation.go Show resolved Hide resolved
pkg/controllers/updaterun/validation.go Outdated Show resolved Hide resolved
pkg/controllers/updaterun/validation.go Show resolved Hide resolved
pkg/controllers/updaterun/validation_integration_test.go Outdated Show resolved Hide resolved
pkg/controllers/updaterun/validation_integration_test.go Outdated Show resolved Hide resolved
@jwtty jwtty force-pushed the stagerun-validation branch 3 times, most recently from ddc7a6b to 4afc143 Compare December 17, 2024 20:28
@@ -258,6 +256,22 @@ func validateDeleteStageStatus(
klog.ErrorS(unexpectedErr, "Failed to find the deletionStageStatus in the clusterStagedUpdateRun", "clusterStagedUpdateRun", updateRunRef)
return -1, fmt.Errorf("%w: %s", errStagedUpdatedAborted, unexpectedErr.Error())
}

// Validate whether toBeDeletedBindings are a subnet of the clusters in the delete stage status.
// We only validate if it's a subnet because clusters can unjoin from the fleet and we allow that.
Copy link
Contributor

Choose a reason for hiding this comment

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

the real reason is not about cluster leave the fleet ( we don't allow that for updating ones). It's about the action on the cluster in the deleting stages is to delete the binding so they will disappear in the next round of validation.

Copy link
Contributor Author

@jwtty jwtty Dec 18, 2024

Choose a reason for hiding this comment

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

Yea, I realized that when I write the execution code. Updated this comments.

Comment on lines 73 to 77
// if condition.IsConditionStatusFalse(meta.FindStatusCondition(updateRun.Status.Conditions, string(placementv1alpha1.StagedUpdateRunConditionProgressing)), updateRun.Generation) {
// // The clusterStagedUpdateRun has not started yet.
// klog.V(2).InfoS("Starting the staged update run from the beginning", "clusterStagedUpdateRun", updateRunRef)
// return 0, scheduledBindings, toBeDeletedBindings, nil
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

it's a bit different though. The condition is a short cut to save any validation. Do we want that?

@jwtty jwtty force-pushed the stagerun-validation branch from 0346c3d to 3bfcfa2 Compare December 18, 2024 21:49
@jwtty jwtty merged commit 96fd96a into Azure:main Dec 18, 2024
12 checks passed
@jwtty jwtty deleted the stagerun-validation branch December 18, 2024 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants