Skip to content

Commit a1345bb

Browse files
author
OpenShift Bot
committed
Merge pull request #3688 from deads2k/show-pods
Merged by openshift-bot
2 parents b2ff5d6 + 8cd29ef commit a1345bb

File tree

4 files changed

+216
-22
lines changed

4 files changed

+216
-22
lines changed
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
apiVersion: v1
2+
items:
3+
- apiVersion: v1
4+
kind: Service
5+
metadata:
6+
creationTimestamp: 2015-07-13T19:36:04Z
7+
labels:
8+
template: ruby-helloworld-sample
9+
name: frontend-app
10+
namespace: example
11+
resourceVersion: "32433"
12+
selfLink: /api/v1/namespaces/example/services/frontend-app
13+
uid: 667e1293-2996-11e5-b9e2-28d2447dc82b
14+
spec:
15+
clusterIP: 172.30.197.115
16+
portalIP: 172.30.197.115
17+
ports:
18+
- nodePort: 0
19+
port: 5432
20+
protocol: TCP
21+
targetPort: 8080
22+
selector:
23+
name: frontend
24+
sessionAffinity: None
25+
type: ClusterIP
26+
status:
27+
loadBalancer: {}
28+
- apiVersion: v1
29+
kind: Pod
30+
metadata:
31+
annotations:
32+
kubernetes.io/created-by: '{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicationController","namespace":"example","name":"frontend-app-1","uid":"666e12d7-2996-11e5-b9e2-28d2447dc82b","apiVersion":"v1","resourceVersion":"32416"}}'
33+
openshift.io/scc: restricted
34+
creationTimestamp: 2015-07-13T19:36:04Z
35+
generateName: frontend-app-1-
36+
labels:
37+
deconflict: frontend.app
38+
name: frontend
39+
template: ruby-helloworld-sample
40+
name: frontend-app-1-bjwh8
41+
namespace: example
42+
resourceVersion: "32467"
43+
selfLink: /api/v1/namespaces/example/pods/frontend-app-1-bjwh8
44+
uid: 669a3b5d-2996-11e5-b9e2-28d2447dc82b
45+
spec:
46+
containers:
47+
- env:
48+
- name: ADMIN_USERNAME
49+
value: admin6TM
50+
- name: ADMIN_PASSWORD
51+
value: xImx1tHR
52+
- name: MYSQL_ROOT_PASSWORD
53+
value: rQHfVnTo
54+
- name: MYSQL_DATABASE
55+
value: root
56+
image: openshift/ruby-hello-world
57+
imagePullPolicy: IfNotPresent
58+
name: ruby-helloworld
59+
ports:
60+
- containerPort: 8080
61+
protocol: TCP
62+
resources: {}
63+
securityContext:
64+
capabilities: {}
65+
privileged: false
66+
runAsUser: 1000060000
67+
seLinuxOptions:
68+
level: s0:c8,c2
69+
terminationMessagePath: /dev/termination-log
70+
volumeMounts:
71+
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
72+
name: default-token-mmv27
73+
readOnly: true
74+
dnsPolicy: ClusterFirst
75+
host: deads-dev-01
76+
imagePullSecrets:
77+
- name: default-dockercfg-yr2e3
78+
nodeName: deads-dev-01
79+
restartPolicy: Always
80+
serviceAccount: default
81+
serviceAccountName: default
82+
volumes:
83+
- name: default-token-mmv27
84+
secret:
85+
secretName: default-token-mmv27
86+
status:
87+
conditions:
88+
- status: "False"
89+
type: Ready
90+
containerStatuses:
91+
- image: openshift/ruby-hello-world
92+
imageID: ""
93+
lastState: {}
94+
name: ruby-helloworld
95+
ready: false
96+
restartCount: 0
97+
state:
98+
waiting:
99+
reason: 'Image: openshift/ruby-hello-world is not ready on the node'
100+
phase: Pending
101+
startTime: 2015-07-13T19:36:05Z
102+
kind: List
103+
metadata: {}

pkg/api/kubegraph/edges.go

+28
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const (
1313
// ExposedThroughServiceEdgeKind is an edge that goes from a podtemplatespec or a pod to service.
1414
// The head should make the service's selector
1515
ExposedThroughServiceEdgeKind = "ExposedThroughService"
16+
// ManagedByRCEdgeKind goes from Pod to ReplicationController when the Pod satisfies the ReplicationController's label selector
17+
ManagedByRCEdgeKind = "ManagedByRC"
1618
)
1719

