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 sources types #3226

Merged
merged 2 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/apis/sources/v1alpha2/apiserver_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ var apiserverCondSet = apis.NewLivingConditionSet(
ApiServerConditionSufficientPermissions,
)

// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface.
func (*ApiServerSource) GetConditionSet() apis.ConditionSet {
return apiserverCondSet
}

// GetGroupVersionKind returns the GroupVersionKind.
func (s *ApiServerSource) GetGroupVersionKind() schema.GroupVersionKind {
func (*ApiServerSource) GetGroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind("ApiServerSource")
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/sources/v1alpha2/apiserver_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ var (
}
)

func TestApiServerSourceGetConditionSet(t *testing.T) {
r := &ApiServerSource{}

if got, want := r.GetConditionSet().GetTopLevelConditionType(), apis.ConditionReady; got != want {
t.Errorf("GetTopLevelCondition=%v, want=%v", got, want)
}
}

func TestApiServerSourceGetGroupVersionKind(t *testing.T) {
r := &ApiServerSource{}
want := schema.GroupVersionKind{
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/sources/v1alpha2/apiserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
_ apis.Validatable = (*ApiServerSource)(nil)
_ apis.Defaultable = (*ApiServerSource)(nil)
_ apis.HasSpec = (*ApiServerSource)(nil)
_ duckv1.KRShaped = (*PingSource)(nil)
whaught marked this conversation as resolved.
Show resolved Hide resolved
)

const (
Expand Down Expand Up @@ -153,3 +154,8 @@ type ApiServerSourceList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []ApiServerSource `json:"items"`
}

// GetStatus retrieves the status of the ApiServerSource . Implements the KRShaped interface.
func (a *ApiServerSource) GetStatus() *duckv1.Status {
return &a.Status.Status
}
9 changes: 9 additions & 0 deletions pkg/apis/sources/v1alpha2/apiserver_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ package v1alpha2

import "testing"

func TestApiServerSource_GetStatus(t *testing.T) {
r := &ApiServerSource{
Status: ApiServerSourceStatus{},
}
if got, want := r.GetStatus(), &r.Status.Status; got != want {
t.Errorf("GetStatus=%v, want=%v", got, want)
}
}

func TestApiServerSource_GetGroupVersionKind(t *testing.T) {
ass := ApiServerSource{}
gvk := ass.GetGroupVersionKind()
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/sources/v1alpha2/container_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ var containerCondSet = apis.NewLivingConditionSet(
ContainerSourceConditionReceiveAdapterReady,
)

// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface.
func (*ContainerSource) GetConditionSet() apis.ConditionSet {
return containerCondSet
}

// GetCondition returns the condition currently associated with the given type, or nil.
func (s *ContainerSourceStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return containerCondSet.Manage(s).GetCondition(t)
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/sources/v1alpha2/container_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ var (
}
)

func TestContainerSourceGetConditionSet(t *testing.T) {
r := &ContainerSource{}

if got, want := r.GetConditionSet().GetTopLevelConditionType(), apis.ConditionReady; got != want {
t.Errorf("GetTopLevelCondition=%v, want=%v", got, want)
}
}

func TestContainerSourceStatusIsReady(t *testing.T) {
tests := []struct {
name string
Expand Down
8 changes: 7 additions & 1 deletion pkg/apis/sources/v1alpha2/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
_ apis.Validatable = (*ContainerSource)(nil)
_ apis.Defaultable = (*ContainerSource)(nil)
_ apis.HasSpec = (*ContainerSource)(nil)
_ duckv1.KRShaped = (*ContainerSource)(nil)
)

// ContainerSourceSpec defines the desired state of ContainerSource
Expand All @@ -61,7 +62,7 @@ type ContainerSourceSpec struct {
}

// GetGroupVersionKind returns the GroupVersionKind.
func (s *ContainerSource) GetGroupVersionKind() schema.GroupVersionKind {
func (*ContainerSource) GetGroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind("ContainerSource")
}

Expand Down Expand Up @@ -90,3 +91,8 @@ type ContainerSourceList struct {
func (c *ContainerSource) GetUntypedSpec() interface{} {
return c.Spec
}

// GetStatus retrieves the status of the ContainerSource. Implements the KRShaped interface.
func (c *ContainerSource) GetStatus() *duckv1.Status {
return &c.Status.Status
}
5 changes: 5 additions & 0 deletions pkg/apis/sources/v1alpha2/ping_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ const (
PingSourceEventType = "dev.knative.sources.ping"
)

// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface.
func (*PingSource) GetConditionSet() apis.ConditionSet {
return PingSourceCondSet
}

// PingSourceSource returns the PingSource CloudEvent source.
func PingSourceSource(namespace, name string) string {
return fmt.Sprintf("/apis/v1/namespaces/%s/pingsources/%s", namespace, name)
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/sources/v1alpha2/ping_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ var (
}
)

func TestPingSourceGetConditionSet(t *testing.T) {
r := &v1alpha2.PingSource{}

if got, want := r.GetConditionSet().GetTopLevelConditionType(), apis.ConditionReady; got != want {
t.Errorf("GetTopLevelCondition=%v, want=%v", got, want)
}
}

func TestPingSource_GetGroupVersionKind(t *testing.T) {
src := v1alpha2.PingSource{}
gvk := src.GetGroupVersionKind()
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/sources/v1alpha2/ping_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
_ apis.Validatable = (*PingSource)(nil)
_ apis.Defaultable = (*PingSource)(nil)
_ apis.HasSpec = (*PingSource)(nil)
_ duckv1.KRShaped = (*PingSource)(nil)
)

// PingSourceSpec defines the desired state of the PingSource.
Expand Down Expand Up @@ -88,3 +89,8 @@ type PingSourceList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []PingSource `json:"items"`
}

// GetStatus retrieves the status of the PingSource. Implements the KRShaped interface.
func (p *PingSource) GetStatus() *duckv1.Status {
return &p.Status.Status
}
7 changes: 6 additions & 1 deletion pkg/apis/sources/v1alpha2/sinkbinding_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ import (

var sbCondSet = apis.NewLivingConditionSet()

// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface.
func (*SinkBinding) GetConditionSet() apis.ConditionSet {
return sbCondSet
}

// GetGroupVersionKind returns the GroupVersionKind.
func (s *SinkBinding) GetGroupVersionKind() schema.GroupVersionKind {
func (*SinkBinding) GetGroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind("SinkBinding")
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/sources/v1alpha2/sinkbinding_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ import (
"knative.dev/pkg/tracker"
)

func TestSinkBindingGetConditionSet(t *testing.T) {
r := &SinkBinding{}

if got, want := r.GetConditionSet().GetTopLevelConditionType(), apis.ConditionReady; got != want {
t.Errorf("GetTopLevelCondition=%v, want=%v", got, want)
}
}

func TestSinkBindingGetGroupVersionKind(t *testing.T) {
r := &SinkBinding{}
want := schema.GroupVersionKind{
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/sources/v1alpha2/sinkbinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
_ apis.Validatable = (*SinkBinding)(nil)
_ apis.Defaultable = (*SinkBinding)(nil)
_ apis.HasSpec = (*SinkBinding)(nil)
_ duckv1.KRShaped = (*SinkBinding)(nil)
)

// SinkBindingSpec holds the desired state of the SinkBinding (from the client).
Expand Down Expand Up @@ -93,3 +94,8 @@ type SinkBindingList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []SinkBinding `json:"items"`
}

// GetStatus retrieves the status of the SinkBinding. Implements the KRShaped interface.
func (s *SinkBinding) GetStatus() *duckv1.Status {
return &s.Status.Status
}
9 changes: 9 additions & 0 deletions pkg/apis/sources/v1alpha2/sinkbinding_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ package v1alpha2

import "testing"

func TestSinkBinding_GetStatus(t *testing.T) {
r := &SinkBinding{
Status: SinkBindingStatus{},
}
if got, want := r.GetStatus(), &r.Status.Status; got != want {
t.Errorf("GetStatus=%v, want=%v", got, want)
}
}

func TestSinkBinding_GetGroupVersionKind(t *testing.T) {
sb := SinkBinding{}
gvk := sb.GetGroupVersionKind()
Expand Down