Browse code

show RCs for services in oc status

deads2k authored on 2015/07/09 03:23:44
Showing 4 changed files
... ...
@@ -74,7 +74,6 @@ func (d *ProjectStatusDescriber) MakeGraph(namespace string) (osgraph.Graph, err
74 74
 	buildedges.AddAllBuildEdges(g)
75 75
 	deployedges.AddAllTriggerEdges(g)
76 76
 	deployedges.AddAllDeploymentEdges(g)
77
-
78 77
 	imageedges.AddAllImageStreamRefEdges(g)
79 78
 
80 79
 	return g, nil
... ...
@@ -114,6 +113,16 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
114 114
 			for _, dcPipeline := range service.DeploymentConfigPipelines {
115 115
 				printLines(out, indent, 1, describeDeploymentInServiceGroup(dcPipeline)...)
116 116
 			}
117
+
118
+		rcNode:
119
+			for _, rcNode := range service.FulfillingRCs {
120
+				for _, coveredDC := range service.FulfillingDCs {
121
+					if deployedges.BelongsToDeploymentConfig(coveredDC.DeploymentConfig, rcNode.ReplicationController) {
122
+						continue rcNode
123
+					}
124
+				}
125
+				printLines(out, indent, 1, describeRCInServiceGroup(rcNode)...)
126
+			}
117 127
 		}
118 128
 
119 129
 		for _, standaloneDC := range standaloneDCs {
... ...
@@ -196,6 +205,22 @@ func describeDeploymentInServiceGroup(deploy graphview.DeploymentConfigPipeline)
196 196
 	return lines
197 197
 }
198 198
 
199
+func describeRCInServiceGroup(rcNode *kubegraph.ReplicationControllerNode) []string {
200
+	if rcNode.ReplicationController.Spec.Template == nil {
201
+		return []string{}
202
+	}
203
+
204
+	images := []string{}
205
+	for _, container := range rcNode.ReplicationController.Spec.Template.Spec.Containers {
206
+		images = append(images, container.Image)
207
+	}
208
+
209
+	lines := []string{fmt.Sprintf("rc/%s runs %s", rcNode.ReplicationController.Name, strings.Join(images, ", "))}
210
+	lines = append(lines, describeRCStatus(rcNode.ReplicationController))
211
+
212
+	return lines
213
+}
214
+
199 215
 func describeDeploymentConfigTrigger(dc *deployapi.DeploymentConfig) string {
200 216
 	if len(dc.Triggers) == 0 {
201 217
 		return "(manual)"
... ...
@@ -461,35 +486,40 @@ func describeDeploymentStatus(deploy *kapi.ReplicationController, first bool) st
461 461
 			reason = fmt.Sprintf(": %s", reason)
462 462
 		}
463 463
 		// TODO: encode fail time in the rc
464
-		return fmt.Sprintf("#%d deployment failed %s ago%s%s", version, timeAt, reason, describeDeploymentPodSummaryInline(deploy, false))
464
+		return fmt.Sprintf("#%d deployment failed %s ago%s%s", version, timeAt, reason, describePodSummaryInline(deploy, false))
465 465
 	case deployapi.DeploymentStatusComplete:
466 466
 		// TODO: pod status output
467
-		return fmt.Sprintf("#%d deployed %s ago%s", version, timeAt, describeDeploymentPodSummaryInline(deploy, first))
467
+		return fmt.Sprintf("#%d deployed %s ago%s", version, timeAt, describePodSummaryInline(deploy, first))
468 468
 	case deployapi.DeploymentStatusRunning:
469
-		return fmt.Sprintf("#%d deployment running for %s%s", version, timeAt, describeDeploymentPodSummaryInline(deploy, false))
469
+		return fmt.Sprintf("#%d deployment running for %s%s", version, timeAt, describePodSummaryInline(deploy, false))
470 470
 	default:
471
-		return fmt.Sprintf("#%d deployment %s %s ago%s", version, strings.ToLower(string(status)), timeAt, describeDeploymentPodSummaryInline(deploy, false))
471
+		return fmt.Sprintf("#%d deployment %s %s ago%s", version, strings.ToLower(string(status)), timeAt, describePodSummaryInline(deploy, false))
472 472
 	}
473 473
 }
474 474
 
