Skip to content
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: 9 additions & 4 deletions apis/condition_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ type ConditionsAccessor interface {
SetConditions(Conditions)
}

// ConditionAccessor is used to access a condition through it's type
type ConditionAccessor interface {
// GetCondition finds and returns the Condition that matches the ConditionType
// It should return nil if the condition type is not present
GetCondition(t ConditionType) *Condition
}

// ConditionSet is an abstract collection of the possible ConditionType values
// that a particular resource might expose. It also holds the "happy condition"
// for that resource, which we define to be one of Ready or Succeeded depending
Expand All @@ -48,17 +55,15 @@ type ConditionSet struct {
// ConditionManager allows a resource to operate on its Conditions using higher
// order operations.
type ConditionManager interface {
ConditionAccessor

// IsHappy looks at the happy condition and returns true if that condition is
// set to true.
IsHappy() bool

// GetTopLevelCondition finds and returns the top level Condition (happy Condition).
GetTopLevelCondition() *Condition

// GetCondition finds and returns the Condition that matches the ConditionType
// previously set on Conditions.
GetCondition(t ConditionType) *Condition

// SetCondition sets or updates the Condition on Conditions for Condition.Type.
// If there is an update, Conditions are stored back sorted.
SetCondition(new Condition)
Expand Down
21 changes: 8 additions & 13 deletions apis/testing/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ import (

corev1 "k8s.io/api/core/v1"
"knative.dev/pkg/apis"
duckv1b1 "knative.dev/pkg/apis/duck/v1beta1"
"knative.dev/pkg/test"
)

// CheckCondition checks if condition `c` on `cc` has value `cs`.
// DEPRECATED: Use versioned test helper
func CheckCondition(s *duckv1b1.Status, c apis.ConditionType, cs corev1.ConditionStatus) error {
cond := s.GetCondition(c)
func CheckCondition(a apis.ConditionAccessor, c apis.ConditionType, cs corev1.ConditionStatus) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not use the condtionManager interface?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That interface is huge for what these helpers need

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

secondly we're passing duck.Status types here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You might also want gettoplevel in the new interface

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

duck.Status doesn't have that method so don't want to add it

cond := a.GetCondition(c)
if cond == nil {
return fmt.Errorf("condition %v is nil", c)
}
Expand All @@ -38,28 +36,25 @@ func CheckCondition(s *duckv1b1.Status, c apis.ConditionType, cs corev1.Conditio
}

// CheckConditionOngoing checks if the condition is in state `Unknown`.
// DEPRECATED: Use versioned test helper
func CheckConditionOngoing(s *duckv1b1.Status, c apis.ConditionType, t test.T) {
func CheckConditionOngoing(a apis.ConditionAccessor, c apis.ConditionType, t test.T) {
t.Helper()
if err := CheckCondition(s, c, corev1.ConditionUnknown); err != nil {
if err := CheckCondition(a, c, corev1.ConditionUnknown); err != nil {
t.Error(err)
}
}

// CheckConditionFailed checks if the condition is in state `False`.
// DEPRECATED: Use versioned test helper
func CheckConditionFailed(s *duckv1b1.Status, c apis.ConditionType, t test.T) {
func CheckConditionFailed(a apis.ConditionAccessor, c apis.ConditionType, t test.T) {
t.Helper()
if err := CheckCondition(s, c, corev1.ConditionFalse); err != nil {
if err := CheckCondition(a, c, corev1.ConditionFalse); err != nil {
t.Error(err)
}
}

// CheckConditionSucceeded checks if the condition is in state `True`.
// DEPRECATED: Use versioned test helper
func CheckConditionSucceeded(s *duckv1b1.Status, c apis.ConditionType, t test.T) {
func CheckConditionSucceeded(a apis.ConditionAccessor, c apis.ConditionType, t test.T) {
t.Helper()
if err := CheckCondition(s, c, corev1.ConditionTrue); err != nil {
if err := CheckCondition(a, c, corev1.ConditionTrue); err != nil {
t.Error(err)
}
}
61 changes: 0 additions & 61 deletions apis/testing/v1/conditions.go

This file was deleted.

61 changes: 0 additions & 61 deletions apis/testing/v1beta1/conditions.go

This file was deleted.