Skip to content

Commit

Permalink
drop eventing/pkg/logger and use pkg/logger (#3964)
Browse files Browse the repository at this point in the history
* drop eventing/pkg/logger and use pkg/logger

* lint

* return valid mod file
  • Loading branch information
Scott Nichols authored Aug 31, 2020
1 parent a7223d8 commit 868a815
Show file tree
Hide file tree
Showing 23 changed files with 198 additions and 225 deletions.
10 changes: 5 additions & 5 deletions pkg/adapter/mtping/pingsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ import (
"fmt"
"sync"

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

"github.com/robfig/cron/v3"
"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"

"knative.dev/pkg/logging"
pkgreconciler "knative.dev/pkg/reconciler"

"knative.dev/eventing/pkg/apis/eventing"
"knative.dev/eventing/pkg/apis/sources/v1alpha2"
clientset "knative.dev/eventing/pkg/client/clientset/versioned"
pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource"
sourceslisters "knative.dev/eventing/pkg/client/listers/sources/v1alpha2"
"knative.dev/eventing/pkg/logging"
)

// Reconciler reconciles PingSources
Expand All @@ -57,7 +57,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSou
scope, ok := source.Annotations[eventing.ScopeAnnotationKey]
if ok && scope != eventing.ScopeCluster {
// Not our responsibility
logging.FromContext(ctx).Info("Skipping non-cluster-scoped PingSource", zap.Any("namespace", source.Namespace), zap.Any("name", source.Name))
logging.FromContext(ctx).Infow("Skipping non-cluster-scoped PingSource", zap.Any("namespace", source.Namespace), zap.Any("name", source.Name))
return nil
}

Expand All @@ -67,7 +67,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha2.PingSou

reconcileErr := r.reconcile(ctx, source)
if reconcileErr != nil {
logging.FromContext(ctx).Error("Error reconciling PingSource", zap.Error(reconcileErr))
logging.FromContext(ctx).Errorw("Error reconciling PingSource", zap.Error(reconcileErr))
} else {
logging.FromContext(ctx).Debug("PingSource reconciled")
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/adapter/mtping/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (
"time"

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

kubeclient "knative.dev/pkg/client/injection/kube/client"
_ "knative.dev/pkg/client/injection/kube/client/fake"
"knative.dev/pkg/logging"
rectesting "knative.dev/pkg/reconciler/testing"

adaptertesting "knative.dev/eventing/pkg/adapter/v2/test"
"knative.dev/eventing/pkg/logging"
)

const threeSecondsTillNextMinCronJob = 60 - 3
Expand Down Expand Up @@ -65,7 +66,7 @@ func TestAddRunRemoveSchedules(t *testing.T) {
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {
ctx, _ := rectesting.SetupFakeContext(t)
logger := logging.FromContext(ctx).Sugar()
logger := logging.FromContext(ctx)
ce := adaptertesting.NewTestClient()

runner := NewCronJobsRunner(ce, kubeclient.Get(ctx), logger)
Expand All @@ -92,7 +93,7 @@ func TestAddRunRemoveSchedules(t *testing.T) {

func TestUpdateConfigMap(t *testing.T) {
ctx, _ := rectesting.SetupFakeContext(t)
logger := logging.FromContext(ctx).Sugar()
logger := logging.FromContext(ctx)
ce := adaptertesting.NewTestClient()
runner := NewCronJobsRunner(ce, kubeclient.Get(ctx), logger)

Expand Down Expand Up @@ -183,7 +184,7 @@ func TestUpdateConfigMap(t *testing.T) {

func TestStartStopCron(t *testing.T) {
ctx, _ := rectesting.SetupFakeContext(t)
logger := logging.FromContext(ctx).Sugar()
logger := logging.FromContext(ctx)
ce := adaptertesting.NewTestClient()

runner := NewCronJobsRunner(ce, kubeclient.Get(ctx), logger)
Expand Down Expand Up @@ -213,7 +214,7 @@ func TestStartStopCronDelayWait(t *testing.T) {
time.Sleep(time.Second * 4) // ward off edge cases
}
ctx, _ := rectesting.SetupFakeContext(t)
logger := logging.FromContext(ctx).Sugar()
logger := logging.FromContext(ctx)
ce := adaptertesting.NewTestClientWithDelay(time.Second * 5)

runner := NewCronJobsRunner(ce, kubeclient.Get(ctx), logger)
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/sources/v1alpha1/sinkbinding_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package v1alpha1
import (
"context"
"encoding/json"
"fmt"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/eventing/pkg/logging"

"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/logging"
"knative.dev/pkg/tracker"
)

Expand Down Expand Up @@ -81,14 +81,14 @@ func (sb *SinkBinding) Do(ctx context.Context, ps *duckv1.WithPod) {

uri := GetSinkURI(ctx)
if uri == nil {
logging.FromContext(ctx).Error(fmt.Sprintf("No sink URI associated with context for %+v", sb))
logging.FromContext(ctx).Errorf("No sink URI associated with context for %+v", sb)
return
}

var ceOverrides string
if sb.Spec.CloudEventOverrides != nil {
if co, err := json.Marshal(sb.Spec.SourceSpec.CloudEventOverrides); err != nil {
logging.FromContext(ctx).Error(fmt.Sprintf("Failed to marshal CloudEventOverrides into JSON for %+v, %v", sb, err))
logging.FromContext(ctx).Errorf("Failed to marshal CloudEventOverrides into JSON for %+v, %v", sb, err)
} else if len(co) > 0 {
ceOverrides = string(co)
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/apis/sources/v1alpha2/sinkbinding_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ import (
"encoding/json"
"fmt"

"go.uber.org/zap"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/eventing/pkg/logging"

"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/logging"
"knative.dev/pkg/tracker"
)

Expand Down Expand Up @@ -86,14 +89,14 @@ func (sb *SinkBinding) Do(ctx context.Context, ps *duckv1.WithPod) {

uri := GetSinkURI(ctx)
if uri == nil {
logging.FromContext(ctx).Error(fmt.Sprintf("No sink URI associated with context for %+v", sb))
logging.FromContext(ctx).Errorf("No sink URI associated with context for %+v", sb)
return
}

var ceOverrides string
if sb.Spec.CloudEventOverrides != nil {
if co, err := json.Marshal(sb.Spec.SourceSpec.CloudEventOverrides); err != nil {
logging.FromContext(ctx).Error(fmt.Sprintf("Failed to marshal CloudEventOverrides into JSON for %+v, %v", sb, err))
logging.FromContext(ctx).Errorw(fmt.Sprintf("Failed to marshal CloudEventOverrides into JSON for %+v", sb), zap.Error(err))
} else if len(co) > 0 {
ceOverrides = string(co)
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/apis/sources/v1beta1/sinkbinding_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ import (
"encoding/json"
"fmt"

"go.uber.org/zap"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/eventing/pkg/logging"

"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/logging"
"knative.dev/pkg/tracker"
)

Expand Down Expand Up @@ -86,14 +89,14 @@ func (sb *SinkBinding) Do(ctx context.Context, ps *duckv1.WithPod) {

uri := GetSinkURI(ctx)
if uri == nil {
logging.FromContext(ctx).Error(fmt.Sprintf("No sink URI associated with context for %+v", sb))
logging.FromContext(ctx).Errorf("No sink URI associated with context for %+v", sb)
return
}

var ceOverrides string
if sb.Spec.CloudEventOverrides != nil {
if co, err := json.Marshal(sb.Spec.SourceSpec.CloudEventOverrides); err != nil {
logging.FromContext(ctx).Error(fmt.Sprintf("Failed to marshal CloudEventOverrides into JSON for %+v, %v", sb, err))
logging.FromContext(ctx).Errorw(fmt.Sprintf("Failed to marshal CloudEventOverrides into JSON for %+v", sb), zap.Error(err))
} else if len(co) > 0 {
ceOverrides = string(co)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/duck/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"

"knative.dev/eventing/pkg/logging"
duckapis "knative.dev/pkg/apis"
"knative.dev/pkg/logging"
)

// DomainToURL converts a domain into an HTTP URL.
Expand All @@ -56,7 +56,7 @@ func ResourceInterface(dynamicClient dynamic.Interface, namespace string, gvk sc
func ObjectReference(ctx context.Context, dynamicClient dynamic.Interface, namespace string, ref *corev1.ObjectReference) (json.Marshaler, error) {
resourceClient, err := ResourceInterface(dynamicClient, namespace, ref.GroupVersionKind())
if err != nil {
logging.FromContext(ctx).Warn("Failed to create dynamic resource client", zap.Error(err))
logging.FromContext(ctx).Warnw("Failed to create dynamic resource client", zap.Error(err))
return nil, err
}

Expand Down
38 changes: 0 additions & 38 deletions pkg/logging/logging.go

This file was deleted.

8 changes: 4 additions & 4 deletions pkg/reconciler/apiserversource/apiserversource.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import (

duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/controller"
"knative.dev/pkg/logging"
pkgreconciler "knative.dev/pkg/reconciler"
"knative.dev/pkg/resolver"

"knative.dev/eventing/pkg/apis/sources/v1beta1"
apiserversourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/apiserversource"
"knative.dev/eventing/pkg/logging"
"knative.dev/eventing/pkg/reconciler/apiserversource/resources"
reconcilersource "knative.dev/eventing/pkg/reconciler/source"
"knative.dev/eventing/pkg/utils"
Expand Down Expand Up @@ -101,13 +101,13 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1beta1.ApiServe

err = r.runAccessCheck(source)
if err != nil {
logging.FromContext(ctx).Error("Not enough permission", zap.Error(err))
logging.FromContext(ctx).Errorw("Not enough permission", zap.Error(err))
return err
}

ra, err := r.createReceiveAdapter(ctx, source, sinkURI.String())
if err != nil {
logging.FromContext(ctx).Error("Unable to create the receive adapter", zap.Error(err))
logging.FromContext(ctx).Errorw("Unable to create the receive adapter", zap.Error(err))
return err
}
source.Status.PropagateDeploymentAvailability(ra)
Expand Down Expand Up @@ -165,7 +165,7 @@ func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1beta1.ApiS
controller.GetEventRecorder(ctx).Eventf(src, corev1.EventTypeNormal, apiserversourceDeploymentUpdated, "Deployment %q updated", ra.Name)
return ra, nil
} else {
logging.FromContext(ctx).Debug("Reusing existing receive adapter", zap.Any("receiveAdapter", ra))
logging.FromContext(ctx).Debugw("Reusing existing receive adapter", zap.Any("receiveAdapter", ra))
}
return ra, nil
}
Expand Down
19 changes: 10 additions & 9 deletions pkg/reconciler/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import (
channelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1/channel"
listers "knative.dev/eventing/pkg/client/listers/messaging/v1"
eventingduck "knative.dev/eventing/pkg/duck"
"knative.dev/eventing/pkg/logging"
"knative.dev/eventing/pkg/reconciler/channel/resources"
duckapis "knative.dev/pkg/apis/duck"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/logging"
pkgreconciler "knative.dev/pkg/reconciler"
)

Expand Down Expand Up @@ -124,9 +124,10 @@ func (r *Reconciler) getChannelableStatus(ctx context.Context, bc *duckv1alpha1.

// reconcileBackingChannel reconciles Channel's 'c' underlying CRD channel.
func (r *Reconciler) reconcileBackingChannel(ctx context.Context, channelResourceInterface dynamic.ResourceInterface, c *v1.Channel, backingChannelObjRef duckv1.KReference) (*duckv1alpha1.ChannelableCombined, error) {
logger := logging.FromContext(ctx)
lister, err := r.channelableTracker.ListerForKReference(backingChannelObjRef)
if err != nil {
logging.FromContext(ctx).Error("Error getting lister for Channel", zap.Any("backingChannel", backingChannelObjRef), zap.Error(err))
logger.Errorw("Error getting lister for Channel", zap.Any("backingChannel", backingChannelObjRef), zap.Error(err))
return nil, err
}
backingChannel, err := lister.ByNamespace(backingChannelObjRef.Namespace).Get(backingChannelObjRef.Name)
Expand All @@ -135,29 +136,29 @@ func (r *Reconciler) reconcileBackingChannel(ctx context.Context, channelResourc
if apierrs.IsNotFound(err) {
newBackingChannel, err := resources.NewChannel(c)
if err != nil {
logging.FromContext(ctx).Error("Failed to create Channel from ChannelTemplate", zap.Any("channelTemplate", c.Spec.ChannelTemplate), zap.Error(err))
logger.Errorw("Failed to create Channel from ChannelTemplate", zap.Any("channelTemplate", c.Spec.ChannelTemplate), zap.Error(err))
return nil, err
}
logging.FromContext(ctx).Debug(fmt.Sprintf("Creating Channel Object: %+v", newBackingChannel))
logger.Debugf("Creating Channel Object: %+v", newBackingChannel)
created, err := channelResourceInterface.Create(newBackingChannel, metav1.CreateOptions{})
if err != nil {
logging.FromContext(ctx).Error("Failed to create backing Channel", zap.Any("backingChannel", newBackingChannel), zap.Error(err))
logger.Errorw("Failed to create backing Channel", zap.Any("backingChannel", newBackingChannel), zap.Error(err))
return nil, err
}
logging.FromContext(ctx).Debug("Created backing Channel", zap.Any("backingChannel", newBackingChannel))
logger.Debug("Created backing Channel", zap.Any("backingChannel", newBackingChannel))
channelable := &duckv1alpha1.ChannelableCombined{}
err = duckapis.FromUnstructured(created, channelable)
if err != nil {
logging.FromContext(ctx).Error("Failed to convert to Channelable Object", zap.Any("backingChannel", backingChannelObjRef), zap.Any("createdChannel", created), zap.Error(err))
logger.Errorw("Failed to convert to Channelable Object", zap.Any("backingChannel", backingChannelObjRef), zap.Any("createdChannel", created), zap.Error(err))
return nil, err

}
return channelable, nil
}
logging.FromContext(ctx).Info("Failed to get backing Channel", zap.Any("backingChannel", backingChannelObjRef), zap.Error(err))
logger.Infow("Failed to get backing Channel", zap.Any("backingChannel", backingChannelObjRef), zap.Error(err))
return nil, err
}
logging.FromContext(ctx).Debug("Found backing Channel", zap.Any("backingChannel", backingChannelObjRef))
logger.Debugw("Found backing Channel", zap.Any("backingChannel", backingChannelObjRef))
channelable, ok := backingChannel.(*duckv1alpha1.ChannelableCombined)
if !ok {
return nil, fmt.Errorf("Failed to convert to Channelable Object %+v", backingChannel)
Expand Down
10 changes: 5 additions & 5 deletions pkg/reconciler/containersource/containersource.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
clientset "knative.dev/eventing/pkg/client/clientset/versioned"
"knative.dev/eventing/pkg/client/injection/reconciler/sources/v1beta1/containersource"
listers "knative.dev/eventing/pkg/client/listers/sources/v1beta1"
"knative.dev/eventing/pkg/logging"
"knative.dev/eventing/pkg/reconciler/containersource/resources"
"knative.dev/pkg/controller"
"knative.dev/pkg/logging"
pkgreconciler "knative.dev/pkg/reconciler"
)

Expand Down Expand Up @@ -72,13 +72,13 @@ var _ containersource.Interface = (*Reconciler)(nil)
func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1beta1.ContainerSource) pkgreconciler.Event {
_, err := r.reconcileSinkBinding(ctx, source)
if err != nil {
logging.FromContext(ctx).Error("Error reconciling SinkBinding", zap.Error(err))
logging.FromContext(ctx).Errorw("Error reconciling SinkBinding", zap.Error(err))
return err
}

_, err = r.reconcileReceiveAdapter(ctx, source)
if err != nil {
logging.FromContext(ctx).Error("Error reconciling ReceiveAdapter", zap.Error(err))
logging.FromContext(ctx).Errorw("Error reconciling ReceiveAdapter", zap.Error(err))
return err
}

Expand Down Expand Up @@ -108,7 +108,7 @@ func (r *Reconciler) reconcileReceiveAdapter(ctx context.Context, source *v1beta
}
controller.GetEventRecorder(ctx).Eventf(source, corev1.EventTypeNormal, deploymentUpdated, "Deployment updated %q", ra.Name)
} else {
logging.FromContext(ctx).Debug("Reusing existing Deployment", zap.Any("Deployment", ra))
logging.FromContext(ctx).Debugw("Reusing existing Deployment", zap.Any("Deployment", ra))
}

source.Status.PropagateReceiveAdapterStatus(ra)
Expand Down Expand Up @@ -138,7 +138,7 @@ func (r *Reconciler) reconcileSinkBinding(ctx context.Context, source *v1beta1.C
}
controller.GetEventRecorder(ctx).Eventf(source, corev1.EventTypeNormal, sinkBindingUpdated, "SinkBinding updated %q", sb.Name)
} else {
logging.FromContext(ctx).Debug("Reusing existing SinkBinding", zap.Any("SinkBinding", sb))
logging.FromContext(ctx).Debugw("Reusing existing SinkBinding", zap.Any("SinkBinding", sb))
}

source.Status.PropagateSinkBindingStatus(&sb.Status)
Expand Down
Loading

0 comments on commit 868a815

Please sign in to comment.