Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Implement KRShaped for serving v1 #7878

Merged
merged 13 commits into from
May 18, 2020
5 changes: 5 additions & 0 deletions pkg/apis/serving/v1/configuration_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
whaught marked this conversation as resolved.
Show resolved Hide resolved
}

// GetGroupVersionKind returns the GroupVersionKind.
func (r *Configuration) GetGroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind("Configuration")
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/serving/v1/configuration_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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("GotTopLevelCondition=%v, want=%v", got, want)
whaught marked this conversation as resolved.
Show resolved Hide resolved
}
}

func TestConfigurationGetGroupVersionKind(t *testing.T) {
r := &Configuration{}
want := schema.GroupVersionKind{
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/serving/v1/configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -105,3 +108,13 @@ type ConfigurationList struct {

Items []Configuration `json:"items"`
}

// GetTypeMeta retrieves the ObjectMeta of the Configuration. Implements the KRShaped interface.
func (t *Configuration) GetTypeMeta() *metav1.TypeMeta {
whaught marked this conversation as resolved.
Show resolved Hide resolved
return &t.TypeMeta
}

// GetStatus retrieves the status of the Configuration. Implements the KRShaped interface.
func (t *Configuration) GetStatus() *duckv1.Status {
return &t.Status.Status
}
55 changes: 55 additions & 0 deletions pkg/apis/serving/v1/configuration_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
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"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)

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) {
r := &Configuration{
Status: ConfigurationStatus{},
}

if got, want := r.GetStatus(), &r.Status.Status; got != want {
t.Errorf("GotStatus=%v, want=%v", got, want)
}
}

func TestConfigurationGetObjectMeta(t *testing.T) {
r := &Configuration{
TypeMeta: metav1.TypeMeta{},
}

if got, want := r.GetTypeMeta(), &r.TypeMeta; got != want {
t.Errorf("GotTypeMeta=%v, want=%v", got, want)
}
}
5 changes: 5 additions & 0 deletions pkg/apis/serving/v1/revision_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/serving/v1/revision_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("GotTopLevelCondition=%v, want=%v", got, want)
}
}

func TestRevisionGetGroupVersionKind(t *testing.T) {
r := &Revision{}
want := schema.GroupVersionKind{
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/serving/v1/revision_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -167,3 +170,13 @@ type RevisionList struct {

Items []Revision `json:"items"`
}

// GetTypeMeta retrieves the ObjectMeta of the Revision. Implements the KRShaped interface.
whaught marked this conversation as resolved.
Show resolved Hide resolved
func (t *Revision) GetTypeMeta() *metav1.TypeMeta {
return &t.TypeMeta
}

// GetStatus retrieves the status of the Revision. Implements the KRShaped interface.
func (t *Revision) GetStatus() *duckv1.Status {
return &t.Status.Status
}
55 changes: 55 additions & 0 deletions pkg/apis/serving/v1/revision_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
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"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)

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) {
r := &Revision{
Status: RevisionStatus{},
}

if got, want := r.GetStatus(), &r.Status.Status; got != want {
t.Errorf("GotStatus=%v, want=%v", got, want)
}
}

func TestRevisionGetObjectMeta(t *testing.T) {
r := &Revision{
TypeMeta: metav1.TypeMeta{},
}

if got, want := r.GetTypeMeta(), &r.TypeMeta; got != want {
t.Errorf("GotTypeMeta=%v, want=%v", got, want)
}
}
5 changes: 5 additions & 0 deletions pkg/apis/serving/v1/route_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/serving/v1/route_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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("GotTopLevelCondition=%v, want=%v", got, want)
}
}

func TestRouteGetGroupVersionKind(t *testing.T) {
r := &Route{}
want := schema.GroupVersionKind{
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/serving/v1/route_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -184,3 +187,13 @@ type RouteList struct {

Items []Route `json:"items"`
}

// GetTypeMeta retrieves the ObjectMeta of the Route. Implements the KRShaped interface.
func (t *Route) GetTypeMeta() *metav1.TypeMeta {
return &t.TypeMeta
}

// GetStatus retrieves the status of the Route. Implements the KRShaped interface.
func (t *Route) GetStatus() *duckv1.Status {
return &t.Status.Status
}
55 changes: 55 additions & 0 deletions pkg/apis/serving/v1/route_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
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"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)

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) {
r := &Route{
Status: RouteStatus{},
}

if got, want := r.GetStatus(), &r.Status.Status; got != want {
t.Errorf("GotStatus=%v, want=%v", got, want)
}
}

func TestRouteGetObjectMeta(t *testing.T) {
r := &Route{
TypeMeta: metav1.TypeMeta{},
}

if got, want := r.GetTypeMeta(), &r.TypeMeta; got != want {
t.Errorf("GotTypeMeta=%v, want=%v", got, want)
}
}
5 changes: 5 additions & 0 deletions pkg/apis/serving/v1/service_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/serving/v1/service_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("GotTopLevelCondition=%v, want=%v", got, want)
}
}

func TestServiceGetGroupVersionKind(t *testing.T) {
r := &Service{}
want := schema.GroupVersionKind{
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/serving/v1/service_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -132,3 +135,13 @@ type ServiceList struct {

Items []Service `json:"items"`
}

// GetTypeMeta retrieves the ObjectMeta of the Service. Implements the KRShaped interface.
func (t *Service) GetTypeMeta() *metav1.TypeMeta {
return &t.TypeMeta
}

// GetStatus retrieves the status of the Service. Implements the KRShaped interface.
func (t *Service) GetStatus() *duckv1.Status {
return &t.Status.Status
}
Loading