@@ -10,6 +10,8 @@ import (
10
10
"github.com/docker/distribution/reference"
11
11
"github.com/fsouza/go-dockerclient"
12
12
13
+ kclient "k8s.io/kubernetes/pkg/client/unversioned"
14
+
13
15
"github.com/openshift/origin/pkg/build/api"
14
16
"github.com/openshift/origin/pkg/client"
15
17
"github.com/openshift/origin/pkg/generate/git"
@@ -20,7 +22,14 @@ import (
20
22
// client facing libraries should not be using glog
21
23
var glog = utilglog .ToFile (os .Stderr , 2 )
22
24
23
- const OriginalSourceURLAnnotationKey = "openshift.io/original-source-url"
25
+ const (
26
+ OriginalSourceURLAnnotationKey = "openshift.io/original-source-url"
27
+
28
+ // containerNamePrefix prefixes the name of containers launched by a build.
29
+ // We cannot reuse the prefix "k8s" because we don't want the containers to
30
+ // be managed by a kubelet.
31
+ containerNamePrefix = "openshift"
32
+ )
24
33
25
34
// KeyValue can be used to build ordered lists of key-value pairs.
26
35
type KeyValue struct {
@@ -66,35 +75,6 @@ func buildInfo(build *api.Build) []KeyValue {
66
75
return kv
67
76
}
68
77
69
- func updateBuildRevision (c client.BuildInterface , build * api.Build , sourceInfo * git.SourceInfo ) {
70
- if build .Spec .Revision != nil {
71
- return
72
- }
73
- build .Spec .Revision = & api.SourceRevision {
74
- Git : & api.GitSourceRevision {
75
- Commit : sourceInfo .CommitID ,
76
- Message : sourceInfo .Message ,
77
- Author : api.SourceControlUser {
78
- Name : sourceInfo .AuthorName ,
79
- Email : sourceInfo .AuthorEmail ,
80
- },
81
- Committer : api.SourceControlUser {
82
- Name : sourceInfo .CommitterName ,
83
- Email : sourceInfo .CommitterEmail ,
84
- },
85
- },
86
- }
87
-
88
- // Reset ResourceVersion to avoid a conflict with other updates to the build
89
- build .ResourceVersion = ""
90
-
91
- glog .V (4 ).Infof ("Setting build revision to %#v" , build .Spec .Revision .Git )
92
- _ , err := c .UpdateDetails (build )
93
- if err != nil {
94
- glog .V (0 ).Infof ("error: An error occurred saving build revision: %v" , err )
95
- }
96
- }
97
-
98
78
// randomBuildTag generates a random tag used for building images in such a way
99
79
// that the built image can be referred to unambiguously even in the face of
100
80
// concurrent builds with the same name in the same namespace.
@@ -108,11 +88,6 @@ func randomBuildTag(namespace, name string) string {
108
88
return fmt .Sprintf ("%s:%s" , repo , randomTag )
109
89
}
110
90
111
- // containerNamePrefix prefixes the name of containers launched by a build. We
112
- // cannot reuse the prefix "k8s" because we don't want the containers to be
113
- // managed by a kubelet.
114
- const containerNamePrefix = "openshift"
115
-
116
91
// containerName creates names for Docker containers launched by a build. It is
117
92
// meant to resemble Kubernetes' pkg/kubelet/dockertools.BuildDockerName.
118
93
func containerName (strategyName , buildName , namespace , containerPurpose string ) string {
@@ -180,3 +155,47 @@ func execPostCommitHook(client DockerClient, postCommitSpec api.BuildPostCommitS
180
155
Stderr : true ,
181
156
})
182
157
}
158
+
159
+ func updateBuildRevision (build * api.Build , sourceInfo * git.SourceInfo ) * api.SourceRevision {
160
+ if build .Spec .Revision != nil {
161
+ return build .Spec .Revision
162
+ }
163
+ return & api.SourceRevision {
164
+ Git : & api.GitSourceRevision {
165
+ Commit : sourceInfo .CommitID ,
166
+ Message : sourceInfo .Message ,
167
+ Author : api.SourceControlUser {
168
+ Name : sourceInfo .AuthorName ,
169
+ Email : sourceInfo .AuthorEmail ,
170
+ },
171
+ Committer : api.SourceControlUser {
172
+ Name : sourceInfo .CommitterName ,
173
+ Email : sourceInfo .CommitterEmail ,
174
+ },
175
+ },
176
+ }
177
+ }
178
+
179
+ func retryBuildStatusUpdate (build * api.Build , client client.BuildInterface , sourceRev * api.SourceRevision ) error {
180
+ return kclient .RetryOnConflict (kclient .DefaultBackoff , func () error {
181
+ // before updating, make sure we are using the latest version of the build
182
+ latestBuild , err := client .Get (build .Name )
183
+ if err != nil {
184
+ // usually this means we failed to get resources due to the missing
185
+ // privilleges
186
+ return err
187
+ }
188
+ if sourceRev != nil {
189
+ latestBuild .Spec .Revision = sourceRev
190
+ latestBuild .ResourceVersion = ""
191
+ }
192
+
193
+ latestBuild .Status .Reason = build .Status .Reason
194
+ latestBuild .Status .Message = build .Status .Message
195
+
196
+ if _ , err := client .UpdateDetails (latestBuild ); err != nil {
197
+ return err
198
+ }
199
+ return nil
200
+ })
201
+ }
0 commit comments