diff --git a/pkg/apis/serving/v1/configuration_lifecycle.go b/pkg/apis/serving/v1/configuration_lifecycle.go index 74d70a31e514..ff410e952c32 100644 --- a/pkg/apis/serving/v1/configuration_lifecycle.go +++ b/pkg/apis/serving/v1/configuration_lifecycle.go @@ -24,6 +24,11 @@ import ( var configCondSet = apis.NewLivingConditionSet() +// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface. +func (*Configuration) GetConditionSet() apis.ConditionSet { + return configCondSet +} + // GetGroupVersionKind returns the GroupVersionKind. func (r *Configuration) GetGroupVersionKind() schema.GroupVersionKind { return SchemeGroupVersion.WithKind("Configuration") diff --git a/pkg/apis/serving/v1/configuration_lifecycle_test.go b/pkg/apis/serving/v1/configuration_lifecycle_test.go index 5644fda44b9b..1006314529bb 100644 --- a/pkg/apis/serving/v1/configuration_lifecycle_test.go +++ b/pkg/apis/serving/v1/configuration_lifecycle_test.go @@ -21,6 +21,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime/schema" + "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" apistest "knative.dev/pkg/apis/testing" @@ -45,6 +46,14 @@ func TestConfigurationDuckTypes(t *testing.T) { } } +func TestConfigurationGetConditionSet(t *testing.T) { + r := &Configuration{} + + if got, want := r.GetConditionSet().GetTopLevelConditionType(), apis.ConditionReady; got != want { + t.Errorf("GetTopLevelCondition=%v, want=%v", got, want) + } +} + func TestConfigurationGetGroupVersionKind(t *testing.T) { r := &Configuration{} want := schema.GroupVersionKind{ diff --git a/pkg/apis/serving/v1/configuration_types.go b/pkg/apis/serving/v1/configuration_types.go index 065e55ad58b4..fbf1ae155c00 100644 --- a/pkg/apis/serving/v1/configuration_types.go +++ b/pkg/apis/serving/v1/configuration_types.go @@ -55,6 +55,9 @@ var ( // Check that we can create OwnerReferences to a Configuration. _ kmeta.OwnerRefable = (*Configuration)(nil) + + // Check that the type conforms to the duck Knative Resource shape. + _ duckv1.KRShaped = (*Configuration)(nil) ) // ConfigurationSpec holds the desired state of the Configuration (from the client). @@ -105,3 +108,8 @@ type ConfigurationList struct { Items []Configuration `json:"items"` } + +// GetStatus retrieves the status of the Configuration. Implements the KRShaped interface. +func (t *Configuration) GetStatus() *duckv1.Status { + return &t.Status.Status +} diff --git a/pkg/apis/serving/v1/configuration_types_test.go b/pkg/apis/serving/v1/configuration_types_test.go new file mode 100644 index 000000000000..8cc5ea3507f1 --- /dev/null +++ b/pkg/apis/serving/v1/configuration_types_test.go @@ -0,0 +1,49 @@ +/* +Copyright 2020 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 ( + "testing" + + "github.com/google/go-cmp/cmp" + "knative.dev/pkg/apis" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +func TestIsConfigurationCondition(t *testing.T) { + cType := apis.ConditionType("DefinitelyNotConfigurationType") + + if IsConfigurationCondition(cType) { + t.Error("Not expected to be a configuration type") + } + + if !IsConfigurationCondition(ConfigurationConditionReady) { + t.Error("Expected to be a configuration type") + } +} + +func TestConfigurationGetStatus(t *testing.T) { + status := &duckv1.Status{} + config := Configuration{ + Status: ConfigurationStatus{ + Status: *status, + }, + } + + if !cmp.Equal(config.GetStatus(), status) { + t.Errorf("GetStatus did not retrieve status. Got=%v Want=%v", config.GetStatus(), status) + } +} diff --git a/pkg/apis/serving/v1/revision_lifecycle.go b/pkg/apis/serving/v1/revision_lifecycle.go index 7be076a3f2ea..ca1b69da5510 100644 --- a/pkg/apis/serving/v1/revision_lifecycle.go +++ b/pkg/apis/serving/v1/revision_lifecycle.go @@ -52,6 +52,11 @@ var revisionCondSet = apis.NewLivingConditionSet( RevisionConditionContainerHealthy, ) +// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface. +func (*Revision) GetConditionSet() apis.ConditionSet { + return revisionCondSet +} + // GetGroupVersionKind returns the GroupVersionKind. func (r *Revision) GetGroupVersionKind() schema.GroupVersionKind { return SchemeGroupVersion.WithKind("Revision") diff --git a/pkg/apis/serving/v1/revision_lifecycle_test.go b/pkg/apis/serving/v1/revision_lifecycle_test.go index 52a43cd74671..06ba0c17a9b7 100644 --- a/pkg/apis/serving/v1/revision_lifecycle_test.go +++ b/pkg/apis/serving/v1/revision_lifecycle_test.go @@ -58,6 +58,14 @@ func TestRevisionDuckTypes(t *testing.T) { } } +func TestRevisionGetConditionSet(t *testing.T) { + r := &Revision{} + + if got, want := r.GetConditionSet().GetTopLevelConditionType(), apis.ConditionReady; got != want { + t.Errorf("GetTopLevelCondition=%v, want=%v", got, want) + } +} + func TestRevisionGetGroupVersionKind(t *testing.T) { r := &Revision{} want := schema.GroupVersionKind{ diff --git a/pkg/apis/serving/v1/revision_types.go b/pkg/apis/serving/v1/revision_types.go index 61efe107a381..dbad280b13e0 100644 --- a/pkg/apis/serving/v1/revision_types.go +++ b/pkg/apis/serving/v1/revision_types.go @@ -56,6 +56,9 @@ var ( // Check that we can create OwnerReferences to a Revision. _ kmeta.OwnerRefable = (*Revision)(nil) + + // Check that the type conforms to the duck Knative Resource shape. + _ duckv1.KRShaped = (*Revision)(nil) ) // RevisionTemplateSpec describes the data a revision should have when created from a template. @@ -167,3 +170,8 @@ type RevisionList struct { Items []Revision `json:"items"` } + +// GetStatus retrieves the status of the Revision. Implements the KRShaped interface. +func (t *Revision) GetStatus() *duckv1.Status { + return &t.Status.Status +} diff --git a/pkg/apis/serving/v1/revision_types_test.go b/pkg/apis/serving/v1/revision_types_test.go new file mode 100644 index 000000000000..d0b6d48b32d8 --- /dev/null +++ b/pkg/apis/serving/v1/revision_types_test.go @@ -0,0 +1,49 @@ +/* +Copyright 2020 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 ( + "testing" + + "github.com/google/go-cmp/cmp" + "knative.dev/pkg/apis" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +func TestIsRevisionCondition(t *testing.T) { + cType := apis.ConditionType("DefinitelyNotRevisionType") + + if IsRevisionCondition(cType) { + t.Error("Not expected to be a revision type") + } + + if !IsRevisionCondition(RevisionConditionReady) { + t.Error("Expected to be a revision type") + } +} + +func TestRevisionGetStatus(t *testing.T) { + status := &duckv1.Status{} + config := Revision{ + Status: RevisionStatus{ + Status: *status, + }, + } + + if !cmp.Equal(config.GetStatus(), status) { + t.Errorf("GetStatus did not retrieve status. Got=%v Want=%v", config.GetStatus(), status) + } +} diff --git a/pkg/apis/serving/v1/route_lifecycle.go b/pkg/apis/serving/v1/route_lifecycle.go index 4b67a2b9efcf..1942731f53fb 100644 --- a/pkg/apis/serving/v1/route_lifecycle.go +++ b/pkg/apis/serving/v1/route_lifecycle.go @@ -31,6 +31,11 @@ var routeCondSet = apis.NewLivingConditionSet( RouteConditionIngressReady, ) +// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface. +func (*Route) GetConditionSet() apis.ConditionSet { + return routeCondSet +} + // GetGroupVersionKind returns the GroupVersionKind. func (r *Route) GetGroupVersionKind() schema.GroupVersionKind { return SchemeGroupVersion.WithKind("Route") diff --git a/pkg/apis/serving/v1/route_lifecycle_test.go b/pkg/apis/serving/v1/route_lifecycle_test.go index 3b16f5559a00..aea593dfadf8 100644 --- a/pkg/apis/serving/v1/route_lifecycle_test.go +++ b/pkg/apis/serving/v1/route_lifecycle_test.go @@ -20,6 +20,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime/schema" + "knative.dev/pkg/apis" "knative.dev/pkg/apis/duck" duckv1 "knative.dev/pkg/apis/duck/v1" apistest "knative.dev/pkg/apis/testing" @@ -45,6 +46,14 @@ func TestRouteDuckTypes(t *testing.T) { } } +func TestRouteGetConditionSet(t *testing.T) { + r := &Route{} + + if got, want := r.GetConditionSet().GetTopLevelConditionType(), apis.ConditionReady; got != want { + t.Errorf("GetTopLevelCondition=%v, want=%v", got, want) + } +} + func TestRouteGetGroupVersionKind(t *testing.T) { r := &Route{} want := schema.GroupVersionKind{ diff --git a/pkg/apis/serving/v1/route_types.go b/pkg/apis/serving/v1/route_types.go index 2345d545ca87..2d810ebf5013 100644 --- a/pkg/apis/serving/v1/route_types.go +++ b/pkg/apis/serving/v1/route_types.go @@ -59,6 +59,9 @@ var ( // Check that we can create OwnerReferences to a Route. _ kmeta.OwnerRefable = (*Route)(nil) + + // Check that the type conforms to the duck Knative Resource shape. + _ duckv1.KRShaped = (*Route)(nil) ) // TrafficTarget holds a single entry of the routing table for a Route. @@ -184,3 +187,8 @@ type RouteList struct { Items []Route `json:"items"` } + +// GetStatus retrieves the status of the Route. Implements the KRShaped interface. +func (t *Route) GetStatus() *duckv1.Status { + return &t.Status.Status +} diff --git a/pkg/apis/serving/v1/route_types_test.go b/pkg/apis/serving/v1/route_types_test.go new file mode 100644 index 000000000000..11ae39b2f47d --- /dev/null +++ b/pkg/apis/serving/v1/route_types_test.go @@ -0,0 +1,49 @@ +/* +Copyright 2020 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 ( + "testing" + + "github.com/google/go-cmp/cmp" + "knative.dev/pkg/apis" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +func TestIsRouteCondition(t *testing.T) { + cType := apis.ConditionType("DefinitelyNotRouteType") + + if IsRouteCondition(cType) { + t.Error("Not expected to be a route type") + } + + if !IsRouteCondition(RouteConditionReady) { + t.Error("Expected to be a route type") + } +} + +func TestRouteGetStatus(t *testing.T) { + status := &duckv1.Status{} + config := Route{ + Status: RouteStatus{ + Status: *status, + }, + } + + if !cmp.Equal(config.GetStatus(), status) { + t.Errorf("GetStatus did not retrieve status. Got=%v Want=%v", config.GetStatus(), status) + } +} diff --git a/pkg/apis/serving/v1/service_lifecycle.go b/pkg/apis/serving/v1/service_lifecycle.go index 1198263a4213..ea03097fdd5e 100644 --- a/pkg/apis/serving/v1/service_lifecycle.go +++ b/pkg/apis/serving/v1/service_lifecycle.go @@ -35,6 +35,11 @@ var serviceCondSet = apis.NewLivingConditionSet( ServiceConditionRoutesReady, ) +// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface. +func (*Service) GetConditionSet() apis.ConditionSet { + return serviceCondSet +} + // GetGroupVersionKind returns the GroupVersionKind. func (s *Service) GetGroupVersionKind() schema.GroupVersionKind { return SchemeGroupVersion.WithKind("Service") diff --git a/pkg/apis/serving/v1/service_lifecycle_test.go b/pkg/apis/serving/v1/service_lifecycle_test.go index 86cdf7f865d5..0103570db794 100644 --- a/pkg/apis/serving/v1/service_lifecycle_test.go +++ b/pkg/apis/serving/v1/service_lifecycle_test.go @@ -47,6 +47,14 @@ func TestServiceDuckTypes(t *testing.T) { } } +func TestServiceGetConditionSet(t *testing.T) { + r := &Service{} + + if got, want := r.GetConditionSet().GetTopLevelConditionType(), apis.ConditionReady; got != want { + t.Errorf("GetTopLevelCondition=%v, want=%v", got, want) + } +} + func TestServiceGetGroupVersionKind(t *testing.T) { r := &Service{} want := schema.GroupVersionKind{ diff --git a/pkg/apis/serving/v1/service_types.go b/pkg/apis/serving/v1/service_types.go index f25cd91549c5..ce5174319d30 100644 --- a/pkg/apis/serving/v1/service_types.go +++ b/pkg/apis/serving/v1/service_types.go @@ -63,6 +63,9 @@ var ( // Check that we can create OwnerReferences to a Service. _ kmeta.OwnerRefable = (*Service)(nil) + + // Check that the type conforms to the duck Knative Resource shape. + _ duckv1.KRShaped = (*Service)(nil) ) // ServiceSpec represents the configuration for the Service object. @@ -132,3 +135,8 @@ type ServiceList struct { Items []Service `json:"items"` } + +// GetStatus retrieves the status of the Service. Implements the KRShaped interface. +func (t *Service) GetStatus() *duckv1.Status { + return &t.Status.Status +} diff --git a/pkg/apis/serving/v1/service_types_test.go b/pkg/apis/serving/v1/service_types_test.go new file mode 100644 index 000000000000..786f5c952af0 --- /dev/null +++ b/pkg/apis/serving/v1/service_types_test.go @@ -0,0 +1,49 @@ +/* +Copyright 2020 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 ( + "testing" + + "github.com/google/go-cmp/cmp" + "knative.dev/pkg/apis" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +func TestIsServiceCondition(t *testing.T) { + cType := apis.ConditionType("DefinitelyNotServiceType") + + if IsServiceCondition(cType) { + t.Error("Not expected to be a service type") + } + + if !IsServiceCondition(ServiceConditionReady) { + t.Error("Expected to be a service type") + } +} + +func TestServiceGetStatus(t *testing.T) { + status := &duckv1.Status{} + config := Service{ + Status: ServiceStatus{ + Status: *status, + }, + } + + if !cmp.Equal(config.GetStatus(), status) { + t.Errorf("GetStatus did not retrieve status. Got=%v Want=%v", config.GetStatus(), status) + } +}