@@ -11,81 +11,9 @@ import (
11
11
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
12
12
13
13
deployapi "github.com/openshift/origin/pkg/deploy/api"
14
- deployv3 "github.com/openshift/origin/pkg/deploy/api/v1beta3"
15
14
"github.com/openshift/origin/pkg/util/namer"
16
15
)
17
16
18
- // These constants represent keys used for correlating objects related to deployments.
19
- const (
20
- // DeploymentConfigAnnotation is an annotation name used to correlate a deployment with the
21
- // DeploymentConfig on which the deployment is based.
22
- v1beta1DeploymentConfigAnnotation = "deploymentConfig"
23
- // DeploymentAnnotation is an annotation on a deployer Pod. The annotation value is the name
24
- // of the deployment (a ReplicationController) on which the deployer Pod acts.
25
- v1beta1DeploymentAnnotation = "deployment"
26
- // DeploymentPodAnnotation is an annotation on a deployment (a ReplicationController). The
27
- // annotation value is the name of the deployer Pod which will act upon the ReplicationController
28
- // to implement the deployment behavior.
29
- v1beta1DeploymentPodAnnotation = "pod"
30
- // DeploymentStatusAnnotation is an annotation name used to retrieve the DeploymentStatus of
31
- // a deployment.
32
- v1beta1DeploymentStatusAnnotation = "deploymentStatus"
33
- // DeploymentEncodedConfigAnnotation is an annotation name used to retrieve specific encoded
34
- // DeploymentConfig on which a given deployment is based.
35
- v1beta1DeploymentEncodedConfigAnnotation = "encodedDeploymentConfig"
36
- // DeploymentVersionAnnotation is an annotation on a deployment (a ReplicationController). The
37
- // annotation value is the LatestVersion value of the DeploymentConfig which was the basis for
38
- // the deployment.
39
- v1beta1DeploymentVersionAnnotation = "deploymentVersion"
40
- // DeploymentLabel is the name of a label used to correlate a deployment with the Pod created
41
- // to execute the deployment logic.
42
- // TODO: This is a workaround for upstream's lack of annotation support on PodTemplate. Once
43
- // annotations are available on PodTemplate, audit this constant with the goal of removing it.
44
- v1beta1DeploymentLabel = "deployment"
45
- // DeploymentConfigLabel is the name of a label used to correlate a deployment with the
46
- // DeploymentConfigs on which the deployment is based.
47
- v1beta1DeploymentConfigLabel = "deploymentconfig"
48
- // DeploymentStatusReasonAnnotation represents the reason for deployment being in a given state
49
- // Used for specifying the reason for cancellation or failure of a deployment
50
- v1beta1DeploymentStatusReasonAnnotation = "openshift.io/deployment.status-reason"
51
- // DeploymentCancelledAnnotation indicates that the deployment has been cancelled
52
- // The annotation value does not matter and its mere presence indicates cancellation
53
- v1beta1DeploymentCancelledAnnotation = "openshift.io/deployment.cancelled"
54
- )
55
-
56
- // Maps the latest annotation keys to all known previous key names. Keys not represented here
57
- // may still be looked up directly via mappedAnnotationFor
58
- var annotationMap = map [string ][]string {
59
- deployapi .DeploymentConfigAnnotation : {
60
- v1beta1DeploymentConfigAnnotation ,
61
- deployv3 .DeploymentConfigAnnotation ,
62
- },
63
- deployapi .DeploymentAnnotation : {
64
- v1beta1DeploymentAnnotation ,
65
- deployv3 .DeploymentAnnotation ,
66
- },
67
- deployapi .DeploymentPodAnnotation : {
68
- v1beta1DeploymentPodAnnotation ,
69
- deployv3 .DeploymentPodAnnotation ,
70
- },
71
- deployapi .DeploymentStatusAnnotation : {
72
- v1beta1DeploymentStatusAnnotation ,
73
- deployv3 .DeploymentPhaseAnnotation ,
74
- },
75
- deployapi .DeploymentEncodedConfigAnnotation : {
76
- v1beta1DeploymentEncodedConfigAnnotation ,
77
- deployv3 .DeploymentEncodedConfigAnnotation ,
78
- },
79
- deployapi .DeploymentVersionAnnotation : {
80
- v1beta1DeploymentVersionAnnotation ,
81
- deployv3 .DeploymentVersionAnnotation ,
82
- },
83
- deployapi .DeploymentCancelledAnnotation : {
84
- v1beta1DeploymentCancelledAnnotation ,
85
- deployv3 .DeploymentCancelledAnnotation ,
86
- },
87
- }
88
-
89
17
// LatestDeploymentNameForConfig returns a stable identifier for config based on its version.
90
18
func LatestDeploymentNameForConfig (config * deployapi.DeploymentConfig ) string {
91
19
return fmt .Sprintf ("%s-%d" , config .Name , config .LatestVersion )
@@ -251,27 +179,27 @@ func (lw *ListWatcherImpl) Watch(resourceVersion string) (watch.Interface, error
251
179
}
252
180
253
181
func DeploymentConfigNameFor (obj runtime.Object ) string {
254
- return mappedAnnotationFor (obj , deployapi .DeploymentConfigAnnotation )
182
+ return annotationFor (obj , deployapi .DeploymentConfigAnnotation )
255
183
}
256
184
257
185
func DeploymentNameFor (obj runtime.Object ) string {
258
- return mappedAnnotationFor (obj , deployapi .DeploymentAnnotation )
186
+ return annotationFor (obj , deployapi .DeploymentAnnotation )
259
187
}
260
188
261
189
func DeployerPodNameFor (obj runtime.Object ) string {
262
- return mappedAnnotationFor (obj , deployapi .DeploymentPodAnnotation )
190
+ return annotationFor (obj , deployapi .DeploymentPodAnnotation )
263
191
}
264
192
265
193
func DeploymentStatusFor (obj runtime.Object ) deployapi.DeploymentStatus {
266
- return deployapi .DeploymentStatus (mappedAnnotationFor (obj , deployapi .DeploymentStatusAnnotation ))
194
+ return deployapi .DeploymentStatus (annotationFor (obj , deployapi .DeploymentStatusAnnotation ))
267
195
}
268
196
269
197
func DeploymentStatusReasonFor (obj runtime.Object ) string {
270
- return mappedAnnotationFor (obj , deployapi .DeploymentStatusReasonAnnotation )
198
+ return annotationFor (obj , deployapi .DeploymentStatusReasonAnnotation )
271
199
}
272
200
273
201
func DeploymentDesiredReplicas (obj runtime.Object ) (int , bool ) {
274
- s := mappedAnnotationFor (obj , deployapi .DesiredReplicasAnnotation )
202
+ s := annotationFor (obj , deployapi .DesiredReplicasAnnotation )
275
203
if len (s ) == 0 {
276
204
return 0 , false
277
205
}
@@ -283,38 +211,29 @@ func DeploymentDesiredReplicas(obj runtime.Object) (int, bool) {
283
211
}
284
212
285
213
func EncodedDeploymentConfigFor (obj runtime.Object ) string {
286
- return mappedAnnotationFor (obj , deployapi .DeploymentEncodedConfigAnnotation )
214
+ return annotationFor (obj , deployapi .DeploymentEncodedConfigAnnotation )
287
215
}
288
216
289
217
func DeploymentVersionFor (obj runtime.Object ) int {
290
- v , err := strconv .Atoi (mappedAnnotationFor (obj , deployapi .DeploymentVersionAnnotation ))
218
+ v , err := strconv .Atoi (annotationFor (obj , deployapi .DeploymentVersionAnnotation ))
291
219
if err != nil {
292
220
return - 1
293
221
}
294
222
return v
295
223
}
296
224
297
225
func IsDeploymentCancelled (deployment * api.ReplicationController ) bool {
298
- value := mappedAnnotationFor (deployment , deployapi .DeploymentCancelledAnnotation )
226
+ value := annotationFor (deployment , deployapi .DeploymentCancelledAnnotation )
299
227
return strings .EqualFold (value , deployapi .DeploymentCancelledAnnotationValue )
300
228
}
301
229
302
- // mappedAnnotationFor finds the given annotation in obj using the annotation
303
- // map to search all known key variants.
304
- func mappedAnnotationFor (obj runtime.Object , key string ) string {
230
+ // annotationFor returns the annotation with key for obj.
231
+ func annotationFor (obj runtime.Object , key string ) string {
305
232
meta , err := api .ObjectMetaFor (obj )
306
233
if err != nil {
307
234
return ""
308
235
}
309
- for _ , mappedKey := range annotationMap [key ] {
310
- if val , ok := meta .Annotations [mappedKey ]; ok {
311
- return val
312
- }
313
- }
314
- if val , ok := meta .Annotations [key ]; ok {
315
- return val
316
- }
317
- return ""
236
+ return meta .Annotations [key ]
318
237
}
319
238
320
239
// DeploymentsByLatestVersionAsc sorts deployments by LatestVersion ascending.
0 commit comments