Skip to content

Commit

Permalink
Handle alternate forms of resource status (#233)
Browse files Browse the repository at this point in the history
We previously assumed that a resource either conformed to our notion of
status or didn't have a status field at all. If a status field existed,
but either didn't have the structure we expected or did have the
structure but was a pointer, would err.

Now we gracefully unpack the status as best we can, and safely ignore
cases where the structure does not conform to our ideal structure. In
those cases the functionality that would be applied is skipped. This
includes:
- calling `status.InitializeConditions()`
- setting `status.ObservedGeneration`
- normalizing the LastTransitionTime for conditions

When we can't  apply these behaviors, a warning is logged during
setup of the ParentReconciler.

Signed-off-by: Scott Andrews <andrewssc@vmware.com>
  • Loading branch information
scothis committed May 13, 2022
1 parent fb14c38 commit eed91e0
Show file tree
Hide file tree
Showing 10 changed files with 1,061 additions and 27 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -41,6 +41,8 @@ The parent is responsible for:
- fetching the resource being reconciled
- creating a stash to pass state between sub reconcilers
- passing the resource to each sub reconciler in turn
- initialize conditions on the status by calling status.InitializeConditions() if defined
- normalizing the .status.conditions[].lastTransitionTime for status conditions that are metav1.Condition (the previous timestamp is preserved if the condition is otherwise unchanged)
- reflects the observed generation on the status
- updates the resource status if it was modified
- logging the reconcilers activities
Expand Down
20 changes: 19 additions & 1 deletion internal/resources/dies/dies.go
Expand Up @@ -56,5 +56,23 @@ func (d *TestResourceStatusDie) AddField(key, value string) *TestResourceStatusD
})
}

// +die:object=true
// +die:object=true,spec=TestResourceSpec
type _ = resources.TestResourceEmptyStatus

// +die
type _ = resources.TestResourceEmptyStatusStatus

// +die:object=true,spec=TestResourceSpec
type _ = resources.TestResourceNoStatus

// +die:object=true,spec=TestResourceSpec
type _ = resources.TestResourceNilableStatus

// StatusDie stamps the resource's status field with a mutable die.
func (d *TestResourceNilableStatusDie) StatusDie(fn func(d *TestResourceStatusDie)) *TestResourceNilableStatusDie {
return d.DieStamp(func(r *resources.TestResourceNilableStatus) {
d := TestResourceStatusBlank.DieImmutable(false).DieFeedPtr(r.Status)
fn(d)
r.Status = d.DieReleasePtr()
})
}

0 comments on commit eed91e0

Please sign in to comment.