Browse code

oc: hide markers from different projects on oc status

Michail Kargakis authored on 2016/02/11 21:22:57
Showing 11 changed files
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	"github.com/gonum/graph/concrete"
11 11
 	"github.com/gonum/graph/encoding/dot"
12 12
 
13
+	"k8s.io/kubernetes/pkg/api/meta"
13 14
 	"k8s.io/kubernetes/pkg/util/sets"
14 15
 )
15 16
 
... ...
@@ -636,6 +637,24 @@ func NodesByKind(g Interface, nodes []graph.Node, kinds ...string) [][]graph.Nod
636 636
 	return result
637 637
 }
638 638
 
639
+// IsFromDifferentNamespace returns if a node is in a different namespace
640
+// than the one provided.
641
+func IsFromDifferentNamespace(namespace string, node graph.Node) bool {
642
+	potentiallySyntheticNode, ok := node.(ExistenceChecker)
643
+	if !ok || potentiallySyntheticNode.Found() {
644
+		return false
645
+	}
646
+	objectified, ok := node.(objectifier)
647
+	if !ok {
648
+		return false
649
+	}
650
+	object, err := meta.Accessor(objectified)
651
+	if err != nil {
652
+		return false
653
+	}
654
+	return object.GetNamespace() != namespace
655
+}
656
+
639 657
 func pathCovered(path []graph.Node, paths map[int][]graph.Node) bool {
640 658
 	l := len(path)
641 659
 	for _, existing := range paths {
... ...
@@ -51,6 +51,30 @@ func (m Markers) BySeverity(severity Severity) []Marker {
51 51
 	return ret
52 52
 }
53 53
 
54
+// FilterByNamespace returns all the markers that are not associated with missing nodes
55
+// from other namespaces (other than the provided namespace).
56
+func (m Markers) FilterByNamespace(namespace string) Markers {
57
+	filtered := Markers{}
58
+
59
+	for i := range m {
60
+		markerNodes := []graph.Node{}
61
+		markerNodes = append(markerNodes, m[i].Node)
62
+		markerNodes = append(markerNodes, m[i].RelatedNodes...)
63
+		hasCrossNamespaceLink := false
64
+		for _, node := range markerNodes {
65
+			if IsFromDifferentNamespace(namespace, node) {
66
+				hasCrossNamespaceLink = true
67
+				break
68
+			}
69
+		}
70
+		if !hasCrossNamespaceLink {
71
+			filtered = append(filtered, m[i])
72
+		}
73
+	}
74
+
75
+	return filtered
76
+}
77
+
54 78
 type BySeverity []Marker
55 79
 
56 80
 func (m BySeverity) Len() int      { return len(m) }
... ...
@@ -7,6 +7,7 @@ items:
7 7
   metadata:
8 8
     creationTimestamp: null
9 9
     name: existing-secret
10
+    namespace: example
10 11
   type: Opaque
11 12
 - apiVersion: v1
12 13
   kind: ReplicationController
... ...
@@ -16,6 +17,7 @@ items:
16 16
     labels:
17 17
       name: my-rc
18 18
     name: my-rc
19
+    namespace: example
19 20
   spec:
20 21
     replicas: 1
21 22
     selector:
... ...
@@ -5,6 +5,7 @@ items:
5 5
   metadata:
6 6
     creationTimestamp: null
7 7
     name: ruby-22-centos7
8
+    namespace: example
8 9
   spec:
9 10
     output:
10 11
       to:
... ...
@@ -37,6 +38,7 @@ items:
37 37
   metadata:
38 38
     creationTimestamp: null
39 39
     name: ruby-hello-world
40
+    namespace: example
40 41
   spec:
41 42
     output:
42 43
       to:
... ...
@@ -69,6 +71,7 @@ items:
69 69
   metadata:
70 70
     creationTimestamp: null
71 71
     name: ruby-something-else
72
+    namespace: example
72 73
   spec:
73 74
     output:
74 75
       to:
75 76
new file mode 100644
... ...
@@ -0,0 +1,65 @@
0
+apiVersion: v1
1
+items:
2
+- apiVersion: v1
3
+  kind: DeploymentConfig
4
+  metadata:
5
+    annotations:
6
+      openshift.io/generated-by: OpenShiftNewApp
7
+    creationTimestamp: 2016-02-11T11:57:22Z
8
+    labels:
9
+      app: ruby-hello-world
10
+    name: ruby-hello-world
11
+    namespace: example
12
+    resourceVersion: "615"
13
+    selfLink: /oapi/v1/namespaces/example/deploymentconfigs/ruby-hello-world
14
+    uid: 9c06a926-d0b6-11e5-99f7-080027242396
15
+  spec:
16
+    replicas: 1
17
+    selector:
18
+      app: ruby-hello-world
19
+      deploymentconfig: ruby-hello-world
20
+    strategy:
21
+      resources: {}
22
+      rollingParams:
23
+        intervalSeconds: 1
24
+        maxSurge: 25%
25
+        maxUnavailable: 25%
26
+        timeoutSeconds: 600
27
+        updatePeriodSeconds: 1
28
+      type: Rolling
29
+    template:
30
+      metadata:
31
+        annotations:
32
+          openshift.io/generated-by: OpenShiftNewApp
33
+        creationTimestamp: null
34
+        labels:
35
+          app: ruby-hello-world
36
+          deploymentconfig: ruby-hello-world
37
+      spec:
38
+        containers:
39
+        - image: 172.30.164.11:5000/test/origin-ruby-sample@sha256:857010da6b7ef44ecd566eb390a702c2f24a254f7408a8f2fad524a2673a1b87
40
+          imagePullPolicy: Always
41
+          name: ruby-hello-world
42
+          ports:
43
+          - containerPort: 8080
44
+            protocol: TCP
45
+          resources: {}
46
+          terminationMessagePath: /dev/termination-log
47
+        dnsPolicy: ClusterFirst
48
+        restartPolicy: Always
49
+        securityContext: {}
50
+        terminationGracePeriodSeconds: 30
51
+    test: false
52
+    triggers:
53
+    - type: ConfigChange
54
+    - imageChangeParams:
55
+        automatic: true
56
+        containerNames:
57
+        - ruby-hello-world
58
+        from:
59
+          kind: ImageStreamTag
60
+          name: origin-ruby-sample:latest
61
+          namespace: different
62
+      type: ImageChange
63
+kind: List
64
+metadata: {}
... ...
@@ -7,6 +7,7 @@ items:
7 7
     labels:
8 8
       app: ruby
9 9
     name: ruby-hello-world
10
+    namespace: example
10 11
   spec:
11 12
     output:
12 13
       to:
... ...
@@ -42,6 +43,7 @@ items:
42 42
       app: ruby
43 43
       buildconfig: ruby-hello-world
44 44
     name: ruby-hello-world-1
45
+    namespace: example
45 46
   spec:
46 47
     output:
47 48
       to:
... ...
@@ -72,6 +74,7 @@ items:
72 72
     labels:
73 73
       app: ruby
74 74
     name: ruby-22-centos7
75
+    namespace: example
75 76
   spec:
76 77
     dockerImageRepository: centos/ruby-22-centos7
77 78
   status:
... ...
@@ -83,6 +86,7 @@ items:
83 83
     labels:
84 84
       app: ruby
85 85
     name: ruby-hello-world
86
+    namespace: example
86 87
   spec: {}
87 88
   status:
88 89
     dockerImageRepository: ""
... ...
@@ -93,6 +97,7 @@ items:
93 93
     labels:
94 94
       app: ruby
95 95
     name: ruby-hello-world
96
+    namespace: example
96 97
   spec:
97 98
     replicas: 1
98 99
     selector:
... ...
@@ -143,6 +148,7 @@ items:
143 143
     labels:
144 144
       app: ruby
145 145
     name: ruby-hello-world
146
+    namespace: example
146 147
   spec:
147 148
     portalIP: ""
148 149
     ports:
... ...
@@ -31,13 +31,13 @@ func TestUnpushableBuild(t *testing.T) {
31 31
 	}
32 32
 
33 33
 	actualBC := osgraph.GetTopLevelContainerNode(g, markers[0].Node)
34
-	expectedBC := g.Find(osgraph.UniqueName("BuildConfig|/ruby-hello-world"))
34
+	expectedBC := g.Find(osgraph.UniqueName("BuildConfig|example/ruby-hello-world"))
35 35
 	if e, a := expectedBC.ID(), actualBC.ID(); e != a {
36 36
 		t.Errorf("expected %v, got %v", e, a)
37 37
 	}
38 38
 
39 39
 	actualIST := markers[0].RelatedNodes[0]
40
-	expectedIST := g.Find(osgraph.UniqueName("ImageStreamTag|/ruby-hello-world:latest"))
40
+	expectedIST := g.Find(osgraph.UniqueName("ImageStreamTag|example/ruby-hello-world:latest"))
41 41
 	if e, a := expectedIST.ID(), actualIST.ID(); e != a {
42 42
 		t.Errorf("expected %v, got %v: \n%v", e, a, g)
43 43
 	}
... ...
@@ -119,6 +119,7 @@ func (o *StatusOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args
119 119
 		Server:  config.Host,
120 120
 		Suggest: o.verbose,
121 121
 
122
+		// TODO: Remove these and reference them inside the markers using constants.
122 123
 		LogsCommandName:             o.logsCommandName,
123 124
 		SecurityPolicyCommandFormat: o.securityPolicyCommandFormat,
124 125
 		SetProbeCommandName:         o.setProbeCommandName,
... ...
@@ -223,6 +223,9 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
223 223
 			allMarkers = append(allMarkers, scanner(g, f)...)
224 224
 		}
225 225
 
226
+		// TODO: Provide an option to chase these hidden markers.
227
+		allMarkers = allMarkers.FilterByNamespace(namespace)
228
+
226 229
 		fmt.Fprintln(out)
227 230
 
228 231
 		sort.Stable(osgraph.ByKey(allMarkers))
... ...
@@ -279,6 +279,20 @@ func TestProjectStatus(t *testing.T) {
279 279
 				`policycommand example default`,             // verifies that we print the help command
280 280
 			},
281 281
 		},
282
+		"cross namespace reference": {
283
+			Path: "../../../api/graph/test/different-project-image-deployment.yaml",
284
+			Extra: []runtime.Object{
285
+				&projectapi.Project{
286
+					ObjectMeta: kapi.ObjectMeta{Name: "example", Namespace: ""},
287
+				},
288
+			},
289
+			ErrFn: func(err error) bool { return err == nil },
290
+			Contains: []string{
291
+				// If there was a warning we wouldn't get the following message. Since we ignore cross-namespace
292
+				// links by default, there should be no warning here.
293
+				`View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.`,
294
+			},
295
+		},
282 296
 	}
