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

Switch EventType reconciler to v1beta1 version #3200

Merged
merged 8 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
20 changes: 20 additions & 0 deletions pkg/apis/eventing/v1alpha1/broker_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"

corev1 "k8s.io/api/core/v1"
"knative.dev/eventing/pkg/apis/eventing/v1beta1"
"knative.dev/pkg/apis"
)
Expand Down Expand Up @@ -60,3 +61,22 @@ func (sink *Broker) ConvertFrom(ctx context.Context, obj apis.Convertible) error
return fmt.Errorf("Unknown conversion, got: %T", source)
}
}

// PropagateV1Alpha1BrokerStatus propagates a v1alpha1 BrokerStatus to a v1beta1 EventTypeStatus
func PropagateV1Alpha1BrokerStatus(et *v1beta1.EventTypeStatus, bs *BrokerStatus) {
bc := brokerCondSet.Manage(bs).GetTopLevelCondition()
if bc == nil {
et.MarkBrokerNotConfigured()
return
}
switch {
case bc.Status == corev1.ConditionUnknown:
et.MarkBrokerUnknown(bc.Reason, bc.Message)
case bc.Status == corev1.ConditionTrue:
eventTypeCondSet.Manage(et).MarkTrue(EventTypeConditionBrokerReady)
case bc.Status == corev1.ConditionFalse:
et.MarkBrokerFailed(bc.Reason, bc.Message)
default:
et.MarkBrokerUnknown("BrokerUnknown", "The status of Broker is invalid: %v", bc.Status)
}
}
54 changes: 54 additions & 0 deletions pkg/apis/eventing/v1alpha1/broker_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,60 @@ func TestBrokerConversion(t *testing.T) {
}
}

func TestBrokerPropagateStatus(t *testing.T) {
tests := []struct {
name string
markBrokerExists *bool
brokerStatus *BrokerStatus
wantConditionStatus corev1.ConditionStatus
}{{
name: "all happy",
markBrokerExists: &trueValue,
brokerStatus: TestHelper.ReadyBrokerStatus(),
wantConditionStatus: corev1.ConditionTrue,
}, {
name: "broker exist sad",
markBrokerExists: &falseValue,
brokerStatus: nil,
wantConditionStatus: corev1.ConditionFalse,
}, {
name: "broker ready sad",
markBrokerExists: &trueValue,
brokerStatus: TestHelper.FalseBrokerStatus(),
wantConditionStatus: corev1.ConditionFalse,
}, {
name: "broker ready unknown",
markBrokerExists: &trueValue,
brokerStatus: TestHelper.UnknownBrokerStatus(),
wantConditionStatus: corev1.ConditionUnknown,
}, {
name: "all sad",
markBrokerExists: &falseValue,
brokerStatus: nil,
wantConditionStatus: corev1.ConditionFalse,
}}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ets := &v1beta1.EventTypeStatus{}
if test.markBrokerExists != nil {
if *test.markBrokerExists {
ets.MarkBrokerExists()
} else {
ets.MarkBrokerDoesNotExist()
}
}
if test.brokerStatus != nil {
PropagateV1Alpha1BrokerStatus(ets, test.brokerStatus)
}

got := ets.GetTopLevelCondition().Status
if test.wantConditionStatus != got {
t.Errorf("unexpected readiness: want %v, got %v", test.wantConditionStatus, got)
}
})
}
}

// Since v1beta1 to v1alpha1 is lossy but semantically equivalent,
// fix that so diff works.
func fixBrokerDeprecated(in *Broker) *Broker {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/eventing/v1beta1/eventtype_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1beta1

import (
corev1 "k8s.io/api/core/v1"

"knative.dev/pkg/apis"
)

Expand Down
1 change: 1 addition & 0 deletions pkg/apis/eventing/v1beta1/eventtype_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
)

// +genclient
// +genreconciler
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type EventType struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/eventing/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Broker{},
&BrokerList{},
// &EventType{},
// &EventTypeList{},
&EventType{},
&EventTypeList{},
&Trigger{},
&TriggerList{},
)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading