@@ -11,6 +11,7 @@ import (
11
11
"k8s.io/kubernetes/pkg/client/cache"
12
12
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
13
13
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
14
+ "k8s.io/kubernetes/pkg/client/record"
14
15
kcontroller "k8s.io/kubernetes/pkg/controller"
15
16
utilruntime "k8s.io/kubernetes/pkg/util/runtime"
16
17
"k8s.io/kubernetes/pkg/util/wait"
@@ -49,16 +50,22 @@ type BuildPodController struct {
49
50
podStoreSynced func () bool
50
51
51
52
runPolicies []policy.RunPolicy
53
+
54
+ recorder record.EventRecorder
52
55
}
53
56
54
57
// NewBuildPodController creates a new BuildPodController.
55
58
func NewBuildPodController (buildInformer , podInformer cache.SharedIndexInformer , kc kclientset.Interface , oc osclient.Interface ) * BuildPodController {
59
+ eventBroadcaster := record .NewBroadcaster ()
60
+ eventBroadcaster .StartRecordingToSink (& kcoreclient.EventSinkImpl {Interface : kc .Core ().Events ("" )})
61
+
56
62
buildListerUpdater := buildclient .NewOSClientBuildClient (oc )
57
63
c := & BuildPodController {
58
64
buildUpdater : buildListerUpdater ,
59
65
secretClient : kc .Core (), // TODO: Replace with cache client
60
66
podClient : kc .Core (),
61
67
queue : workqueue .NewRateLimitingQueue (workqueue .DefaultControllerRateLimiter ()),
68
+ recorder : eventBroadcaster .NewRecorder (kapi.EventSource {Component : "build-pod-controller" }),
62
69
}
63
70
64
71
c .runPolicies = policy .GetAllRunPolicies (buildListerUpdater , buildListerUpdater )
@@ -197,6 +204,7 @@ func (bc *BuildPodController) HandlePod(pod *kapi.Pod) error {
197
204
if build .Status .Phase == buildapi .BuildPhaseRunning {
198
205
now := unversioned .Now ()
199
206
build .Status .StartTimestamp = & now
207
+ bc .recorder .Eventf (build , kapi .EventTypeNormal , buildapi .BuildStartedEventReason , fmt .Sprintf (buildapi .BuildStartedEventMessage , build .Namespace , build .Name ))
200
208
}
201
209
}
202
210
@@ -218,6 +226,12 @@ func (bc *BuildPodController) HandlePod(pod *kapi.Pod) error {
218
226
// handle completion for it. otherwise ignore it because we've already
219
227
// handled its completion previously.
220
228
if ! buildWasComplete && buildutil .IsBuildComplete (build ) {
229
+ switch build .Status .Phase {
230
+ case buildapi .BuildPhaseComplete :
231
+ bc .recorder .Eventf (build , kapi .EventTypeNormal , buildapi .BuildCompletedEventReason , fmt .Sprintf (buildapi .BuildCompletedEventMessage , build .Namespace , build .Name ))
232
+ case buildapi .BuildPhaseError , buildapi .BuildPhaseFailed :
233
+ bc .recorder .Eventf (build , kapi .EventTypeNormal , buildapi .BuildFailedEventReason , fmt .Sprintf (buildapi .BuildFailedEventMessage , build .Namespace , build .Name ))
234
+ }
221
235
common .HandleBuildCompletion (build , bc .runPolicies )
222
236
}
223
237
@@ -259,6 +273,8 @@ func (bc *BuildPodController) HandleBuildPodDeletion(pod *kapi.Pod) error {
259
273
build .Status .Reason = buildapi .StatusReasonBuildPodDeleted
260
274
build .Status .Message = buildapi .StatusMessageBuildPodDeleted
261
275
common .SetBuildCompletionTimeAndDuration (build )
276
+ bc .recorder .Eventf (build , kapi .EventTypeNormal , buildapi .BuildFailedEventReason , fmt .Sprintf (buildapi .BuildFailedEventMessage , build .Namespace , build .Name ))
277
+
262
278
if err := bc .buildUpdater .Update (build .Namespace , build ); err != nil {
263
279
return fmt .Errorf ("Failed to update build %s/%s: %v" , build .Namespace , build .Name , err )
264
280
}
0 commit comments