Skip to content

Commit 6496fc8

Browse files
author
OpenShift Bot
committed
Merge pull request #3488 from ironcladlou/remove-beta1-deployment-mappings
Merged by openshift-bot
2 parents 46c8505 + 5c8a0be commit 6496fc8

File tree

2 files changed

+40
-121
lines changed

2 files changed

+40
-121
lines changed

pkg/deploy/util/util.go

+12-93
Original file line numberDiff line numberDiff line change
@@ -11,81 +11,9 @@ import (
1111
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
1212

1313
deployapi "github.com/openshift/origin/pkg/deploy/api"
14-
deployv3 "github.com/openshift/origin/pkg/deploy/api/v1beta3"
1514
"github.com/openshift/origin/pkg/util/namer"
1615
)
1716

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-
8917
// LatestDeploymentNameForConfig returns a stable identifier for config based on its version.
9018
func LatestDeploymentNameForConfig(config *deployapi.DeploymentConfig) string {
9119
return fmt.Sprintf("%s-%d", config.Name, config.LatestVersion)
@@ -251,27 +179,27 @@ func (lw *ListWatcherImpl) Watch(resourceVersion string) (watch.Interface, error
251179
}
252180

253181
func DeploymentConfigNameFor(obj runtime.Object) string {
254-
return mappedAnnotationFor(obj, deployapi.DeploymentConfigAnnotation)
182+
return annotationFor(obj, deployapi.DeploymentConfigAnnotation)
255183
}
256184

257185
func DeploymentNameFor(obj runtime.Object) string {
258-
return mappedAnnotationFor(obj, deployapi.DeploymentAnnotation)
186+
return annotationFor(obj, deployapi.DeploymentAnnotation)
259187
}
260188

261189
func DeployerPodNameFor(obj runtime.Object) string {
262-
return mappedAnnotationFor(obj, deployapi.DeploymentPodAnnotation)
190+
return annotationFor(obj, deployapi.DeploymentPodAnnotation)
263191
}
264192

265193
func DeploymentStatusFor(obj runtime.Object) deployapi.DeploymentStatus {
266-
return deployapi.DeploymentStatus(mappedAnnotationFor(obj, deployapi.DeploymentStatusAnnotation))
194+
return deployapi.DeploymentStatus(annotationFor(obj, deployapi.DeploymentStatusAnnotation))
267195
}
268196

269197
func DeploymentStatusReasonFor(obj runtime.Object) string {
270-
return mappedAnnotationFor(obj, deployapi.DeploymentStatusReasonAnnotation)
198+
return annotationFor(obj, deployapi.DeploymentStatusReasonAnnotation)
271199
}
272200

273201
func DeploymentDesiredReplicas(obj runtime.Object) (int, bool) {
274-
s := mappedAnnotationFor(obj, deployapi.DesiredReplicasAnnotation)
202+
s := annotationFor(obj, deployapi.DesiredReplicasAnnotation)
275203
if len(s) == 0 {
276204
return 0, false
277205
}
@@ -283,38 +211,29 @@ func DeploymentDesiredReplicas(obj runtime.Object) (int, bool) {
283211
}
284212

285213
func EncodedDeploymentConfigFor(obj runtime.Object) string {
286-
return mappedAnnotationFor(obj, deployapi.DeploymentEncodedConfigAnnotation)
214+
return annotationFor(obj, deployapi.DeploymentEncodedConfigAnnotation)
287215
}
288216

289217
func DeploymentVersionFor(obj runtime.Object) int {
290-
v, err := strconv.Atoi(mappedAnnotationFor(obj, deployapi.DeploymentVersionAnnotation))
218+
v, err := strconv.Atoi(annotationFor(obj, deployapi.DeploymentVersionAnnotation))
291219
if err != nil {
292220
return -1
293221
}
294222
return v
295223
}
296224

297225
func IsDeploymentCancelled(deployment *api.ReplicationController) bool {
298-
value := mappedAnnotationFor(deployment, deployapi.DeploymentCancelledAnnotation)
226+
value := annotationFor(deployment, deployapi.DeploymentCancelledAnnotation)
299227
return strings.EqualFold(value, deployapi.DeploymentCancelledAnnotationValue)
300228
}
301229

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 {
305232
meta, err := api.ObjectMetaFor(obj)
306233
if err != nil {
307234
return ""
308235
}
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]
318237
}
319238

320239
// DeploymentsByLatestVersionAsc sorts deployments by LatestVersion ascending.

0 commit comments

Comments
 (0)