From 20983fb0a6d715ba4e646d0c8a9073118c98372b Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Wed, 20 May 2020 13:06:12 +0100 Subject: [PATCH] Move events to a common package Move both events.go and the cloudevents module under a new module reconciler.events. We want to the controllers to be able to emit both kubernetes events and cloudevents, so this change is in preparation to creating a common event interface to be used by controllers. Partially addresses #2082 --- .../cloudevent/cloud_event_controller.go | 0 .../cloudevent/cloud_event_controller_test.go | 0 .../cloudevent/cloudevent.go | 0 .../cloudevent/cloudevent_test.go | 0 .../cloudevent/cloudeventclient.go | 0 .../cloudevent/cloudeventsfakeclient.go | 0 pkg/reconciler/events/doc.go | 21 +++++++++++++++++++ pkg/reconciler/{ => events}/event.go | 2 +- pkg/reconciler/{ => events}/event_test.go | 2 +- pkg/reconciler/pipelinerun/pipelinerun.go | 5 +++-- pkg/reconciler/taskrun/controller.go | 2 +- pkg/reconciler/taskrun/taskrun.go | 9 ++++---- pkg/reconciler/taskrun/taskrun_test.go | 2 +- 13 files changed, 33 insertions(+), 10 deletions(-) rename pkg/reconciler/{taskrun/resources => events}/cloudevent/cloud_event_controller.go (100%) rename pkg/reconciler/{taskrun/resources => events}/cloudevent/cloud_event_controller_test.go (100%) rename pkg/reconciler/{taskrun/resources => events}/cloudevent/cloudevent.go (100%) rename pkg/reconciler/{taskrun/resources => events}/cloudevent/cloudevent_test.go (100%) rename pkg/reconciler/{taskrun/resources => events}/cloudevent/cloudeventclient.go (100%) rename pkg/reconciler/{taskrun/resources => events}/cloudevent/cloudeventsfakeclient.go (100%) create mode 100644 pkg/reconciler/events/doc.go rename pkg/reconciler/{ => events}/event.go (99%) rename pkg/reconciler/{ => events}/event_test.go (99%) diff --git a/pkg/reconciler/taskrun/resources/cloudevent/cloud_event_controller.go b/pkg/reconciler/events/cloudevent/cloud_event_controller.go similarity index 100% rename from pkg/reconciler/taskrun/resources/cloudevent/cloud_event_controller.go rename to pkg/reconciler/events/cloudevent/cloud_event_controller.go diff --git a/pkg/reconciler/taskrun/resources/cloudevent/cloud_event_controller_test.go b/pkg/reconciler/events/cloudevent/cloud_event_controller_test.go similarity index 100% rename from pkg/reconciler/taskrun/resources/cloudevent/cloud_event_controller_test.go rename to pkg/reconciler/events/cloudevent/cloud_event_controller_test.go diff --git a/pkg/reconciler/taskrun/resources/cloudevent/cloudevent.go b/pkg/reconciler/events/cloudevent/cloudevent.go similarity index 100% rename from pkg/reconciler/taskrun/resources/cloudevent/cloudevent.go rename to pkg/reconciler/events/cloudevent/cloudevent.go diff --git a/pkg/reconciler/taskrun/resources/cloudevent/cloudevent_test.go b/pkg/reconciler/events/cloudevent/cloudevent_test.go similarity index 100% rename from pkg/reconciler/taskrun/resources/cloudevent/cloudevent_test.go rename to pkg/reconciler/events/cloudevent/cloudevent_test.go diff --git a/pkg/reconciler/taskrun/resources/cloudevent/cloudeventclient.go b/pkg/reconciler/events/cloudevent/cloudeventclient.go similarity index 100% rename from pkg/reconciler/taskrun/resources/cloudevent/cloudeventclient.go rename to pkg/reconciler/events/cloudevent/cloudeventclient.go diff --git a/pkg/reconciler/taskrun/resources/cloudevent/cloudeventsfakeclient.go b/pkg/reconciler/events/cloudevent/cloudeventsfakeclient.go similarity index 100% rename from pkg/reconciler/taskrun/resources/cloudevent/cloudeventsfakeclient.go rename to pkg/reconciler/events/cloudevent/cloudeventsfakeclient.go diff --git a/pkg/reconciler/events/doc.go b/pkg/reconciler/events/doc.go new file mode 100644 index 00000000000..1a60711b227 --- /dev/null +++ b/pkg/reconciler/events/doc.go @@ -0,0 +1,21 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package events defines the interface and different implementations for events +// +// Tekton uses events to notify about changes in Condition of resources, like a +// TaskRun is starting, a PipelineRun failed to run or could not be validated. +package events diff --git a/pkg/reconciler/event.go b/pkg/reconciler/events/event.go similarity index 99% rename from pkg/reconciler/event.go rename to pkg/reconciler/events/event.go index 85e04d60da0..c1f83162449 100644 --- a/pkg/reconciler/event.go +++ b/pkg/reconciler/events/event.go @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package reconciler +package events import ( corev1 "k8s.io/api/core/v1" diff --git a/pkg/reconciler/event_test.go b/pkg/reconciler/events/event_test.go similarity index 99% rename from pkg/reconciler/event_test.go rename to pkg/reconciler/events/event_test.go index f535ccb97ee..be0e345a69f 100644 --- a/pkg/reconciler/event_test.go +++ b/pkg/reconciler/events/event_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package reconciler +package events import ( "errors" diff --git a/pkg/reconciler/pipelinerun/pipelinerun.go b/pkg/reconciler/pipelinerun/pipelinerun.go index 9b595f46fcf..30e22d13f3c 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun.go +++ b/pkg/reconciler/pipelinerun/pipelinerun.go @@ -36,6 +36,7 @@ import ( resourcelisters "github.com/tektoncd/pipeline/pkg/client/resource/listers/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/contexts" "github.com/tektoncd/pipeline/pkg/reconciler" + "github.com/tektoncd/pipeline/pkg/reconciler/events" "github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag" "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun" @@ -196,7 +197,7 @@ func (c *Reconciler) Reconcile(ctx context.Context, key string) error { before := pr.Status.GetCondition(apis.ConditionSucceeded) merr = multierror.Append(merr, cancelPipelineRun(c.Logger, pr, c.PipelineClientSet)) after := pr.Status.GetCondition(apis.ConditionSucceeded) - reconciler.EmitEvent(c.Recorder, before, after, pr) + events.EmitEvent(c.Recorder, before, after, pr) default: if err := c.tracker.Track(pr.GetTaskRunRef(), pr); err != nil { c.Logger.Errorf("Failed to create tracker for TaskRuns for PipelineRun %s: %v", pr.Name, err) @@ -605,7 +606,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun) err before := pr.Status.GetCondition(apis.ConditionSucceeded) after := resources.GetPipelineConditionStatus(pr, pipelineState, c.Logger, d) pr.Status.SetCondition(after) - reconciler.EmitEvent(c.Recorder, before, after, pr) + events.EmitEvent(c.Recorder, before, after, pr) pr.Status.TaskRuns = getTaskRunsStatus(pr, pipelineState) c.Logger.Infof("PipelineRun %s status is being set to %s", pr.Name, pr.Status.GetCondition(apis.ConditionSucceeded)) diff --git a/pkg/reconciler/taskrun/controller.go b/pkg/reconciler/taskrun/controller.go index 9bb05f33971..ec74030d28a 100644 --- a/pkg/reconciler/taskrun/controller.go +++ b/pkg/reconciler/taskrun/controller.go @@ -29,7 +29,7 @@ import ( resourceinformer "github.com/tektoncd/pipeline/pkg/client/resource/injection/informers/resource/v1alpha1/pipelineresource" "github.com/tektoncd/pipeline/pkg/pod" "github.com/tektoncd/pipeline/pkg/reconciler" - cloudeventclient "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources/cloudevent" + cloudeventclient "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" "github.com/tektoncd/pipeline/pkg/reconciler/volumeclaim" "k8s.io/client-go/tools/cache" kubeclient "knative.dev/pkg/client/injection/kube/client" diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index ed5345a4c39..7636ba71189 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -34,8 +34,9 @@ import ( "github.com/tektoncd/pipeline/pkg/contexts" podconvert "github.com/tektoncd/pipeline/pkg/pod" "github.com/tektoncd/pipeline/pkg/reconciler" + "github.com/tektoncd/pipeline/pkg/reconciler/events" + "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" - "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources/cloudevent" "github.com/tektoncd/pipeline/pkg/reconciler/volumeclaim" "github.com/tektoncd/pipeline/pkg/termination" "github.com/tektoncd/pipeline/pkg/workspace" @@ -116,7 +117,7 @@ func (c *Reconciler) Reconcile(ctx context.Context, key string) error { // We also want to send the "Started" event as soon as possible for anyone who may be waiting // on the event to perform user facing initialisations, such has reset a CI check status afterCondition := tr.Status.GetCondition(apis.ConditionSucceeded) - reconciler.EmitEvent(c.Recorder, nil, afterCondition, tr) + events.EmitEvent(c.Recorder, nil, afterCondition, tr) } // If the TaskRun is complete, run some post run fixtures when applicable @@ -209,9 +210,9 @@ func (c *Reconciler) Reconcile(ctx context.Context, key string) error { func (c *Reconciler) finishReconcileUpdateEmitEvents(tr, original *v1beta1.TaskRun, beforeCondition *apis.Condition, previousError error) error { afterCondition := tr.Status.GetCondition(apis.ConditionSucceeded) - reconciler.EmitEvent(c.Recorder, beforeCondition, afterCondition, tr) + events.EmitEvent(c.Recorder, beforeCondition, afterCondition, tr) err := c.updateStatusLabelsAndAnnotations(tr, original) - reconciler.EmitErrorEvent(c.Recorder, err, tr) + events.EmitErrorEvent(c.Recorder, err, tr) return multierror.Append(previousError, err).ErrorOrNil() } diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 79a43ee4c9d..c66d7a60f7f 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -32,7 +32,7 @@ import ( resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" podconvert "github.com/tektoncd/pipeline/pkg/pod" - "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources/cloudevent" + "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" "github.com/tektoncd/pipeline/pkg/system" test "github.com/tektoncd/pipeline/test"