Skip to content

Commit

Permalink
Update v1alpha1 status types to inline fields
Browse files Browse the repository at this point in the history
Splits up the status types into two structs:

* XXXStatus
* XXXStatusFields

This first inlines both knative's duck status type and the
XXXStatusFields. The second stores all the fields that were originially
in XXXStatus. This is advantageous as downstream users can now embed a
the XXXStatusFields if their CRDs manage a Tekton object.

This pattern is demonstrated in Knative (e.g., Serving). Moving to this
pattern does not change the JSON/YAML structure in anyway, however it
does change how status objects have to be instantiated in Go.

fixes #1590
  • Loading branch information
poy authored and tekton-robot committed Dec 11, 2019
1 parent db33fd7 commit a90f2ae
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 134 deletions.
8 changes: 8 additions & 0 deletions pkg/apis/pipeline/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ type Condition struct {
type ConditionCheckStatus struct {
duckv1beta1.Status `json:",inline"`

// ConditionCheckStatusFields inlines the status fields.
ConditionCheckStatusFields `json:",inline"`
}

// ConditionCheckStatusFields holds the fields of ConfigurationCheck's status.
// This is defined separately and inlined so that other types can readily
// consume these fields via duck typing.
type ConditionCheckStatusFields struct {
// PodName is the name of the pod responsible for executing this condition check.
PodName string `json:"podName"`

Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ type PipelineRef struct {
type PipelineRunStatus struct {
duckv1beta1.Status `json:",inline"`

// PipelineRunStatusFields inlines the status fields.
PipelineRunStatusFields `json:",inline"`
}

// PipelineRunStatusFields holds the fields of PipelineRunStatus' status.
// This is defined separately and inlined so that other types can readily
// consume these fields via duck typing.
type PipelineRunStatusFields struct {
// StartTime is the time the PipelineRun is actually started.
// +optional
StartTime *metav1.Time `json:"startTime,omitempty"`
Expand Down
8 changes: 6 additions & 2 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,17 @@ func TestPipelineRunHasStarted(t *testing.T) {
}, {
name: "prWithStartTime",
prStatus: v1alpha1.PipelineRunStatus{
StartTime: &metav1.Time{Time: time.Now()},
PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{
StartTime: &metav1.Time{Time: time.Now()},
},
},
expectedValue: true,
}, {
name: "prWithZeroStartTime",
prStatus: v1alpha1.PipelineRunStatus{
StartTime: &metav1.Time{},
PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{
StartTime: &metav1.Time{},
},
},
expectedValue: false,
}}
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/pipeline/v1alpha1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ var taskRunCondSet = apis.NewBatchConditionSet()
type TaskRunStatus struct {
duckv1beta1.Status `json:",inline"`

// TaskRunStatusFields inlines the status fields.
TaskRunStatusFields `json:",inline"`
}

// TaskRunStatusFields holds the fields of TaskRun's status. This is defined
// separately and inlined so that other types can readily consume these fields
// via duck typing.
type TaskRunStatusFields struct {
// PodName is the name of the pod responsible for executing this task's steps.
PodName string `json:"podName"`

Expand Down
8 changes: 6 additions & 2 deletions pkg/apis/pipeline/v1alpha1/taskrun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,17 @@ func TestTaskRunHasStarted(t *testing.T) {
}, {
name: "trWithStartTime",
trStatus: v1alpha1.TaskRunStatus{
StartTime: &metav1.Time{Time: time.Now()},
TaskRunStatusFields: v1alpha1.TaskRunStatusFields{
StartTime: &metav1.Time{Time: time.Now()},
},
},
expectedValue: true,
}, {
name: "trWithZeroStartTime",
trStatus: v1alpha1.TaskRunStatus{
StartTime: &metav1.Time{},
TaskRunStatusFields: v1alpha1.TaskRunStatusFields{
StartTime: &metav1.Time{},
},
},
expectedValue: false,
}}
Expand Down
69 changes: 60 additions & 9 deletions pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit a90f2ae

Please sign in to comment.