@@ -51,6 +51,12 @@ func (c *ImageChangeController) HandleImageRepo(repo *imageapi.ImageStream) erro
51
51
// TODO: this is inefficient
52
52
for _ , bc := range c .BuildConfigStore .List () {
53
53
config := bc .(* buildapi.BuildConfig )
54
+ obj , err := kapi .Scheme .Copy (config )
55
+ if err != nil {
56
+ continue
57
+ }
58
+ originalConfig := obj .(* buildapi.BuildConfig )
59
+
54
60
from := buildutil .GetImageStreamForStrategy (config )
55
61
if from == nil || from .Kind != "ImageStreamTag" {
56
62
continue
@@ -98,6 +104,21 @@ func (c *ImageChangeController) HandleImageRepo(repo *imageapi.ImageStream) erro
98
104
}
99
105
100
106
if shouldBuild {
107
+ // The following update is meant to reduce the chance that the image change controller
108
+ // will kick off multiple builds on an image change in a HA setup, where multiple controllers
109
+ // of the same type may be looking at the same etcd data.
110
+ // If multiple controllers read the same build config (with same ResourceVersion) above and
111
+ // make a determination that a build needs to be kicked off, the update will only allow one of
112
+ // those controllers to continue to launch the build, while the rest will return an error and
113
+ // reset their queue. This won't eliminate the chance of multiple builds, since another controller
114
+ // can read the build after this update and launch its own build.
115
+ // TODO: Find a better mechanism to synchronize in a HA setup.
116
+ if err := c .BuildConfigUpdater .Update (originalConfig ); err != nil {
117
+ // Cannot make an update to the original build config. Likely it has been changed by another process
118
+ glog .V (4 ).Infof ("Cannot update build config %s when preparing to update LastTriggeredImageID: %v" , config .Name , err )
119
+ return err
120
+ }
121
+
101
122
glog .V (4 ).Infof ("Running build for buildConfig %s in namespace %s" , config .Name , config .Namespace )
102
123
// instantiate new build
103
124
request := & buildapi.BuildRequest {ObjectMeta : kapi.ObjectMeta {Name : config .Name }}
0 commit comments