diff --git a/apis/condition_set.go b/apis/condition_set.go index 1e90aa9eae..2691dcf0fa 100644 --- a/apis/condition_set.go +++ b/apis/condition_set.go @@ -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 @@ -48,6 +55,8 @@ 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 @@ -55,10 +64,6 @@ type ConditionManager interface { // 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) diff --git a/apis/testing/conditions.go b/apis/testing/conditions.go index 02d1fe8b0a..68b0018ab6 100644 --- a/apis/testing/conditions.go +++ b/apis/testing/conditions.go @@ -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 { + cond := a.GetCondition(c) if cond == nil { return fmt.Errorf("condition %v is nil", c) } @@ -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) } } diff --git a/apis/testing/v1/conditions.go b/apis/testing/v1/conditions.go deleted file mode 100644 index 6ace88eb5c..0000000000 --- a/apis/testing/v1/conditions.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2019 The Knative Authors - Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - "fmt" - - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/test" -) - -// CheckCondition checks if condition `c` on `cc` has value `cs`. -func CheckCondition(s *duckv1.Status, c apis.ConditionType, cs corev1.ConditionStatus) error { - cond := s.GetCondition(c) - if cond == nil { - return fmt.Errorf("condition %v is nil", c) - } - if cond.Status != cs { - return fmt.Errorf("condition(%v) = %v, wanted: %v", c, cond, cs) - } - return nil -} - -// CheckConditionOngoing checks if the condition is in state `Unknown`. -func CheckConditionOngoing(s *duckv1.Status, c apis.ConditionType, t test.T) { - t.Helper() - if err := CheckCondition(s, c, corev1.ConditionUnknown); err != nil { - t.Error(err) - } -} - -// CheckConditionFailed checks if the condition is in state `False`. -func CheckConditionFailed(s *duckv1.Status, c apis.ConditionType, t test.T) { - t.Helper() - if err := CheckCondition(s, c, corev1.ConditionFalse); err != nil { - t.Error(err) - } -} - -// CheckConditionSucceeded checks if the condition is in state `True`. -func CheckConditionSucceeded(s *duckv1.Status, c apis.ConditionType, t test.T) { - t.Helper() - if err := CheckCondition(s, c, corev1.ConditionTrue); err != nil { - t.Error(err) - } -} diff --git a/apis/testing/v1beta1/conditions.go b/apis/testing/v1beta1/conditions.go deleted file mode 100644 index 74aa26b2ad..0000000000 --- a/apis/testing/v1beta1/conditions.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2019 The Knative Authors - Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package testing - -import ( - "fmt" - - 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`. -func CheckCondition(s *duckv1b1.Status, c apis.ConditionType, cs corev1.ConditionStatus) error { - cond := s.GetCondition(c) - if cond == nil { - return fmt.Errorf("condition %v is nil", c) - } - if cond.Status != cs { - return fmt.Errorf("condition(%v) = %v, wanted: %v", c, cond, cs) - } - return nil -} - -// CheckConditionOngoing checks if the condition is in state `Unknown`. -func CheckConditionOngoing(s *duckv1b1.Status, c apis.ConditionType, t test.T) { - t.Helper() - if err := CheckCondition(s, c, corev1.ConditionUnknown); err != nil { - t.Error(err) - } -} - -// CheckConditionFailed checks if the condition is in state `False`. -func CheckConditionFailed(s *duckv1b1.Status, c apis.ConditionType, t test.T) { - t.Helper() - if err := CheckCondition(s, c, corev1.ConditionFalse); err != nil { - t.Error(err) - } -} - -// CheckConditionSucceeded checks if the condition is in state `True`. -func CheckConditionSucceeded(s *duckv1b1.Status, c apis.ConditionType, t test.T) { - t.Helper() - if err := CheckCondition(s, c, corev1.ConditionTrue); err != nil { - t.Error(err) - } -}