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

Terminal condition sets ResourceSynced=False #94

Merged
merged 1 commit into from
Jun 15, 2022
Merged
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
5 changes: 3 additions & 2 deletions pkg/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ var (
NotManagedReason = "This resource already exists but is not managed by ACK. " +
"To bring the resource under ACK management, you should explicitly adopt " +
"the resource by creating a services.k8s.aws/AdoptedResource"
NotSyncedMessage = "Resource not synced"
SyncedMessage = "Resource synced successfully"
UnknownSyncedMessage = "Unable to determine if desired resource state matches latest observed state"
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of desired resource state do we want to just plainly say spec?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Instead of desired resource state do we want to just plainly say spec?

The issue with saying "spec" is that the spec can contain both the desired and latest state :) We compare full AWSResource objects to determine desired versus latest because some fields representing the latest state are set in the spec...

NotSyncedMessage = "Resource not synced"
SyncedMessage = "Resource synced successfully"
)

// Synced returns the Condition in the resource's Conditions collection that is
Expand Down
18 changes: 11 additions & 7 deletions pkg/runtime/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,19 @@ func (r *resourceReconciler) ensureConditions(
if reconcileErr != nil {
condReason = reconcileErr.Error()
if reconcileErr == ackerr.Terminal {
// A terminal condition by its very nature indicates a stable state
// for a resource being synced. The resource is considered synced
// because its state will not change.
condStatus = corev1.ConditionTrue
condMessage = ackcondition.SyncedMessage
} else {
// For any other reconciler error, set synced condition to false
// A terminal condition is a stable state for a resource.
// Terminal conditions indicate that without changes to the
// desired state of a resource, the resource's desired state
// will never match the latest observed state. Thus,
// ACK.ResourceSynced must be False.
condStatus = corev1.ConditionFalse
condMessage = ackcondition.NotSyncedMessage
} else {
// For any other reconciler error, set synced condition to
// unknown, since we don't know whether the resource's desired
// state matches the resource's latest observed state.
condStatus = corev1.ConditionUnknown
condMessage = ackcondition.UnknownSyncedMessage
}
}
ackcondition.SetSynced(res, condStatus, &condMessage, &condReason)
Expand Down
13 changes: 7 additions & 6 deletions pkg/runtime/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,9 +994,10 @@ func TestReconcilerUpdate_ErrorInLateInitialization(t *testing.T) {
hasSynced = true
// Even though mocked IsSynced method returns (true, nil),
// the reconciler error from late initialization correctly causes
// the ResourceSynced condition to be False
assert.Equal(corev1.ConditionFalse, condition.Status)
assert.Equal(ackcondition.NotSyncedMessage, *condition.Message)
// the ResourceSynced condition to be Unknown since the reconciler
// error is not a Terminal error.
assert.Equal(corev1.ConditionUnknown, condition.Status)
assert.Equal(ackcondition.UnknownSyncedMessage, *condition.Message)
assert.Equal(requeueError.Error(), *condition.Reason)
}
assert.True(hasSynced)
Expand Down Expand Up @@ -1112,9 +1113,9 @@ func TestReconcilerUpdate_ResourceNotManaged(t *testing.T) {
}
hasSynced = true
// The terminal error from reconciler correctly causes
// the ResourceSynced condition to be True
assert.Equal(corev1.ConditionTrue, condition.Status)
assert.Equal(ackcondition.SyncedMessage, *condition.Message)
// the ResourceSynced condition to be False
assert.Equal(corev1.ConditionFalse, condition.Status)
assert.Equal(ackcondition.NotSyncedMessage, *condition.Message)
}
assert.True(hasSynced)
})
Expand Down