-
Notifications
You must be signed in to change notification settings - Fork 19
feat: update stagedUpdateRun to use latest resource snapshot #320
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
Open
britaniar
wants to merge
14
commits into
kubefleet-dev:main
Choose a base branch
from
britaniar:updateStagedUpdateRunResourceIndex
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fb9d41c
update stagedUpdateRun to use latest resource snapshot if resourceInd…
britaniar 7d1ae16
fix UT
britaniar 8b4b5fd
address comments
britaniar edc8555
fix some e2es
britaniar 7607c58
fix the rest of the e2es
britaniar 734d82c
minor fix
britaniar 1b86e43
address comments
britaniar a2a4a70
fix UT
britaniar 04e5467
fix
britaniar e6f6a52
address comments
britaniar e65e33f
address comments
britaniar e5164ea
address comments
britaniar 32bd918
fix e2es
britaniar 9a7b744
restore unrelated change
britaniar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -471,30 +471,10 @@ func validateAfterStageTask(tasks []placementv1beta1.StageTask) error { | |
| func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey types.NamespacedName, updateRun placementv1beta1.UpdateRunObj) error { | ||
| updateRunRef := klog.KObj(updateRun) | ||
| updateRunSpec := updateRun.GetUpdateRunSpec() | ||
| placementName := placementKey.Name | ||
|
|
||
| snapshotIndex, err := strconv.Atoi(updateRunSpec.ResourceSnapshotIndex) | ||
| if err != nil || snapshotIndex < 0 { | ||
| err := controller.NewUserError(fmt.Errorf("invalid resource snapshot index `%s` provided, expected an integer >= 0", updateRunSpec.ResourceSnapshotIndex)) | ||
| klog.ErrorS(err, "Failed to parse the resource snapshot index", "updateRun", updateRunRef) | ||
| // no more retries here. | ||
| return fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) | ||
| } | ||
|
|
||
| resourceSnapshotList, err := controller.ListAllResourceSnapshotWithAnIndex(ctx, r.Client, updateRunSpec.ResourceSnapshotIndex, placementName, placementKey.Namespace) | ||
| resourceSnapshotObjs, err := r.getResourceSnapshotObjs(ctx, placementKey, updateRun) | ||
| if err != nil { | ||
| klog.ErrorS(err, "Failed to list the resourceSnapshots associated with the placement", | ||
| "placement", placementKey, "resourceSnapshotIndex", snapshotIndex, "updateRun", updateRunRef) | ||
| // err can be retried. | ||
| return controller.NewAPIServerError(true, err) | ||
| } | ||
|
|
||
| resourceSnapshotObjs := resourceSnapshotList.GetResourceSnapshotObjs() | ||
| if len(resourceSnapshotObjs) == 0 { | ||
| err := controller.NewUserError(fmt.Errorf("no resourceSnapshots with index `%d` found for placement `%s`", snapshotIndex, placementKey)) | ||
| klog.ErrorS(err, "No specified resourceSnapshots found", "updateRun", updateRunRef) | ||
| // no more retries here. | ||
| return fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) | ||
| return err | ||
| } | ||
|
|
||
| // Look for the master resourceSnapshot. | ||
|
|
@@ -509,12 +489,18 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t | |
|
|
||
| // No masterResourceSnapshot found. | ||
| if masterResourceSnapshot == nil { | ||
| err := controller.NewUnexpectedBehaviorError(fmt.Errorf("no master resourceSnapshot found for placement `%s` with index `%d`", placementKey, snapshotIndex)) | ||
| err := controller.NewUnexpectedBehaviorError(fmt.Errorf("no master resourceSnapshot found for placement %s", placementKey)) | ||
| klog.ErrorS(err, "Failed to find master resourceSnapshot", "updateRun", updateRunRef) | ||
| // no more retries here. | ||
| return fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) | ||
| } | ||
| klog.V(2).InfoS("Found master resourceSnapshot", "placement", placementKey, "index", snapshotIndex, "updateRun", updateRunRef) | ||
|
|
||
| klog.V(2).InfoS("Found master resourceSnapshot", "placement", placementKey, "masterResourceSnapshot", masterResourceSnapshot.GetName(), "updateRun", updateRunRef) | ||
|
|
||
| // Record the resource snapshot index used. | ||
| updateRunStatus := updateRun.GetUpdateRunStatus() | ||
| updateRunStatus.ResourceSnapshotIndexUsed = masterResourceSnapshot.GetLabels()[placementv1beta1.ResourceIndexLabel] | ||
| updateRun.SetUpdateRunStatus(*updateRunStatus) | ||
|
|
||
| resourceSnapshotRef := klog.KObj(masterResourceSnapshot) | ||
| // Fetch all the matching overrides. | ||
|
|
@@ -526,7 +512,6 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t | |
| } | ||
|
|
||
| // Pick the overrides associated with each target cluster. | ||
| updateRunStatus := updateRun.GetUpdateRunStatus() | ||
| for _, stageStatus := range updateRunStatus.StagesStatus { | ||
| for i := range stageStatus.Clusters { | ||
| clusterStatus := &stageStatus.Clusters[i] | ||
|
|
@@ -543,6 +528,58 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t | |
| return nil | ||
| } | ||
|
|
||
| // getResourceSnapshotObjs retrieves the list of resource snapshot objects from the specified ResourceSnapshotIndex. | ||
| // If ResourceSnapshotIndex is unspecified, it returns the list of latest resource snapshots. | ||
| func (r *Reconciler) getResourceSnapshotObjs(ctx context.Context, placementKey types.NamespacedName, updateRun placementv1beta1.UpdateRunObj) ([]placementv1beta1.ResourceSnapshotObj, error) { | ||
| updateRunRef := klog.KObj(updateRun) | ||
| updateRunSpec := updateRun.GetUpdateRunSpec() | ||
| var resourceSnapshotObjs []placementv1beta1.ResourceSnapshotObj | ||
| if updateRunSpec.ResourceSnapshotIndex != "" { | ||
| snapshotIndex, err := strconv.Atoi(updateRunSpec.ResourceSnapshotIndex) | ||
| if err != nil || snapshotIndex < 0 { | ||
| err := controller.NewUserError(fmt.Errorf("invalid resource snapshot index `%s` provided, expected an integer >= 0", updateRunSpec.ResourceSnapshotIndex)) | ||
| klog.ErrorS(err, "Failed to parse the resource snapshot index", "updateRun", updateRunRef) | ||
| // no more retries here. | ||
| return nil, fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) | ||
britaniar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| resourceSnapshotList, err := controller.ListAllResourceSnapshotWithAnIndex(ctx, r.Client, updateRunSpec.ResourceSnapshotIndex, placementKey.Name, placementKey.Namespace) | ||
| if err != nil { | ||
| klog.ErrorS(err, "Failed to list the resourceSnapshots associated with the placement", | ||
| "placement", placementKey, "resourceSnapshotIndex", snapshotIndex, "updateRun", updateRunRef) | ||
| // list err can be retried. | ||
| return nil, controller.NewAPIServerError(true, err) | ||
britaniar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| resourceSnapshotObjs = resourceSnapshotList.GetResourceSnapshotObjs() | ||
| if len(resourceSnapshotObjs) == 0 { | ||
| err := controller.NewUserError(fmt.Errorf("no resourceSnapshots with index `%d` found for placement `%s`", snapshotIndex, placementKey)) | ||
| klog.ErrorS(err, "No specified resourceSnapshots found", "updateRun", updateRunRef) | ||
| // no more retries here. | ||
| return resourceSnapshotObjs, fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) | ||
| } | ||
| return resourceSnapshotObjs, nil | ||
| } | ||
|
|
||
| klog.V(2).InfoS("No resource snapshot index specified, fetching latest resource snapshots", "placement", placementKey, "updateRun", updateRunRef) | ||
| latestResourceSnapshots, err := controller.ListLatestResourceSnapshots(ctx, r.Client, placementKey) | ||
britaniar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| klog.ErrorS(err, "Failed to list the latest resourceSnapshots associated with the placement", | ||
| "placement", placementKey, "updateRun", updateRunRef) | ||
| // list err can be retried. | ||
| return nil, controller.NewAPIServerError(true, err) | ||
britaniar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| resourceSnapshotObjs = latestResourceSnapshots.GetResourceSnapshotObjs() | ||
| if len(resourceSnapshotObjs) == 0 { | ||
| err := fmt.Errorf("no latest resourceSnapshots found for placement `%s`. This might be a transient state, need retry", placementKey) | ||
| klog.ErrorS(err, "No latest resourceSnapshots found for placement. This might be transient, need retry", "placement", placementKey, "updateRun", updateRunRef) | ||
| // retryable error. | ||
| return resourceSnapshotObjs, fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Retriable error should NOT be wrapped w/ errInitializedfailed. |
||
| } | ||
| return resourceSnapshotObjs, nil | ||
| } | ||
|
|
||
| // recordInitializationSucceeded records the successful initialization condition in the UpdateRun status. | ||
| func (r *Reconciler) recordInitializationSucceeded(ctx context.Context, updateRun placementv1beta1.UpdateRunObj) error { | ||
| updateRunStatus := updateRun.GetUpdateRunStatus() | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test this in an e2e env? Please paste your test updateRun obj (including both spec and status) in PR description.