diff --git a/Gopkg.lock b/Gopkg.lock index 1ff793d4d3e2..bd5c296d8fdb 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1810,7 +1810,7 @@ [[projects]] branch = "master" - digest = "1:cc94fa80f6e4903c1c5b2fc8673156762b2ab2dfe3be11486fea0307e9de71b8" + digest = "1:2f22005f6915f0dd6bc45479507601547a369ed1da0982ed454a76207894e876" name = "knative.dev/pkg" packages = [ "apis", @@ -1818,9 +1818,9 @@ "apis/duck/v1", "apis/duck/v1alpha1", "apis/duck/v1beta1", + "apis/testing", "apis/testing/fuzzer", "apis/testing/roundtrip", - "apis/testing/v1", "changeset", "client/injection/apiextensions/client", "client/injection/apiextensions/informers/apiextensions/v1beta1/customresourcedefinition", @@ -1917,7 +1917,7 @@ "websocket", ] pruneopts = "T" - revision = "a2e3b66654c1bcd82df07f8b4c45b19bad7ab21a" + revision = "5bc49f27e690d0c30bdd079e473d5419998b3259" [[projects]] branch = "master" @@ -2084,9 +2084,9 @@ "knative.dev/pkg/apis/duck/v1", "knative.dev/pkg/apis/duck/v1alpha1", "knative.dev/pkg/apis/duck/v1beta1", + "knative.dev/pkg/apis/testing", "knative.dev/pkg/apis/testing/fuzzer", "knative.dev/pkg/apis/testing/roundtrip", - "knative.dev/pkg/apis/testing/v1", "knative.dev/pkg/client/injection/kube/client", "knative.dev/pkg/client/injection/kube/client/fake", "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment", diff --git a/pkg/apis/autoscaling/v1alpha1/metric_lifecycle.go b/pkg/apis/autoscaling/v1alpha1/metric_lifecycle.go index 838577a5b9f2..d7e9e8581f4f 100644 --- a/pkg/apis/autoscaling/v1alpha1/metric_lifecycle.go +++ b/pkg/apis/autoscaling/v1alpha1/metric_lifecycle.go @@ -19,7 +19,6 @@ package v1alpha1 import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" ) const ( @@ -65,9 +64,5 @@ func (ms *MetricStatus) MarkMetricFailed(reason, message string) { // IsReady looks at the conditions and if the condition MetricConditionReady // is true func (ms *MetricStatus) IsReady() bool { - return condSet.Manage(ms.duck()).IsHappy() -} - -func (ms *MetricStatus) duck() *duckv1.Status { - return (*duckv1.Status)(&ms.Status) + return condSet.Manage(ms).IsHappy() } diff --git a/pkg/apis/autoscaling/v1alpha1/metric_lifecycle_test.go b/pkg/apis/autoscaling/v1alpha1/metric_lifecycle_test.go index d03ce1051bbc..87d1b66493ce 100644 --- a/pkg/apis/autoscaling/v1alpha1/metric_lifecycle_test.go +++ b/pkg/apis/autoscaling/v1alpha1/metric_lifecycle_test.go @@ -25,7 +25,7 @@ import ( "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" "knative.dev/serving/pkg/apis/autoscaling" ) @@ -140,26 +140,26 @@ func TestMetricGetSetCondition(t *testing.T) { func TestTypicalFlowWithMetricCondition(t *testing.T) { m := &MetricStatus{} m.InitializeConditions() - apitestv1.CheckConditionOngoing(m.duck(), MetricConditionReady, t) + apistest.CheckConditionOngoing(m, MetricConditionReady, t) const ( wantReason = "reason" wantMessage = "the error message" ) m.MarkMetricFailed(wantReason, wantMessage) - apitestv1.CheckConditionFailed(m.duck(), MetricConditionReady, t) + apistest.CheckConditionFailed(m, MetricConditionReady, t) if got := m.GetCondition(MetricConditionReady); got == nil || got.Reason != wantReason || got.Message != wantMessage { t.Errorf("MarkMetricFailed = %v, wantReason %v, wantMessage %v", got, wantReason, wantMessage) } m.MarkMetricNotReady(wantReason, wantMessage) - apitestv1.CheckConditionOngoing(m.duck(), MetricConditionReady, t) + apistest.CheckConditionOngoing(m, MetricConditionReady, t) if got := m.GetCondition(MetricConditionReady); got == nil || got.Reason != wantReason || got.Message != wantMessage { t.Errorf("MarkMetricNotReady = %v, wantReason %v, wantMessage %v", got, wantReason, wantMessage) } m.MarkMetricReady() - apitestv1.CheckConditionSucceeded(m.duck(), MetricConditionReady, t) + apistest.CheckConditionSucceeded(m, MetricConditionReady, t) } func TestMetricGetGroupVersionKind(t *testing.T) { diff --git a/pkg/apis/autoscaling/v1alpha1/pa_lifecycle.go b/pkg/apis/autoscaling/v1alpha1/pa_lifecycle.go index 53203e56fb04..26cbdd62637d 100644 --- a/pkg/apis/autoscaling/v1alpha1/pa_lifecycle.go +++ b/pkg/apis/autoscaling/v1alpha1/pa_lifecycle.go @@ -25,7 +25,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/serving/pkg/apis/autoscaling" ) @@ -133,7 +132,7 @@ func (pa *PodAutoscaler) PanicThresholdPercentage() (percentage float64, ok bool // IsReady looks at the conditions and if the Status has a condition // PodAutoscalerConditionReady returns true if ConditionStatus is True func (pas *PodAutoscalerStatus) IsReady() bool { - return podCondSet.Manage(pas.duck()).IsHappy() + return podCondSet.Manage(pas).IsHappy() } // IsActivating returns true if the pod autoscaler is Activating if it is neither @@ -151,27 +150,27 @@ func (pas *PodAutoscalerStatus) IsInactive() bool { // GetCondition gets the condition `t`. func (pas *PodAutoscalerStatus) GetCondition(t apis.ConditionType) *apis.Condition { - return podCondSet.Manage(pas.duck()).GetCondition(t) + return podCondSet.Manage(pas).GetCondition(t) } // InitializeConditions initializes the conditionhs of the PA. func (pas *PodAutoscalerStatus) InitializeConditions() { - podCondSet.Manage(pas.duck()).InitializeConditions() + podCondSet.Manage(pas).InitializeConditions() } // MarkActive marks the PA active. func (pas *PodAutoscalerStatus) MarkActive() { - podCondSet.Manage(pas.duck()).MarkTrue(PodAutoscalerConditionActive) + podCondSet.Manage(pas).MarkTrue(PodAutoscalerConditionActive) } // MarkActivating marks the PA as activating. func (pas *PodAutoscalerStatus) MarkActivating(reason, message string) { - podCondSet.Manage(pas.duck()).MarkUnknown(PodAutoscalerConditionActive, reason, message) + podCondSet.Manage(pas).MarkUnknown(PodAutoscalerConditionActive, reason, message) } // MarkInactive marks the PA as inactive. func (pas *PodAutoscalerStatus) MarkInactive(reason, message string) { - podCondSet.Manage(pas.duck()).MarkFalse(PodAutoscalerConditionActive, reason, message) + podCondSet.Manage(pas).MarkFalse(PodAutoscalerConditionActive, reason, message) } // MarkResourceNotOwned changes the "Active" condition to false to reflect that the @@ -216,10 +215,6 @@ func (pas *PodAutoscalerStatus) inStatusFor(status corev1.ConditionStatus, now t return now.Sub(cond.LastTransitionTime.Inner.Add(dur)) } -func (pas *PodAutoscalerStatus) duck() *duckv1.Status { - return (*duckv1.Status)(&pas.Status) -} - // GetDesiredScale returns the desired scale if ever set, or -1. func (pas *PodAutoscalerStatus) GetDesiredScale() int32 { if pas.DesiredScale != nil { diff --git a/pkg/apis/autoscaling/v1alpha1/pa_lifecycle_test.go b/pkg/apis/autoscaling/v1alpha1/pa_lifecycle_test.go index f71d5006f25e..85b997348229 100644 --- a/pkg/apis/autoscaling/v1alpha1/pa_lifecycle_test.go +++ b/pkg/apis/autoscaling/v1alpha1/pa_lifecycle_test.go @@ -26,7 +26,7 @@ import ( "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" "knative.dev/pkg/ptr" "knative.dev/serving/pkg/apis/autoscaling" ) @@ -606,7 +606,7 @@ func TestMarkResourceNotOwned(t *testing.T) { func TestMarkResourceFailedCreation(t *testing.T) { pa := &PodAutoscalerStatus{} pa.MarkResourceFailedCreation("doesn't", "matter") - apitestv1.CheckConditionFailed(pa.duck(), PodAutoscalerConditionActive, t) + apistest.CheckConditionFailed(pa, PodAutoscalerConditionActive, t) active := pa.GetCondition("Active") if active.Status != corev1.ConditionFalse { @@ -868,38 +868,38 @@ func pa(annotations map[string]string) *PodAutoscaler { func TestTypicalFlow(t *testing.T) { r := &PodAutoscalerStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), PodAutoscalerConditionActive, t) - apitestv1.CheckConditionOngoing(r.duck(), PodAutoscalerConditionReady, t) + apistest.CheckConditionOngoing(r, PodAutoscalerConditionActive, t) + apistest.CheckConditionOngoing(r, PodAutoscalerConditionReady, t) // When we see traffic, mark ourselves active. r.MarkActive() - apitestv1.CheckConditionSucceeded(r.duck(), PodAutoscalerConditionActive, t) - apitestv1.CheckConditionSucceeded(r.duck(), PodAutoscalerConditionReady, t) + apistest.CheckConditionSucceeded(r, PodAutoscalerConditionActive, t) + apistest.CheckConditionSucceeded(r, PodAutoscalerConditionReady, t) // Check idempotency. r.MarkActive() - apitestv1.CheckConditionSucceeded(r.duck(), PodAutoscalerConditionActive, t) - apitestv1.CheckConditionSucceeded(r.duck(), PodAutoscalerConditionReady, t) + apistest.CheckConditionSucceeded(r, PodAutoscalerConditionActive, t) + apistest.CheckConditionSucceeded(r, PodAutoscalerConditionReady, t) // When we stop seeing traffic, mark outselves inactive. r.MarkInactive("TheReason", "the message") - apitestv1.CheckConditionFailed(r.duck(), PodAutoscalerConditionActive, t) + apistest.CheckConditionFailed(r, PodAutoscalerConditionActive, t) if !r.IsInactive() { t.Error("IsInactive was not set.") } - apitestv1.CheckConditionFailed(r.duck(), PodAutoscalerConditionReady, t) + apistest.CheckConditionFailed(r, PodAutoscalerConditionReady, t) // When traffic hits the activator and we scale up the deployment we mark // ourselves as activating. r.MarkActivating("Activating", "Red team, GO!") - apitestv1.CheckConditionOngoing(r.duck(), PodAutoscalerConditionActive, t) - apitestv1.CheckConditionOngoing(r.duck(), PodAutoscalerConditionReady, t) + apistest.CheckConditionOngoing(r, PodAutoscalerConditionActive, t) + apistest.CheckConditionOngoing(r, PodAutoscalerConditionReady, t) // When the activator successfully forwards traffic to the deployment, // we mark ourselves as active once more. r.MarkActive() - apitestv1.CheckConditionSucceeded(r.duck(), PodAutoscalerConditionActive, t) - apitestv1.CheckConditionSucceeded(r.duck(), PodAutoscalerConditionReady, t) + apistest.CheckConditionSucceeded(r, PodAutoscalerConditionActive, t) + apistest.CheckConditionSucceeded(r, PodAutoscalerConditionReady, t) } func TestTargetBC(t *testing.T) { diff --git a/pkg/apis/networking/v1alpha1/certificate_lifecycle.go b/pkg/apis/networking/v1alpha1/certificate_lifecycle.go index 38b77a9615ed..4f485e8842fd 100644 --- a/pkg/apis/networking/v1alpha1/certificate_lifecycle.go +++ b/pkg/apis/networking/v1alpha1/certificate_lifecycle.go @@ -21,7 +21,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" ) // InitializeConditions initializes the certificate conditions. @@ -74,7 +73,3 @@ var certificateCondSet = apis.NewLivingConditionSet(CertificateConditionReady) func (c *Certificate) GetGroupVersionKind() schema.GroupVersionKind { return SchemeGroupVersion.WithKind("Certificate") } - -func (cs *CertificateStatus) duck() *duckv1.Status { - return &cs.Status -} diff --git a/pkg/apis/networking/v1alpha1/certificate_lifecycle_test.go b/pkg/apis/networking/v1alpha1/certificate_lifecycle_test.go index 39d09493b600..9320b8f1aad6 100644 --- a/pkg/apis/networking/v1alpha1/certificate_lifecycle_test.go +++ b/pkg/apis/networking/v1alpha1/certificate_lifecycle_test.go @@ -23,7 +23,7 @@ import ( "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" ) func TestCertificateDuckTypes(t *testing.T) { @@ -56,7 +56,7 @@ func TestCertificateGetGroupVersionKind(t *testing.T) { func TestMarkReady(t *testing.T) { c := &CertificateStatus{} c.InitializeConditions() - apitestv1.CheckConditionOngoing(c.duck(), CertificateConditionReady, t) + apistest.CheckConditionOngoing(c, CertificateConditionReady, t) c.MarkReady() if !c.IsReady() { @@ -67,26 +67,26 @@ func TestMarkReady(t *testing.T) { func TestMarkNotReady(t *testing.T) { c := &CertificateStatus{} c.InitializeConditions() - apitestv1.CheckCondition(c.duck(), CertificateConditionReady, corev1.ConditionUnknown) + apistest.CheckCondition(c, CertificateConditionReady, corev1.ConditionUnknown) c.MarkNotReady("unknow", "unknown") - apitestv1.CheckCondition(c.duck(), CertificateConditionReady, corev1.ConditionUnknown) + apistest.CheckCondition(c, CertificateConditionReady, corev1.ConditionUnknown) } func TestMarkFailed(t *testing.T) { c := &CertificateStatus{} c.InitializeConditions() - apitestv1.CheckCondition(c.duck(), CertificateConditionReady, corev1.ConditionUnknown) + apistest.CheckCondition(c, CertificateConditionReady, corev1.ConditionUnknown) c.MarkFailed("failed", "failed") - apitestv1.CheckConditionFailed(c.duck(), CertificateConditionReady, t) + apistest.CheckConditionFailed(c, CertificateConditionReady, t) } func TestMarkResourceNotOwned(t *testing.T) { c := &CertificateStatus{} c.InitializeConditions() c.MarkResourceNotOwned("doesn't", "own") - apitestv1.CheckConditionFailed(c.duck(), CertificateConditionReady, t) + apistest.CheckConditionFailed(c, CertificateConditionReady, t) } func TestGetCondition(t *testing.T) { diff --git a/pkg/apis/networking/v1alpha1/ingress_lifecycle.go b/pkg/apis/networking/v1alpha1/ingress_lifecycle.go index c6fd1b9e28d1..45756f736dfa 100644 --- a/pkg/apis/networking/v1alpha1/ingress_lifecycle.go +++ b/pkg/apis/networking/v1alpha1/ingress_lifecycle.go @@ -21,7 +21,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" ) var ingressCondSet = apis.NewLivingConditionSet( @@ -93,7 +92,3 @@ func (is *IngressStatus) MarkIngressNotReady(reason, message string) { func (is *IngressStatus) IsReady() bool { return ingressCondSet.Manage(is).IsHappy() } - -func (is *IngressStatus) duck() *duckv1.Status { - return &is.Status -} diff --git a/pkg/apis/networking/v1alpha1/ingress_lifecycle_test.go b/pkg/apis/networking/v1alpha1/ingress_lifecycle_test.go index 284d7a6c7c01..8c1c9793be0c 100644 --- a/pkg/apis/networking/v1alpha1/ingress_lifecycle_test.go +++ b/pkg/apis/networking/v1alpha1/ingress_lifecycle_test.go @@ -23,7 +23,7 @@ import ( "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" ) func TestIngressDuckTypes(t *testing.T) { @@ -75,21 +75,21 @@ func TestIngressTypicalFlow(t *testing.T) { r := &IngressStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), IngressConditionReady, t) + apistest.CheckConditionOngoing(r, IngressConditionReady, t) // Then network is configured. r.MarkNetworkConfigured() - apitestv1.CheckConditionSucceeded(r.duck(), IngressConditionNetworkConfigured, t) - apitestv1.CheckConditionOngoing(r.duck(), IngressConditionReady, t) + apistest.CheckConditionSucceeded(r, IngressConditionNetworkConfigured, t) + apistest.CheckConditionOngoing(r, IngressConditionReady, t) // Then ingress is pending. r.MarkLoadBalancerNotReady() - apitestv1.CheckConditionOngoing(r.duck(), IngressConditionLoadBalancerReady, t) - apitestv1.CheckConditionOngoing(r.duck(), IngressConditionReady, t) + apistest.CheckConditionOngoing(r, IngressConditionLoadBalancerReady, t) + apistest.CheckConditionOngoing(r, IngressConditionReady, t) r.MarkLoadBalancerFailed("some reason", "some message") - apitestv1.CheckConditionFailed(r.duck(), IngressConditionLoadBalancerReady, t) - apitestv1.CheckConditionFailed(r.duck(), IngressConditionLoadBalancerReady, t) + apistest.CheckConditionFailed(r, IngressConditionLoadBalancerReady, t) + apistest.CheckConditionFailed(r, IngressConditionLoadBalancerReady, t) // Then ingress has address. r.MarkLoadBalancerReady( @@ -97,26 +97,26 @@ func TestIngressTypicalFlow(t *testing.T) { []LoadBalancerIngressStatus{{DomainInternal: "gateway.default.svc"}}, []LoadBalancerIngressStatus{{DomainInternal: "private.gateway.default.svc"}}, ) - apitestv1.CheckConditionSucceeded(r.duck(), IngressConditionLoadBalancerReady, t) - apitestv1.CheckConditionSucceeded(r.duck(), IngressConditionReady, t) + apistest.CheckConditionSucceeded(r, IngressConditionLoadBalancerReady, t) + apistest.CheckConditionSucceeded(r, IngressConditionReady, t) if !r.IsReady() { t.Fatal("IsReady()=false, wanted true") } // Mark not owned. r.MarkResourceNotOwned("i own", "you") - apitestv1.CheckConditionFailed(r.duck(), IngressConditionReady, t) + apistest.CheckConditionFailed(r, IngressConditionReady, t) // Mark network configured, and check that ingress is ready again r.MarkNetworkConfigured() - apitestv1.CheckConditionSucceeded(r.duck(), IngressConditionReady, t) + apistest.CheckConditionSucceeded(r, IngressConditionReady, t) if !r.IsReady() { t.Fatal("IsReady()=false, wanted true") } // Mark ingress not ready r.MarkIngressNotReady("", "") - apitestv1.CheckConditionOngoing(r.duck(), IngressConditionReady, t) + apistest.CheckConditionOngoing(r, IngressConditionReady, t) } func TestIngressGetCondition(t *testing.T) { diff --git a/pkg/apis/networking/v1alpha1/serverlessservice_lifecycle.go b/pkg/apis/networking/v1alpha1/serverlessservice_lifecycle.go index e8ad84fdc5f8..fd32fb9b29b8 100644 --- a/pkg/apis/networking/v1alpha1/serverlessservice_lifecycle.go +++ b/pkg/apis/networking/v1alpha1/serverlessservice_lifecycle.go @@ -23,7 +23,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" ) var serverlessServiceCondSet = apis.NewLivingConditionSet( @@ -91,10 +90,6 @@ func (sss *ServerlessServiceStatus) IsReady() bool { return serverlessServiceCondSet.Manage(sss).IsHappy() } -func (sss *ServerlessServiceStatus) duck() *duckv1.Status { - return &sss.Status -} - // ProxyFor returns how long it has been since Activator was moved // to the request path. func (sss *ServerlessServiceStatus) ProxyFor() time.Duration { diff --git a/pkg/apis/networking/v1alpha1/serverlessservice_lifecycle_test.go b/pkg/apis/networking/v1alpha1/serverlessservice_lifecycle_test.go index e07ebcebd192..074aa0a52898 100644 --- a/pkg/apis/networking/v1alpha1/serverlessservice_lifecycle_test.go +++ b/pkg/apis/networking/v1alpha1/serverlessservice_lifecycle_test.go @@ -22,7 +22,7 @@ import ( "github.com/google/go-cmp/cmp" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" ) func TestServerlessServiceDuckTypes(t *testing.T) { @@ -56,41 +56,41 @@ func TestSSTypicalFlow(t *testing.T) { r := &ServerlessServiceStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), ServerlessServiceConditionReady, t) + apistest.CheckConditionOngoing(r, ServerlessServiceConditionReady, t) r.MarkEndpointsReady() - apitestv1.CheckConditionSucceeded(r.duck(), ServerlessServiceConditionEndspointsPopulated, t) - apitestv1.CheckConditionSucceeded(r.duck(), ServerlessServiceConditionReady, t) + apistest.CheckConditionSucceeded(r, ServerlessServiceConditionEndspointsPopulated, t) + apistest.CheckConditionSucceeded(r, ServerlessServiceConditionReady, t) // Verify that activator endpoints status is informational and does not // affect readiness. r.MarkActivatorEndpointsPopulated() - apitestv1.CheckConditionSucceeded(r.duck(), ServerlessServiceConditionReady, t) + apistest.CheckConditionSucceeded(r, ServerlessServiceConditionReady, t) r.MarkActivatorEndpointsRemoved() - apitestv1.CheckConditionSucceeded(r.duck(), ServerlessServiceConditionReady, t) + apistest.CheckConditionSucceeded(r, ServerlessServiceConditionReady, t) // Or another way to check the same condition. if !r.IsReady() { t.Error("IsReady=false, want: true") } r.MarkEndpointsNotReady("random") - apitestv1.CheckConditionOngoing(r.duck(), ServerlessServiceConditionReady, t) + apistest.CheckConditionOngoing(r, ServerlessServiceConditionReady, t) // Verify that activator endpoints status is informational and does not // affect readiness. r.MarkActivatorEndpointsPopulated() - apitestv1.CheckConditionOngoing(r.duck(), ServerlessServiceConditionReady, t) + apistest.CheckConditionOngoing(r, ServerlessServiceConditionReady, t) r.MarkActivatorEndpointsRemoved() - apitestv1.CheckConditionOngoing(r.duck(), ServerlessServiceConditionReady, t) + apistest.CheckConditionOngoing(r, ServerlessServiceConditionReady, t) r.MarkEndpointsNotOwned("service", "jukebox") - apitestv1.CheckConditionFailed(r.duck(), ServerlessServiceConditionReady, t) + apistest.CheckConditionFailed(r, ServerlessServiceConditionReady, t) // Verify that activator endpoints status is informational and does not // affect readiness. r.MarkActivatorEndpointsPopulated() - apitestv1.CheckConditionFailed(r.duck(), ServerlessServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(r.duck(), ActivatorEndpointsPopulated, t) + apistest.CheckConditionFailed(r, ServerlessServiceConditionReady, t) + apistest.CheckConditionSucceeded(r, ActivatorEndpointsPopulated, t) time.Sleep(time.Millisecond * 1) if got, want := r.ProxyFor(), time.Duration(0); got == want { @@ -98,8 +98,8 @@ func TestSSTypicalFlow(t *testing.T) { } r.MarkActivatorEndpointsRemoved() - apitestv1.CheckConditionFailed(r.duck(), ServerlessServiceConditionReady, t) - apitestv1.CheckConditionFailed(r.duck(), ActivatorEndpointsPopulated, t) + apistest.CheckConditionFailed(r, ServerlessServiceConditionReady, t) + apistest.CheckConditionFailed(r, ActivatorEndpointsPopulated, t) if got, want := r.ProxyFor(), time.Duration(0); got != want { t.Errorf("ProxyFor = %v, want: %v", got, want) diff --git a/pkg/apis/serving/v1/configuration_lifecycle.go b/pkg/apis/serving/v1/configuration_lifecycle.go index 558bd8782d1d..74d70a31e514 100644 --- a/pkg/apis/serving/v1/configuration_lifecycle.go +++ b/pkg/apis/serving/v1/configuration_lifecycle.go @@ -20,7 +20,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" ) var configCondSet = apis.NewLivingConditionSet() @@ -90,7 +89,3 @@ func (cs *ConfigurationStatus) MarkLatestReadyDeleted() { "RevisionDeleted", "Revision %q was deleted.", cs.LatestReadyRevisionName) } - -func (cs *ConfigurationStatus) duck() *duckv1.Status { - return &cs.Status -} diff --git a/pkg/apis/serving/v1/configuration_lifecycle_test.go b/pkg/apis/serving/v1/configuration_lifecycle_test.go index bf9c044fe2cc..5644fda44b9b 100644 --- a/pkg/apis/serving/v1/configuration_lifecycle_test.go +++ b/pkg/apis/serving/v1/configuration_lifecycle_test.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" ) func TestConfigurationDuckTypes(t *testing.T) { @@ -231,76 +231,76 @@ func TestLatestReadyRevisionNameUpToDate(t *testing.T) { func TestTypicalFlow(t *testing.T) { r := &ConfigurationStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestCreatedRevisionName("foo") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestReadyRevisionName("foo") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) // Verify a second call to SetLatestCreatedRevisionName doesn't change the status from Ready // e.g. on a subsequent reconciliation. r.SetLatestCreatedRevisionName("foo") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) r.SetLatestCreatedRevisionName("bar") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestReadyRevisionName("bar") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) } func TestFailingFirstRevisionWithRecovery(t *testing.T) { r := &ConfigurationStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) // Our first attempt to create the revision fails const want = "transient API server failure" r.MarkRevisionCreationFailed(want) - apitestv1.CheckConditionFailed(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionFailed(r, ConfigurationConditionReady, t) if c := r.GetCondition(ConfigurationConditionReady); !strings.Contains(c.Message, want) { t.Errorf("MarkRevisionCreationFailed = %v, want substring %v", c.Message, want) } r.SetLatestCreatedRevisionName("foo") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) // Then we create it, but it fails to come up. const want2 = "the message" r.MarkLatestCreatedFailed("foo", want2) - apitestv1.CheckConditionFailed(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionFailed(r, ConfigurationConditionReady, t) if c := r.GetCondition(ConfigurationConditionReady); !strings.Contains(c.Message, want2) { t.Errorf("MarkLatestCreatedFailed = %v, want substring %v", c.Message, want2) } // When a new revision comes along the Ready condition becomes Unknown. r.SetLatestCreatedRevisionName("bar") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) // When the new revision becomes ready, then Ready becomes true as well. r.SetLatestReadyRevisionName("bar") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) } func TestFailingSecondRevision(t *testing.T) { r := &ConfigurationStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestCreatedRevisionName("foo") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestReadyRevisionName("foo") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) r.SetLatestCreatedRevisionName("bar") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) // When the second revision fails, the Configuration becomes Failed. const want = "the message" r.MarkLatestCreatedFailed("bar", want) - apitestv1.CheckConditionFailed(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionFailed(r, ConfigurationConditionReady, t) if c := r.GetCondition(ConfigurationConditionReady); !strings.Contains(c.Message, want) { t.Errorf("MarkLatestCreatedFailed = %v, want substring %v", c.Message, want) } @@ -309,26 +309,26 @@ func TestFailingSecondRevision(t *testing.T) { func TestLatestRevisionDeletedThenFixed(t *testing.T) { r := &ConfigurationStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestCreatedRevisionName("foo") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestReadyRevisionName("foo") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) // When the latest revision is deleted, the Configuration became Failed. const want = "was deleted" r.MarkLatestReadyDeleted() - apitestv1.CheckConditionFailed(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionFailed(r, ConfigurationConditionReady, t) if cnd := r.GetCondition(ConfigurationConditionReady); cnd == nil || !strings.Contains(cnd.Message, want) { t.Errorf("MarkLatestReadyDeleted = %v, want substring %v", cnd.Message, want) } // But creating new revision 'bar' and making it Ready will fix things. r.SetLatestCreatedRevisionName("bar") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestReadyRevisionName("bar") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) } diff --git a/pkg/apis/serving/v1/revision_helpers.go b/pkg/apis/serving/v1/revision_helpers.go index 03dfc592e848..f49762e12496 100644 --- a/pkg/apis/serving/v1/revision_helpers.go +++ b/pkg/apis/serving/v1/revision_helpers.go @@ -21,7 +21,6 @@ import ( "time" corev1 "k8s.io/api/core/v1" - duckv1 "knative.dev/pkg/apis/duck/v1" net "knative.dev/serving/pkg/apis/networking" "knative.dev/serving/pkg/apis/serving" ) @@ -151,7 +150,3 @@ func (rs *RevisionStatus) IsActivationRequired() bool { func RevisionLastPinnedString(t time.Time) string { return fmt.Sprintf("%d", t.Unix()) } - -func (rs *RevisionStatus) duck() *duckv1.Status { - return &rs.Status -} diff --git a/pkg/apis/serving/v1/revision_lifecycle_test.go b/pkg/apis/serving/v1/revision_lifecycle_test.go index de61ee008e94..6deb24478df2 100644 --- a/pkg/apis/serving/v1/revision_lifecycle_test.go +++ b/pkg/apis/serving/v1/revision_lifecycle_test.go @@ -29,7 +29,7 @@ import ( "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" "knative.dev/pkg/ptr" av1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1" "knative.dev/serving/pkg/apis/config" @@ -302,14 +302,14 @@ func TestRevisionInitializeConditions(t *testing.T) { func TestTypicalFlowWithProgressDeadlineExceeded(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) const want = "the error message" r.MarkResourcesAvailableFalse(ReasonProgressDeadlineExceeded, want) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionFailed(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionFailed(r, RevisionConditionReady, t) if got := r.GetCondition(RevisionConditionResourcesAvailable); got == nil || got.Message != want { t.Errorf("MarkProgressDeadlineExceeded = %v, want %v", got, want) } @@ -321,15 +321,15 @@ func TestTypicalFlowWithProgressDeadlineExceeded(t *testing.T) { func TestTypicalFlowWithContainerMissing(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) const want = "something about the container being not found" r.MarkContainerHealthyFalse(ReasonContainerMissing, want) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionFailed(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) if got := r.GetCondition(RevisionConditionContainerHealthy); got == nil || got.Message != want { t.Errorf("MarkContainerMissing = %v, want %v", got, want) } else if got.Reason != "ContainerMissing" { @@ -342,65 +342,65 @@ func TestTypicalFlowWithContainerMissing(t *testing.T) { } r.MarkContainerHealthyUnknown(ReasonDeploying, want) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) } func TestTypicalFlowWithSuspendResume(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) // Enter a Ready state. r.MarkActiveTrue() r.MarkContainerHealthyTrue() r.MarkResourcesAvailableTrue() - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) // From a Ready state, make the revision inactive to simulate scale to zero. const want = "Deactivated" r.MarkActiveFalse(want, "Reserve") - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionActive, t) + apistest.CheckConditionSucceeded(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(r, RevisionConditionActive, t) if got := r.GetCondition(RevisionConditionActive); got == nil || got.Reason != want { t.Errorf("MarkInactive = %v, want %v", got, want) } - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) // From an Inactive state, start to activate the revision. const want2 = "Activating" r.MarkActiveUnknown(want2, "blah blah blah") - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionActive, t) + apistest.CheckConditionSucceeded(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionActive, t) if got := r.GetCondition(RevisionConditionActive); got == nil || got.Reason != want2 { t.Errorf("MarkInactive = %v, want %v", got, want2) } - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) // From the activating state, simulate the transition back to readiness. r.MarkActiveTrue() - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) } func TestRevisionNotOwnedStuff(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) const want = "NotOwned" r.MarkResourcesAvailableFalse(ReasonNotOwned, "mark") - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionFailed(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionFailed(r, RevisionConditionReady, t) if got := r.GetCondition(RevisionConditionResourcesAvailable); got == nil || got.Reason != want { t.Errorf("MarkResourceNotOwned = %v, want %v", got, want) } @@ -412,14 +412,14 @@ func TestRevisionNotOwnedStuff(t *testing.T) { func TestRevisionResourcesUnavailable(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) const wantReason, wantMessage = "unschedulable", "insufficient energy" r.MarkResourcesAvailableFalse(wantReason, wantMessage) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionFailed(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionFailed(r, RevisionConditionReady, t) if got := r.GetCondition(RevisionConditionResourcesAvailable); got == nil || got.Reason != wantReason { t.Errorf("RevisionConditionResourcesAvailable.Reason = %v, want %v", got, wantReason) } @@ -428,8 +428,8 @@ func TestRevisionResourcesUnavailable(t *testing.T) { } r.MarkResourcesAvailableUnknown(wantReason, wantMessage) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) } func TestRevisionGetProtocol(t *testing.T) { @@ -599,17 +599,17 @@ func TestPropagateDeploymentStatus(t *testing.T) { rev.InitializeConditions() // We start out ongoing. - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(rev, RevisionConditionReady, t) + apistest.CheckConditionOngoing(rev, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(rev, RevisionConditionResourcesAvailable, t) // Empty deployment conditions shouldn't affect our readiness. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ Conditions: []appsv1.DeploymentCondition{}, }) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(rev, RevisionConditionReady, t) + apistest.CheckConditionOngoing(rev, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(rev, RevisionConditionResourcesAvailable, t) // Deployment failures should be propagated and not affect ContainerHealthy. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -621,15 +621,15 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionUnknown, }}, }) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(rev, RevisionConditionReady, t) + apistest.CheckConditionFailed(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(rev, RevisionConditionContainerHealthy, t) // Marking container healthy doesn't affect deployment status. rev.MarkContainerHealthyTrue() - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(rev, RevisionConditionReady, t) + apistest.CheckConditionFailed(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) // We can recover from deployment failures. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -638,9 +638,9 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionTrue, }}, }) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionReady, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) // We can go unknown. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -649,9 +649,9 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionUnknown, }}, }) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(rev, RevisionConditionReady, t) + apistest.CheckConditionOngoing(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) // ReplicaFailure=True translates into Ready=False. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -660,9 +660,9 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionTrue, }}, }) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(rev, RevisionConditionReady, t) + apistest.CheckConditionFailed(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) // ReplicaFailure=True trumps Progressing=Unknown. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -674,9 +674,9 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionTrue, }}, }) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(rev, RevisionConditionReady, t) + apistest.CheckConditionFailed(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) // ReplicaFailure=False + Progressing=True yields Ready. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -688,21 +688,21 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionFalse, }}, }) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionReady, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) } func TestPropagateAutoscalerStatus(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) // PodAutoscaler has no active condition, so we are just coming up. r.PropagateAutoscalerStatus(&av1alpha1.PodAutoscalerStatus{ Status: duckv1.Status{}, }) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionActive, t) + apistest.CheckConditionOngoing(r, RevisionConditionActive, t) // PodAutoscaler becomes ready, making us active. r.PropagateAutoscalerStatus(&av1alpha1.PodAutoscalerStatus{ @@ -713,8 +713,8 @@ func TestPropagateAutoscalerStatus(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionActive, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionActive, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) // PodAutoscaler flipping back to Unknown causes Active become ongoing immediately. r.PropagateAutoscalerStatus(&av1alpha1.PodAutoscalerStatus{ @@ -725,8 +725,8 @@ func TestPropagateAutoscalerStatus(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionActive, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionActive, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) // PodAutoscaler becoming unready makes Active false, but doesn't affect readiness. r.PropagateAutoscalerStatus(&av1alpha1.PodAutoscalerStatus{ @@ -737,10 +737,10 @@ func TestPropagateAutoscalerStatus(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionActive, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionResourcesAvailable, t) + apistest.CheckConditionFailed(r, RevisionConditionActive, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionSucceeded(r, RevisionConditionResourcesAvailable, t) } func TestGetContainer(t *testing.T) { diff --git a/pkg/apis/serving/v1/route_lifecycle.go b/pkg/apis/serving/v1/route_lifecycle.go index f112c0138dbb..4b67a2b9efcf 100644 --- a/pkg/apis/serving/v1/route_lifecycle.go +++ b/pkg/apis/serving/v1/route_lifecycle.go @@ -23,7 +23,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/serving/pkg/apis/networking/v1alpha1" ) @@ -158,7 +157,3 @@ func (rs *RouteStatus) PropagateIngressStatus(cs v1alpha1.IngressStatus) { m.MarkUnknown(RouteConditionIngressReady, cc.Reason, cc.Message) } } - -func (rs *RouteStatus) duck() *duckv1.Status { - return &rs.Status -} diff --git a/pkg/apis/serving/v1/route_lifecycle_test.go b/pkg/apis/serving/v1/route_lifecycle_test.go index fbf417fe1e31..3b16f5559a00 100644 --- a/pkg/apis/serving/v1/route_lifecycle_test.go +++ b/pkg/apis/serving/v1/route_lifecycle_test.go @@ -22,7 +22,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" netv1alpha1 "knative.dev/serving/pkg/apis/networking/v1alpha1" ) @@ -163,14 +163,14 @@ func TestRouteIsReady(t *testing.T) { func TestTypicalRouteFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkTrafficAssigned() - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.PropagateIngressStatus(netv1alpha1.IngressStatus{ Status: duckv1.Status{ @@ -180,83 +180,83 @@ func TestTypicalRouteFlow(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionSucceeded(r, RouteConditionIngressReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionReady, t) } func TestTrafficNotAssignedFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkMissingTrafficTarget("Revision", "does-not-exist") - apitestv1.CheckConditionFailed(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionFailed(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) } func TestTargetConfigurationNotYetReadyFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkConfigurationNotReady("i-have-no-ready-revision") - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) } func TestUnknownErrorWhenConfiguringTraffic(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkUnknownTrafficError("unknown-error") - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) } func TestTargetConfigurationFailedToBeReadyFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkConfigurationFailed("permanently-failed") - apitestv1.CheckConditionFailed(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionFailed(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) } func TestTargetRevisionNotYetReadyFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkRevisionNotReady("not-yet-ready") - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) } func TestTargetRevisionFailedToBeReadyFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkRevisionFailed("cannot-find-image") - apitestv1.CheckConditionFailed(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionFailed(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) } func TestIngressFailureRecovery(t *testing.T) { @@ -270,15 +270,15 @@ func TestIngressFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) // Empty IngressStatus marks ingress "NotConfigured" r.PropagateIngressStatus(netv1alpha1.IngressStatus{}) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkTrafficAssigned() r.PropagateIngressStatus(netv1alpha1.IngressStatus{ @@ -289,9 +289,9 @@ func TestIngressFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionSucceeded(r, RouteConditionIngressReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionReady, t) r.PropagateIngressStatus(netv1alpha1.IngressStatus{ Status: duckv1.Status{ @@ -301,9 +301,9 @@ func TestIngressFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionFailed(r, RouteConditionIngressReady, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) r.PropagateIngressStatus(netv1alpha1.IngressStatus{ Status: duckv1.Status{ @@ -313,9 +313,9 @@ func TestIngressFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionSucceeded(r, RouteConditionIngressReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionReady, t) } func TestRouteNotOwnedStuff(t *testing.T) { @@ -330,14 +330,14 @@ func TestRouteNotOwnedStuff(t *testing.T) { }, }) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkServiceNotOwned("evan") - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionFailed(r, RouteConditionIngressReady, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) } func TestCertificateReady(t *testing.T) { @@ -345,7 +345,7 @@ func TestCertificateReady(t *testing.T) { r.InitializeConditions() r.MarkCertificateReady("cert") - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionCertificateProvisioned, t) + apistest.CheckConditionSucceeded(r, RouteConditionCertificateProvisioned, t) } func TestCertificateNotReady(t *testing.T) { @@ -353,7 +353,7 @@ func TestCertificateNotReady(t *testing.T) { r.InitializeConditions() r.MarkCertificateNotReady("cert") - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionCertificateProvisioned, t) + apistest.CheckConditionOngoing(r, RouteConditionCertificateProvisioned, t) } func TestCertificateProvisionFailed(t *testing.T) { @@ -361,7 +361,7 @@ func TestCertificateProvisionFailed(t *testing.T) { r.InitializeConditions() r.MarkCertificateProvisionFailed("cert") - apitestv1.CheckConditionFailed(r.duck(), RouteConditionCertificateProvisioned, t) + apistest.CheckConditionFailed(r, RouteConditionCertificateProvisioned, t) } func TestRouteNotOwnCertificate(t *testing.T) { @@ -369,7 +369,7 @@ func TestRouteNotOwnCertificate(t *testing.T) { r.InitializeConditions() r.MarkCertificateNotOwned("cert") - apitestv1.CheckConditionFailed(r.duck(), RouteConditionCertificateProvisioned, t) + apistest.CheckConditionFailed(r, RouteConditionCertificateProvisioned, t) } func TestIngressNotConfigured(t *testing.T) { @@ -377,5 +377,5 @@ func TestIngressNotConfigured(t *testing.T) { r.InitializeConditions() r.MarkIngressNotConfigured() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) } diff --git a/pkg/apis/serving/v1/service_lifecycle.go b/pkg/apis/serving/v1/service_lifecycle.go index 1bb47827f890..1198263a4213 100644 --- a/pkg/apis/serving/v1/service_lifecycle.go +++ b/pkg/apis/serving/v1/service_lifecycle.go @@ -23,7 +23,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" ) const ( @@ -131,7 +130,3 @@ func (ss *ServiceStatus) PropagateRouteStatus(rs *RouteStatus) { m.MarkUnknown(ServiceConditionRoutesReady, rc.Reason, rc.Message) } } - -func (ss *ServiceStatus) duck() *duckv1.Status { - return &ss.Status -} diff --git a/pkg/apis/serving/v1/service_lifecycle_test.go b/pkg/apis/serving/v1/service_lifecycle_test.go index e5d3019686c3..86cdf7f865d5 100644 --- a/pkg/apis/serving/v1/service_lifecycle_test.go +++ b/pkg/apis/serving/v1/service_lifecycle_test.go @@ -24,7 +24,7 @@ import ( "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" "knative.dev/pkg/ptr" ) @@ -162,21 +162,21 @@ func TestServiceIsReady(t *testing.T) { func TestServiceHappyPath(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Nothing from Configuration is nothing to us. svc.PropagateConfigurationStatus(&ConfigurationStatus{}) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Nothing from Route is nothing to us. svc.PropagateRouteStatus(&RouteStatus{}) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Done from Configuration moves our ConfigurationsReady condition svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -187,9 +187,9 @@ func TestServiceHappyPath(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Done from Route moves our RoutesReady condition, which triggers us to be Ready. svc.PropagateRouteStatus(&RouteStatus{ @@ -200,9 +200,9 @@ func TestServiceHappyPath(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) // Check idempotency. svc.PropagateRouteStatus(&RouteStatus{ @@ -213,20 +213,20 @@ func TestServiceHappyPath(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) } func TestMarkRouteNotYetReady(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) svc.MarkRouteNotYetReady() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) dt := svc.GetCondition(ServiceConditionReady) if got, want := dt.Reason, trafficNotMigratedReason; got != want { t.Errorf("Condition Reason: got: %s, want: %s", got, want) @@ -239,12 +239,12 @@ func TestMarkRouteNotYetReady(t *testing.T) { func TestMarkRouteNotReconciled(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) svc.MarkRouteNotReconciled() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) dt := svc.GetCondition(ServiceConditionReady) if got, want := dt.Reason, "OutOfDate"; got != want { t.Errorf("Condition Reason: got: %s, want: %s", got, want) @@ -254,12 +254,12 @@ func TestMarkRouteNotReconciled(t *testing.T) { func TestMarkRevisionNameTaken(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) svc.MarkRevisionNameTaken("revision-name") - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) dt := svc.GetCondition(ServiceConditionReady) if got, want := dt.Reason, "RevisionNameTaken"; got != want { t.Errorf("Condition Reason: got: %s, want: %s", got, want) @@ -269,12 +269,12 @@ func TestMarkRevisionNameTaken(t *testing.T) { func TestMarkConfigurationNotReconciled(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) svc.MarkConfigurationNotReconciled() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) dt := svc.GetCondition(ServiceConditionReady) if got, want := dt.Reason, "OutOfDate"; got != want { t.Errorf("Condition Reason: got: %s, want: %s", got, want) @@ -284,9 +284,9 @@ func TestMarkConfigurationNotReconciled(t *testing.T) { func TestFailureRecovery(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Config failure causes us to become unready immediately (route still ok). svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -297,9 +297,9 @@ func TestFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Route failure causes route to become failed (config and service still failed). svc.PropagateRouteStatus(&RouteStatus{ @@ -310,9 +310,9 @@ func TestFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionRoutesReady, t) // Fix Configuration moves our ConfigurationsReady condition (route and service still failed). svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -323,9 +323,9 @@ func TestFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionRoutesReady, t) // Fix route, should make everything ready. svc.PropagateRouteStatus(&RouteStatus{ @@ -336,17 +336,17 @@ func TestFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) } func TestConfigurationFailurePropagation(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Failure causes us to become unready immediately. svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -357,18 +357,18 @@ func TestConfigurationFailurePropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) } func TestConfigurationFailureRecovery(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Done from Route moves our RoutesReady condition svc.PropagateRouteStatus(&RouteStatus{ @@ -379,9 +379,9 @@ func TestConfigurationFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) // Failure causes us to become unready immediately (route still ok). svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -392,9 +392,9 @@ func TestConfigurationFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) // Fixed the glitch. svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -405,17 +405,17 @@ func TestConfigurationFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) } func TestConfigurationUnknownPropagation(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Configuration and Route become ready, making us ready. svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -434,9 +434,9 @@ func TestConfigurationUnknownPropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) // Configuration flipping back to Unknown causes us to become ongoing immediately svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -447,10 +447,10 @@ func TestConfigurationUnknownPropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) // Route is unaffected. - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) } func TestConfigurationStatusPropagation(t *testing.T) { @@ -476,9 +476,9 @@ func TestConfigurationStatusPropagation(t *testing.T) { func TestRouteFailurePropagation(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Failure causes us to become unready immediately svc.PropagateRouteStatus(&RouteStatus{ @@ -489,17 +489,17 @@ func TestRouteFailurePropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionRoutesReady, t) } func TestRouteFailureRecovery(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Done from Configuration moves our ConfigurationsReady condition svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -510,9 +510,9 @@ func TestRouteFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Failure causes us to become unready immediately (config still ok). svc.PropagateRouteStatus(&RouteStatus{ @@ -523,9 +523,9 @@ func TestRouteFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionRoutesReady, t) // Fixed the glitch. svc.PropagateRouteStatus(&RouteStatus{ @@ -536,17 +536,17 @@ func TestRouteFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) } func TestRouteUnknownPropagation(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Configuration and Route become ready, making us ready. svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -565,9 +565,9 @@ func TestRouteUnknownPropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) // Route flipping back to Unknown causes us to become ongoing immediately. svc.PropagateRouteStatus(&RouteStatus{ @@ -578,26 +578,26 @@ func TestRouteUnknownPropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Configuration is unaffected. - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) } func TestServiceNotOwnedStuff(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) svc.MarkRouteNotOwned("mark") - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionRoutesReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) svc.MarkConfigurationNotOwned("jon") - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) } func TestRouteStatusPropagation(t *testing.T) { diff --git a/pkg/apis/serving/v1alpha1/configuration_lifecycle.go b/pkg/apis/serving/v1alpha1/configuration_lifecycle.go index 25d532de5876..8f21e80eadf1 100644 --- a/pkg/apis/serving/v1alpha1/configuration_lifecycle.go +++ b/pkg/apis/serving/v1alpha1/configuration_lifecycle.go @@ -20,7 +20,6 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" ) var confCondSet = apis.NewLivingConditionSet() @@ -113,7 +112,3 @@ func (cs *ConfigurationStatus) MarkLatestReadyDeleted() { "RevisionDeleted", "Revision %q was deleted.", cs.LatestReadyRevisionName) } - -func (cs *ConfigurationStatus) duck() *duckv1.Status { - return &cs.Status -} diff --git a/pkg/apis/serving/v1alpha1/configuration_lifecycle_test.go b/pkg/apis/serving/v1alpha1/configuration_lifecycle_test.go index abd2d519624d..7e4cfbcc69d4 100644 --- a/pkg/apis/serving/v1alpha1/configuration_lifecycle_test.go +++ b/pkg/apis/serving/v1alpha1/configuration_lifecycle_test.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" ) func TestConfigurationDuckTypes(t *testing.T) { @@ -219,80 +219,80 @@ func TestLatestReadyRevisionNameUpToDate(t *testing.T) { func TestTypicalFlow(t *testing.T) { r := &ConfigurationStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestCreatedRevisionName("foo") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestReadyRevisionName("foo") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) // Verify a second call to SetLatestCreatedRevisionName doesn't change the status from Ready // e.g. on a subsequent reconciliation. r.SetLatestCreatedRevisionName("foo") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) r.SetLatestCreatedRevisionName("bar") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestReadyRevisionName("bar") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) r.MarkResourceNotConvertible(ConvertErrorf("build", "something something not allowed.").(*CannotConvertError)) - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) - apitestv1.CheckConditionFailed(r.duck(), ConditionTypeConvertible, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) + apistest.CheckConditionFailed(r, ConditionTypeConvertible, t) } func TestFailingFirstRevisionWithRecovery(t *testing.T) { r := &ConfigurationStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) // Our first attempt to create the revision fails const want = "transient API server failure" r.MarkRevisionCreationFailed(want) - apitestv1.CheckConditionFailed(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionFailed(r, ConfigurationConditionReady, t) if c := r.GetCondition(ConfigurationConditionReady); !strings.Contains(c.Message, want) { t.Errorf("MarkRevisionCreationFailed = %v, want substring %v", c.Message, want) } r.SetLatestCreatedRevisionName("foo") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) // Then we create it, but it fails to come up. const want2 = "the message" r.MarkLatestCreatedFailed("foo", want2) - apitestv1.CheckConditionFailed(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionFailed(r, ConfigurationConditionReady, t) if c := r.GetCondition(ConfigurationConditionReady); !strings.Contains(c.Message, want2) { t.Errorf("MarkLatestCreatedFailed = %v, want substring %v", c.Message, want2) } // When a new revision comes along the Ready condition becomes Unknown. r.SetLatestCreatedRevisionName("bar") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) // When the new revision becomes ready, then Ready becomes true as well. r.SetLatestReadyRevisionName("bar") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) } func TestFailingSecondRevision(t *testing.T) { r := &ConfigurationStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestCreatedRevisionName("foo") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestReadyRevisionName("foo") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) r.SetLatestCreatedRevisionName("bar") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) // When the second revision fails, the Configuration becomes Failed. const want = "the message" r.MarkLatestCreatedFailed("bar", want) - apitestv1.CheckConditionFailed(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionFailed(r, ConfigurationConditionReady, t) if c := r.GetCondition(ConfigurationConditionReady); !strings.Contains(c.Message, want) { t.Errorf("MarkLatestCreatedFailed = %v, want substring %v", c.Message, want) } @@ -301,28 +301,28 @@ func TestFailingSecondRevision(t *testing.T) { func TestLatestRevisionDeletedThenFixed(t *testing.T) { r := &ConfigurationStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestCreatedRevisionName("foo") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestReadyRevisionName("foo") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) // When the latest revision is deleted, the Configuration became Failed. const want = "was deleted" r.MarkLatestReadyDeleted() - apitestv1.CheckConditionFailed(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionFailed(r, ConfigurationConditionReady, t) if cnd := r.GetCondition(ConfigurationConditionReady); cnd == nil || !strings.Contains(cnd.Message, want) { t.Errorf("MarkLatestReadyDeleted = %v, want substring %v", cnd.Message, want) } // But creating new revision 'bar' and making it Ready will fix things. r.SetLatestCreatedRevisionName("bar") - apitestv1.CheckConditionOngoing(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionOngoing(r, ConfigurationConditionReady, t) r.SetLatestReadyRevisionName("bar") - apitestv1.CheckConditionSucceeded(r.duck(), ConfigurationConditionReady, t) + apistest.CheckConditionSucceeded(r, ConfigurationConditionReady, t) } func TestConfigurationGetGroupVersionKind(t *testing.T) { diff --git a/pkg/apis/serving/v1alpha1/revision_lifecycle.go b/pkg/apis/serving/v1alpha1/revision_lifecycle.go index 4d54e8f86ae7..7c333281e4da 100644 --- a/pkg/apis/serving/v1alpha1/revision_lifecycle.go +++ b/pkg/apis/serving/v1alpha1/revision_lifecycle.go @@ -25,7 +25,6 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" av1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1" "knative.dev/serving/pkg/apis/config" net "knative.dev/serving/pkg/apis/networking" @@ -334,10 +333,6 @@ func (r *Revision) IsReachable() bool { return r.ObjectMeta.Labels[serving.RouteLabelKey] != "" } -func (rs *RevisionStatus) duck() *duckv1.Status { - return &rs.Status -} - // PropagateDeploymentStatus takes the Deployment status and applies its values // to the Revision status. func (rs *RevisionStatus) PropagateDeploymentStatus(original *appsv1.DeploymentStatus) { diff --git a/pkg/apis/serving/v1alpha1/revision_lifecycle_test.go b/pkg/apis/serving/v1alpha1/revision_lifecycle_test.go index e5772708679c..a819e5b37973 100644 --- a/pkg/apis/serving/v1alpha1/revision_lifecycle_test.go +++ b/pkg/apis/serving/v1alpha1/revision_lifecycle_test.go @@ -29,7 +29,7 @@ import ( "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" "knative.dev/pkg/ptr" av1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1" net "knative.dev/serving/pkg/apis/networking" @@ -269,14 +269,14 @@ func TestGetSetCondition(t *testing.T) { func TestTypicalFlowWithProgressDeadlineExceeded(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) const want = "the error message" r.MarkResourcesAvailableFalse(ProgressDeadlineExceeded, want) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionFailed(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionFailed(r, RevisionConditionReady, t) if got := r.GetCondition(RevisionConditionResourcesAvailable); got == nil || got.Message != want { t.Errorf("MarkProgressDeadlineExceeded = %v, want %v", got, want) } @@ -288,15 +288,15 @@ func TestTypicalFlowWithProgressDeadlineExceeded(t *testing.T) { func TestTypicalFlowWithContainerMissing(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) const want = "something about the container being not found" r.MarkContainerHealthyFalse(ContainerMissing, want) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionFailed(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) if got := r.GetCondition(RevisionConditionContainerHealthy); got == nil || got.Message != want { t.Errorf("MarkContainerMissing = %v, want %v", got, want) } else if got.Reason != "ContainerMissing" { @@ -312,58 +312,58 @@ func TestTypicalFlowWithContainerMissing(t *testing.T) { func TestTypicalFlowWithSuspendResume(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) // Enter a Ready state. r.MarkActiveTrue() r.MarkContainerHealthyTrue() r.MarkResourcesAvailableTrue() - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) // From a Ready state, make the revision inactive to simulate scale to zero. const want = "Deactivated" r.MarkActiveFalse(want, "Reserve") - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionActive, t) + apistest.CheckConditionSucceeded(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(r, RevisionConditionActive, t) if got := r.GetCondition(RevisionConditionActive); got == nil || got.Reason != want { t.Errorf("MarkInactive = %v, want %v", got, want) } - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) // From an Inactive state, start to activate the revision. const want2 = "Activating" r.MarkActiveUnknown(want2, "blah blah blah") - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionActive, t) + apistest.CheckConditionSucceeded(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionActive, t) if got := r.GetCondition(RevisionConditionActive); got == nil || got.Reason != want2 { t.Errorf("MarkInactive = %v, want %v", got, want2) } - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) // From the activating state, simulate the transition back to readiness. r.MarkActiveTrue() - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) } func TestRevisionNotOwnedStuff(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) const want = "NotOwned" r.MarkResourcesAvailableFalse(NotOwned, "mark") - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionFailed(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionFailed(r, RevisionConditionReady, t) if got := r.GetCondition(RevisionConditionResourcesAvailable); got == nil || got.Reason != want { t.Errorf("MarkResourceNotOwned = %v, want %v", got, want) } @@ -375,14 +375,14 @@ func TestRevisionNotOwnedStuff(t *testing.T) { func TestRevisionResourcesUnavailable(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) const wantReason, wantMessage = "unschedulable", "insufficient energy" r.MarkResourcesAvailableFalse(wantReason, wantMessage) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionFailed(r, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionFailed(r, RevisionConditionReady, t) if got := r.GetCondition(RevisionConditionResourcesAvailable); got == nil || got.Reason != wantReason { t.Errorf("RevisionConditionResourcesAvailable = %v, want %v", got, wantReason) } @@ -627,17 +627,17 @@ func TestPropagateDeploymentStatus(t *testing.T) { rev.InitializeConditions() // We start out ongoing. - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(rev, RevisionConditionReady, t) + apistest.CheckConditionOngoing(rev, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(rev, RevisionConditionResourcesAvailable, t) // Empty deployment conditions shouldn't affect our readiness. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ Conditions: []appsv1.DeploymentCondition{}, }) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(rev, RevisionConditionReady, t) + apistest.CheckConditionOngoing(rev, RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(rev, RevisionConditionResourcesAvailable, t) // Deployment failures should be propagated and not affect ContainerHealthy. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -649,15 +649,15 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionUnknown, }}, }) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(rev, RevisionConditionReady, t) + apistest.CheckConditionFailed(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionOngoing(rev, RevisionConditionContainerHealthy, t) // Marking container healthy doesn't affect deployment status. rev.MarkContainerHealthyTrue() - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(rev, RevisionConditionReady, t) + apistest.CheckConditionFailed(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) // We can recover from deployment failures. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -666,9 +666,9 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionTrue, }}, }) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionReady, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) // We can go unknown. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -677,9 +677,9 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionUnknown, }}, }) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionOngoing(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionOngoing(rev, RevisionConditionReady, t) + apistest.CheckConditionOngoing(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) // ReplicaFailure=True translates into Ready=False. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -688,9 +688,9 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionTrue, }}, }) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(rev, RevisionConditionReady, t) + apistest.CheckConditionFailed(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) // ReplicaFailure=True trumps Progressing=Unknown. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -702,9 +702,9 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionTrue, }}, }) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionFailed(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionFailed(rev, RevisionConditionReady, t) + apistest.CheckConditionFailed(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) // ReplicaFailure=False + Progressing=True yields Ready. rev.PropagateDeploymentStatus(&appsv1.DeploymentStatus{ @@ -716,21 +716,21 @@ func TestPropagateDeploymentStatus(t *testing.T) { Status: corev1.ConditionFalse, }}, }) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionResourcesAvailable, t) - apitestv1.CheckConditionSucceeded(rev.duck(), RevisionConditionContainerHealthy, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionReady, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionResourcesAvailable, t) + apistest.CheckConditionSucceeded(rev, RevisionConditionContainerHealthy, t) } func TestPropagateAutoscalerStatus(t *testing.T) { r := &RevisionStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionReady, t) // PodAutoscaler has no active condition, so we are just coming up. r.PropagateAutoscalerStatus(&av1alpha1.PodAutoscalerStatus{ Status: duckv1.Status{}, }) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionActive, t) + apistest.CheckConditionOngoing(r, RevisionConditionActive, t) // PodAutoscaler becomes ready, making us active. r.PropagateAutoscalerStatus(&av1alpha1.PodAutoscalerStatus{ @@ -741,8 +741,8 @@ func TestPropagateAutoscalerStatus(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionActive, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionActive, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) // PodAutoscaler flipping back to Unknown causes Active become ongoing immediately. r.PropagateAutoscalerStatus(&av1alpha1.PodAutoscalerStatus{ @@ -753,8 +753,8 @@ func TestPropagateAutoscalerStatus(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(r.duck(), RevisionConditionActive, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) + apistest.CheckConditionOngoing(r, RevisionConditionActive, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) // PodAutoscaler becoming unready makes Active false, but doesn't affect readiness. r.PropagateAutoscalerStatus(&av1alpha1.PodAutoscalerStatus{ @@ -765,10 +765,10 @@ func TestPropagateAutoscalerStatus(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(r.duck(), RevisionConditionActive, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionReady, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionContainerHealthy, t) - apitestv1.CheckConditionSucceeded(r.duck(), RevisionConditionResourcesAvailable, t) + apistest.CheckConditionFailed(r, RevisionConditionActive, t) + apistest.CheckConditionSucceeded(r, RevisionConditionReady, t) + apistest.CheckConditionSucceeded(r, RevisionConditionContainerHealthy, t) + apistest.CheckConditionSucceeded(r, RevisionConditionResourcesAvailable, t) } func TestGetContainerConcurrency(t *testing.T) { diff --git a/pkg/apis/serving/v1alpha1/route_lifecycle.go b/pkg/apis/serving/v1alpha1/route_lifecycle.go index d3fe6fa3e418..017e6dc42995 100644 --- a/pkg/apis/serving/v1alpha1/route_lifecycle.go +++ b/pkg/apis/serving/v1alpha1/route_lifecycle.go @@ -23,7 +23,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/serving/pkg/apis/networking/v1alpha1" ) @@ -171,7 +170,3 @@ func (rs *RouteStatus) PropagateIngressStatus(cs v1alpha1.IngressStatus) { m.MarkUnknown(RouteConditionIngressReady, cc.Reason, cc.Message) } } - -func (rs *RouteStatus) duck() *duckv1.Status { - return &rs.Status -} diff --git a/pkg/apis/serving/v1alpha1/route_lifecycle_test.go b/pkg/apis/serving/v1alpha1/route_lifecycle_test.go index 9e11a4c63e79..04dec0bf6ac4 100644 --- a/pkg/apis/serving/v1alpha1/route_lifecycle_test.go +++ b/pkg/apis/serving/v1alpha1/route_lifecycle_test.go @@ -23,7 +23,7 @@ import ( "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" netv1alpha1 "knative.dev/serving/pkg/apis/networking/v1alpha1" ) @@ -155,14 +155,14 @@ func TestRouteIsReady(t *testing.T) { func TestTypicalRouteFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkTrafficAssigned() - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.PropagateIngressStatus(netv1alpha1.IngressStatus{ Status: duckv1.Status{ @@ -172,83 +172,83 @@ func TestTypicalRouteFlow(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionSucceeded(r, RouteConditionIngressReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionReady, t) } func TestTrafficNotAssignedFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkMissingTrafficTarget("Revision", "does-not-exist") - apitestv1.CheckConditionFailed(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionFailed(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) } func TestTargetConfigurationNotYetReadyFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkConfigurationNotReady("i-have-no-ready-revision") - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) } func TestUnknownErrorWhenConfiguringTraffic(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkUnknownTrafficError("unknown-error") - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) } func TestTargetConfigurationFailedToBeReadyFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkConfigurationFailed("permanently-failed") - apitestv1.CheckConditionFailed(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionFailed(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) } func TestTargetRevisionNotYetReadyFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkRevisionNotReady("not-yet-ready") - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) } func TestTargetRevisionFailedToBeReadyFlow(t *testing.T) { r := &RouteStatus{} r.InitializeConditions() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkRevisionFailed("cannot-find-image") - apitestv1.CheckConditionFailed(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionFailed(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) } func TestIngressFailureRecovery(t *testing.T) { @@ -262,15 +262,15 @@ func TestIngressFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) // Empty IngressStatus marks ingress "NotConfigured" r.PropagateIngressStatus(netv1alpha1.IngressStatus{}) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkTrafficAssigned() r.PropagateIngressStatus(netv1alpha1.IngressStatus{ @@ -281,9 +281,9 @@ func TestIngressFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionSucceeded(r, RouteConditionIngressReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionReady, t) r.PropagateIngressStatus(netv1alpha1.IngressStatus{ Status: duckv1.Status{ @@ -293,9 +293,9 @@ func TestIngressFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionFailed(r, RouteConditionIngressReady, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) r.PropagateIngressStatus(netv1alpha1.IngressStatus{ Status: duckv1.Status{ @@ -305,9 +305,9 @@ func TestIngressFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionSucceeded(r, RouteConditionIngressReady, t) + apistest.CheckConditionSucceeded(r, RouteConditionReady, t) } func TestRouteNotOwnedStuff(t *testing.T) { @@ -322,14 +322,14 @@ func TestRouteNotOwnedStuff(t *testing.T) { }, }) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionReady, t) r.MarkServiceNotOwned("evan") - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionAllTrafficAssigned, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionIngressReady, t) - apitestv1.CheckConditionFailed(r.duck(), RouteConditionReady, t) + apistest.CheckConditionOngoing(r, RouteConditionAllTrafficAssigned, t) + apistest.CheckConditionFailed(r, RouteConditionIngressReady, t) + apistest.CheckConditionFailed(r, RouteConditionReady, t) } func TestRouteGetGroupVersionKind(t *testing.T) { @@ -349,7 +349,7 @@ func TestCertificateReady(t *testing.T) { r.InitializeConditions() r.MarkCertificateReady("cert") - apitestv1.CheckConditionSucceeded(r.duck(), RouteConditionCertificateProvisioned, t) + apistest.CheckConditionSucceeded(r, RouteConditionCertificateProvisioned, t) } func TestCertificateNotReady(t *testing.T) { @@ -357,7 +357,7 @@ func TestCertificateNotReady(t *testing.T) { r.InitializeConditions() r.MarkCertificateNotReady("cert") - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionCertificateProvisioned, t) + apistest.CheckConditionOngoing(r, RouteConditionCertificateProvisioned, t) } func TestCertificateProvisionFailed(t *testing.T) { @@ -365,7 +365,7 @@ func TestCertificateProvisionFailed(t *testing.T) { r.InitializeConditions() r.MarkCertificateProvisionFailed("cert") - apitestv1.CheckConditionFailed(r.duck(), RouteConditionCertificateProvisioned, t) + apistest.CheckConditionFailed(r, RouteConditionCertificateProvisioned, t) } func TestRouteNotOwnCertificate(t *testing.T) { @@ -373,7 +373,7 @@ func TestRouteNotOwnCertificate(t *testing.T) { r.InitializeConditions() r.MarkCertificateNotOwned("cert") - apitestv1.CheckConditionFailed(r.duck(), RouteConditionCertificateProvisioned, t) + apistest.CheckConditionFailed(r, RouteConditionCertificateProvisioned, t) } func TestIngressNotConfigured(t *testing.T) { @@ -381,5 +381,5 @@ func TestIngressNotConfigured(t *testing.T) { r.InitializeConditions() r.MarkIngressNotConfigured() - apitestv1.CheckConditionOngoing(r.duck(), RouteConditionIngressReady, t) + apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t) } diff --git a/pkg/apis/serving/v1alpha1/service_lifecycle.go b/pkg/apis/serving/v1alpha1/service_lifecycle.go index 6db322cdf831..2e54e84dcb72 100644 --- a/pkg/apis/serving/v1alpha1/service_lifecycle.go +++ b/pkg/apis/serving/v1alpha1/service_lifecycle.go @@ -23,7 +23,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" ) var serviceCondSet = apis.NewLivingConditionSet( @@ -157,7 +156,3 @@ func (ss *ServiceStatus) PropagateRouteStatus(rs *RouteStatus) { m.MarkUnknown(ServiceConditionRoutesReady, rc.Reason, rc.Message) } } - -func (ss *ServiceStatus) duck() *duckv1.Status { - return &ss.Status -} diff --git a/pkg/apis/serving/v1alpha1/service_lifecycle_test.go b/pkg/apis/serving/v1alpha1/service_lifecycle_test.go index 1156c8683828..606d8e0298c3 100644 --- a/pkg/apis/serving/v1alpha1/service_lifecycle_test.go +++ b/pkg/apis/serving/v1alpha1/service_lifecycle_test.go @@ -25,7 +25,7 @@ import ( "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - apitestv1 "knative.dev/pkg/apis/testing/v1" + apistest "knative.dev/pkg/apis/testing" "knative.dev/pkg/ptr" v1 "knative.dev/serving/pkg/apis/serving/v1" @@ -169,21 +169,21 @@ func TestServiceIsReady(t *testing.T) { func TestServiceHappyPath(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Nothing from Configuration is nothing to us. svc.PropagateConfigurationStatus(&ConfigurationStatus{}) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Nothing from Route is nothing to us. svc.PropagateRouteStatus(&RouteStatus{}) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Done from Configuration moves our ConfigurationsReady condition svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -194,15 +194,15 @@ func TestServiceHappyPath(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) svc.MarkResourceNotConvertible(ConvertErrorf("manual", "something something not allowed.").(*CannotConvertError)) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ConditionTypeConvertible, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ConditionTypeConvertible, t) // Done from Route moves our RoutesReady condition, which triggers us to be Ready. svc.PropagateRouteStatus(&RouteStatus{ @@ -213,9 +213,9 @@ func TestServiceHappyPath(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) // Check idempotency. svc.PropagateRouteStatus(&RouteStatus{ @@ -226,20 +226,20 @@ func TestServiceHappyPath(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) } func TestMarkRouteNotYetReady(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) svc.MarkRouteNotYetReady() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) dt := svc.GetCondition(ServiceConditionReady) if got, want := dt.Reason, trafficNotMigratedReason; got != want { t.Errorf("Condition Reason: got: %s, want: %s", got, want) @@ -252,9 +252,9 @@ func TestMarkRouteNotYetReady(t *testing.T) { func TestFailureRecovery(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Config failure causes us to become unready immediately (route still ok). svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -265,9 +265,9 @@ func TestFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Route failure causes route to become failed (config and service still failed). svc.PropagateRouteStatus(&RouteStatus{ @@ -278,9 +278,9 @@ func TestFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionRoutesReady, t) // Fix Configuration moves our ConfigurationsReady condition (route and service still failed). svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -291,9 +291,9 @@ func TestFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionRoutesReady, t) // Fix route, should make everything ready. svc.PropagateRouteStatus(&RouteStatus{ @@ -304,17 +304,17 @@ func TestFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) } func TestConfigurationFailurePropagation(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Failure causes us to become unready immediately. svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -325,18 +325,18 @@ func TestConfigurationFailurePropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) } func TestConfigurationFailureRecovery(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Done from Route moves our RoutesReady condition svc.PropagateRouteStatus(&RouteStatus{ @@ -347,9 +347,9 @@ func TestConfigurationFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) // Failure causes us to become unready immediately (route still ok). svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -360,9 +360,9 @@ func TestConfigurationFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) // Fixed the glitch. svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -373,17 +373,17 @@ func TestConfigurationFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) } func TestConfigurationUnknownPropagation(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Configuration and Route become ready, making us ready. svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -402,9 +402,9 @@ func TestConfigurationUnknownPropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) // Configuration flipping back to Unknown causes us to become ongoing immediately svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -415,10 +415,10 @@ func TestConfigurationUnknownPropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) // Route is unaffected. - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) } func TestConfigurationStatusPropagation(t *testing.T) { @@ -444,9 +444,9 @@ func TestConfigurationStatusPropagation(t *testing.T) { func TestRouteFailurePropagation(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Failure causes us to become unready immediately svc.PropagateRouteStatus(&RouteStatus{ @@ -457,17 +457,17 @@ func TestRouteFailurePropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionRoutesReady, t) } func TestRouteFailureRecovery(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Done from Configuration moves our ConfigurationsReady condition svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -478,9 +478,9 @@ func TestRouteFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Failure causes us to become unready immediately (config still ok). svc.PropagateRouteStatus(&RouteStatus{ @@ -491,9 +491,9 @@ func TestRouteFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionRoutesReady, t) // Fixed the glitch. svc.PropagateRouteStatus(&RouteStatus{ @@ -504,17 +504,17 @@ func TestRouteFailureRecovery(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) } func TestRouteUnknownPropagation(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Configuration and Route become ready, making us ready. svc.PropagateConfigurationStatus(&ConfigurationStatus{ @@ -533,9 +533,9 @@ func TestRouteUnknownPropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionRoutesReady, t) // Route flipping back to Unknown causes us to become ongoing immediately. svc.PropagateRouteStatus(&RouteStatus{ @@ -546,26 +546,26 @@ func TestRouteUnknownPropagation(t *testing.T) { }}, }, }) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) // Configuration is unaffected. - apitestv1.CheckConditionSucceeded(svc.duck(), ServiceConditionConfigurationsReady, t) + apistest.CheckConditionSucceeded(svc, ServiceConditionConfigurationsReady, t) } func TestServiceNotOwnedStuff(t *testing.T) { svc := &ServiceStatus{} svc.InitializeConditions() - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionOngoing(svc.duck(), ServiceConditionRoutesReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionOngoing(svc, ServiceConditionRoutesReady, t) svc.MarkRouteNotOwned("mark") - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionRoutesReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionRoutesReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) svc.MarkConfigurationNotOwned("jon") - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionConfigurationsReady, t) - apitestv1.CheckConditionFailed(svc.duck(), ServiceConditionReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionConfigurationsReady, t) + apistest.CheckConditionFailed(svc, ServiceConditionReady, t) } func TestRouteStatusPropagation(t *testing.T) { diff --git a/vendor/knative.dev/pkg/Gopkg.lock b/vendor/knative.dev/pkg/Gopkg.lock index 2cb02a321926..1a008c57dda8 100644 --- a/vendor/knative.dev/pkg/Gopkg.lock +++ b/vendor/knative.dev/pkg/Gopkg.lock @@ -1461,7 +1461,6 @@ "k8s.io/apimachinery/pkg/version", "k8s.io/apimachinery/pkg/watch", "k8s.io/client-go/discovery", - "k8s.io/client-go/discovery/fake", "k8s.io/client-go/dynamic", "k8s.io/client-go/dynamic/fake", "k8s.io/client-go/informers", @@ -1489,7 +1488,6 @@ "k8s.io/client-go/tools/clientcmd", "k8s.io/client-go/tools/metrics", "k8s.io/client-go/tools/record", - "k8s.io/client-go/util/flowcontrol", "k8s.io/client-go/util/retry", "k8s.io/client-go/util/workqueue", "k8s.io/code-generator/cmd/client-gen", diff --git a/vendor/knative.dev/pkg/apis/condition_set.go b/vendor/knative.dev/pkg/apis/condition_set.go index 1e90aa9eae0d..2691dcf0faea 100644 --- a/vendor/knative.dev/pkg/apis/condition_set.go +++ b/vendor/knative.dev/pkg/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/vendor/knative.dev/pkg/apis/testing/conditions.go b/vendor/knative.dev/pkg/apis/testing/conditions.go index 02d1fe8b0a05..68b0018ab6ba 100644 --- a/vendor/knative.dev/pkg/apis/testing/conditions.go +++ b/vendor/knative.dev/pkg/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/vendor/knative.dev/pkg/apis/testing/v1/conditions.go b/vendor/knative.dev/pkg/apis/testing/v1/conditions.go deleted file mode 100644 index 6ace88eb5cc6..000000000000 --- a/vendor/knative.dev/pkg/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/vendor/knative.dev/pkg/apis/testing/v1beta1/conditions.go b/vendor/knative.dev/pkg/apis/testing/v1beta1/conditions.go deleted file mode 100644 index 74aa26b2adf0..000000000000 --- a/vendor/knative.dev/pkg/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) - } -} diff --git a/vendor/knative.dev/pkg/test/presubmit-tests.sh b/vendor/knative.dev/pkg/test/presubmit-tests.sh index 5bcb6262004d..7c10a5e0a56e 100755 --- a/vendor/knative.dev/pkg/test/presubmit-tests.sh +++ b/vendor/knative.dev/pkg/test/presubmit-tests.sh @@ -24,12 +24,15 @@ export DISABLE_MD_LINTING=1 source $(dirname $0)/../vendor/knative.dev/test-infra/scripts/presubmit-tests.sh -# Test the custom code generators. This makes sure we can compile the output -# of the injection generators. -$(dirname $0)/update-test-codegen.sh - # TODO(#17): Write integration tests. # We use the default build, unit and integration test runners. +function pre_build_tests() { + # Test the custom code generators. This makes sure we can compile the output + # of the injection generators. + $(dirname $0)/test-reconciler-codegen.sh + return 0 +} + main $@ diff --git a/vendor/knative.dev/pkg/test/update-test-codegen.sh b/vendor/knative.dev/pkg/test/test-reconciler-codegen.sh similarity index 87% rename from vendor/knative.dev/pkg/test/update-test-codegen.sh rename to vendor/knative.dev/pkg/test/test-reconciler-codegen.sh index 470576378d0a..598de24fbecf 100755 --- a/vendor/knative.dev/pkg/test/update-test-codegen.sh +++ b/vendor/knative.dev/pkg/test/test-reconciler-codegen.sh @@ -24,10 +24,11 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${REPO_ROOT_DIR}; ls -d -1 $(dirname $0)/../vend KNATIVE_CODEGEN_PKG=${KNATIVE_CODEGEN_PKG:-$(cd ${REPO_ROOT_DIR}; ls -d -1 $(dirname $0)/../vendor/knative.dev/pkg 2>/dev/null || echo ../pkg)} GENCLIENT_PKG=knative.dev/pkg/test/genclient -( - cd ${REPO_ROOT_DIR} - rm -rf ${REPO_ROOT_DIR}/pkg/test/genclient -) + +echo "Pre-deleting $(dirname $0)/genclient" +rm -rf $(dirname $0)/genclient + +header "Test Generated Reconciler Builds." ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \ ${GENCLIENT_PKG} knative.dev/pkg/apis/test \ @@ -52,3 +53,9 @@ ${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh "injection" \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt +if ! go build -v $(dirname $0)/genclient/... ; then + exit 1 +fi + +echo "Finished, deleting $(dirname $0)/genclient" +rm -rf $(dirname $0)/genclient