Skip to content

Commit

Permalink
Implement KRShaped for serving v1 (#7878)
Browse files Browse the repository at this point in the history
* serving v1 implements krshaped

* merge validation changes

* merge from master

* Update tests with review feedback

* fix typos

* Remove gettypemeta function

* remove unessecary unit tests

* update deps

* unmerge

* include getStatus test
  • Loading branch information
whaught authored May 18, 2020
1 parent 6e70d90 commit 99eb115
Show file tree
Hide file tree
Showing 16 changed files with 282 additions and 0 deletions.
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
}

// 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("GetTopLevelCondition=%v, want=%v", got, want)
}
}

func TestConfigurationGetGroupVersionKind(t *testing.T) {
r := &Configuration{}
want := schema.GroupVersionKind{
Expand Down
8 changes: 8 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,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
}
49 changes: 49 additions & 0 deletions pkg/apis/serving/v1/configuration_types_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
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("GetTopLevelCondition=%v, want=%v", got, want)
}
}

func TestRevisionGetGroupVersionKind(t *testing.T) {
r := &Revision{}
want := schema.GroupVersionKind{
Expand Down
8 changes: 8 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,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
}
49 changes: 49 additions & 0 deletions pkg/apis/serving/v1/revision_types_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
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("GetTopLevelCondition=%v, want=%v", got, want)
}
}

func TestRouteGetGroupVersionKind(t *testing.T) {
r := &Route{}
want := schema.GroupVersionKind{
Expand Down
8 changes: 8 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,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
}
49 changes: 49 additions & 0 deletions pkg/apis/serving/v1/route_types_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
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("GetTopLevelCondition=%v, want=%v", got, want)
}
}

func TestServiceGetGroupVersionKind(t *testing.T) {
r := &Service{}
want := schema.GroupVersionKind{
Expand Down
8 changes: 8 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,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
}
49 changes: 49 additions & 0 deletions pkg/apis/serving/v1/service_types_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 99eb115

Please sign in to comment.