283 297
 	oldTimeFn := timeNowFn
284 298
 	defer func() { timeNowFn = oldTimeFn }()
... ...
@@ -8,6 +8,7 @@ items:
8 8
       name: ruby-sample-build
9 9
       template: application-template-stibuild
10 10
     name: ruby-sample-build
11
+    namespace: example
11 12
   spec:
12 13
     output:
13 14
       to:
... ...
@@ -46,6 +47,7 @@ items:
46 46
       name: ruby-sample-build
47 47
       template: application-template-stibuild
48 48
     name: ruby-sample-build-1
49
+    namespace: example
49 50
   spec:
50 51
     output:
51 52
       to:
... ...
@@ -84,6 +86,7 @@ items:
84 84
     labels:
85 85
       template: application-template-stibuild
86 86
     name: database-2
87
+    namespace: example
87 88
   spec:
88 89
     replicas: 1
89 90
     selector:
... ...
@@ -140,6 +143,7 @@ items:
140 140
     labels:
141 141
       template: application-template-stibuild
142 142
     name: database-1
143
+    namespace: example
143 144
   spec:
144 145
     replicas: 1
145 146
     selector:
... ...
@@ -190,6 +194,7 @@ items:
190 190
     labels:
191 191
       template: application-template-stibuild
192 192
     name: database
