Refactor deployment annotations in v1beta3 to be namespaced. Normalize
all access to annotations through utility functions which support all
former key names.
| ... | ... |
@@ -208,10 +208,7 @@ angular.module('openshiftConsole')
|
| 208 | 208 |
angular.forEach($scope.deployments, function(deployment, depName){
|
| 209 | 209 |
var foundMatch = false; |
| 210 | 210 |
var deploymentSelector = new LabelSelector(deployment.spec.selector); |
| 211 |
- var depConfigName = ""; |
|
| 212 |
- if (deployment.metadata.annotations) {
|
|
| 213 |
- depConfigName = deployment.metadata.annotations.deploymentConfig || ""; |
|
| 214 |
- } |
|
| 211 |
+ var depConfigName = $filter('annotation')(deployment, 'deploymentConfig') || "";
|
|
| 215 | 212 |
|
| 216 | 213 |
angular.forEach($scope.unfilteredServices, function(service, name){
|
| 217 | 214 |
bySvc[name] = bySvc[name] || {};
|
| ... | ... |
@@ -236,9 +233,10 @@ angular.module('openshiftConsole')
|
| 236 | 236 |
}; |
| 237 | 237 |
|
| 238 | 238 |
function parseEncodedDeploymentConfig(deployment) {
|
| 239 |
- if (deployment.metadata.annotations && deployment.metadata.annotations.encodedDeploymentConfig) {
|
|
| 239 |
+ var configJson = $filter('annotation')(deployment, 'encodedDeploymentConfig')
|
|
| 240 |
+ if (configJson) {
|
|
| 240 | 241 |
try {
|
| 241 |
- var depConfig = $.parseJSON(deployment.metadata.annotations.encodedDeploymentConfig); |
|
| 242 |
+ var depConfig = $.parseJSON(configJson); |
|
| 242 | 243 |
deployment.details = depConfig.details; |
| 243 | 244 |
} |
| 244 | 245 |
catch (e) {
|
| ... | ... |
@@ -14,6 +14,16 @@ angular.module('openshiftConsole')
|
| 14 | 14 |
} |
| 15 | 15 |
}) |
| 16 | 16 |
.filter('annotation', function() {
|
| 17 |
+ // This maps a an annotation key to all known synonymous keys to insulate |
|
| 18 |
+ // the referring code from key renames across API versions. |
|
| 19 |
+ var annotationMap = {
|
|
| 20 |
+ "deploymentConfig": ["openshift.io/deployment-config.name"], |
|
| 21 |
+ "deployment": ["openshift.io/deployment.name"], |
|
| 22 |
+ "pod": ["openshift.io/deployer-pod.name"], |
|
| 23 |
+ "deploymentStatus": ["openshift.io/deployment.phase"], |
|
| 24 |
+ "encodedDeploymentConfig": ["openshift.io/encoded-deployment-config"], |
|
| 25 |
+ "deploymentVersion": ["openshift.io/deployment-config.latest-version"] |
|
| 26 |
+ }; |
|
| 17 | 27 |
return function(resource, key) {
|
| 18 | 28 |
if (resource && resource.spec && resource.spec.tags && key.indexOf(".") !== -1){
|
| 19 | 29 |
var tagAndKey = key.split(".");
|
| ... | ... |
@@ -28,7 +38,20 @@ angular.module('openshiftConsole')
|
| 28 | 28 |
} |
| 29 | 29 |
} |
| 30 | 30 |
if (resource && resource.metadata && resource.metadata.annotations) {
|
| 31 |
- return resource.metadata.annotations[key]; |
|
| 31 |
+ // If the key's already in the annotation map, return it. |
|
| 32 |
+ if (resource.metadata.annotations[key] !== undefined) {
|
|
| 33 |
+ return resource.metadata.annotations[key] |
|
| 34 |
+ } |
|
| 35 |
+ // Try and return a value for a mapped key. |
|
| 36 |
+ var mappings = annotationMap[key] || []; |
|
| 37 |
+ for (var i=0; i < mappings.length; i++) {
|
|
| 38 |
+ var mappedKey = mappings[i]; |
|
| 39 |
+ if (resource.metadata.annotations[mappedKey] !== undefined) {
|
|
| 40 |
+ return resource.metadata.annotations[mappedKey]; |
|
| 41 |
+ } |
|
| 42 |
+ } |
|
| 43 |
+ // Couldn't find anything. |
|
| 44 |
+ return null; |
|
| 32 | 45 |
} |
| 33 | 46 |
return null; |
| 34 | 47 |
}; |
| ... | ... |
@@ -11,10 +11,10 @@ |
| 11 | 11 |
</div> |
| 12 | 12 |
</div> |
| 13 | 13 |
<div style="margin-bottom: 10px;" ng-repeat="deployment in deployments"> |
| 14 |
- <h3>{{deployment.metadata.annotations.deploymentConfig}} <span class="small">({{deployment.metadata.name}})</span></h3>
|
|
| 14 |
+ <h3>{{deployment | annotation:'deploymentConfig'}} <span class="small">({{deployment.metadata.name}})</span></h3>
|
|
| 15 | 15 |
<div>Created: <relative-timestamp timestamp="deployment.metadata.creationTimestamp"></relative-timestamp></div> |
| 16 |
- <div>Status: {{deployment.metadata.annotations.deploymentStatus}}</div>
|
|
| 17 |
- <div>Version: {{deployment.metadata.annotations.deploymentVersion}}</div>
|
|
| 16 |
+ <div>Status: {{deployment | annotation:'deploymentStatus'}}</div>
|
|
| 17 |
+ <div>Version: {{deployment | annotation:'deploymentVersion'}}</div>
|
|
| 18 | 18 |
<div>Replicas: {{deployment.spec.replicas}}</div>
|
| 19 | 19 |
<pod-template ng-init="podTemplate = deployment.spec.template"></pod-template> |
| 20 | 20 |
</div> |
| ... | ... |
@@ -2,7 +2,6 @@ package graph |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"sort" |
| 5 |
- "strconv" |
|
| 6 | 5 |
|
| 7 | 6 |
"github.com/gonum/graph" |
| 8 | 7 |
"github.com/gonum/graph/search" |
| ... | ... |
@@ -11,6 +10,7 @@ import ( |
| 11 | 11 |
|
| 12 | 12 |
build "github.com/openshift/origin/pkg/build/api" |
| 13 | 13 |
deploy "github.com/openshift/origin/pkg/deploy/api" |
| 14 |
+ deployutil "github.com/openshift/origin/pkg/deploy/util" |
|
| 14 | 15 |
image "github.com/openshift/origin/pkg/image/api" |
| 15 | 16 |
) |
| 16 | 17 |
|
| ... | ... |
@@ -348,15 +348,7 @@ type RecentDeploymentReferences []*kapi.ReplicationController |
| 348 | 348 |
func (m RecentDeploymentReferences) Len() int { return len(m) }
|
| 349 | 349 |
func (m RecentDeploymentReferences) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
|
| 350 | 350 |
func (m RecentDeploymentReferences) Less(i, j int) bool {
|
| 351 |
- a, err := strconv.Atoi(m[i].Annotations[deploy.DeploymentVersionAnnotation]) |
|
| 352 |
- if err != nil {
|
|
| 353 |
- return false |
|
| 354 |
- } |
|
| 355 |
- b, err := strconv.Atoi(m[j].Annotations[deploy.DeploymentVersionAnnotation]) |
|
| 356 |
- if err != nil {
|
|
| 357 |
- return true |
|
| 358 |
- } |
|
| 359 |
- return a > b |
|
| 351 |
+ return deployutil.DeploymentVersionFor(m[i]) > deployutil.DeploymentVersionFor(m[j]) |
|
| 360 | 352 |
} |
| 361 | 353 |
|
| 362 | 354 |
func CompareObjectMeta(a, b *kapi.ObjectMeta) bool {
|
| ... | ... |
@@ -3,7 +3,6 @@ package graph |
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"sort" |
| 6 |
- "strconv" |
|
| 7 | 6 |
"strings" |
| 8 | 7 |
|
| 9 | 8 |
"github.com/golang/glog" |
| ... | ... |
@@ -15,6 +14,7 @@ import ( |
| 15 | 15 |
build "github.com/openshift/origin/pkg/build/api" |
| 16 | 16 |
buildutil "github.com/openshift/origin/pkg/build/util" |
| 17 | 17 |
deploy "github.com/openshift/origin/pkg/deploy/api" |
| 18 |
+ deployutil "github.com/openshift/origin/pkg/deploy/util" |
|
| 18 | 19 |
image "github.com/openshift/origin/pkg/image/api" |
| 19 | 20 |
) |
| 20 | 21 |
|
| ... | ... |
@@ -402,7 +402,7 @@ func JoinDeployments(node *DeploymentConfigNode, deploys []kapi.ReplicationContr |
| 402 | 402 |
return |
| 403 | 403 |
} |
| 404 | 404 |
sort.Sort(RecentDeploymentReferences(matches)) |
| 405 |
- if strconv.Itoa(node.DeploymentConfig.LatestVersion) == matches[0].Annotations[deploy.DeploymentVersionAnnotation] {
|
|
| 405 |
+ if node.DeploymentConfig.LatestVersion == deployutil.DeploymentVersionFor(matches[0]) {
|
|
| 406 | 406 |
node.ActiveDeployment = matches[0] |
| 407 | 407 |
node.Deployments = matches[1:] |
| 408 | 408 |
return |
| ... | ... |
@@ -422,7 +422,7 @@ func belongsToBuildConfig(config *build.BuildConfig, b *build.Build) bool {
|
| 422 | 422 |
|
| 423 | 423 |
func belongsToDeploymentConfig(config *deploy.DeploymentConfig, b *kapi.ReplicationController) bool {
|
| 424 | 424 |
if b.Annotations != nil {
|
| 425 |
- return config.Name == b.Annotations[deploy.DeploymentConfigAnnotation] |
|
| 425 |
+ return config.Name == deployutil.DeploymentConfigNameFor(b) |
|
| 426 | 426 |
} |
| 427 | 427 |
return false |
| 428 | 428 |
} |
| ... | ... |
@@ -15837,24 +15837,25 @@ h.covers(e) && (a.deploymentConfigsByService[g][c] = b, d = !0); |
| 15837 | 15837 |
function j() {
|
| 15838 | 15838 |
var b = a.deploymentsByService = {
|
| 15839 | 15839 |
"":{}
|
| 15840 |
-}, c = a.deploymentsByServiceByDeploymentConfig = {
|
|
| 15840 |
+}, d = a.deploymentsByServiceByDeploymentConfig = {
|
|
| 15841 | 15841 |
"":{}
|
| 15842 | 15842 |
}; |
| 15843 |
-angular.forEach(a.deployments, function(d, e) {
|
|
| 15844 |
-var f = !1, g = new LabelSelector(d.spec.selector), h = ""; |
|
| 15845 |
-d.metadata.annotations && (h = d.metadata.annotations.deploymentConfig || ""), angular.forEach(a.unfilteredServices, function(a, i) {
|
|
| 15846 |
-b[i] = b[i] || {}, c[i] = c[i] || {};
|
|
| 15843 |
+angular.forEach(a.deployments, function(e, f) {
|
|
| 15844 |
+var g = !1, h = new LabelSelector(e.spec.selector), i = c("annotation")(e, "deploymentConfig") || "";
|
|
| 15845 |
+angular.forEach(a.unfilteredServices, function(a, c) {
|
|
| 15846 |
+b[c] = b[c] || {}, d[c] = d[c] || {};
|
|
| 15847 | 15847 |
var j = new LabelSelector(a.spec.selector); |
| 15848 |
-j.covers(g) && (b[i][e] = d, c[i][h] = c[i][h] || {}, c[i][h][e] = d, f = !0);
|
|
| 15849 |
-}), f || (b[""][e] = d, c[""][h] = c[""][h] || {}, c[""][h][e] = d);
|
|
| 15848 |
+j.covers(h) && (b[c][f] = e, d[c][i] = d[c][i] || {}, d[c][i][f] = e, g = !0);
|
|
| 15849 |
+}), g || (b[""][f] = e, d[""][i] = d[""][i] || {}, d[""][i][f] = e);
|
|
| 15850 | 15850 |
}); |
| 15851 | 15851 |
} |
| 15852 | 15852 |
function k(a) {
|
| 15853 |
-if (a.metadata.annotations && a.metadata.annotations.encodedDeploymentConfig) try {
|
|
| 15854 |
-var b = $.parseJSON(a.metadata.annotations.encodedDeploymentConfig); |
|
| 15855 |
-a.details = b.details; |
|
| 15856 |
-} catch (c) {
|
|
| 15857 |
-e.error("Failed to parse encoded deployment config", c);
|
|
| 15853 |
+var b = c("annotation")(a, "encodedDeploymentConfig");
|
|
| 15854 |
+if (b) try {
|
|
| 15855 |
+var d = $.parseJSON(b); |
|
| 15856 |
+a.details = d.details; |
|
| 15857 |
+} catch (f) {
|
|
| 15858 |
+e.error("Failed to parse encoded deployment config", f);
|
|
| 15858 | 15859 |
} |
| 15859 | 15860 |
} |
| 15860 | 15861 |
function l(a, b) {
|
| ... | ... |
@@ -16949,12 +16950,28 @@ return function(a) {
|
| 16949 | 16949 |
return a && a.metadata && a.metadata.uid ? a.metadata.uid :a; |
| 16950 | 16950 |
}; |
| 16951 | 16951 |
}).filter("annotation", function() {
|
| 16952 |
-return function(a, b) {
|
|
| 16953 |
-if (a && a.spec && a.spec.tags && -1 !== b.indexOf(".")) for (var c = b.split("."), d = a.spec.tags, e = 0; e < d.length; ++e) {
|
|
| 16954 |
-var f = d[e], g = c[0], h = c[1]; |
|
| 16955 |
-if (g === f.name && f.annotations) return f.annotations[h]; |
|
| 16952 |
+var a = {
|
|
| 16953 |
+deploymentConfig:[ "openshift.io/deployment-config.name" ], |
|
| 16954 |
+deployment:[ "openshift.io/deployment.name" ], |
|
| 16955 |
+pod:[ "openshift.io/deployer-pod.name" ], |
|
| 16956 |
+deploymentStatus:[ "openshift.io/deployment.phase" ], |
|
| 16957 |
+encodedDeploymentConfig:[ "openshift.io/encoded-deployment-config" ], |
|
| 16958 |
+deploymentVersion:[ "openshift.io/deployment-config.latest-version" ] |
|
| 16959 |
+}; |
|
| 16960 |
+return function(b, c) {
|
|
| 16961 |
+if (b && b.spec && b.spec.tags && -1 !== c.indexOf(".")) for (var d = c.split("."), e = b.spec.tags, f = 0; f < e.length; ++f) {
|
|
| 16962 |
+var g = e[f], h = d[0], i = d[1]; |
|
| 16963 |
+if (h === g.name && g.annotations) return g.annotations[i]; |
|
| 16964 |
+} |
|
| 16965 |
+if (b && b.metadata && b.metadata.annotations) {
|
|
| 16966 |
+if (void 0 !== b.metadata.annotations[c]) return b.metadata.annotations[c]; |
|
| 16967 |
+for (var j = a[c] || [], f = 0; f < j.length; f++) {
|
|
| 16968 |
+var k = j[f]; |
|
| 16969 |
+if (void 0 !== b.metadata.annotations[k]) return b.metadata.annotations[k]; |
|
| 16956 | 16970 |
} |
| 16957 |
-return a && a.metadata && a.metadata.annotations ? a.metadata.annotations[b] :null; |
|
| 16971 |
+return null; |
|
| 16972 |
+} |
|
| 16973 |
+return null; |
|
| 16958 | 16974 |
}; |
| 16959 | 16975 |
}).filter("description", [ "annotationFilter", function(a) {
|
| 16960 | 16976 |
return function(b) {
|
| ... | ... |
@@ -63901,10 +63918,10 @@ var _views_deployments_html = []byte(`<div ng-controller="ProjectController" cla |
| 63901 | 63901 |
</div> |
| 63902 | 63902 |
</div> |
| 63903 | 63903 |
<div style="margin-bottom: 10px" ng-repeat="deployment in deployments"> |
| 63904 |
-<h3>{{deployment.metadata.annotations.deploymentConfig}} <span class="small">({{deployment.metadata.name}})</span></h3>
|
|
| 63904 |
+<h3>{{deployment | annotation:'deploymentConfig'}} <span class="small">({{deployment.metadata.name}})</span></h3>
|
|
| 63905 | 63905 |
<div>Created: <relative-timestamp timestamp="deployment.metadata.creationTimestamp"></relative-timestamp></div> |
| 63906 |
-<div>Status: {{deployment.metadata.annotations.deploymentStatus}}</div>
|
|
| 63907 |
-<div>Version: {{deployment.metadata.annotations.deploymentVersion}}</div>
|
|
| 63906 |
+<div>Status: {{deployment | annotation:'deploymentStatus'}}</div>
|
|
| 63907 |
+<div>Version: {{deployment | annotation:'deploymentVersion'}}</div>
|
|
| 63908 | 63908 |
<div>Replicas: {{deployment.spec.replicas}}</div>
|
| 63909 | 63909 |
<pod-template ng-init="podTemplate = deployment.spec.template"></pod-template> |
| 63910 | 63910 |
</div> |
| ... | ... |
@@ -174,7 +174,7 @@ func (c *deployLatestCommand) deploy(config *deployapi.DeploymentConfig, out io. |
| 174 | 174 |
} |
| 175 | 175 |
} else {
|
| 176 | 176 |
// Reject attempts to start a concurrent deployment. |
| 177 |
- status := statusFor(deployment) |
|
| 177 |
+ status := deployutil.DeploymentStatusFor(deployment) |
|
| 178 | 178 |
if status != deployapi.DeploymentStatusComplete && status != deployapi.DeploymentStatusFailed {
|
| 179 | 179 |
return fmt.Errorf("#%d is already in progress (%s)", config.LatestVersion, status)
|
| 180 | 180 |
} |
| ... | ... |
@@ -206,9 +206,7 @@ func (c *retryDeploymentCommand) retry(config *deployapi.DeploymentConfig, out i |
| 206 | 206 |
return err |
| 207 | 207 |
} |
| 208 | 208 |
|
| 209 |
- status := statusFor(deployment) |
|
| 210 |
- |
|
| 211 |
- if status != deployapi.DeploymentStatusFailed {
|
|
| 209 |
+ if status := deployutil.DeploymentStatusFor(deployment); status != deployapi.DeploymentStatusFailed {
|
|
| 212 | 210 |
return fmt.Errorf("#%d is %s; only failed deployments can be retried", config.LatestVersion, status)
|
| 213 | 211 |
} |
| 214 | 212 |
|
| ... | ... |
@@ -220,10 +218,6 @@ func (c *retryDeploymentCommand) retry(config *deployapi.DeploymentConfig, out i |
| 220 | 220 |
return err |
| 221 | 221 |
} |
| 222 | 222 |
|
| 223 |
-func statusFor(deployment *kapi.ReplicationController) deployapi.DeploymentStatus {
|
|
| 224 |
- return deployapi.DeploymentStatus(deployment.Annotations[deployapi.DeploymentStatusAnnotation]) |
|
| 225 |
-} |
|
| 226 |
- |
|
| 227 | 223 |
// deployCommandClientImpl is a pluggable deployCommandClient. |
| 228 | 224 |
type deployCommandClientImpl struct {
|
| 229 | 225 |
GetDeploymentFn func(namespace, name string) (*kapi.ReplicationController, error) |
| ... | ... |
@@ -157,7 +157,7 @@ func TestCmdDeploy_retryOk(t *testing.T) {
|
| 157 | 157 |
t.Fatalf("expected updated config")
|
| 158 | 158 |
} |
| 159 | 159 |
|
| 160 |
- if e, a := deployapi.DeploymentStatusNew, statusFor(updatedDeployment); e != a {
|
|
| 160 |
+ if e, a := deployapi.DeploymentStatusNew, deployutil.DeploymentStatusFor(updatedDeployment); e != a {
|
|
| 161 | 161 |
t.Fatalf("expected deployment status %s, got %s", e, a)
|
| 162 | 162 |
} |
| 163 | 163 |
} |
| ... | ... |
@@ -139,7 +139,7 @@ func (d *DeploymentConfigDescriber) Describe(namespace, name string) (string, er |
| 139 | 139 |
formatString(out, "Latest Deployment", fmt.Sprintf("error: %v", err))
|
| 140 | 140 |
} |
| 141 | 141 |
} else {
|
| 142 |
- header := fmt.Sprintf("Deployment #%v (latest)", deployment.Annotations[deployapi.DeploymentVersionAnnotation])
|
|
| 142 |
+ header := fmt.Sprintf("Deployment #%d (latest)", deployutil.DeploymentVersionFor(deployment))
|
|
| 143 | 143 |
printDeploymentRc(deployment, d.client, out, header, true) |
| 144 | 144 |
} |
| 145 | 145 |
deploymentsHistory, err := d.client.listDeployments(namespace, labels.Everything()) |
| ... | ... |
@@ -148,8 +148,8 @@ func (d *DeploymentConfigDescriber) Describe(namespace, name string) (string, er |
| 148 | 148 |
sorted = append(sorted, deploymentsHistory.Items...) |
| 149 | 149 |
sort.Sort(sorted) |
| 150 | 150 |
for _, item := range sorted {
|
| 151 |
- if item.Name != deploymentName && deploymentConfig.Name == item.Annotations[deployapi.DeploymentConfigAnnotation] {
|
|
| 152 |
- header := fmt.Sprintf("Deployment #%v", item.Annotations[deployapi.DeploymentVersionAnnotation])
|
|
| 151 |
+ if item.Name != deploymentName && deploymentConfig.Name == deployutil.DeploymentConfigNameFor(&item) {
|
|
| 152 |
+ header := fmt.Sprintf("Deployment #%d", deployutil.DeploymentVersionFor(&item))
|
|
| 153 | 153 |
printDeploymentRc(&item, d.client, out, header, false) |
| 154 | 154 |
} |
| 155 | 155 |
} |
| ... | ... |
@@ -249,7 +249,7 @@ func printDeploymentRc(deployment *kapi.ReplicationController, client deployment |
| 249 | 249 |
} |
| 250 | 250 |
timeAt := strings.ToLower(formatRelativeTime(deployment.CreationTimestamp.Time)) |
| 251 | 251 |
fmt.Fprintf(w, "\tCreated:\t%s ago\n", timeAt) |
| 252 |
- fmt.Fprintf(w, "\tStatus:\t%s\n", deployment.Annotations[deployapi.DeploymentStatusAnnotation]) |
|
| 252 |
+ fmt.Fprintf(w, "\tStatus:\t%s\n", deployutil.DeploymentStatusFor(deployment)) |
|
| 253 | 253 |
fmt.Fprintf(w, "\tReplicas:\t%d current / %d desired\n", deployment.Status.Replicas, deployment.Spec.Replicas) |
| 254 | 254 |
|
| 255 | 255 |
if verbose {
|
| ... | ... |
@@ -16,6 +16,7 @@ import ( |
| 16 | 16 |
buildapi "github.com/openshift/origin/pkg/build/api" |
| 17 | 17 |
"github.com/openshift/origin/pkg/client" |
| 18 | 18 |
deployapi "github.com/openshift/origin/pkg/deploy/api" |
| 19 |
+ deployutil "github.com/openshift/origin/pkg/deploy/util" |
|
| 19 | 20 |
) |
| 20 | 21 |
|
| 21 | 22 |
// ProjectStatusDescriber generates extended information about a Project |
| ... | ... |
@@ -374,8 +375,7 @@ func describeDeployments(node *graph.DeploymentConfigNode, count int) []string {
|
| 374 | 374 |
|
| 375 | 375 |
switch {
|
| 376 | 376 |
case count == -1: |
| 377 |
- status := deployment.Annotations[deployapi.DeploymentStatusAnnotation] |
|
| 378 |
- if deployapi.DeploymentStatus(status) == deployapi.DeploymentStatusComplete {
|
|
| 377 |
+ if deployutil.DeploymentStatusFor(deployment) == deployapi.DeploymentStatusComplete {
|
|
| 379 | 378 |
return out |
| 380 | 379 |
} |
| 381 | 380 |
default: |
| ... | ... |
@@ -389,15 +389,17 @@ func describeDeployments(node *graph.DeploymentConfigNode, count int) []string {
|
| 389 | 389 |
|
| 390 | 390 |
func describeDeploymentStatus(deploy *kapi.ReplicationController) string {
|
| 391 | 391 |
timeAt := strings.ToLower(formatRelativeTime(deploy.CreationTimestamp.Time)) |
| 392 |
- switch s := deploy.Annotations[deployapi.DeploymentStatusAnnotation]; deployapi.DeploymentStatus(s) {
|
|
| 392 |
+ status := deployutil.DeploymentStatusFor(deploy) |
|
| 393 |
+ version := deployutil.DeploymentVersionFor(deploy) |
|
| 394 |
+ switch status {
|
|
| 393 | 395 |
case deployapi.DeploymentStatusFailed: |
| 394 | 396 |
// TODO: encode fail time in the rc |
| 395 |
- return fmt.Sprintf("#%s deployment failed %s ago. You can restart this deployment with osc deploy --retry.", deploy.Annotations[deployapi.DeploymentVersionAnnotation], timeAt)
|
|
| 397 |
+ return fmt.Sprintf("#%d deployment failed %s ago. You can restart this deployment with osc deploy --retry.", version, timeAt)
|
|
| 396 | 398 |
case deployapi.DeploymentStatusComplete: |
| 397 | 399 |
// TODO: pod status output |
| 398 |
- return fmt.Sprintf("#%s deployed %s ago", deploy.Annotations[deployapi.DeploymentVersionAnnotation], timeAt)
|
|
| 400 |
+ return fmt.Sprintf("#%d deployed %s ago", version, timeAt)
|
|
| 399 | 401 |
default: |
| 400 |
- return fmt.Sprintf("#%s deployment %s %s ago", deploy.Annotations[deployapi.DeploymentVersionAnnotation], strings.ToLower(s), timeAt)
|
|
| 402 |
+ return fmt.Sprintf("#%d deployment %s %s ago", version, strings.ToLower(string(status)), timeAt)
|
|
| 401 | 403 |
} |
| 402 | 404 |
} |
| 403 | 405 |
|
| ... | ... |
@@ -2,7 +2,6 @@ package deployer |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
- "strconv" |
|
| 6 | 5 |
|
| 7 | 6 |
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
| 8 | 7 |
kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client" |
| ... | ... |
@@ -136,20 +135,12 @@ func getDeployerContext(controllerGetter replicationControllerGetter, namespace, |
| 136 | 136 |
|
| 137 | 137 |
glog.Infof("Inspecting %d potential prior deployments", len(allControllers.Items))
|
| 138 | 138 |
for i, controller := range allControllers.Items {
|
| 139 |
- if configName, hasConfigName := controller.Annotations[deployapi.DeploymentConfigAnnotation]; !hasConfigName {
|
|
| 140 |
- glog.Infof("Disregarding replicationController %s (not a deployment)", controller.Name)
|
|
| 139 |
+ if oldName := deployutil.DeploymentConfigNameFor(&controller); oldName != newConfig.Name {
|
|
| 140 |
+ glog.Infof("Disregarding deployment %s (doesn't match target deploymentConfig %s)", controller.Name, oldName)
|
|
| 141 | 141 |
continue |
| 142 |
- } else if configName != newConfig.Name {
|
|
| 143 |
- glog.Infof("Disregarding deployment %s (doesn't match target deploymentConfig %s)", controller.Name, configName)
|
|
| 144 |
- continue |
|
| 145 |
- } |
|
| 146 |
- |
|
| 147 |
- var oldVersion int |
|
| 148 |
- if oldVersion, err = strconv.Atoi(controller.Annotations[deployapi.DeploymentVersionAnnotation]); err != nil {
|
|
| 149 |
- return nil, nil, fmt.Errorf("Couldn't determine version of deployment %s: %v", controller.Name, err)
|
|
| 150 | 142 |
} |
| 151 | 143 |
|
| 152 |
- if oldVersion < newConfig.LatestVersion {
|
|
| 144 |
+ if deployutil.DeploymentVersionFor(&controller) < newConfig.LatestVersion {
|
|
| 153 | 145 |
glog.Infof("Marking deployment %s as a prior deployment", controller.Name)
|
| 154 | 146 |
oldDeployments = append(oldDeployments, &allControllers.Items[i]) |
| 155 | 147 |
} else {
|
| ... | ... |
@@ -158,44 +158,6 @@ func TestGetDeploymentContextWithPriorDeployments(t *testing.T) {
|
| 158 | 158 |
} |
| 159 | 159 |
} |
| 160 | 160 |
|
| 161 |
-func TestGetDeploymentContextInvalidPriorDeployment(t *testing.T) {
|
|
| 162 |
- getter := &testReplicationControllerGetter{
|
|
| 163 |
- getFunc: func(namespace, name string) (*kapi.ReplicationController, error) {
|
|
| 164 |
- deployment, _ := deployutil.MakeDeployment(deploytest.OkDeploymentConfig(1), kapi.Codec) |
|
| 165 |
- return deployment, nil |
|
| 166 |
- }, |
|
| 167 |
- listFunc: func(namespace string, selector labels.Selector) (*kapi.ReplicationControllerList, error) {
|
|
| 168 |
- return &kapi.ReplicationControllerList{
|
|
| 169 |
- Items: []kapi.ReplicationController{
|
|
| 170 |
- {
|
|
| 171 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 172 |
- Name: "corrupt-deployment", |
|
| 173 |
- Annotations: map[string]string{
|
|
| 174 |
- deployapi.DeploymentConfigAnnotation: "config", |
|
| 175 |
- deployapi.DeploymentVersionAnnotation: "junk", |
|
| 176 |
- }, |
|
| 177 |
- }, |
|
| 178 |
- }, |
|
| 179 |
- }, |
|
| 180 |
- }, nil |
|
| 181 |
- }, |
|
| 182 |
- } |
|
| 183 |
- |
|
| 184 |
- newDeployment, oldDeployments, err := getDeployerContext(getter, kapi.NamespaceDefault, "deployment") |
|
| 185 |
- |
|
| 186 |
- if newDeployment != nil {
|
|
| 187 |
- t.Fatalf("unexpected newDeployment: %#v", newDeployment)
|
|
| 188 |
- } |
|
| 189 |
- |
|
| 190 |
- if oldDeployments != nil {
|
|
| 191 |
- t.Fatalf("unexpected oldDeployments: %#v", oldDeployments)
|
|
| 192 |
- } |
|
| 193 |
- |
|
| 194 |
- if err == nil {
|
|
| 195 |
- t.Fatal("expected an error")
|
|
| 196 |
- } |
|
| 197 |
-} |
|
| 198 |
- |
|
| 199 | 161 |
type testReplicationControllerGetter struct {
|
| 200 | 162 |
getFunc func(namespace, name string) (*kapi.ReplicationController, error) |
| 201 | 163 |
listFunc func(namespace string, selector labels.Selector) (*kapi.ReplicationControllerList, error) |
| ... | ... |
@@ -153,24 +153,24 @@ type DeploymentList struct {
|
| 153 | 153 |
const ( |
| 154 | 154 |
// DeploymentConfigAnnotation is an annotation name used to correlate a deployment with the |
| 155 | 155 |
// DeploymentConfig on which the deployment is based. |
| 156 |
- DeploymentConfigAnnotation = "deploymentConfig" |
|
| 156 |
+ DeploymentConfigAnnotation = "openshift.io/deployment-config.name" |
|
| 157 | 157 |
// DeploymentAnnotation is an annotation on a deployer Pod. The annotation value is the name |
| 158 | 158 |
// of the deployment (a ReplicationController) on which the deployer Pod acts. |
| 159 |
- DeploymentAnnotation = "deployment" |
|
| 159 |
+ DeploymentAnnotation = "openshift.io/deployment.name" |
|
| 160 | 160 |
// DeploymentPodAnnotation is an annotation on a deployment (a ReplicationController). The |
| 161 | 161 |
// annotation value is the name of the deployer Pod which will act upon the ReplicationController |
| 162 | 162 |
// to implement the deployment behavior. |
| 163 |
- DeploymentPodAnnotation = "pod" |
|
| 164 |
- // DeploymentStatusAnnotation is an annotation name used to retrieve the DeploymentStatus of |
|
| 163 |
+ DeploymentPodAnnotation = "openshift.io/deployer-pod.name" |
|
| 164 |
+ // DeploymentStatusAnnotation is an annotation name used to retrieve the DeploymentPhase of |
|
| 165 | 165 |
// a deployment. |
| 166 |
- DeploymentStatusAnnotation = "deploymentStatus" |
|
| 166 |
+ DeploymentStatusAnnotation = "openshift.io/deployment.phase" |
|
| 167 | 167 |
// DeploymentEncodedConfigAnnotation is an annotation name used to retrieve specific encoded |
| 168 | 168 |
// DeploymentConfig on which a given deployment is based. |
| 169 |
- DeploymentEncodedConfigAnnotation = "encodedDeploymentConfig" |
|
| 169 |
+ DeploymentEncodedConfigAnnotation = "openshift.io/encoded-deployment-config" |
|
| 170 | 170 |
// DeploymentVersionAnnotation is an annotation on a deployment (a ReplicationController). The |
| 171 | 171 |
// annotation value is the LatestVersion value of the DeploymentConfig which was the basis for |
| 172 | 172 |
// the deployment. |
| 173 |
- DeploymentVersionAnnotation = "deploymentVersion" |
|
| 173 |
+ DeploymentVersionAnnotation = "openshift.io/deployment-config.latest-version" |
|
| 174 | 174 |
// DeploymentLabel is the name of a label used to correlate a deployment with the Pod created |
| 175 | 175 |
// to execute the deployment logic. |
| 176 | 176 |
// TODO: This is a workaround for upstream's lack of annotation support on PodTemplate. Once |
| ... | ... |
@@ -121,24 +121,24 @@ type RollingDeploymentStrategyParams struct {
|
| 121 | 121 |
const ( |
| 122 | 122 |
// DeploymentConfigAnnotation is an annotation name used to correlate a deployment with the |
| 123 | 123 |
// DeploymentConfig on which the deployment is based. |
| 124 |
- DeploymentConfigAnnotation = "deploymentConfig" |
|
| 124 |
+ DeploymentConfigAnnotation = "openshift.io/deployment-config.name" |
|
| 125 | 125 |
// DeploymentAnnotation is an annotation on a deployer Pod. The annotation value is the name |
| 126 | 126 |
// of the deployment (a ReplicationController) on which the deployer Pod acts. |
| 127 |
- DeploymentAnnotation = "deployment" |
|
| 127 |
+ DeploymentAnnotation = "openshift.io/deployment.name" |
|
| 128 | 128 |
// DeploymentPodAnnotation is an annotation on a deployment (a ReplicationController). The |
| 129 | 129 |
// annotation value is the name of the deployer Pod which will act upon the ReplicationController |
| 130 | 130 |
// to implement the deployment behavior. |
| 131 |
- DeploymentPodAnnotation = "pod" |
|
| 131 |
+ DeploymentPodAnnotation = "openshift.io/deployer-pod.name" |
|
| 132 | 132 |
// DeploymentPhaseAnnotation is an annotation name used to retrieve the DeploymentPhase of |
| 133 | 133 |
// a deployment. |
| 134 |
- DeploymentPhaseAnnotation = "deploymentStatus" |
|
| 134 |
+ DeploymentPhaseAnnotation = "openshift.io/deployment.phase" |
|
| 135 | 135 |
// DeploymentEncodedConfigAnnotation is an annotation name used to retrieve specific encoded |
| 136 | 136 |
// DeploymentConfig on which a given deployment is based. |
| 137 |
- DeploymentEncodedConfigAnnotation = "encodedDeploymentConfig" |
|
| 137 |
+ DeploymentEncodedConfigAnnotation = "openshift.io/encoded-deployment-config" |
|
| 138 | 138 |
// DeploymentVersionAnnotation is an annotation on a deployment (a ReplicationController). The |
| 139 | 139 |
// annotation value is the LatestVersion value of the DeploymentConfig which was the basis for |
| 140 | 140 |
// the deployment. |
| 141 |
- DeploymentVersionAnnotation = "deploymentVersion" |
|
| 141 |
+ DeploymentVersionAnnotation = "openshift.io/deployment-config.latest-version" |
|
| 142 | 142 |
// DeploymentLabel is the name of a label used to correlate a deployment with the Pod created |
| 143 | 143 |
// to execute the deployment logic. |
| 144 | 144 |
// TODO: This is a workaround for upstream's lack of annotation support on PodTemplate. Once |
| ... | ... |
@@ -23,8 +23,8 @@ type DeployerPodController struct {
|
| 23 | 23 |
// Handle syncs pod's status with any associated deployment. |
| 24 | 24 |
func (c *DeployerPodController) Handle(pod *kapi.Pod) error {
|
| 25 | 25 |
// Verify the assumption that we'll be given only pods correlated to a deployment |
| 26 |
- deploymentName, hasDeploymentName := pod.Annotations[deployapi.DeploymentAnnotation] |
|
| 27 |
- if !hasDeploymentName {
|
|
| 26 |
+ deploymentName := deployutil.DeploymentNameFor(pod) |
|
| 27 |
+ if len(deploymentName) == 0 {
|
|
| 28 | 28 |
glog.V(2).Infof("Ignoring pod %s; no deployment annotation found", pod.Name)
|
| 29 | 29 |
return nil |
| 30 | 30 |
} |
| ... | ... |
@@ -34,7 +34,7 @@ func (c *DeployerPodController) Handle(pod *kapi.Pod) error {
|
| 34 | 34 |
return fmt.Errorf("couldn't get deployment %s/%s associated with pod %s", pod.Namespace, deploymentName, pod.Name)
|
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 |
- currentStatus := deployutil.StatusForDeployment(deployment) |
|
| 37 |
+ currentStatus := deployutil.DeploymentStatusFor(deployment) |
|
| 38 | 38 |
nextStatus := currentStatus |
| 39 | 39 |
|
| 40 | 40 |
switch pod.Status.Phase {
|
| ... | ... |
@@ -85,7 +85,7 @@ func TestHandle_runningPod(t *testing.T) {
|
| 85 | 85 |
t.Fatalf("expected deployment update")
|
| 86 | 86 |
} |
| 87 | 87 |
|
| 88 |
- if e, a := deployapi.DeploymentStatusRunning, deployutil.StatusForDeployment(updatedDeployment); e != a {
|
|
| 88 |
+ if e, a := deployapi.DeploymentStatusRunning, deployutil.DeploymentStatusFor(updatedDeployment); e != a {
|
|
| 89 | 89 |
t.Fatalf("expected updated deployment status %s, got %s", e, a)
|
| 90 | 90 |
} |
| 91 | 91 |
} |
| ... | ... |
@@ -120,7 +120,7 @@ func TestHandle_podTerminatedOk(t *testing.T) {
|
| 120 | 120 |
t.Fatalf("expected deployment update")
|
| 121 | 121 |
} |
| 122 | 122 |
|
| 123 |
- if e, a := deployapi.DeploymentStatusComplete, deployutil.StatusForDeployment(updatedDeployment); e != a {
|
|
| 123 |
+ if e, a := deployapi.DeploymentStatusComplete, deployutil.DeploymentStatusFor(updatedDeployment); e != a {
|
|
| 124 | 124 |
t.Fatalf("expected updated deployment status %s, got %s", e, a)
|
| 125 | 125 |
} |
| 126 | 126 |
} |
| ... | ... |
@@ -155,7 +155,7 @@ func TestHandle_podTerminatedFail(t *testing.T) {
|
| 155 | 155 |
t.Fatalf("expected deployment update")
|
| 156 | 156 |
} |
| 157 | 157 |
|
| 158 |
- if e, a := deployapi.DeploymentStatusFailed, deployutil.StatusForDeployment(updatedDeployment); e != a {
|
|
| 158 |
+ if e, a := deployapi.DeploymentStatusFailed, deployutil.DeploymentStatusFor(updatedDeployment); e != a {
|
|
| 159 | 159 |
t.Fatalf("expected updated deployment status %s, got %s", e, a)
|
| 160 | 160 |
} |
| 161 | 161 |
} |
| ... | ... |
@@ -91,11 +91,11 @@ func pollPods(deploymentStore cache.Store, kClient kclient.PodsNamespacer) (cach |
| 91 | 91 |
for _, obj := range deploymentStore.List() {
|
| 92 | 92 |
deployment := obj.(*kapi.ReplicationController) |
| 93 | 93 |
|
| 94 |
- switch deployapi.DeploymentStatus(deployment.Annotations[deployapi.DeploymentStatusAnnotation]) {
|
|
| 94 |
+ switch deployutil.DeploymentStatusFor(deployment) {
|
|
| 95 | 95 |
case deployapi.DeploymentStatusPending, deployapi.DeploymentStatusRunning: |
| 96 | 96 |
// Validate the correlating pod annotation |
| 97 |
- podID, hasPodID := deployment.Annotations[deployapi.DeploymentPodAnnotation] |
|
| 98 |
- if !hasPodID {
|
|
| 97 |
+ podID := deployutil.DeployerPodNameFor(deployment) |
|
| 98 |
+ if len(podID) == 0 {
|
|
| 99 | 99 |
glog.V(2).Infof("Unexpected state: deployment %s has no pod annotation; skipping pod polling", deployment.Name)
|
| 100 | 100 |
continue |
| 101 | 101 |
} |
| ... | ... |
@@ -44,7 +44,7 @@ func (e fatalError) Error() string { return "fatal error handling deployment: "
|
| 44 | 44 |
// Handle processes deployment and either creates a deployer pod or responds |
| 45 | 45 |
// to a terminal deployment status. |
| 46 | 46 |
func (c *DeploymentController) Handle(deployment *kapi.ReplicationController) error {
|
| 47 |
- currentStatus := deployutil.StatusForDeployment(deployment) |
|
| 47 |
+ currentStatus := deployutil.DeploymentStatusFor(deployment) |
|
| 48 | 48 |
nextStatus := currentStatus |
| 49 | 49 |
|
| 50 | 50 |
switch currentStatus {
|
| ... | ... |
@@ -76,7 +76,7 @@ func (c *DeploymentController) Handle(deployment *kapi.ReplicationController) er |
| 76 | 76 |
// Automatically clean up successful pods |
| 77 | 77 |
// TODO: Could probably do a lookup here to skip the delete call, but it's not worth adding |
| 78 | 78 |
// yet since (delete retries will only normally occur during full a re-sync). |
| 79 |
- podName := deployment.Annotations[deployapi.DeploymentPodAnnotation] |
|
| 79 |
+ podName := deployutil.DeployerPodNameFor(deployment) |
|
| 80 | 80 |
if err := c.podClient.deletePod(deployment.Namespace, podName); err != nil {
|
| 81 | 81 |
if !kerrors.IsNotFound(err) {
|
| 82 | 82 |
return fmt.Errorf("couldn't delete completed deployer pod %s/%s for deployment %s: %v", deployment.Namespace, podName, deployutil.LabelForDeployment(deployment), err)
|
| ... | ... |
@@ -37,6 +37,7 @@ func TestHandle_createPodOk(t *testing.T) {
|
| 37 | 37 |
podClient: &podClientImpl{
|
| 38 | 38 |
createPodFunc: func(namespace string, pod *kapi.Pod) (*kapi.Pod, error) {
|
| 39 | 39 |
createdPod = pod |
| 40 |
+ pod.Name = pod.GenerateName |
|
| 40 | 41 |
return pod, nil |
| 41 | 42 |
}, |
| 42 | 43 |
}, |
| ... | ... |
@@ -60,7 +61,7 @@ func TestHandle_createPodOk(t *testing.T) {
|
| 60 | 60 |
t.Fatalf("expected an updated deployment")
|
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 |
- if e, a := string(deployapi.DeploymentStatusPending), updatedDeployment.Annotations[deployapi.DeploymentStatusAnnotation]; e != a {
|
|
| 63 |
+ if e, a := deployapi.DeploymentStatusPending, deployutil.DeploymentStatusFor(updatedDeployment); e != a {
|
|
| 64 | 64 |
t.Fatalf("expected updated deployment status %s, got %s", e, a)
|
| 65 | 65 |
} |
| 66 | 66 |
|
| ... | ... |
@@ -68,19 +69,19 @@ func TestHandle_createPodOk(t *testing.T) {
|
| 68 | 68 |
t.Fatalf("expected a pod to be created")
|
| 69 | 69 |
} |
| 70 | 70 |
|
| 71 |
- if _, hasPodAnnotation := updatedDeployment.Annotations[deployapi.DeploymentPodAnnotation]; !hasPodAnnotation {
|
|
| 71 |
+ if e := deployutil.DeployerPodNameFor(updatedDeployment); len(e) == 0 {
|
|
| 72 | 72 |
t.Fatalf("missing deployment pod annotation")
|
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 |
- if e, a := createdPod.Name, updatedDeployment.Annotations[deployapi.DeploymentPodAnnotation]; e != a {
|
|
| 75 |
+ if e, a := createdPod.Name, deployutil.DeployerPodNameFor(updatedDeployment); e != a {
|
|
| 76 | 76 |
t.Fatalf("expected deployment pod annotation %s, got %s", e, a)
|
| 77 | 77 |
} |
| 78 | 78 |
|
| 79 |
- if _, hasDeploymentAnnotation := createdPod.Annotations[deployapi.DeploymentAnnotation]; !hasDeploymentAnnotation {
|
|
| 79 |
+ if e := deployutil.DeploymentNameFor(createdPod); len(e) == 0 {
|
|
| 80 | 80 |
t.Fatalf("missing deployment annotation")
|
| 81 | 81 |
} |
| 82 | 82 |
|
| 83 |
- if e, a := updatedDeployment.Name, createdPod.Annotations[deployapi.DeploymentAnnotation]; e != a {
|
|
| 83 |
+ if e, a := updatedDeployment.Name, deployutil.DeploymentNameFor(createdPod); e != a {
|
|
| 84 | 84 |
t.Fatalf("expected pod deployment annotation %s, got %s", e, a)
|
| 85 | 85 |
} |
| 86 | 86 |
|
| ... | ... |
@@ -71,7 +71,7 @@ func (c *DeploymentConfigController) Handle(config *deployapi.DeploymentConfig) |
| 71 | 71 |
return fmt.Errorf("couldn't list deployments for config %s: %v", deployutil.LabelForDeploymentConfig(config), err)
|
| 72 | 72 |
} |
| 73 | 73 |
for _, deployment := range existingDeployments.Items {
|
| 74 |
- deploymentStatus := deployutil.StatusForDeployment(&deployment) |
|
| 74 |
+ deploymentStatus := deployutil.DeploymentStatusFor(&deployment) |
|
| 75 | 75 |
switch deploymentStatus {
|
| 76 | 76 |
case deployapi.DeploymentStatusFailed, |
| 77 | 77 |
deployapi.DeploymentStatusComplete: |
| ... | ... |
@@ -2,7 +2,6 @@ package rolling |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
- "strconv" |
|
| 6 | 5 |
"time" |
| 7 | 6 |
|
| 8 | 7 |
"github.com/golang/glog" |
| ... | ... |
@@ -14,7 +13,6 @@ import ( |
| 14 | 14 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" |
| 15 | 15 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait" |
| 16 | 16 |
|
| 17 |
- deployapi "github.com/openshift/origin/pkg/deploy/api" |
|
| 18 | 17 |
"github.com/openshift/origin/pkg/deploy/strategy" |
| 19 | 18 |
deployutil "github.com/openshift/origin/pkg/deploy/util" |
| 20 | 19 |
) |
| ... | ... |
@@ -158,17 +156,10 @@ func (s *RollingDeploymentStrategy) findLatestDeployment(oldDeployments []*kapi. |
| 158 | 158 |
var latest *kapi.ReplicationController |
| 159 | 159 |
latestVersion := 0 |
| 160 | 160 |
for _, deployment := range oldDeployments {
|
| 161 |
- if val, hasVersion := deployment.Annotations[deployapi.DeploymentVersionAnnotation]; hasVersion {
|
|
| 162 |
- version, err := strconv.Atoi(val) |
|
| 163 |
- if err != nil {
|
|
| 164 |
- return nil, fmt.Errorf("deployment %s/%s has invalid version annotation value '%s': %v", deployment.Namespace, deployment.Name, val, err)
|
|
| 165 |
- } |
|
| 166 |
- if version > latestVersion {
|
|
| 167 |
- latest = deployment |
|
| 168 |
- latestVersion = version |
|
| 169 |
- } |
|
| 170 |
- } else {
|
|
| 171 |
- glog.Infof("Ignoring deployment with missing version annotation: %s/%s", deployment.Namespace, deployment.Name)
|
|
| 161 |
+ version := deployutil.DeploymentVersionFor(deployment) |
|
| 162 |
+ if version > latestVersion {
|
|
| 163 |
+ latest = deployment |
|
| 164 |
+ latestVersion = version |
|
| 172 | 165 |
} |
| 173 | 166 |
} |
| 174 | 167 |
if latest != nil {
|
| ... | ... |
@@ -142,10 +142,6 @@ func TestRolling_findLatestDeployment(t *testing.T) {
|
| 142 | 142 |
deployments[deployment.Name] = deployment |
| 143 | 143 |
} |
| 144 | 144 |
|
| 145 |
- ignoredDeployment, _ := deployutil.MakeDeployment(deploytest.OkDeploymentConfig(12), kapi.Codec) |
|
| 146 |
- delete(ignoredDeployment.Annotations, deployapi.DeploymentVersionAnnotation) |
|
| 147 |
- deployments[ignoredDeployment.Name] = ignoredDeployment |
|
| 148 |
- |
|
| 149 | 145 |
strategy := &RollingDeploymentStrategy{
|
| 150 | 146 |
codec: api.Codec, |
| 151 | 147 |
client: &rollingUpdaterClient{
|
| ... | ... |
@@ -178,7 +174,6 @@ func TestRolling_findLatestDeployment(t *testing.T) {
|
| 178 | 178 |
"config-3", |
| 179 | 179 |
"config-1", |
| 180 | 180 |
"config-7", |
| 181 |
- ignoredDeployment.Name, |
|
| 182 | 181 |
}, |
| 183 | 182 |
latest: "config-7", |
| 184 | 183 |
}, |
| ... | ... |
@@ -206,24 +201,6 @@ func TestRolling_findLatestDeployment(t *testing.T) {
|
| 206 | 206 |
} |
| 207 | 207 |
} |
| 208 | 208 |
|
| 209 |
-func TestRolling_findLatestDeploymentInvalidDeployment(t *testing.T) {
|
|
| 210 |
- deployment, _ := deployutil.MakeDeployment(deploytest.OkDeploymentConfig(1), kapi.Codec) |
|
| 211 |
- deployment.Annotations[deployapi.DeploymentVersionAnnotation] = "" |
|
| 212 |
- |
|
| 213 |
- strategy := &RollingDeploymentStrategy{
|
|
| 214 |
- codec: api.Codec, |
|
| 215 |
- client: &rollingUpdaterClient{
|
|
| 216 |
- GetReplicationControllerFn: func(namespace, name string) (*kapi.ReplicationController, error) {
|
|
| 217 |
- return deployment, nil |
|
| 218 |
- }, |
|
| 219 |
- }, |
|
| 220 |
- } |
|
| 221 |
- _, err := strategy.findLatestDeployment([]*kapi.ReplicationController{deployment})
|
|
| 222 |
- if err == nil {
|
|
| 223 |
- t.Errorf("expected an error")
|
|
| 224 |
- } |
|
| 225 |
-} |
|
| 226 |
- |
|
| 227 | 209 |
type testStrategy struct {
|
| 228 | 210 |
deployFn func(deployment *kapi.ReplicationController, oldDeployments []*kapi.ReplicationController) error |
| 229 | 211 |
} |
| ... | ... |
@@ -14,8 +14,38 @@ import ( |
| 14 | 14 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" |
| 15 | 15 |
|
| 16 | 16 |
deployapi "github.com/openshift/origin/pkg/deploy/api" |
| 17 |
+ deployv1 "github.com/openshift/origin/pkg/deploy/api/v1beta1" |
|
| 18 |
+ deployv3 "github.com/openshift/origin/pkg/deploy/api/v1beta3" |
|
| 17 | 19 |
) |
| 18 | 20 |
|
| 21 |
+// Maps the latest annotation keys to all known previous key names. |
|
| 22 |
+var annotationMap = map[string][]string{
|
|
| 23 |
+ deployapi.DeploymentConfigAnnotation: {
|
|
| 24 |
+ deployv1.DeploymentConfigAnnotation, |
|
| 25 |
+ deployv3.DeploymentConfigAnnotation, |
|
| 26 |
+ }, |
|
| 27 |
+ deployapi.DeploymentAnnotation: {
|
|
| 28 |
+ deployv1.DeploymentAnnotation, |
|
| 29 |
+ deployv3.DeploymentAnnotation, |
|
| 30 |
+ }, |
|
| 31 |
+ deployapi.DeploymentPodAnnotation: {
|
|
| 32 |
+ deployv1.DeploymentPodAnnotation, |
|
| 33 |
+ deployv3.DeploymentPodAnnotation, |
|
| 34 |
+ }, |
|
| 35 |
+ deployapi.DeploymentStatusAnnotation: {
|
|
| 36 |
+ deployv1.DeploymentStatusAnnotation, |
|
| 37 |
+ deployv3.DeploymentPhaseAnnotation, |
|
| 38 |
+ }, |
|
| 39 |
+ deployapi.DeploymentEncodedConfigAnnotation: {
|
|
| 40 |
+ deployv1.DeploymentEncodedConfigAnnotation, |
|
| 41 |
+ deployv3.DeploymentEncodedConfigAnnotation, |
|
| 42 |
+ }, |
|
| 43 |
+ deployapi.DeploymentVersionAnnotation: {
|
|
| 44 |
+ deployv1.DeploymentVersionAnnotation, |
|
| 45 |
+ deployv3.DeploymentVersionAnnotation, |
|
| 46 |
+ }, |
|
| 47 |
+} |
|
| 48 |
+ |
|
| 19 | 49 |
// LatestDeploymentNameForConfig returns a stable identifier for config based on its version. |
| 20 | 50 |
func LatestDeploymentNameForConfig(config *deployapi.DeploymentConfig) string {
|
| 21 | 51 |
return config.Name + "-" + strconv.Itoa(config.LatestVersion) |
| ... | ... |
@@ -25,11 +55,6 @@ func DeployerPodNameForDeployment(deployment *api.ReplicationController) string |
| 25 | 25 |
return fmt.Sprintf("deploy-%s", deployment.Name)
|
| 26 | 26 |
} |
| 27 | 27 |
|
| 28 |
-// StatusForDeployment gets the DeploymentStatus for deployment from its annotations. |
|
| 29 |
-func StatusForDeployment(deployment *api.ReplicationController) deployapi.DeploymentStatus {
|
|
| 30 |
- return deployapi.DeploymentStatus(deployment.Annotations[deployapi.DeploymentStatusAnnotation]) |
|
| 31 |
-} |
|
| 32 |
- |
|
| 33 | 28 |
// LabelForDeployment builds a string identifier for a Deployment. |
| 34 | 29 |
func LabelForDeployment(deployment *api.ReplicationController) string {
|
| 35 | 30 |
return fmt.Sprintf("%s/%s", deployment.Namespace, deployment.Name)
|
| ... | ... |
@@ -67,7 +92,7 @@ func PodSpecsEqual(a, b api.PodSpec) bool {
|
| 67 | 67 |
// DecodeDeploymentConfig decodes a DeploymentConfig from controller using codec. An error is returned |
| 68 | 68 |
// if the controller doesn't contain an encoded config. |
| 69 | 69 |
func DecodeDeploymentConfig(controller *api.ReplicationController, codec runtime.Codec) (*deployapi.DeploymentConfig, error) {
|
| 70 |
- encodedConfig := []byte(controller.Annotations[deployapi.DeploymentEncodedConfigAnnotation]) |
|
| 70 |
+ encodedConfig := []byte(EncodedDeploymentConfigFor(controller)) |
|
| 71 | 71 |
if decoded, err := codec.Decode(encodedConfig); err == nil {
|
| 72 | 72 |
if config, ok := decoded.(*deployapi.DeploymentConfig); ok {
|
| 73 | 73 |
return config, nil |
| ... | ... |
@@ -177,3 +202,47 @@ func (lw *ListWatcherImpl) List() (runtime.Object, error) {
|
| 177 | 177 |
func (lw *ListWatcherImpl) Watch(resourceVersion string) (watch.Interface, error) {
|
| 178 | 178 |
return lw.WatchFunc(resourceVersion) |
| 179 | 179 |
} |
| 180 |
+ |
|
| 181 |
+func DeploymentConfigNameFor(obj runtime.Object) string {
|
|
| 182 |
+ return mappedAnnotationFor(obj, deployapi.DeploymentConfigAnnotation) |
|
| 183 |
+} |
|
| 184 |
+ |
|
| 185 |
+func DeploymentNameFor(obj runtime.Object) string {
|
|
| 186 |
+ return mappedAnnotationFor(obj, deployapi.DeploymentAnnotation) |
|
| 187 |
+} |
|
| 188 |
+ |
|
| 189 |
+func DeployerPodNameFor(obj runtime.Object) string {
|
|
| 190 |
+ return mappedAnnotationFor(obj, deployapi.DeploymentPodAnnotation) |
|
| 191 |
+} |
|
| 192 |
+ |
|
| 193 |
+func DeploymentStatusFor(obj runtime.Object) deployapi.DeploymentStatus {
|
|
| 194 |
+ return deployapi.DeploymentStatus(mappedAnnotationFor(obj, deployapi.DeploymentStatusAnnotation)) |
|
| 195 |
+} |
|
| 196 |
+ |
|
| 197 |
+func EncodedDeploymentConfigFor(obj runtime.Object) string {
|
|
| 198 |
+ return mappedAnnotationFor(obj, deployapi.DeploymentEncodedConfigAnnotation) |
|
| 199 |
+} |
|
| 200 |
+ |
|
| 201 |
+func DeploymentVersionFor(obj runtime.Object) int {
|
|
| 202 |
+ v, err := strconv.Atoi(mappedAnnotationFor(obj, deployapi.DeploymentVersionAnnotation)) |
|
| 203 |
+ if err != nil {
|
|
| 204 |
+ return -1 |
|
| 205 |
+ } |
|
| 206 |
+ return v |
|
| 207 |
+} |
|
| 208 |
+ |
|
| 209 |
+// mappedAnnotationFor finds the given annotation in obj using the annotation |
|
| 210 |
+// map to search all known key variants. |
|
| 211 |
+func mappedAnnotationFor(obj runtime.Object, key string) string {
|
|
| 212 |
+ meta, err := api.ObjectMetaFor(obj) |
|
| 213 |
+ if err != nil {
|
|
| 214 |
+ return "" |
|
| 215 |
+ } |
|
| 216 |
+ for _, mappedKey := range annotationMap[key] {
|
|
| 217 |
+ val, hasVal := meta.Annotations[mappedKey] |
|
| 218 |
+ if hasVal {
|
|
| 219 |
+ return val |
|
| 220 |
+ } |
|
| 221 |
+ } |
|
| 222 |
+ return "" |
|
| 223 |
+} |
| ... | ... |
@@ -108,7 +108,7 @@ func TestMakeDeploymentOk(t *testing.T) {
|
| 108 | 108 |
} |
| 109 | 109 |
} |
| 110 | 110 |
|
| 111 |
- if len(deployment.Annotations[deployapi.DeploymentEncodedConfigAnnotation]) == 0 {
|
|
| 111 |
+ if len(EncodedDeploymentConfigFor(deployment)) == 0 {
|
|
| 112 | 112 |
t.Fatalf("expected deployment with DeploymentEncodedConfigAnnotation annotation")
|
| 113 | 113 |
} |
| 114 | 114 |
|
| ... | ... |
@@ -35,6 +35,7 @@ import ( |
| 35 | 35 |
deployconfiggenerator "github.com/openshift/origin/pkg/deploy/generator" |
| 36 | 36 |
deployconfigregistry "github.com/openshift/origin/pkg/deploy/registry/deployconfig" |
| 37 | 37 |
deployetcd "github.com/openshift/origin/pkg/deploy/registry/etcd" |
| 38 |
+ deployutil "github.com/openshift/origin/pkg/deploy/util" |
|
| 38 | 39 |
imageapi "github.com/openshift/origin/pkg/image/api" |
| 39 | 40 |
"github.com/openshift/origin/pkg/image/registry/image" |
| 40 | 41 |
imageetcd "github.com/openshift/origin/pkg/image/registry/image/etcd" |
| ... | ... |
@@ -97,10 +98,10 @@ func TestTriggers_manual(t *testing.T) {
|
| 97 | 97 |
} |
| 98 | 98 |
deployment := event.Object.(*kapi.ReplicationController) |
| 99 | 99 |
|
| 100 |
- if e, a := config.Name, deployment.Annotations[deployapi.DeploymentConfigAnnotation]; e != a {
|
|
| 100 |
+ if e, a := config.Name, deployutil.DeploymentConfigNameFor(deployment); e != a {
|
|
| 101 | 101 |
t.Fatalf("Expected deployment annotated with deploymentConfig '%s', got '%s'", e, a)
|
| 102 | 102 |
} |
| 103 |
- if e, a := "1", deployment.Annotations[deployapi.DeploymentVersionAnnotation]; e != a {
|
|
| 103 |
+ if e, a := 1, deployutil.DeploymentVersionFor(deployment); e != a {
|
|
| 104 | 104 |
t.Fatalf("Deployment annotation version does not match: %#v", deployment)
|
| 105 | 105 |
} |
| 106 | 106 |
} |
| ... | ... |
@@ -201,7 +202,7 @@ waitForNewRC: |
| 201 | 201 |
} |
| 202 | 202 |
} |
| 203 | 203 |
|
| 204 |
- if e, a := config.Name, deployment.Annotations[deployapi.DeploymentConfigAnnotation]; e != a {
|
|
| 204 |
+ if e, a := config.Name, deployutil.DeploymentConfigNameFor(deployment); e != a {
|
|
| 205 | 205 |
t.Fatalf("Expected deployment annotated with deploymentConfig '%s', got '%s'", e, a)
|
| 206 | 206 |
} |
| 207 | 207 |
|
| ... | ... |
@@ -217,7 +218,7 @@ waitForPendingStatus: |
| 217 | 217 |
} |
| 218 | 218 |
} |
| 219 | 219 |
} |
| 220 |
- if e, a := string(deployapi.DeploymentStatusPending), deployment.Annotations[deployapi.DeploymentStatusAnnotation]; e != a {
|
|
| 220 |
+ if e, a := deployapi.DeploymentStatusPending, deployutil.DeploymentStatusFor(deployment); e != a {
|
|
| 221 | 221 |
t.Fatalf("expected deployment status %q, got %q", e, a)
|
| 222 | 222 |
} |
| 223 | 223 |
|
| ... | ... |
@@ -287,7 +288,7 @@ func TestTriggers_configChange(t *testing.T) {
|
| 287 | 287 |
|
| 288 | 288 |
deployment := event.Object.(*kapi.ReplicationController) |
| 289 | 289 |
|
| 290 |
- if e, a := config.Name, deployment.Annotations[deployapi.DeploymentConfigAnnotation]; e != a {
|
|
| 290 |
+ if e, a := config.Name, deployutil.DeploymentConfigNameFor(deployment); e != a {
|
|
| 291 | 291 |
t.Fatalf("Expected deployment annotated with deploymentConfig '%s', got '%s'", e, a)
|
| 292 | 292 |
} |
| 293 | 293 |
|