1820
// AddExposedPodTemplateSpecEdges ensures that a directed edge exists between a service and all the PodTemplateSpecs
@@ -66,3 +68,29 @@ func AddAllExposedPodEdges(g osgraph.MutableUniqueGraph) {
6668
}
6769
}
6870
}
71+
72+
// AddManagedByRCPodEdges ensures that a directed edge exists between an RC and all the pods
73+
// in the graph that match the label selector
74+
func AddManagedByRCPodEdges(g osgraph.MutableUniqueGraph, rcNode *kubegraph.ReplicationControllerNode) {
75+
if rcNode.Spec.Selector == nil {
76+
return
77+
}
78+
query := labels.SelectorFromSet(rcNode.Spec.Selector)
79+
for _, n := range g.(graph.Graph).NodeList() {
80+
switch target := n.(type) {
81+
case *kubegraph.PodNode:
82+
if query.Matches(labels.Set(target.Labels)) {
83+
g.AddEdge(target, rcNode, ManagedByRCEdgeKind)
84+
}
85+
}
86+
}
87+
}
88+
89+
// AddAllManagedByRCPodEdges calls AddManagedByRCPodEdges for every ServiceNode in the graph
90+
func AddAllManagedByRCPodEdges(g osgraph.MutableUniqueGraph) {
91+
for _, node := range g.(graph.Graph).NodeList() {
92+
if rcNode, ok := node.(*kubegraph.ReplicationControllerNode); ok {
93+
AddManagedByRCPodEdges(g, rcNode)
94+
}
95+
}
96+
}

pkg/cmd/cli/describe/projectstatus.go

+70-22
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func (d *ProjectStatusDescriber) MakeGraph(namespace string) (osgraph.Graph, err
4444
loaders := []GraphLoader{
4545
&serviceLoader{namespace: namespace, lister: d.K},
4646
&rcLoader{namespace: namespace, lister: d.K},
47+
&podLoader{namespace: namespace, lister: d.K},
4748
&bcLoader{namespace: namespace, lister: d.C},
4849
&buildLoader{namespace: namespace, lister: d.C},
4950
&isLoader{namespace: namespace, lister: d.C},
@@ -63,6 +64,8 @@ func (d *ProjectStatusDescriber) MakeGraph(namespace string) (osgraph.Graph, err
6364
}
6465

6566
kubeedges.AddAllExposedPodTemplateSpecEdges(g)
67+
kubeedges.AddAllExposedPodEdges(g)
68+
kubeedges.AddAllManagedByRCPodEdges(g)
6669
buildedges.AddAllInputOutputEdges(g)
6770
buildedges.AddAllBuildEdges(g)
6871
deployedges.AddAllTriggerEdges(g)
@@ -116,6 +119,17 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
116119
}
117120
printLines(out, indent, 1, describeRCInServiceGroup(rcNode)...)
118121
}
122+
123+
pod:
124+
for _, podNode := range service.FulfillingPods {
125+
// skip pods that have been displayed in a roll-up of RCs and DCs (by implicit usage of RCs)
126+
for _, coveredRC := range service.FulfillingRCs {
127+
if g.EdgeBetween(podNode, coveredRC) != nil {
128+
continue pod
129+
}
130+
}
131+
printLines(out, indent, 1, describePodInServiceGroup(podNode)...)
132+
}
119133
}
120134

121135
for _, standaloneDC := range standaloneDCs {
@@ -139,8 +153,8 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
139153

140154
if hasUnresolvedImageStreamTag(g) {
141155
fmt.Fprintln(out, "Warning: Some of your builds are pointing to image streams, but the administrator has not configured the integrated Docker registry (oadm registry).")
142-
143156
}
157+
144158
fmt.Fprintln(out, "To see more, use 'oc describe service <name>' or 'oc describe dc <name>'.")
145159
fmt.Fprintln(out, "You can use 'oc get all' to see a list of other objects.")
146160
}
@@ -214,6 +228,16 @@ func describeRCInServiceGroup(rcNode *kubegraph.ReplicationControllerNode) []str
214228
return lines
215229
}
216230

