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

Emitting corev1 Events for debugging purposes #746

Merged
merged 12 commits into from
Jan 25, 2019
Merged
5 changes: 0 additions & 5 deletions config/provisioners/in-memory-channel/in-memory-channel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,7 @@ rules:
resources:
- events
verbs:
nachocano marked this conversation as resolved.
Show resolved Hide resolved
- get
- list
- watch
- create
- update
- patch

---

Expand Down
2 changes: 1 addition & 1 deletion hack/boilerplate/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018 The Knative Authors
Copyright 2019 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.
Expand Down
6 changes: 2 additions & 4 deletions pkg/controller/eventing/inmemory/channel/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const (

// Name of the corev1.Events emitted from the reconciliation process
channelReconciled = "ChannelReconciled"
channelReconcileFailed = "ChannelReconcileFailed"
channelUpdateStatusFailed = "ChannelUpdateStatusFailed"
channelConfigSyncFailed = "ChannelConfigSyncFailed"
k8sServiceCreateFailed = "K8sServiceCreateFailed"
Expand Down Expand Up @@ -99,7 +98,6 @@ func (r *reconciler) Reconcile(request reconcile.Request) (reconcile.Result, err
err = r.reconcile(ctx, c)
if err != nil {
logger.Info("Error reconciling Channel", zap.Error(err))
r.recorder.Eventf(c, corev1.EventTypeWarning, channelReconcileFailed, "Failed to reconcile Channel: %v", err)
// Note that we do not return the error here, because we want to update the Status
// regardless of the error.
} else {
Expand Down Expand Up @@ -154,15 +152,15 @@ func (r *reconciler) reconcile(ctx context.Context, c *eventingv1alpha1.Channel)
svc, err := util.CreateK8sService(ctx, r.client, c)
if err != nil {
logger.Info("Error creating the Channel's K8s Service", zap.Error(err))
r.recorder.Eventf(c, corev1.EventTypeWarning, k8sServiceCreateFailed, "Failed to create Channel's K8s Service: %v", err)
r.recorder.Eventf(c, corev1.EventTypeWarning, k8sServiceCreateFailed, "Failed to reconcile Channel's K8s Service: %v", err)
return err
}
c.Status.SetAddress(controller.ServiceHostName(svc.Name, svc.Namespace))

_, err = util.CreateVirtualService(ctx, r.client, c, svc)
if err != nil {
logger.Info("Error creating the Virtual Service for the Channel", zap.Error(err))
r.recorder.Eventf(c, corev1.EventTypeWarning, virtualServiceCreateFailed, "Failed to create Virtual Service for the Channel: %v", err)
r.recorder.Eventf(c, corev1.EventTypeWarning, virtualServiceCreateFailed, "Failed to reconcile Virtual Service for the Channel: %v", err)
return err
}

Expand Down
19 changes: 9 additions & 10 deletions pkg/controller/eventing/inmemory/channel/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ var (

// map of events to set test cases' expectations easier
events = map[string]corev1.Event{
channelReconcileFailed: {Reason: channelReconcileFailed, Type: corev1.EventTypeWarning},
channelReconciled: {Reason: channelReconciled, Type: corev1.EventTypeNormal},
channelUpdateStatusFailed: {Reason: channelUpdateStatusFailed, Type: corev1.EventTypeWarning},
channelConfigSyncFailed: {Reason: channelConfigSyncFailed, Type: corev1.EventTypeWarning},
Expand Down Expand Up @@ -262,7 +261,7 @@ func TestReconcile(t *testing.T) {
},
WantErrMsg: testErrorMessage,
WantEvent: []corev1.Event{
events[channelConfigSyncFailed], events[channelReconcileFailed],
events[channelConfigSyncFailed],
},
},
{
Expand All @@ -287,7 +286,7 @@ func TestReconcile(t *testing.T) {
},
WantErrMsg: testErrorMessage,
WantEvent: []corev1.Event{
events[channelConfigSyncFailed], events[channelReconcileFailed],
events[channelConfigSyncFailed],
},
},
{
Expand All @@ -300,7 +299,7 @@ func TestReconcile(t *testing.T) {
},
WantErrMsg: testErrorMessage,
WantEvent: []corev1.Event{
events[channelConfigSyncFailed], events[channelReconcileFailed],
events[channelConfigSyncFailed],
},
},
{
Expand All @@ -313,7 +312,7 @@ func TestReconcile(t *testing.T) {
},
WantErrMsg: testErrorMessage,
WantEvent: []corev1.Event{
events[channelConfigSyncFailed], events[channelReconcileFailed],
events[channelConfigSyncFailed],
},
},
{
Expand All @@ -327,7 +326,7 @@ func TestReconcile(t *testing.T) {
},
WantErrMsg: testErrorMessage,
WantEvent: []corev1.Event{
events[channelConfigSyncFailed], events[channelReconcileFailed],
events[channelConfigSyncFailed],
},
},
{
Expand All @@ -344,7 +343,7 @@ func TestReconcile(t *testing.T) {
},
WantErrMsg: testErrorMessage,
WantEvent: []corev1.Event{
events[k8sServiceCreateFailed], events[channelReconcileFailed],
events[k8sServiceCreateFailed],
},
},
{
Expand All @@ -362,7 +361,7 @@ func TestReconcile(t *testing.T) {
},
WantErrMsg: testErrorMessage,
WantEvent: []corev1.Event{
events[k8sServiceCreateFailed], events[channelReconcileFailed],
events[k8sServiceCreateFailed],
},
},
{
Expand All @@ -383,7 +382,7 @@ func TestReconcile(t *testing.T) {
},
WantErrMsg: testErrorMessage,
WantEvent: []corev1.Event{
events[virtualServiceCreateFailed], events[channelReconcileFailed],
events[virtualServiceCreateFailed],
},
},
{
Expand All @@ -403,7 +402,7 @@ func TestReconcile(t *testing.T) {
},
WantErrMsg: testErrorMessage,
WantEvent: []corev1.Event{
events[virtualServiceCreateFailed], events[channelReconcileFailed],
events[virtualServiceCreateFailed],
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const (

// Name of the corev1.Events emitted from the reconciliation process
ccpReconciled = "CcpReconciled"
ccpReconcileFailed = "CcpReconcileFailed"
ccpUpdateStatusFailed = "CcpUpdateStatusFailed"
k8sServiceCreateFailed = "K8sServiceCreateFailed"
k8sServiceDeleteFailed = "K8sServiceDeleteFailed"
Expand Down Expand Up @@ -103,7 +102,6 @@ func (r *reconciler) Reconcile(request reconcile.Request) (reconcile.Result, err
err = r.reconcile(ctx, ccp)
if err != nil {
logger.Info("Error reconciling ClusterChannelProvisioner", zap.Error(err))
r.recorder.Eventf(ccp, corev1.EventTypeWarning, ccpReconcileFailed, "Failed to reconcile ClusterChannelProvisioner: %v", err)
// Note that we do not return the error here, because we want to update the Status
// regardless of the error.
} else {
Expand Down Expand Up @@ -152,7 +150,7 @@ func (r *reconciler) reconcile(ctx context.Context, ccp *eventingv1alpha1.Cluste

if err != nil {
logger.Info("Error creating the ClusterChannelProvisioner's K8s Service", zap.Error(err))
r.recorder.Eventf(ccp, corev1.EventTypeWarning, k8sServiceCreateFailed, "Failed to create ClusterChannelProvisioner's K8s Service: %v", err)
r.recorder.Eventf(ccp, corev1.EventTypeWarning, k8sServiceCreateFailed, "Failed to reconcile ClusterChannelProvisioner's K8s Service: %v", err)
return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var (
// map of events to set test cases' expectations easier
events = map[string]corev1.Event{
ccpReconciled: {Reason: ccpReconciled, Type: corev1.EventTypeNormal},
ccpReconcileFailed: {Reason: ccpReconcileFailed, Type: corev1.EventTypeWarning},
ccpUpdateStatusFailed: {Reason: ccpUpdateStatusFailed, Type: corev1.EventTypeWarning},
k8sServiceCreateFailed: {Reason: k8sServiceCreateFailed, Type: corev1.EventTypeWarning},
k8sServiceDeleteFailed: {Reason: k8sServiceDeleteFailed, Type: corev1.EventTypeWarning},
Expand Down Expand Up @@ -180,7 +179,7 @@ func TestReconcile(t *testing.T) {
},
WantErrMsg: testErrorMessage,
WantEvent: []corev1.Event{
events[k8sServiceCreateFailed], events[ccpReconcileFailed],
events[k8sServiceCreateFailed],
},
},
{
Expand Down
10 changes: 4 additions & 6 deletions pkg/controller/eventing/subscription/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ const (

// Name of the corev1.Events emitted from the reconciliation process
subscriptionReconciled = "SubscriptionReconciled"
subscriptionReconcileFailed = "SubscriptionReconcileFailed"
subscriptionUpdateStatusFailed = "SubscriptionUpdateStatusFailed"
physicalChannelSyncFailed = "PhysicalChannelSyncFailed"
objectReferenceFetchFailed = "ObjectReferenceFetchFailed"
channelReferenceFetchFailed = "ChannelReferenceFetchFailed"
subscriberResolveFailed = "SubscriberResolveFailed"
resultResolveFailed = "ResultResolveFailed"
)
Expand Down Expand Up @@ -76,7 +75,6 @@ func (r *reconciler) Reconcile(request reconcile.Request) (reconcile.Result, err
err = r.reconcile(subscription)
if err != nil {
glog.Warningf("Error reconciling Subscription: %v", err)
r.recorder.Eventf(subscription, corev1.EventTypeWarning, subscriptionReconcileFailed, "Failed to reconcile Subscription: %v", err)
} else {
glog.Info("Subscription reconciled")
r.recorder.Eventf(subscription, corev1.EventTypeNormal, subscriptionReconciled, "Subscription reconciled: %q", subscription.Name)
Expand Down Expand Up @@ -123,13 +121,13 @@ func (r *reconciler) reconcile(subscription *v1alpha1.Subscription) error {
_, err = r.fetchObjectReference(subscription.Namespace, &subscription.Spec.Channel)
if err != nil {
glog.Warningf("Failed to validate `channel` exists: %+v, %v", subscription.Spec.Channel, err)
r.recorder.Eventf(subscription, corev1.EventTypeWarning, objectReferenceFetchFailed, "Failed to validate Channel exists: %v", err)
r.recorder.Eventf(subscription, corev1.EventTypeWarning, channelReferenceFetchFailed, "Failed to validate spec.channel exists: %v", err)
return err
}

if subscriberURI, err := r.resolveSubscriberSpec(subscription.Namespace, subscription.Spec.Subscriber); err != nil {
glog.Warningf("Failed to resolve Subscriber %+v : %s", *subscription.Spec.Subscriber, err)
r.recorder.Eventf(subscription, corev1.EventTypeWarning, subscriberResolveFailed, "Failed to resolve Subscriber: %v", err)
r.recorder.Eventf(subscription, corev1.EventTypeWarning, subscriberResolveFailed, "Failed to resolve spec.subscriber: %v", err)
return err
} else {
subscription.Status.PhysicalSubscription.SubscriberURI = subscriberURI
Expand All @@ -138,7 +136,7 @@ func (r *reconciler) reconcile(subscription *v1alpha1.Subscription) error {

if replyURI, err := r.resolveResult(subscription.Namespace, subscription.Spec.Reply); err != nil {
glog.Warningf("Failed to resolve Result %v : %v", subscription.Spec.Reply, err)
r.recorder.Eventf(subscription, corev1.EventTypeWarning, resultResolveFailed, "Failed to resolve Result: %v", err)
r.recorder.Eventf(subscription, corev1.EventTypeWarning, resultResolveFailed, "Failed to resolve spec.reply: %v", err)
return err
} else {
subscription.Status.PhysicalSubscription.ReplyURI = replyURI
Expand Down
Loading