Skip to content

Commit

Permalink
Move events to a common package
Browse files Browse the repository at this point in the history
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
  • Loading branch information
afrittoli authored and tekton-robot committed May 21, 2020
1 parent e83aa5f commit a6081f1
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 10 deletions.
21 changes: 21 additions & 0 deletions pkg/reconciler/events/doc.go
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pkg/reconciler/event.go → pkg/reconciler/events/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package reconciler
package events

import (
"errors"
Expand Down
5 changes: 3 additions & 2 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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"
Expand Down Expand Up @@ -198,7 +199,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)
Expand Down Expand Up @@ -615,7 +616,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))
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/taskrun/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a6081f1

Please sign in to comment.