Skip to content

Commit

Permalink
Expand the Conditions duck type to also encompass ObservedGeneration. (
Browse files Browse the repository at this point in the history
…#324)

With this, the expectation is that folks can embed the following in
the status of their resource:

```go
type FooStatus struct {
	duckv1alpha1.Status `json:",inline"`

	// other fields
}
```

`ObservedGeneration` is important to the usefulness of our standard
conditions because `{Ready,Succeeded}: True` is only meaningful when
`.status.observedGeneration == .metadata.generation`.

When `.status.observedGeneration != .metadata.generation` it indicates
that the controller has not yet attempted to reconcile a change in the
desired state of the world (aka `spec:`).
  • Loading branch information
mattmoor authored and knative-prow-robot committed Mar 17, 2019
1 parent 35d3a1b commit 374ae9e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 38 deletions.
2 changes: 1 addition & 1 deletion apis/duck/v1alpha1/condition_set_test.go
Expand Up @@ -90,7 +90,7 @@ func TestNewBatchConditionSet(t *testing.T) {

func TestNonTerminalCondition(t *testing.T) {
set := NewLivingConditionSet("Foo")
status := &KResourceStatus{}
status := &Status{}

manager := set.Manage(status)
manager.InitializeConditions()
Expand Down
24 changes: 10 additions & 14 deletions apis/duck/v1alpha1/conditions_types.go
Expand Up @@ -129,26 +129,21 @@ type KResource struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Status KResourceStatus `json:"status"`
Status Status `json:"status"`
}

// KResourceStatus shows how we expect folks to embed Conditions in
// Status shows how we expect folks to embed Conditions in
// their Status field.
type KResourceStatus struct {
Conditions Conditions `json:"conditions,omitempty"`
}

func (krs *KResourceStatus) GetConditions() Conditions {
return krs.Conditions
}
type Status struct {
// ObservedGeneration is the 'Generation' of the Service that
// was last processed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

func (krs *KResourceStatus) SetConditions(conditions Conditions) {
krs.Conditions = conditions
// +optional
Conditions Conditions `json:"conditions,omitempty"`
}

// Ensure KResourceStatus satisfies ConditionsAccessor
var _ ConditionsAccessor = (*KResourceStatus)(nil)

// In order for Conditions to be Implementable, KResource must be Populatable.
var _ duck.Populatable = (*KResource)(nil)

Expand All @@ -162,6 +157,7 @@ func (_ *Conditions) GetFullType() duck.Populatable {

// Populate implements duck.Populatable
func (t *KResource) Populate() {
t.Status.ObservedGeneration = 42
t.Status.Conditions = Conditions{{
// Populate ALL fields
Type: "Birthday",
Expand Down
46 changes: 23 additions & 23 deletions apis/duck/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 374ae9e

Please sign in to comment.