Skip to content

Commit 35dd8c1

Browse files
authored
Terminal condition sets ResourceSynced=False (#94)
This patch updates the `resourceReconciler.ensureConditions()` method to set the `ACK.ResourceSynced` Condition value to `False` when a Terminal error has been returned from the resource manager. Previously, the `ACK.ResourceSynced` Condition value was erroneously being set to `True` due to a misunderstanding of what `ACK.ResourceSynced` means. `ACK.ResourceSynced` is a Condition that informs the Kubernetes user *whether the desired state of a resource matches the latest observed state of the resource*. In the case of a Terminal error, the desired state of a resource will *never* match the latest observed state of the resource because there is something invalid about the desired resource state. Further, this patch changes the default value for `ACK.ResourceSynced` Condition to be `Unknown` instead of `False` for any non-Terminal reconciler error. The reasoning behind this change is that for non-Terminal errors, we simply do not know whether the desired resource state matches the latest observed state or not. Signed-off-by: Jay Pipes <[email protected]> By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 71e60cc commit 35dd8c1

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

pkg/condition/condition.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ var (
2929
NotManagedReason = "This resource already exists but is not managed by ACK. " +
3030
"To bring the resource under ACK management, you should explicitly adopt " +
3131
"the resource by creating a services.k8s.aws/AdoptedResource"
32-
NotSyncedMessage = "Resource not synced"
33-
SyncedMessage = "Resource synced successfully"
32+
UnknownSyncedMessage = "Unable to determine if desired resource state matches latest observed state"
33+
NotSyncedMessage = "Resource not synced"
34+
SyncedMessage = "Resource synced successfully"
3435
)
3536

3637
// Synced returns the Condition in the resource's Conditions collection that is

pkg/runtime/reconciler.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,19 @@ func (r *resourceReconciler) ensureConditions(
326326
if reconcileErr != nil {
327327
condReason = reconcileErr.Error()
328328
if reconcileErr == ackerr.Terminal {
329-
// A terminal condition by its very nature indicates a stable state
330-
// for a resource being synced. The resource is considered synced
331-
// because its state will not change.
332-
condStatus = corev1.ConditionTrue
333-
condMessage = ackcondition.SyncedMessage
334-
} else {
335-
// For any other reconciler error, set synced condition to false
329+
// A terminal condition is a stable state for a resource.
330+
// Terminal conditions indicate that without changes to the
331+
// desired state of a resource, the resource's desired state
332+
// will never match the latest observed state. Thus,
333+
// ACK.ResourceSynced must be False.
336334
condStatus = corev1.ConditionFalse
337335
condMessage = ackcondition.NotSyncedMessage
336+
} else {
337+
// For any other reconciler error, set synced condition to
338+
// unknown, since we don't know whether the resource's desired
339+
// state matches the resource's latest observed state.
340+
condStatus = corev1.ConditionUnknown
341+
condMessage = ackcondition.UnknownSyncedMessage
338342
}
339343
}
340344
ackcondition.SetSynced(res, condStatus, &condMessage, &condReason)

pkg/runtime/reconciler_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,10 @@ func TestReconcilerUpdate_ErrorInLateInitialization(t *testing.T) {
994994
hasSynced = true
995995
// Even though mocked IsSynced method returns (true, nil),
996996
// the reconciler error from late initialization correctly causes
997-
// the ResourceSynced condition to be False
998-
assert.Equal(corev1.ConditionFalse, condition.Status)
999-
assert.Equal(ackcondition.NotSyncedMessage, *condition.Message)
997+
// the ResourceSynced condition to be Unknown since the reconciler
998+
// error is not a Terminal error.
999+
assert.Equal(corev1.ConditionUnknown, condition.Status)
1000+
assert.Equal(ackcondition.UnknownSyncedMessage, *condition.Message)
10001001
assert.Equal(requeueError.Error(), *condition.Reason)
10011002
}
10021003
assert.True(hasSynced)
@@ -1112,9 +1113,9 @@ func TestReconcilerUpdate_ResourceNotManaged(t *testing.T) {
11121113
}
11131114
hasSynced = true
11141115
// The terminal error from reconciler correctly causes
1115-
// the ResourceSynced condition to be True
1116-
assert.Equal(corev1.ConditionTrue, condition.Status)
1117-
assert.Equal(ackcondition.SyncedMessage, *condition.Message)
1116+
// the ResourceSynced condition to be False
1117+
assert.Equal(corev1.ConditionFalse, condition.Status)
1118+
assert.Equal(ackcondition.NotSyncedMessage, *condition.Message)
11181119
}
11191120
assert.True(hasSynced)
11201121
})

0 commit comments

Comments
 (0)