Skip to content

Commit

Permalink
add const for channel address status annotation key; prefix this key …
Browse files Browse the repository at this point in the history
…with knative.dev/ (#3684)
  • Loading branch information
tommyreddad authored Jul 23, 2020
1 parent c281fc0 commit 82399b8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/eventing/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const (
// EventTypesAnnotationKey is the annotation key to specify
// if a Source has event types defines in its CRD.
EventTypesAnnotationKey = "registry.knative.dev/eventTypes"

// BrokerChannelAddressStatusAnnotationKey is the broker status
// annotation key used to specify the address of its channel.
BrokerChannelAddressStatusAnnotationKey = "knative.dev/channelAddress"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/eventing/v1beta1/broker_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/utils/pointer"
eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1"
eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1"
"knative.dev/eventing/pkg/apis/eventing"
v1 "knative.dev/eventing/pkg/apis/eventing/v1"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
Expand Down Expand Up @@ -112,7 +113,7 @@ func TestBrokerConversionRoundTripV1beta1(t *testing.T) {
Status: "True",
}},
Annotations: map[string]string{
"channelAddress": "http://foo.bar.svc.cluster.local/",
eventing.BrokerChannelAddressStatusAnnotationKey: "http://foo.bar.svc.cluster.local/",
},
},
Address: duckv1.Addressable{
Expand Down Expand Up @@ -200,7 +201,7 @@ func TestBrokerConversionRoundTripV1(t *testing.T) {
Status: "True",
}},
Annotations: map[string]string{
"channelAddress": "http://foo.bar.svc.cluster.local/",
eventing.BrokerChannelAddressStatusAnnotationKey: "http://foo.bar.svc.cluster.local/",
},
},
Address: duckv1.Addressable{
Expand Down
3 changes: 2 additions & 1 deletion pkg/mtbroker/ingress/ingress_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"go.uber.org/zap"
"k8s.io/apimachinery/pkg/types"

"knative.dev/eventing/pkg/apis/eventing"
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
eventinglisters "knative.dev/eventing/pkg/client/listers/eventing/v1"
"knative.dev/eventing/pkg/health"
Expand Down Expand Up @@ -87,7 +88,7 @@ func (h *Handler) getChannelAddress(name, namespace string) (string, error) {
if broker.Status.Annotations == nil {
return "", fmt.Errorf("Broker status annotations uninitialized")
}
address, present := broker.Status.Annotations["channelAddress"]
address, present := broker.Status.Annotations[eventing.BrokerChannelAddressStatusAnnotationKey]
if !present {
return "", fmt.Errorf("Channel address not found in broker status annotations")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/mtbroker/ingress/ingress_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"go.uber.org/zap"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"knative.dev/eventing/pkg/apis/eventing"
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
broker "knative.dev/eventing/pkg/mtbroker"
reconcilertestingv1 "knative.dev/eventing/pkg/reconciler/testing/v1"
Expand Down Expand Up @@ -208,7 +209,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
if b.Status.Annotations == nil {
b.Status.Annotations = make(map[string]string, 1)
}
b.Status.Annotations["channelAddress"] = s.URL
b.Status.Annotations[eventing.BrokerChannelAddressStatusAnnotationKey] = s.URL
annotatedBrokers = append(annotatedBrokers, b)
}
listers := reconcilertestingv1.NewListers(annotatedBrokers)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/mtbroker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (r *Reconciler) reconcileKind(ctx context.Context, b *eventingv1.Broker) (*
if b.Status.Annotations == nil {
b.Status.Annotations = make(map[string]string, 1)
}
b.Status.Annotations["channelAddress"] = triggerChan.Status.Address.URL.String()
b.Status.Annotations[eventing.BrokerChannelAddressStatusAnnotationKey] = triggerChan.Status.Address.URL.String()

channelStatus := &duckv1.ChannelableStatus{AddressStatus: pkgduckv1.AddressStatus{Address: &pkgduckv1.Addressable{URL: triggerChan.Status.Address.URL}}}
b.Status.PropagateTriggerChannelReadiness(channelStatus)
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/testing/v1/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/eventing/pkg/apis/eventing"
v1 "knative.dev/eventing/pkg/apis/eventing/v1"
"knative.dev/eventing/pkg/client/injection/reconciler/eventing/v1/broker"
"knative.dev/pkg/apis"
Expand Down Expand Up @@ -180,6 +181,6 @@ func WithChannelAddressAnnotation(address string) BrokerOption {
if b.Status.Annotations == nil {
b.Status.Annotations = make(map[string]string, 1)
}
b.Status.Annotations["channelAddress"] = address
b.Status.Annotations[eventing.BrokerChannelAddressStatusAnnotationKey] = address
}
}

0 comments on commit 82399b8

Please sign in to comment.