Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to the v1beta1 Conditions implementation. #744

Merged
merged 4 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Gopkg.lock

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

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ required = [

[[override]]
name = "github.com/knative/pkg"
# HEAD as of 2019-03-21 💖
revision = "60fdcbcabd2faeb34328d8b2725dc76c59189453"
# HEAD as of 2019-04-09 💖
revision = "28cfa161499b88cc5a71cfb7cf8a59fc34bff3d3"

[[override]]
name = "go.uber.org/zap"
Expand Down
4 changes: 2 additions & 2 deletions config/200-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ rules:
- apiGroups: [""]
resources: ["pods", "namespaces", "secrets", "events", "serviceaccounts", "configmaps", "persistentvolumeclaims"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["extensions"]
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["extensions"]
- apiGroups: ["apps"]
resources: ["deployments/finalizers"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["admissionregistration.k8s.io"]
Expand Down
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 @@ -116,16 +117,20 @@ type PipelineTrigger struct {

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing this includes that I don't see here is ObservedGeneration.

For mutable types, this is important to understand whether the overall Status reflects the latest Spec.

Basically, if metadata.generation == status.observedGeneration, then I can believe the conditions.

Not for this change, but probably worth an issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, yeah we'll need to update our usage of Condition to reflect that then 👼
(adding this to my todo 🙃 )


// 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 @@ -140,10 +145,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 @@ -160,7 +165,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 @@ -221,7 +226,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
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1alpha1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var invalidBuildSteps = []corev1.Container{{
Image: "myimage",
}}

func TestTaskSpec_Validate(t *testing.T) {
func TestTaskSpecValidate(t *testing.T) {
type fields struct {
Inputs *Inputs
Outputs *Outputs
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestTaskSpec_Validate(t *testing.T) {
}
}

func TestTaskSpec_ValidateError(t *testing.T) {
func TestTaskSpecValidateError(t *testing.T) {
type fields struct {
Inputs *Inputs
Outputs *Outputs
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestTaskSpec_ValidateError(t *testing.T) {
BuildSteps: validBuildSteps,
},
expectedError: apis.FieldError{
Message: `invalid value "what"`,
Message: `invalid value: what`,
Paths: []string{"taskspec.Inputs.Resources.source.Type"},
},
}, {
Expand All @@ -193,7 +193,7 @@ func TestTaskSpec_ValidateError(t *testing.T) {
BuildSteps: validBuildSteps,
},
expectedError: apis.FieldError{
Message: `invalid value "what"`,
Message: `invalid value: what`,
Paths: []string{"taskspec.Outputs.Resources.who.Type"},
},
}, {
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 @@ -114,13 +114,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 @@ -143,7 +141,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 @@ -155,7 +153,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 @@ -228,7 +226,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
Loading