Skip to content

Commit

Permalink
Handle alternate forms of resource status
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

Signed-off-by: Scott Andrews <andrewssc@vmware.com>
  • Loading branch information
scothis committed May 12, 2022
1 parent 2bcf4ee commit c487726
Show file tree
Hide file tree
Showing 8 changed files with 899 additions and 27 deletions.
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 c487726

Please sign in to comment.