475
-func describeDeploymentPodSummaryInline(deploy *kapi.ReplicationController, includeEmpty bool) string {
476
-	s := describeDeploymentPodSummary(deploy, includeEmpty)
475
+func describeRCStatus(rc *kapi.ReplicationController) string {
476
+	timeAt := strings.ToLower(formatRelativeTime(rc.CreationTimestamp.Time))
477
+	return fmt.Sprintf("rc/%s created %s ago%s", rc.Name, timeAt, describePodSummaryInline(rc, false))
478
+}
479
+
480
+func describePodSummaryInline(rc *kapi.ReplicationController, includeEmpty bool) string {
481
+	s := describePodSummary(rc, includeEmpty)
477 482
 	if len(s) == 0 {
478 483
 		return s
479 484
 	}
480 485
 	change := ""
481
-	desired := deploy.Spec.Replicas
486
+	desired := rc.Spec.Replicas
482 487
 	switch {
483
-	case desired < deploy.Status.Replicas:
488
+	case desired < rc.Status.Replicas:
484 489
 		change = fmt.Sprintf(" reducing to %d", desired)
485
-	case desired > deploy.Status.Replicas:
490
+	case desired > rc.Status.Replicas:
486 491
 		change = fmt.Sprintf(" growing to %d", desired)
487 492
 	}
488 493
 	return fmt.Sprintf(" - %s%s", s, change)
489 494
 }
490 495
 
491
-func describeDeploymentPodSummary(deploy *kapi.ReplicationController, includeEmpty bool) string {
492
-	actual, requested := deploy.Status.Replicas, deploy.Spec.Replicas
496
+func describePodSummary(rc *kapi.ReplicationController, includeEmpty bool) string {
497
+	actual, requested := rc.Status.Replicas, rc.Spec.Replicas
493 498
 	if actual == requested {
494 499
 		switch {
495 500
 		case actual == 0:
... ...
@@ -97,6 +97,22 @@ func TestProjectStatus(t *testing.T) {
97 97
 				"To see more, use",
98 98
 			},
99 99
 		},
100
+		"service with RC": {
101
+			Path: "../../../../test/fixtures/app-scenarios/k8s-unserviced-rc.json",
102
+			Extra: []runtime.Object{
103
+				&projectapi.Project{
104
+					ObjectMeta: kapi.ObjectMeta{Name: "example", Namespace: ""},
105
+				},
106
+			},
107
+			ErrFn: func(err error) bool { return err == nil },
108
+			Contains: []string{
109
+				"In project example\n",
110
+				"service database-rc",
111
+				"rc/database-rc-1 runs mysql",
112
+				"0/1 pods growing to 1",
113
+				"To see more, use",
114
+			},
115
+		},
100 116
 		"unstarted build": {
101 117
 			Path: "../../../../test/fixtures/app-scenarios/new-project-no-build.yaml",
102 118
 			Extra: []runtime.Object{
... ...
@@ -59,7 +59,7 @@ func AddAllTriggerEdges(g osgraph.MutableUniqueGraph) {
59 59
 func AddDeploymentEdges(g osgraph.MutableUniqueGraph, node *deploygraph.DeploymentConfigNode) *deploygraph.DeploymentConfigNode {
60 60
 	for _, n := range g.(graph.Graph).NodeList() {
61 61
 		if rcNode, ok := n.(*kubegraph.ReplicationControllerNode); ok {
62
-			if belongsToDeploymentConfig(node.DeploymentConfig, rcNode.ReplicationController) {
62
+			if BelongsToDeploymentConfig(node.DeploymentConfig, rcNode.ReplicationController) {
63 63
 				g.AddEdge(node, rcNode, DeploymentEdgeKind)
64 64
 			}
65 65
 		}
... ...
@@ -34,7 +34,7 @@ func RelevantDeployments(g osgraph.Graph, dcNode *deploygraph.DeploymentConfigNo
34 34
 	return nil, allDeployments
35 35
 }
36 36
 
37
-func belongsToDeploymentConfig(config *deployapi.DeploymentConfig, b *kapi.ReplicationController) bool {
37
+func BelongsToDeploymentConfig(config *deployapi.DeploymentConfig, b *kapi.ReplicationController) bool {
38 38
 	if b.Annotations != nil {
39 39
 		return config.Name == deployutil.DeploymentConfigNameFor(b)
40 40
 	}