193
+    namespace: example
193 194
   spec:
194 195
     replicas: 1
195 196
     selector:
... ...
@@ -248,6 +253,7 @@ items:
248 248
     labels:
249 249
       template: application-template-stibuild
250 250
     name: frontend-2
251
+    namespace: example
251 252
   spec:
252 253
     replicas: 1
253 254
     selector:
... ...
@@ -308,6 +314,7 @@ items:
308 308
     labels:
309 309
       template: application-template-stibuild
310 310
     name: frontend-1
311
+    namespace: example
311 312
   spec:
312 313
     replicas: 1
313 314
     selector:
... ...
@@ -362,6 +369,7 @@ items:
362 362
     labels:
363 363
       template: application-template-stibuild
364 364
     name: frontend
365
+    namespace: example
365 366
   spec:
366 367
     replicas: 1
367 368
     selector:
... ...
@@ -428,6 +436,7 @@ items:
428 428
     labels:
429 429
       template: application-template-stibuild
430 430
     name: database
431
+    namespace: example
431 432
   spec:
432 433
     portalIP: 172.30.17.240
433 434
     ports:
... ...
@@ -448,6 +457,7 @@ items:
448 448
     labels:
449 449
       template: application-template-stibuild
450 450
     name: database-external
451
+    namespace: example
451 452
   spec:
452 453
     portalIP: 172.30.17.241
453 454
     ports:
... ...
@@ -468,6 +478,7 @@ items:
468 468
     labels:
469 469
       template: application-template-stibuild
470 470
     name: frontend
471
+    namespace: example
471 472
   spec:
472 473
     portalIP: 172.30.17.154
473 474
     ports:
... ...
@@ -490,6 +501,7 @@ items:
490 490
     labels:
491 491
       template: application-template-stibuild
492 492
     name: frontend
493
+    namespace: example
493 494
     resourceVersion: "393"
494 495
   spec:
495 496
     host: frontend-example.router.default.svc.cluster.local
... ...
@@ -517,6 +529,7 @@ items:
517 517
     labels:
518 518
       template: application-template-stibuild
519 519
     name: other
520
+    namespace: example
520 521
     resourceVersion: "393"
521 522
   spec:
522 523
     host: www.test.com