Skip to content

Commit

Permalink
Move to the v1beta1 Conditions implementation
Browse files Browse the repository at this point in the history
See here for more context on what's changed (no breaking changes): knative/pkg#361

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester committed Apr 10, 2019
1 parent 4f0acbf commit 8092498
Show file tree
Hide file tree
Showing 28 changed files with 310 additions and 294 deletions.
17 changes: 11 additions & 6 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
"fmt"
"time"

duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
"github.com/knative/pkg/apis"
duckv1beta1 "github.com/knative/pkg/apis/duck/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -113,16 +114,20 @@ type PipelineTrigger struct {

// PipelineRunStatus defines the observed state of PipelineRun
type PipelineRunStatus struct {
Conditions duckv1alpha1.Conditions `json:"conditions"`
duckv1beta1.Status `json:",inline"`

// In #107 should be updated to hold the location logs have been uploaded to
// +optional
Results *Results `json:"results,omitempty"`

// StartTime is the time the PipelineRun is actually started.
// +optional
StartTime *metav1.Time `json:"startTime,omitempty"`

// CompletionTime is the time the PipelineRun completed.
// +optional
CompletionTime *metav1.Time `json:"completionTime,omitempty"`

// map of PipelineRunTaskRunStatus with the taskRun name as the key
// +optional
TaskRuns map[string]*PipelineRunTaskRunStatus `json:"taskRuns,omitempty"`
Expand All @@ -137,10 +142,10 @@ type PipelineRunTaskRunStatus struct {
Status *TaskRunStatus `json:"status,omitempty"`
}

var pipelineRunCondSet = duckv1alpha1.NewBatchConditionSet()
var pipelineRunCondSet = apis.NewBatchConditionSet()

// GetCondition returns the Condition matching the given type.
func (pr *PipelineRunStatus) GetCondition(t duckv1alpha1.ConditionType) *duckv1alpha1.Condition {
func (pr *PipelineRunStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return pipelineRunCondSet.Manage(pr).GetCondition(t)
}

Expand All @@ -157,7 +162,7 @@ func (pr *PipelineRunStatus) InitializeConditions() {

// SetCondition sets the condition, unsetting previous conditions with the same
// type as necessary.
func (pr *PipelineRunStatus) SetCondition(newCond *duckv1alpha1.Condition) {
func (pr *PipelineRunStatus) SetCondition(newCond *apis.Condition) {
if newCond != nil {
pipelineRunCondSet.Manage(pr).SetCondition(*newCond)
}
Expand Down Expand Up @@ -218,7 +223,7 @@ func (pr *PipelineRun) GetOwnerReference() []metav1.OwnerReference {

// IsDone returns true if the PipelineRun's status indicates that it is done.
func (pr *PipelineRun) IsDone() bool {
return !pr.Status.GetCondition(duckv1alpha1.ConditionSucceeded).IsUnknown()
return !pr.Status.GetCondition(apis.ConditionSucceeded).IsUnknown()
}

// HasStarted function check whether pipelinerun has valid start time set in its status
Expand Down
9 changes: 4 additions & 5 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/knative/pkg/apis"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestPipelineRunStatusConditions(t *testing.T) {
p := &PipelineRun{}
foo := &duckv1alpha1.Condition{
foo := &apis.Condition{
Type: "Foo",
Status: "True",
}
bar := &duckv1alpha1.Condition{
bar := &apis.Condition{
Type: "Bar",
Status: "True",
}
Expand Down Expand Up @@ -91,8 +90,8 @@ func TestInitializeConditions(t *testing.T) {

func TestPipelineRunIsDone(t *testing.T) {
pr := &PipelineRun{}
foo := &duckv1alpha1.Condition{
Type: duckv1alpha1.ConditionSucceeded,
foo := &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
}
pr.Status.SetCondition(foo)
Expand Down
14 changes: 6 additions & 8 deletions pkg/apis/pipeline/v1alpha1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"time"

"github.com/knative/pkg/apis"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
duckv1beta1 "github.com/knative/pkg/apis/duck/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -111,13 +111,11 @@ type TaskTrigger struct {
Name string `json:"name,omitempty"`
}

var taskRunCondSet = duckv1alpha1.NewBatchConditionSet()
var taskRunCondSet = apis.NewBatchConditionSet()

// TaskRunStatus defines the observed state of TaskRun
type TaskRunStatus struct {
// Conditions describes the set of conditions of this build.
// +optional
Conditions duckv1alpha1.Conditions `json:"conditions,omitempty"`
duckv1beta1.Status `json:",inline"`

// In #107 should be updated to hold the location logs have been uploaded to
// +optional
Expand All @@ -140,7 +138,7 @@ type TaskRunStatus struct {
}

// GetCondition returns the Condition matching the given type.
func (tr *TaskRunStatus) GetCondition(t duckv1alpha1.ConditionType) *duckv1alpha1.Condition {
func (tr *TaskRunStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return taskRunCondSet.Manage(tr).GetCondition(t)
}
func (tr *TaskRunStatus) InitializeConditions() {
Expand All @@ -152,7 +150,7 @@ func (tr *TaskRunStatus) InitializeConditions() {

// SetCondition sets the condition, unsetting previous conditions with the same
// type as necessary.
func (tr *TaskRunStatus) SetCondition(newCond *duckv1alpha1.Condition) {
func (tr *TaskRunStatus) SetCondition(newCond *apis.Condition) {
if newCond != nil {
taskRunCondSet.Manage(tr).SetCondition(*newCond)
}
Expand Down Expand Up @@ -225,7 +223,7 @@ func (tr *TaskRun) HasPipelineRunOwnerReference() bool {

// IsDone returns true if the TaskRun's status indicates that it is done.
func (tr *TaskRun) IsDone() bool {
return !tr.Status.GetCondition(duckv1alpha1.ConditionSucceeded).IsUnknown()
return !tr.Status.GetCondition(apis.ConditionSucceeded).IsUnknown()
}

// IsCancelled returns true if the TaskRun's spec status is set to Cancelled state
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1alpha1/taskrun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
"github.com/knative/pkg/apis"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -129,8 +129,8 @@ func TestTaskRun_HasPipelineRun(t *testing.T) {

func TestTaskRunIsDone(t *testing.T) {
tr := &TaskRun{}
foo := &duckv1alpha1.Condition{
Type: duckv1alpha1.ConditionSucceeded,
foo := &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
}
tr.Status.SetCondition(foo)
Expand Down
17 changes: 2 additions & 15 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.

4 changes: 2 additions & 2 deletions pkg/reconciler/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ limitations under the License.
package reconciler

import (
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
"github.com/knative/pkg/apis"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
)

// EmitEvent emits success or failed event for object
// if afterCondition is different from beforeCondition
func EmitEvent(c record.EventRecorder, beforeCondition *duckv1alpha1.Condition, afterCondition *duckv1alpha1.Condition, object runtime.Object) {
func EmitEvent(c record.EventRecorder, beforeCondition *apis.Condition, afterCondition *apis.Condition, object runtime.Object) {
if beforeCondition != afterCondition && afterCondition != nil {
// Create events when the obj result is in.
if afterCondition.Status == corev1.ConditionTrue {
Expand Down
38 changes: 19 additions & 19 deletions pkg/reconciler/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,68 @@ import (
"testing"
"time"

duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
"github.com/knative/pkg/apis"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
)

func Test_EmitEvent(t *testing.T) {
testcases := []struct {
name string
before *duckv1alpha1.Condition
after *duckv1alpha1.Condition
before *apis.Condition
after *apis.Condition
expectEvent bool
}{
{
name: "unknown to true",
before: &duckv1alpha1.Condition{
Type: duckv1alpha1.ConditionSucceeded,
before: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionUnknown,
},
after: &duckv1alpha1.Condition{
Type: duckv1alpha1.ConditionSucceeded,
after: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
},
expectEvent: true,
},
{
name: "true to true",
before: &duckv1alpha1.Condition{
Type: duckv1alpha1.ConditionSucceeded,
before: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
},
after: &duckv1alpha1.Condition{
Type: duckv1alpha1.ConditionSucceeded,
after: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
},
expectEvent: false,
},
{
name: "false to false",
before: &duckv1alpha1.Condition{
Type: duckv1alpha1.ConditionSucceeded,
before: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
},
after: &duckv1alpha1.Condition{
Type: duckv1alpha1.ConditionSucceeded,
after: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
},
expectEvent: false,
},
{
name: "true to nil",
after: nil,
before: &duckv1alpha1.Condition{
Type: duckv1alpha1.ConditionSucceeded,
before: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
},
expectEvent: true,
},
{
name: "nil to true",
before: nil,
after: &duckv1alpha1.Condition{
Type: duckv1alpha1.ConditionSucceeded,
after: &apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
},
expectEvent: true,
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strings"
"testing"

duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
"github.com/knative/pkg/apis"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/reconciler/v1alpha1/pipelinerun/resources"
"github.com/tektoncd/pipeline/test"
Expand All @@ -37,8 +37,8 @@ func TestRecorderOptions(t *testing.T) {

prs := []*v1alpha1.PipelineRun{tb.PipelineRun("test-pipeline-run-completed", "foo",
tb.PipelineRunSpec("test-pipeline", tb.PipelineRunServiceAccount("test-sa")),
tb.PipelineRunStatus(tb.PipelineRunStatusCondition(duckv1alpha1.Condition{
Type: duckv1alpha1.ConditionSucceeded,
tb.PipelineRunStatus(tb.PipelineRunStatusCondition(apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
Reason: resources.ReasonSucceeded,
Message: "All Tasks have completed executing",
Expand Down
Loading

0 comments on commit 8092498

Please sign in to comment.