Skip to content

feat: wait for resource to sync before updating #188

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/runtime/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,13 @@ func (r *resourceReconciler) updateResource(
return latest, err
}

// We don't want to attempt updating the resource until it is Synced!
if synced, err := IsSyncedInRes(ctx, rm, latest); !synced {
Copy link

Choose a reason for hiding this comment

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

Do we want to fully block the update call? For example in Bedrock Agent we need to make an API call to PrepareAgent before the resource is in the synced state of Prepared.

Copy link

Choose a reason for hiding this comment

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

Additionally, I believe @a-hilaly mentioned that we might want to also allow updates, such as tags, that don't depend on the status of the AWS resource.

rlog.Info(
"requeing until resource is synced",
)
return latest, err
}
// Check to see if the latest observed state already matches the
// desired state and if not, update the resource
delta := r.rd.Delta(desired, latest)
Expand Down
22 changes: 22 additions & 0 deletions pkg/runtime/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package runtime

import (
"context"
"encoding/json"
"fmt"
"strings"
Expand Down Expand Up @@ -70,6 +71,27 @@ func IsSynced(res acktypes.AWSResource) bool {
return false
}

// IsSyncedInRes is like IsSynced, but instead of returnning false
Copy link

Choose a reason for hiding this comment

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

nit: spelling

Suggested change
// IsSyncedInRes is like IsSynced, but instead of returnning false
// IsSyncedInRes is like IsSynced, but instead of returning false

// when the Synced condition is not there, it returns true.
Copy link

Choose a reason for hiding this comment

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

// when the Synced condition is not there, it returns true.

Is this this the case? If the for loop doesn't find a ConditionTypeResourceSynced condition it this function returns the result of IsSynced.

// Note(michaelhtm) We will be using this as a preUpdate check to
// see if a resource has a NotSynced condition
func IsSyncedInRes(ctx context.Context, rm acktypes.AWSResourceManager, res acktypes.AWSResource) (bool, error) {
Copy link

Choose a reason for hiding this comment

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

p: "Res" is a bit unclear. Maybe IsSyncedInAWSResource? It's more verbose, but explicit about what is actually being checked.

for _, c := range res.Conditions() {
if c.Type == ackv1alpha1.ConditionTypeResourceSynced {
if c.Status == corev1.ConditionTrue {
return true, nil
}
// TODO(michaelhtm) we should probably start relying more and more in IsSynced below.
// Or maybe store the RequeueError in ackCondition.RequeueError...
return false, fmt.Errorf("resource is not synced")

}
}

synced, err := rm.IsSynced(ctx, res)
return synced, err
}

// IsReadOnly returns true if the supplied AWSResource has an annotation
// indicating that it is in read-only mode.
func IsReadOnly(res acktypes.AWSResource) bool {
Expand Down