231+
func describePodInServiceGroup(podNode *kubegraph.PodNode) []string {
232+
images := []string{}
233+
for _, container := range podNode.Pod.Spec.Containers {
234+
images = append(images, container.Image)
235+
}
236+
237+
lines := []string{fmt.Sprintf("pod/%s runs %s", podNode.Pod.Name, strings.Join(images, ", "))}
238+
return lines
239+
}
240+
217241
func describeDeploymentConfigTrigger(dc *deployapi.DeploymentConfig) string {
218242
if len(dc.Triggers) == 0 {
219243
return "(manual)"
@@ -625,14 +649,14 @@ func (l *serviceLoader) AddToGraph(g osgraph.Graph) error {
625649
return nil
626650
}
627651

628-
type bcLoader struct {
652+
type rcLoader struct {
629653
namespace string
630-
lister client.BuildConfigsNamespacer
631-
items []buildapi.BuildConfig
654+
lister kclient.ReplicationControllersNamespacer
655+
items []kapi.ReplicationController
632656
}
633657

634-
func (l *bcLoader) Load() error {
635-
list, err := l.lister.BuildConfigs(l.namespace).List(labels.Everything(), fields.Everything())
658+
func (l *rcLoader) Load() error {
659+
list, err := l.lister.ReplicationControllers(l.namespace).List(labels.Everything())
636660
if err != nil {
637661
return err
638662
}
@@ -641,9 +665,33 @@ func (l *bcLoader) Load() error {
641665
return nil
642666
}
643667

644-
func (l *bcLoader) AddToGraph(g osgraph.Graph) error {
668+
func (l *rcLoader) AddToGraph(g osgraph.Graph) error {
645669
for i := range l.items {
646-
buildgraph.EnsureBuildConfigNode(g, &l.items[i])
670+
kubegraph.EnsureReplicationControllerNode(g, &l.items[i])
671+
}
672+
673+
return nil
674+
}
675+
676+
type podLoader struct {
677+
namespace string
678+
lister kclient.PodsNamespacer
679+
items []kapi.Pod
680+
}
681+
682+
func (l *podLoader) Load() error {
683+
list, err := l.lister.Pods(l.namespace).List(labels.Everything(), fields.Everything())
684+
if err != nil {
685+
return err
686+
}
687+
688+
l.items = list.Items
689+
return nil
690+
}
691+
692+
func (l *podLoader) AddToGraph(g osgraph.Graph) error {
693+
for i := range l.items {
694+
kubegraph.EnsurePodNode(g, &l.items[i])
647695
}
648696

649697
return nil
@@ -698,14 +746,14 @@ func (l *dcLoader) AddToGraph(g osgraph.Graph) error {
698746
return nil
699747
}
700748

701-
type buildLoader struct {
749+
type bcLoader struct {
702750
namespace string
703-
lister client.BuildsNamespacer
704-
items []buildapi.Build
751+
lister client.BuildConfigsNamespacer
752+
items []buildapi.BuildConfig
705753
}
706754

707-
func (l *buildLoader) Load() error {
708-
list, err := l.lister.Builds(l.namespace).List(labels.Everything(), fields.Everything())
755+
func (l *bcLoader) Load() error {
756+
list, err := l.lister.BuildConfigs(l.namespace).List(labels.Everything(), fields.Everything())
709757
if err != nil {
710758
return err
711759
}
@@ -714,22 +762,22 @@ func (l *buildLoader) Load() error {
714762
return nil
715763
}
716764

717-
func (l *buildLoader) AddToGraph(g osgraph.Graph) error {
765+
func (l *bcLoader) AddToGraph(g osgraph.Graph) error {
718766
for i := range l.items {
719-
buildgraph.EnsureBuildNode(g, &l.items[i])
767+
buildgraph.EnsureBuildConfigNode(g, &l.items[i])
720768
}
721769

722770
return nil
723771
}
724772

725-
type rcLoader struct {
773+
type buildLoader struct {
726774
namespace string
727-
lister kclient.ReplicationControllersNamespacer
728-
items []kapi.ReplicationController
775+
lister client.BuildsNamespacer
776+
items []buildapi.Build
729777
}
730778

731-
func (l *rcLoader) Load() error {
732-
list, err := l.lister.ReplicationControllers(l.namespace).List(labels.Everything())
779+
func (l *buildLoader) Load() error {
780+
list, err := l.lister.Builds(l.namespace).List(labels.Everything(), fields.Everything())
733781
if err != nil {
734782
return err
735783
}
@@ -738,9 +786,9 @@ func (l *rcLoader) Load() error {
738786
return nil
739787
}
740788

741-
func (l *rcLoader) AddToGraph(g osgraph.Graph) error {
789+
func (l *buildLoader) AddToGraph(g osgraph.Graph) error {
742790
for i := range l.items {
743-
kubegraph.EnsureReplicationControllerNode(g, &l.items[i])
791+
buildgraph.EnsureBuildNode(g, &l.items[i])
744792
}
745793

746794
return nil

pkg/cmd/cli/describe/projectstatus_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ func TestProjectStatus(t *testing.T) {
113113
"To see more, use",
114114
},
115115
},
116+
"service with pod": {
117+
Path: "../../../../pkg/api/graph/test/service-with-pod.yaml",
118+
Extra: []runtime.Object{
119+
&projectapi.Project{
120+
ObjectMeta: kapi.ObjectMeta{Name: "example", Namespace: ""},
121+
},
122+
},
123+
ErrFn: func(err error) bool { return err == nil },
124+
Contains: []string{
125+
"In project example\n",
126+
"service frontend-app",
127+
"pod/frontend-app-1-bjwh8 runs openshift/ruby-hello-world",
128+
"To see more, use",
129+
},
130+
},
116131
"unstarted build": {
117132
Path: "../../../../test/fixtures/app-scenarios/new-project-no-build.yaml",
118133
Extra: []runtime.Object{

0 commit comments

Comments
 (0)