diff --git a/prometheus/pkg/reconciler/controller.go b/prometheus/pkg/reconciler/controller.go index 7c627f8156..0bd82cac0d 100644 --- a/prometheus/pkg/reconciler/controller.go +++ b/prometheus/pkg/reconciler/controller.go @@ -21,20 +21,18 @@ import ( "k8s.io/client-go/tools/cache" "knative.dev/eventing-contrib/prometheus/pkg/apis/sources/v1alpha1" - "knative.dev/eventing/pkg/reconciler" - deploymentinformer "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" + "knative.dev/pkg/logging" "knative.dev/pkg/resolver" prometheusinformer "knative.dev/eventing-contrib/prometheus/pkg/client/injection/informers/sources/v1alpha1/prometheussource" promreconciler "knative.dev/eventing-contrib/prometheus/pkg/client/injection/reconciler/sources/v1alpha1/prometheussource" + kubeclient "knative.dev/pkg/client/injection/kube/client" + deploymentinformer "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment" ) const ( - // ReconcilerName is the name of the reconciler - ReconcilerName = "PrometheusSource" - // controllerAgentName is the string used by this controller to identify // itself when creating events. controllerAgentName = "prometheus-source-controller" @@ -50,13 +48,13 @@ func NewController( prometheusSourceInformer := prometheusinformer.Get(ctx) r := &Reconciler{ - Base: reconciler.NewBase(ctx, controllerAgentName, cmw), + kubeClientSet: kubeclient.Get(ctx), deploymentLister: deploymentInformer.Lister(), } impl := promreconciler.NewImpl(ctx, r) r.sinkResolver = resolver.NewURIResolver(ctx, impl.EnqueueKey) - r.Logger.Info("Setting up event handlers") + logging.FromContext(ctx).Info("Setting up event handlers") prometheusSourceInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) deploymentInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ diff --git a/prometheus/pkg/reconciler/prometheussource.go b/prometheus/pkg/reconciler/prometheussource.go index 84ebd366c2..542940ad1c 100644 --- a/prometheus/pkg/reconciler/prometheussource.go +++ b/prometheus/pkg/reconciler/prometheussource.go @@ -20,8 +20,8 @@ import ( "context" "fmt" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" + "k8s.io/client-go/kubernetes" + "knative.dev/pkg/controller" "github.com/kelseyhightower/envconfig" "github.com/robfig/cron" @@ -35,8 +35,9 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" appsv1listers "k8s.io/client-go/listers/apps/v1" "knative.dev/eventing-contrib/prometheus/pkg/reconciler/resources" - "knative.dev/eventing/pkg/logging" - "knative.dev/eventing/pkg/reconciler" + "knative.dev/pkg/apis" + duckv1 "knative.dev/pkg/apis/duck/v1" + "knative.dev/pkg/logging" pkgreconciler "knative.dev/pkg/reconciler" "knative.dev/pkg/resolver" @@ -56,7 +57,7 @@ type envConfig struct { // Reconciler reconciles a PrometheusSource object type Reconciler struct { - *reconciler.Base + kubeClientSet kubernetes.Interface receiveAdapterImage string @@ -102,7 +103,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, source *v1alpha1.Prometh ra, err := r.createReceiveAdapter(ctx, source, sinkURI) if err != nil { - r.Logger.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 } // Update source status// Update source status @@ -122,7 +123,7 @@ func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1alpha1.Pro env := &envConfig{} if err := envconfig.Process("", env); err != nil { - r.Logger.Panicf("required environment variable is not defined: %v", err) + logging.FromContext(ctx).Panicf("required environment variable is not defined: %v", err) } adapterArgs := resources.ReceiveAdapterArgs{ @@ -134,10 +135,10 @@ func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1alpha1.Pro } expected := resources.MakeReceiveAdapter(&adapterArgs) - ra, err := r.KubeClientSet.AppsV1().Deployments(src.Namespace).Get(expected.Name, metav1.GetOptions{}) + ra, err := r.kubeClientSet.AppsV1().Deployments(src.Namespace).Get(expected.Name, metav1.GetOptions{}) if apierrors.IsNotFound(err) { - ra, err = r.KubeClientSet.AppsV1().Deployments(src.Namespace).Create(expected) - r.Recorder.Eventf(src, corev1.EventTypeNormal, prometheussourceDeploymentCreated, "Deployment created, error: %v", err) + ra, err = r.kubeClientSet.AppsV1().Deployments(src.Namespace).Create(expected) + controller.GetEventRecorder(ctx).Eventf(src, corev1.EventTypeNormal, prometheussourceDeploymentCreated, "Deployment created, error: %v", err) return ra, err } else if err != nil { return nil, fmt.Errorf("error getting receive adapter: %v", err) @@ -145,10 +146,10 @@ func (r *Reconciler) createReceiveAdapter(ctx context.Context, src *v1alpha1.Pro return nil, fmt.Errorf("deployment %q is not owned by PrometheusSource %q", ra.Name, src.Name) } else if r.podSpecChanged(ra.Spec.Template.Spec, expected.Spec.Template.Spec) { ra.Spec.Template.Spec = expected.Spec.Template.Spec - if ra, err = r.KubeClientSet.AppsV1().Deployments(src.Namespace).Update(ra); err != nil { + if ra, err = r.kubeClientSet.AppsV1().Deployments(src.Namespace).Update(ra); err != nil { return ra, err } - r.Recorder.Eventf(src, corev1.EventTypeNormal, prometheussourceDeploymentUpdated, "Deployment updated") + controller.GetEventRecorder(ctx).Eventf(src, corev1.EventTypeNormal, prometheussourceDeploymentUpdated, "Deployment updated") return ra, nil } else { logging.FromContext(ctx).Debug("Reusing existing receive adapter", zap.Any("receiveAdapter", ra))