|
1 | 1 | package buildconfigs
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "reflect"
|
5 | 6 |
|
6 | 7 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
| 8 | + utilruntime "k8s.io/apimachinery/pkg/util/runtime" |
| 9 | + v1core "k8s.io/client-go/kubernetes/typed/core/v1" |
| 10 | + clientv1 "k8s.io/client-go/pkg/api/v1" |
| 11 | + "k8s.io/client-go/rest" |
7 | 12 | "k8s.io/client-go/tools/cache"
|
| 13 | + "k8s.io/client-go/tools/record" |
8 | 14 | kapi "k8s.io/kubernetes/pkg/api"
|
9 | 15 |
|
10 | 16 | "github.com/golang/glog"
|
@@ -107,15 +113,25 @@ type BuildConfigInstantiator interface {
|
107 | 113 | Instantiate(namespace string, request *buildapi.BuildRequest) (*buildapi.Build, error)
|
108 | 114 | }
|
109 | 115 |
|
110 |
| -// BuildConfigReactor converts trigger changes into new builds. It will request a build if |
| 116 | +// buildConfigReactor converts trigger changes into new builds. It will request a build if |
111 | 117 | // at least one image is out of date.
|
112 |
| -type BuildConfigReactor struct { |
113 |
| - Instantiator BuildConfigInstantiator |
| 118 | +type buildConfigReactor struct { |
| 119 | + instantiator BuildConfigInstantiator |
| 120 | + eventRecorder record.EventRecorder |
| 121 | +} |
| 122 | + |
| 123 | +// NewBuildConfigReactor creates a new buildConfigReactor |
| 124 | +func NewBuildConfigReactor(instantiator BuildConfigInstantiator, restclient rest.Interface) trigger.ImageReactor { |
| 125 | + eventBroadcaster := record.NewBroadcaster() |
| 126 | + eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: v1core.New(restclient).Events("")}) |
| 127 | + eventRecorder := eventBroadcaster.NewRecorder(kapi.Scheme, clientv1.EventSource{Component: "buildconfig-controller"}) |
| 128 | + |
| 129 | + return &buildConfigReactor{instantiator: instantiator, eventRecorder: eventRecorder} |
114 | 130 | }
|
115 | 131 |
|
116 | 132 | // ImageChanged is passed a build config and a set of changes and updates the object if
|
117 | 133 | // necessary.
|
118 |
| -func (r *BuildConfigReactor) ImageChanged(obj interface{}, tagRetriever trigger.TagRetriever) error { |
| 134 | +func (r *buildConfigReactor) ImageChanged(obj interface{}, tagRetriever trigger.TagRetriever) error { |
119 | 135 | bc := obj.(*buildapi.BuildConfig)
|
120 | 136 |
|
121 | 137 | var request *buildapi.BuildRequest
|
@@ -193,6 +209,11 @@ func (r *BuildConfigReactor) ImageChanged(obj interface{}, tagRetriever trigger.
|
193 | 209 |
|
194 | 210 | // instantiate new build
|
195 | 211 | glog.V(4).Infof("Requesting build for BuildConfig based on image triggers %s/%s: %#v", bc.Namespace, bc.Name, request)
|
196 |
| - _, err := r.Instantiator.Instantiate(bc.Namespace, request) |
| 212 | + _, err := r.instantiator.Instantiate(bc.Namespace, request) |
| 213 | + if err != nil { |
| 214 | + instantiateErr := fmt.Errorf("error triggering Build for BuildConfig %s/%s: %v", bc.Namespace, bc.Name, err) |
| 215 | + utilruntime.HandleError(instantiateErr) |
| 216 | + r.eventRecorder.Event(bc, kapi.EventTypeWarning, "BuildConfigTriggerFailed", instantiateErr.Error()) |
| 217 | + } |
197 | 218 | return err
|
198 | 219 | }
|
0 commit comments